1/* initpri2.c -- test mixing init_array and ctor priorities.
2
3   Copyright (C) 2011-2020 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
29static int count;
30
31static void
32init1005 (void)
33{
34  if (count != 0)
35    abort ();
36  count = 1005;
37}
38void (*const init_array1005[]) (void)
39  __attribute__ ((section (".init_array.01005"), aligned (sizeof (void *))))
40  = { init1005 };
41static void
42fini1005 (void)
43{
44  if (count != 1005)
45    abort ();
46}
47void (*const fini_array1005[]) (void)
48  __attribute__ ((section (".fini_array.01005"), aligned (sizeof (void *))))
49  = { fini1005 };
50
51static void
52ctor1007 (void)
53{
54  if (count != 1005)
55    abort ();
56  count = 1007;
57}
58void (*const ctors1007[]) (void)
59  __attribute__ ((section (".ctors.64528"), aligned (sizeof (void *))))
60  = { ctor1007 };
61static void
62dtor1007 (void)
63{
64  if (count != 1007)
65    abort ();
66  count = 1005;
67}
68void (*const dtors1007[]) (void)
69  __attribute__ ((section (".dtors.64528"), aligned (sizeof (void *))))
70  = { dtor1007 };
71
72static void
73init65530 (void)
74{
75  if (count != 1007)
76    abort ();
77  count = 65530;
78}
79void (*const init_array65530[]) (void)
80  __attribute__ ((section (".init_array.65530"), aligned (sizeof (void *))))
81  = { init65530 };
82static void
83fini65530 (void)
84{
85  if (count != 65530)
86    abort ();
87  count = 1007;
88}
89void (*const fini_array65530[]) (void)
90  __attribute__ ((section (".fini_array.65530"), aligned (sizeof (void *))))
91  = { fini65530 };
92
93static void
94ctor65535 (void)
95{
96  if (count != 65530)
97    abort ();
98  count = 65535;
99}
100void (*const ctors65535[]) (void)
101  __attribute__ ((section (".ctors"), aligned (sizeof (void *))))
102  = { ctor65535 };
103static void
104dtor65535 (void)
105{
106  if (count != 65535)
107    abort ();
108  count = 65530;
109}
110void (*const dtors65535[]) (void)
111  __attribute__ ((section (".dtors"), aligned (sizeof (void *))))
112  = { dtor65535 };
113
114int
115main (void)
116{
117  return 0;
118}
119