summaryrefslogtreecommitdiff
path: root/elf/tst-array1.c
blob: e998932b369fd5b76a7d344add49e61c266c014c (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <unistd.h>

/* Give init non-default priority so that it runs before init_array.  */
static void init (void) __attribute__ ((constructor (1000)));

static void
init (void)
{
  write (STDOUT_FILENO, "init\n", 5);
}

/* Give fini the same priority as init.  */
static void fini (void) __attribute__ ((destructor (1000)));

static void
fini (void)
{
  write (STDOUT_FILENO, "fini\n", 5);
}

static void
preinit_0 (void)
{
  write (STDOUT_FILENO, "preinit array 0\n", 16);
}

static void
preinit_1 (void)
{
  write (STDOUT_FILENO, "preinit array 1\n", 16);
}

static void
preinit_2 (void)
{
  write (STDOUT_FILENO, "preinit array 2\n", 16);
}

void (*const preinit_array []) (void)
     __attribute__ ((section (".preinit_array"), aligned (sizeof (void *)))) =
{
  &preinit_0,
  &preinit_1,
  &preinit_2
};

static void
init_0 (void)
{
  write (STDOUT_FILENO, "init array 0\n", 13);
}

static void
init_1 (void)
{
  write (STDOUT_FILENO, "init array 1\n", 13);
}

static void
init_2 (void)
{
  write (STDOUT_FILENO, "init array 2\n", 13);
}

void (*init_array []) (void)
     __attribute__ ((section (".init_array"), aligned (sizeof (void *)))) =
{
  &init_0,
  &init_1,
  &init_2
};

static void
fini_0 (void)
{
  write (STDOUT_FILENO, "fini array 0\n", 13);
}

static void
fini_1 (void)
{
  write (STDOUT_FILENO, "fini array 1\n", 13);
}

static void
fini_2 (void)
{
  write (STDOUT_FILENO, "fini array 2\n", 13);
}

void (*fini_array []) (void)
     __attribute__ ((section (".fini_array"), aligned (sizeof (void *)))) =
{
  &fini_0,
  &fini_1,
  &fini_2
};

int
main (void)
{
  return 0;
}