132-13
[darwin-xtools.git] / dyld / unit-tests / test-cases / weak-external-reloc / realmain.c
blob6870f5a907840d82bd412947dfcd8018a061ad05
3 #include <stdio.h> // fprintf(), NULL
4 #include <stdlib.h> // exit(), EXIT_SUCCESS
6 #include "test.h" // PASS(), FAIL(), XPASS(), XFAIL()
8 // pfoo is in libfoo.dylib
9 // libfoo.dylib also has weak foo[]
10 // pfoo should be rebound to point into the foo[] in main
11 int foo[] = { 5, 6, 7, 8 };
12 extern int* pfoo;
14 // libfoo.dylib has a weak bar[]
15 // libbar.dylib has a strong bar[]
16 // at build time linker only sees weak bar in libfoo.dylib
17 // at runtime, dyld uses strong bar in libbar.dylib
18 extern int bar[];
19 int* pbar = &bar[1];
21 // there is only one stuff, but it is weak
22 // so we are testing the case when stuff is not overridden
23 int __attribute__((weak)) stuff[] = { 1, 2, 3, 4, 5 };
24 int* pstuff = &stuff[3];
27 void realmain()
29 if ( *pfoo != 7 )
30 FAIL("weak-external-reloc, pfoo=%d", *pfoo);
31 else if ( *pbar != 21 )
32 FAIL("weak-external-reloc, pbar=%d", *pbar);
33 else if ( *pstuff != 4 )
34 FAIL("weak-external-reloc, pstuffr=%d", *pstuff);
35 else
36 PASS("weak-external-reloc");