dyld-733.6.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 // Note this is weak so that we have a bind
11 __attribute__((weak))
12 void* p = 0;
13
14 // Choose a large enough negative offset to be before the shared cache or the image
15 const uintptr_t offset = 1ULL << 36;
16 void* pMinus = (void*)((uintptr_t)&p - offset);
17
18 // Get a pointer to something we assume is in the shared cache
19 // Note we don't declare a function as arm64e would want to sign this
20 extern int objc_msgSend;
21 void* msgSendMinus = (void*)((uintptr_t)&objc_msgSend - offset);
22
23 int main()
24 {
25 printf("[BEGIN] bind-addend\n");
26
27 if ( pMinus != (void*)((uintptr_t)&p - offset) ) {
28 printf("[FAIL] bind-addend: %p != %p\n", pMinus, (void*)((uintptr_t)&p - offset));
29 return 0;
30 }
31
32 if ( msgSendMinus != (void*)((uintptr_t)&objc_msgSend - offset) ) {
33 printf("[FAIL] bind-addend: %p != %p\n", msgSendMinus, (void*)((uintptr_t)&objc_msgSend - offset));
34 return 0;
35 }
36
37 printf("[PASS] bind-addend\n");
38 return 0;
39 }
40