dyld-832.7.1.tar.gz
[apple/dyld.git] / testing / kernel-cache-tests / ppl-data-const / test.py
1 #!/usr/bin/python2.7
2
3 import os
4 import KernelCollection
5
6 # PPL data const should be folded in under data const and allowed to have fixups
7
8 def check(kernel_cache):
9 kernel_cache.buildKernelCollection("arm64", "/ppl-data-const/main.kc", "/ppl-data-const/main.kernel", "/ppl-data-const/extensions", ["com.apple.foo", "com.apple.bar"], [])
10 kernel_cache.analyze("/ppl-data-const/main.kc", ["-layout", "-arch", "arm64"])
11
12 assert kernel_cache.dictionary()["cache-segments"][3]["name"] == "__DATA_CONST"
13 assert kernel_cache.dictionary()["cache-segments"][3]["vmAddr"] == "0x18000"
14 assert kernel_cache.dictionary()["cache-segments"][3]["vmSize"] == "0x8000"
15
16 assert len(kernel_cache.dictionary()["dylibs"]) == 3
17 # main.kernel
18 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
19 assert kernel_cache.dictionary()["dylibs"][0]["segments"][3]["name"] == "__PPLDATA_CONST"
20 assert kernel_cache.dictionary()["dylibs"][0]["segments"][3]["vmAddr"] == "0x18000"
21 # bar.kext
22 assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.bar"
23 # foo.kext
24 assert kernel_cache.dictionary()["dylibs"][2]["name"] == "com.apple.foo"
25
26 # Check we have the correct addresses of the symbols being bound to
27 kernel_cache.analyze("/ppl-data-const/main.kc", ["-symbols", "-arch", "arm64"])
28 # main.kernel
29 # int g = &x;
30 assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][3]["name"] == "_x"
31 assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][3]["vmAddr"] == "0x24000"
32 # foo.kext
33 # foo()
34 assert kernel_cache.dictionary()["dylibs"][2]["global-symbols"][0]["name"] == "_foo"
35 assert kernel_cache.dictionary()["dylibs"][2]["global-symbols"][0]["vmAddr"] == "0x14030"
36
37 kernel_cache.analyze("/ppl-data-const/main.kc", ["-fixups", "-arch", "arm64"])
38 # main.kernel
39 # int g = &x;
40 assert kernel_cache.dictionary()["fixups"]["0x18000"] == "kc(0) + 0x24000"
41 # foo.kext
42 # foo()
43 assert kernel_cache.dictionary()["fixups"]["0x1C000"] == "kc(0) + 0x14030"
44
45 # [~]> xcrun -sdk iphoneos.internal cc -arch arm64 -Wl,-static -mkernel -nostdlib -Wl,-add_split_seg_info -Wl,-rename_section,__TEXT,__text,__TEXT_EXEC,__text -Wl,-e,__start -Wl,-pagezero_size,0x0 -Wl,-pie -Wl,-rename_section,__DATA,__data,__PPLDATA_CONST,__data -Wl,-segprot,__PPLDATA_CONST,r--,r-- main.c -o main.kernel
46 # [~]> xcrun -sdk iphoneos.internal cc -arch arm64 -Wl,-kext -mkernel -nostdlib -Wl,-add_split_seg_info foo.c -o extensions/foo.kext/foo
47 # [~]> xcrun -sdk iphoneos.internal cc -arch arm64 -Wl,-kext -mkernel -nostdlib -Wl,-add_split_seg_info bar.c -o extensions/bar.kext/bar
48 # [~]> rm -r extensions/*.kext/*.ld
49