]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/bind-rebase.dtest/main.c
dyld-851.27.tar.gz
[apple/dyld.git] / testing / test-cases / bind-rebase.dtest / main.c
1
2 // BUILD: $CC main.c -Wl,-fixup_chains -o $BUILD_DIR/bind-rebase.exe
3
4 // RUN: ./bind-rebase.exe
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <dlfcn.h>
10 #include <assert.h>
11
12 #include "test_support.h"
13
14 extern char tzname[]; // a char array in libSystem.dylib
15
16
17 #define VERIFY(a,b) assert(a==(b))
18
19
20 static uint8_t a;
21 uint8_t* const rebasedPtrs[] = { NULL, NULL, &a, &a+1, &a+16, &a+1023, NULL, &a-1 };
22
23 #if __LP64__
24 uint8_t* const tbiPointers[] = { &a+0x8000000000000000, &a, &a+0x9000000000000000 };
25 #endif
26
27 void verifyRebases()
28 {
29 VERIFY(rebasedPtrs[0], NULL);
30 VERIFY(rebasedPtrs[1], NULL);
31 VERIFY(rebasedPtrs[2], &a);
32 VERIFY(rebasedPtrs[3], &a+1);
33 VERIFY(rebasedPtrs[4], &a+16);
34 VERIFY(rebasedPtrs[5], &a+1023);
35 VERIFY(rebasedPtrs[6], NULL);
36 VERIFY(rebasedPtrs[7], &a-1);
37 #if __LP64__
38 VERIFY(tbiPointers[0], &a + 0x8000000000000000);
39 VERIFY(tbiPointers[2], &a + 0x9000000000000000);
40 #endif
41 }
42
43
44 static char* const bindPtrs[] = { NULL, NULL, tzname, tzname+1, &tzname[16], &tzname[1023], NULL, &tzname[-1], (char*)&malloc, (char*)&free };
45
46 void verifyBinds()
47 {
48 VERIFY(bindPtrs[0], NULL);
49 VERIFY(bindPtrs[1], NULL);
50 VERIFY(bindPtrs[2], tzname);
51 VERIFY(bindPtrs[3], tzname+1);
52 VERIFY(bindPtrs[4], tzname+16);
53 VERIFY(bindPtrs[5], tzname+1023);
54 VERIFY(bindPtrs[6], NULL);
55 VERIFY(bindPtrs[7], tzname-1);
56 VERIFY(bindPtrs[8], (char*)&malloc);
57 VERIFY(bindPtrs[9], (char*)&free);
58 }
59
60 #if !__LP64__
61 #define JUNK ((uint8_t*)0x12345678)
62 uint8_t* const otherPtrs[] = {
63 &a,
64 // far enough apart to require co-opting a NULL
65 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
66 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
67 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
68 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
69 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
70 &a+1,
71 // far enough apart to require co-opting two NULLs
72 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
73 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
74 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
75 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
76 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
77 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
78 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
79 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
80 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
81 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
82 &a,
83 // far apart and intermediate values are not co-optable
84 // so a new chain must be used
85 JUNK, JUNK, JUNK, JUNK, JUNK, JUNK, JUNK, JUNK,
86 JUNK, JUNK, JUNK, JUNK, JUNK, JUNK, JUNK, JUNK,
87 JUNK, JUNK, JUNK, JUNK, JUNK, JUNK, JUNK, JUNK,
88 JUNK, JUNK, JUNK, JUNK, JUNK, JUNK, JUNK, JUNK,
89 JUNK, JUNK, JUNK, JUNK, JUNK, JUNK, JUNK, JUNK,
90 &a,
91 &a,
92 };
93
94 void verifyLongChains()
95 {
96 VERIFY(otherPtrs[0], &a);
97 VERIFY(otherPtrs[41], &a+1);
98 VERIFY(otherPtrs[122], &a);
99 VERIFY(otherPtrs[163], &a);
100 VERIFY(otherPtrs[164], &a);
101 }
102 #endif
103
104 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
105 verifyRebases();
106 verifyBinds();
107
108 #if !__LP64__
109 verifyLongChains();
110 #endif
111
112 PASS("Success");
113 }
114