annotate gcc/testsuite/gcc.dg/attr-weakref-1.c @ 145:1830386684a0

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