]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gold/testsuite/initpri2.c
55cfdd8cae801fb80f41cd3b3cb24584f205e648
[thirdparty/binutils-gdb.git] / gold / testsuite / initpri2.c
1 /* initpri2.c -- test mixing init_array and ctor priorities.
2
3 Copyright (C) 2011-2022 Free Software Foundation, Inc.
4 Copied from the gcc configury, where the test was contributed by
5 H.J. Lu <hongjiu.lu@intel.com>.
6
7 This file is part of gold.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 MA 02110-1301, USA. */
23
24 /* This tests that the linker correctly combines .ctor and .init_array
25 sections when both have priorities. */
26
27 #include <stdlib.h>
28
29 static int count;
30
31 static void
32 init1005 (void)
33 {
34 if (count != 0)
35 abort ();
36 count = 1005;
37 }
38 void (*const init_array1005[]) (void)
39 __attribute__ ((section (".init_array.01005"), aligned (sizeof (void *))))
40 = { init1005 };
41 static void
42 fini1005 (void)
43 {
44 if (count != 1005)
45 abort ();
46 }
47 void (*const fini_array1005[]) (void)
48 __attribute__ ((section (".fini_array.01005"), aligned (sizeof (void *))))
49 = { fini1005 };
50
51 static void
52 ctor1007 (void)
53 {
54 if (count != 1005)
55 abort ();
56 count = 1007;
57 }
58 void (*const ctors1007[]) (void)
59 __attribute__ ((section (".ctors.64528"), aligned (sizeof (void *))))
60 = { ctor1007 };
61 static void
62 dtor1007 (void)
63 {
64 if (count != 1007)
65 abort ();
66 count = 1005;
67 }
68 void (*const dtors1007[]) (void)
69 __attribute__ ((section (".dtors.64528"), aligned (sizeof (void *))))
70 = { dtor1007 };
71
72 static void
73 init65530 (void)
74 {
75 if (count != 1007)
76 abort ();
77 count = 65530;
78 }
79 void (*const init_array65530[]) (void)
80 __attribute__ ((section (".init_array.65530"), aligned (sizeof (void *))))
81 = { init65530 };
82 static void
83 fini65530 (void)
84 {
85 if (count != 65530)
86 abort ();
87 count = 1007;
88 }
89 void (*const fini_array65530[]) (void)
90 __attribute__ ((section (".fini_array.65530"), aligned (sizeof (void *))))
91 = { fini65530 };
92
93 static void
94 ctor65535 (void)
95 {
96 if (count != 65530)
97 abort ();
98 count = 65535;
99 }
100 void (*const ctors65535[]) (void)
101 __attribute__ ((section (".ctors"), aligned (sizeof (void *))))
102 = { ctor65535 };
103 static void
104 dtor65535 (void)
105 {
106 if (count != 65535)
107 abort ();
108 count = 65530;
109 }
110 void (*const dtors65535[]) (void)
111 __attribute__ ((section (".dtors"), aligned (sizeof (void *))))
112 = { dtor65535 };
113
114 int
115 main (void)
116 {
117 return 0;
118 }