OSDN Git Service

2009-11-28 Kai Tietz <kai.tietz@onevision.com>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / attr-weakref-1.c
1 // { dg-do run }
2 // { dg-require-weak "" }
3 // On darwin, we use attr-weakref-1-darwin.c.
4 // This test requires support for undefined weak symbols.  This support
5 // is not available on hppa*-*-hpux*.  The test is skipped rather than
6 // xfailed to suppress the warning that would otherwise arise.
7 // { dg-skip-if "" { "*-*-darwin*" "hppa*-*-hpux*" } "*" { "" } }
8 // For kernel modules and static RTPs, the loader treats undefined weak
9 // symbols in the same way as undefined strong symbols.  The test
10 // therefore fails to load, so skip it.
11 // { dg-skip-if "" { "*-*-vxworks*" && nonpic } "*" { "-non-static" } }
12 // { dg-options "-O2" }
13 // { dg-additional-sources "attr-weakref-1a.c" }
14
15 // Copyright 2005 Free Software Foundation, Inc.
16 // Contributed by Alexandre Oliva <aoliva@redhat.com>
17
18 // Torture test for weakrefs.  The first letter of an identifier
19 // indicates whether/how it is defined; the second letter indicates
20 // whether it is part of a variable or function test; the number that
21 // follows is a test counter, and a letter that may follow enables
22 // multiple identifiers within the same test (e.g., multiple weakrefs
23 // or pointers to the same identifier).
24
25 // Identifiers starting with W are weakrefs; those with p are
26 // pointers; those with g are global definitions; those with l are
27 // local definitions; those with w are expected to be weak undefined
28 // in the symbol table; those with u are expected to be marked as
29 // non-weak undefined in the symbol table.
30
31 #include <stdlib.h>
32
33 #define USED __attribute__((used))
34
35 typedef int vtype;
36
37 extern vtype wv1;
38 static vtype Wv1a __attribute__((weakref ("wv1")));
39 static vtype *pv1a USED = &Wv1a;
40
41 vtype gv2;
42 static vtype Wv2a __attribute__((weakref ("gv2")));
43 static vtype *pv2a USED = &Wv2a;
44
45 static vtype lv3;
46 static vtype Wv3a __attribute__((weakref ("lv3")));
47 static vtype *pv3a USED = &Wv3a;
48
49 extern vtype uv4;
50 static vtype Wv4a __attribute__((weakref ("uv4")));
51 static vtype *pv4a USED = &Wv4a;
52 static vtype *pv4 USED = &uv4;
53
54 static vtype Wv5a __attribute__((weakref ("uv5")));
55 static vtype *pv5a USED = &Wv5a;
56 extern vtype uv5;
57 static vtype *pv5 USED = &uv5;
58
59 static vtype Wv6a __attribute__((weakref ("wv6")));
60 static vtype *pv6a USED = &Wv6a;
61 extern vtype wv6;
62
63 static vtype Wv7a __attribute__((weakref ("uv7")));
64 static vtype* USED fv7 (void) {
65   return &Wv7a;
66 }
67 extern vtype uv7;
68 static vtype* USED fv7a (void) {
69   return &uv7;
70 }
71
72 extern vtype uv8;
73 static vtype* USED fv8a (void) {
74   return &uv8;
75 }
76 static vtype Wv8a __attribute__((weakref ("uv8")));
77 static vtype* USED fv8 (void) {
78   return &Wv8a;
79 }
80
81 extern vtype wv9 __attribute__((weak));
82 static vtype Wv9a __attribute__((weakref ("wv9")));
83 static vtype *pv9a USED = &Wv9a;
84
85 static vtype Wv10a __attribute__((weakref ("Wv10b")));
86 static vtype Wv10b __attribute__((weakref ("Wv10c")));
87 static vtype Wv10c __attribute__((weakref ("Wv10d")));
88 static vtype Wv10d __attribute__((weakref ("wv10")));
89 extern vtype wv10;
90
91 extern vtype wv11;
92 static vtype Wv11d __attribute__((weakref ("wv11")));
93 static vtype Wv11c __attribute__((weakref ("Wv11d")));
94 static vtype Wv11b __attribute__((weakref ("Wv11c")));
95 static vtype Wv11a __attribute__((weakref ("Wv11b")));
96
97 static vtype Wv12 __attribute__((weakref ("wv12")));
98 extern vtype wv12 __attribute__((weak));
99
100 static vtype Wv13 __attribute__((weakref ("wv13")));
101 extern vtype wv13 __attribute__((weak));
102
103 static vtype Wv14a __attribute__((weakref ("wv14")));
104 static vtype Wv14b __attribute__((weakref ("wv14")));
105 extern vtype wv14 __attribute__((weak));
106
107 typedef void ftype(void);
108
109 extern ftype wf1;
110 static ftype Wf1a __attribute__((weakref ("wf1")));
111 static ftype *pf1a USED = &Wf1a;
112 static ftype Wf1c __attribute__((weakref));
113 extern ftype Wf1c __attribute__((alias ("wf1")));
114 static ftype *pf1c USED = &Wf1c;
115
116 void gf2(void) {}
117 static ftype Wf2a __attribute__((weakref ("gf2")));
118 static ftype *pf2a USED = &Wf2a;
119
120 static void lf3(void) {}
121 static ftype Wf3a __attribute__((weakref ("lf3")));
122 static ftype *pf3a USED = &Wf3a;
123
124 extern ftype uf4;
125 static ftype Wf4a __attribute__((weakref ("uf4")));
126 static ftype *pf4a USED = &Wf4a;
127 static ftype *pf4 USED = &uf4;
128
129 static ftype Wf5a __attribute__((weakref ("uf5")));
130 static ftype *pf5a USED = &Wf5a;
131 extern ftype uf5;
132 static ftype *pf5 USED = &uf5;
133
134 static ftype Wf6a __attribute__((weakref ("wf6")));
135 static ftype *pf6a USED = &Wf6a;
136 extern ftype wf6;
137
138 static ftype Wf7a __attribute__((weakref ("uf7")));
139 static ftype* USED ff7 (void) {
140   return &Wf7a;
141 }
142 extern ftype uf7;
143 static ftype* USED ff7a (void) {
144   return &uf7;
145 }
146
147 extern ftype uf8;
148 static ftype* USED ff8a (void) {
149   return &uf8;
150 }
151 static ftype Wf8a __attribute__((weakref ("uf8")));
152 static ftype* USED ff8 (void) {
153   return &Wf8a;
154 }
155
156 extern ftype wf9 __attribute__((weak));
157 static ftype Wf9a __attribute__((weakref ("wf9")));
158 static ftype *pf9a USED = &Wf9a;
159
160 static ftype Wf10a __attribute__((weakref ("Wf10b")));
161 static ftype Wf10b __attribute__((weakref ("Wf10c")));
162 static ftype Wf10c __attribute__((weakref ("Wf10d")));
163 static ftype Wf10d __attribute__((weakref ("wf10")));
164 extern ftype wf10;
165
166 extern ftype wf11;
167 static ftype Wf11d __attribute__((weakref ("wf11")));
168 static ftype Wf11c __attribute__((weakref ("Wf11d")));
169 static ftype Wf11b __attribute__((weakref ("Wf11c")));
170 static ftype Wf11a __attribute__((weakref ("Wf11b")));
171
172 static ftype Wf12 __attribute__((weakref ("wf12")));
173 extern ftype wf12 __attribute__((weak));
174
175 static ftype Wf13 __attribute__((weakref ("wf13")));
176 extern ftype wf13 __attribute__((weak));
177
178 static ftype Wf14a __attribute__((weakref ("wf14")));
179 static ftype Wf14b __attribute__((weakref ("wf14")));
180 extern ftype wf14 __attribute__((weak));
181
182 #ifndef __APPLE__
183 #define chk(p) do { if (!p) abort (); } while (0)
184 #else
185 #define chk(p) /* */
186 #endif
187
188 int main () {
189   chk (!pv1a);
190   chk (pv2a);
191   chk (pv3a);
192   chk (pv4a);
193   chk (pv4);
194   chk (pv5a);
195   chk (pv5);
196   chk (!pv6a);
197   chk (fv7 ());
198   chk (fv7a ());
199   chk (fv8 ());
200   chk (fv8a ());
201   chk (!pv9a);
202   chk (!&Wv10a);
203   chk (!&Wv11a);
204   chk (!&Wv12);
205   chk (!&wv12);
206   chk (!&wv13);
207   chk (!&Wv14a);
208
209   chk (!pf1a);
210   chk (!pf1c);
211   chk (pf2a);
212   chk (pf3a);
213   chk (pf4a);
214   chk (pf4);
215   chk (pf5a);
216   chk (pf5);
217   chk (!pf6a);
218   chk (ff7 ());
219   chk (ff7a ());
220   chk (ff8 ());
221   chk (ff8a ());
222   chk (!pf9a);
223   chk (!&Wf10a);
224   chk (!&Wf11a);
225   chk (!&Wf12);
226   chk (!&wf12);
227   chk (!&wf13);
228   chk (!&Wf14a);
229
230   exit (0);
231 }