dyld-832.7.1.tar.gz
[apple/dyld.git] / testing / kernel-cache-tests / kext-missing-weak-bind / test.py
1 #!/usr/bin/python2.7
2
3 import os
4 import KernelCollection
5
6 # Check that weak binds can be missing, so long as we check for the magic symbol
7
8 def check(kernel_cache):
9 kernel_cache.buildKernelCollection("arm64", "/kext-missing-weak-bind/main.kc", "/kext-missing-weak-bind/main.kernel", "/kext-missing-weak-bind/extensions", ["com.apple.foo", "com.apple.bar"], [])
10 kernel_cache.analyze("/kext-missing-weak-bind/main.kc", ["-layout", "-arch", "arm64"])
11 assert kernel_cache.dictionary()["cache-segments"][3]["name"] == "__DATA_CONST"
12 assert kernel_cache.dictionary()["cache-segments"][3]["vmAddr"] == "0x18000"
13
14 assert len(kernel_cache.dictionary()["dylibs"]) == 3
15 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
16 assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.bar"
17 assert kernel_cache.dictionary()["dylibs"][2]["name"] == "com.apple.foo"
18
19 # Symbols
20 kernel_cache.analyze("/kext-missing-weak-bind/main.kc", ["-symbols", "-arch", "arm64"])
21 # kernel
22 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
23 assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][2]["name"] == "_gOSKextUnresolved"
24 assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][2]["vmAddr"] == "0x20000"
25
26 # Check the fixups
27 kernel_cache.analyze("/kext-missing-weak-bind/main.kc", ["-fixups", "-arch", "arm64"])
28 assert len(kernel_cache.dictionary()["fixups"]) == 4
29 assert kernel_cache.dictionary()["fixups"]["0x18000"] == "kc(0) + 0x20000"
30 assert kernel_cache.dictionary()["fixups"]["0x18008"] == "kc(0) + 0x20000"
31 assert kernel_cache.dictionary()["fixups"]["0x18010"] == "kc(0) + 0x20000"
32 assert kernel_cache.dictionary()["fixups"]["0x18018"] == "kc(0) + 0x20000"
33 assert len(kernel_cache.dictionary()["dylibs"]) == 3
34 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
35 assert kernel_cache.dictionary()["dylibs"][0]["fixups"] == "none"
36 assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.bar"
37 assert kernel_cache.dictionary()["dylibs"][1]["fixups"] == "none"
38 assert kernel_cache.dictionary()["dylibs"][2]["name"] == "com.apple.foo"
39 assert kernel_cache.dictionary()["dylibs"][2]["fixups"] == "none"
40
41
42 # [~]> 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,-sectcreate,__LINKINFO,__symbolsets,SymbolSets.plist -Wl,-segprot,__LINKINFO,r--,r-- main.c -o main.kernel
43 # [~]> xcrun -sdk iphoneos.internal cc -arch arm64 -Wl,-kext -mkernel -nostdlib -Wl,-add_split_seg_info foo.c -o extensions/foo.kext/foo
44 # [~]> xcrun -sdk iphoneos.internal cc -arch arm64 -Wl,-kext -mkernel -nostdlib -Wl,-add_split_seg_info bar.c -o extensions/bar.kext/bar -Wl,-fixup_chains
45 # [~]> rm -r extensions/*.kext/*.ld
46