]> git.saurik.com Git - apple/dyld.git/blob - unit-tests/test-cases/weak-non-lazy/realmain.c
dyld-851.27.tar.gz
[apple/dyld.git] / unit-tests / test-cases / weak-non-lazy / realmain.c
1
2
3 #include <stdio.h> // fprintf(), NULL
4 #include <stdlib.h> // exit(), EXIT_SUCCESS
5
6 #include "test.h" // PASS(), FAIL(), XPASS(), XFAIL()
7
8 // getfoo() is in libfoo.dylib and uses a non-lazy pointer to reference foo
9 // libfoo.dylib also has weak foo[]
10 // getfoo() should be rebound to point into the foo[] in main
11 int foo[] = { 5, 6, 7, 8 };
12 extern int* getfoo();
13
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
20
21 int __attribute__((weak)) stuff[] = { 1, 2, 3, 4, 5 };
22
23
24 void realmain()
25 {
26 if ( getfoo()[2] != 7 )
27 FAIL("weak-non-lazy, getfoo()[2]=%d", getfoo()[2]);
28 else if ( bar[1] != 21 )
29 FAIL("weak-non-lazy, bar[1]=%d", bar[1]);
30 else if ( stuff[3] != 4 )
31 FAIL("weak-external-reloc, pstuffr=%d", stuff[3]);
32 else
33 PASS("weak-non-lazy");
34 }
35
36