Commit | Line | Data |
---|---|---|
2fd32231 ILT |
1 | /* initpri1.c -- test constructor priorities. |
2 | ||
3 | Copyright 2007, 2008 Free Software Foundation, Inc. | |
4 | Copied from the gcc testsuite, where the test was contributed by | |
5 | Mark Mitchell <mark@codesourcery.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 is a test of a common symbol in the main program and a | |
25 | versioned symbol in a shared library. The common symbol in the | |
26 | main program should override the shared library symbol. */ | |
27 | ||
28 | #include <stdlib.h> | |
29 | ||
30 | int i; | |
31 | int j; | |
32 | ||
bb6f53d3 ILT |
33 | void c1(void) __attribute__((constructor (500))); |
34 | void c2(void) __attribute__((constructor (700))); | |
35 | void c3(void) __attribute__((constructor (600))); | |
2fd32231 ILT |
36 | |
37 | void c1() { | |
38 | if (i++ != 0) | |
39 | abort (); | |
40 | } | |
41 | ||
42 | void c2() { | |
43 | if (i++ != 2) | |
44 | abort (); | |
45 | } | |
46 | ||
47 | void c3() { | |
48 | if (i++ != 1) | |
49 | abort (); | |
50 | } | |
51 | ||
bb6f53d3 ILT |
52 | void d1(void) __attribute__((destructor (500))); |
53 | void d2(void) __attribute__((destructor (700))); | |
54 | void d3(void) __attribute__((destructor (600))); | |
2fd32231 ILT |
55 | |
56 | void d1() { | |
57 | if (--i != 0) | |
58 | abort (); | |
59 | } | |
60 | ||
61 | void d2() { | |
62 | if (--i != 2) | |
63 | abort (); | |
64 | } | |
65 | ||
66 | void d3() { | |
ab794b6b | 67 | if (j != 4) |
2fd32231 ILT |
68 | abort (); |
69 | if (--i != 1) | |
70 | abort (); | |
71 | } | |
72 | ||
bb6f53d3 | 73 | void cd4(void) __attribute__((constructor (800), destructor (800))); |
2fd32231 ILT |
74 | |
75 | void cd4() { | |
76 | if (i != 3) | |
77 | abort (); | |
78 | ++j; | |
79 | } | |
80 | ||
bb6f53d3 | 81 | void cd5(void) __attribute__((constructor, destructor)); |
ab794b6b ILT |
82 | |
83 | void cd5() { | |
84 | if (i != 3) | |
85 | abort(); | |
86 | ++j; | |
87 | } | |
88 | ||
bb6f53d3 | 89 | int main (void) { |
2fd32231 ILT |
90 | if (i != 3) |
91 | return 1; | |
ab794b6b | 92 | if (j != 2) |
2fd32231 ILT |
93 | abort (); |
94 | return 0; | |
95 | } |