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