]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/bind-addend.dtest/main.c
dyld-851.27.tar.gz
[apple/dyld.git] / testing / test-cases / bind-addend.dtest / main.c
1
2 // BUILD: $CC main.c -o $BUILD_DIR/bind-addend.exe -lobjc
3
4 // RUN: ./bind-addend.exe
5
6 // Verify that negative addends work with pointers in to the shared cache and pointers to the image itself
7
8 #include <stdio.h>
9
10 #include "test_support.h"
11
12 // Note this is weak so that we have a bind
13 __attribute__((weak))
14 void* p = 0;
15
16 // Choose a large enough negative offset to be before the shared cache or the image
17 #if __LP64__
18 const uintptr_t offset = 1ULL << 36;
19 #else
20 const uintptr_t offset = 1ULL << 28;
21 #endif
22 void* pMinus = (void*)((uintptr_t)&p - offset);
23
24 // Get a pointer to something we assume is in the shared cache
25 // Note we don't declare a function as arm64e would want to sign this
26 extern int objc_msgSend;
27 void* msgSendMinus = (void*)((uintptr_t)&objc_msgSend - offset);
28
29 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
30 if ( pMinus != (void*)((uintptr_t)&p - offset) ) {
31 FAIL("bind-addend: %p != %p", pMinus, (void*)((uintptr_t)&p - offset));
32 }
33
34 if ( msgSendMinus != (void*)((uintptr_t)&objc_msgSend - offset) ) {
35 FAIL("bind-addend: %p != %p", msgSendMinus, (void*)((uintptr_t)&objc_msgSend - offset));
36 }
37
38 PASS("bind-addend");
39 }
40