Debian Codegraph @

gcc/testsuite/gcc.dg/attr-weakref-1.c

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