summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/nios/crtend.c
blob: bef6f513d3fa512926b61a490c06a0ae9e07b790 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <errno.h>
#include <stdlib.h>
/*
static void (*__CTOR_END__[1]) __P((void))
    __attribute__((section(".ctors"))) = { (void *)-1 };

static void (*__DTOR_END__[1]) __P((void))
    __attribute__((__unused__))
    __attribute__((section(".dtors"))) = { (void *)0 };
*/
extern void (*__CTOR_END__[]) __P((void));
static void	__do_global_ctors_aux __P((void));

static void
__do_global_ctors_aux()
{
	void (**p)(void) = __CTOR_END__ - 1;

	while (*p)
		(**p--)();
}

static void dummy_init(void) __attribute__((section(".trash")));

void
dummy_init(void)
{
	static smallint initialized;
	static void (*volatile call__ctors)(void) = __do_global_ctors_aux;
	/*
	 * Call global constructors.
	 * Arrange to call global destructors at exit.
	 */
	/* prevent function pointer constant propagation */
	__asm__ __volatile__ (".section .init");
	
	if (!initialized) {
		initialized = 1;
		(*call__ctors)();
	}
	__asm__ __volatile__ (".section .trash");

}