]> git.saurik.com Git - apple/dyld.git/blob - testing/kernel-cache-tests/symbol-sets-and-codeless-kexts/test.py
dyld-832.7.1.tar.gz
[apple/dyld.git] / testing / kernel-cache-tests / symbol-sets-and-codeless-kexts / test.py
1 #!/usr/bin/python2.7
2
3 import os
4 import KernelCollection
5
6 # Test that the codeless bar.kext (with bundle id com.apple.bar) doesn't interfere with foo using the symbol set of the same bundle id
7
8 def check(kernel_cache):
9 kernel_cache.buildKernelCollection("arm64", "/symbol-sets-and-codeless-kexts/main.kc", "/symbol-sets-and-codeless-kexts/main.kernel", "/symbol-sets-and-codeless-kexts/extensions", ["com.apple.foo", "com.apple.bar", "com.apple.baz"], [])
10 kernel_cache.analyze("/symbol-sets-and-codeless-kexts/main.kc", ["-layout", "-arch", "arm64"])
11
12 assert len(kernel_cache.dictionary()["dylibs"]) == 2
13 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
14 assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.foo"
15 assert kernel_cache.dictionary()["dylibs"][1]["segments"][2]["name"] == "__DATA_CONST"
16 assert kernel_cache.dictionary()["dylibs"][1]["segments"][2]["vmAddr"] == "0x14000"
17
18 # Find the address of the symbols to bind to
19 kernel_cache.analyze("/symbol-sets-and-codeless-kexts/main.kc", ["-symbols", "-arch", "arm64"])
20 assert len(kernel_cache.dictionary()["dylibs"]) == 2
21 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
22 assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][2]["name"] == "_symbol_from_xnu"
23 assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][2]["vmAddr"] == "0xC000"
24 assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][3]["name"] == "_symbol_from_xnu_no_alias"
25 assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][3]["vmAddr"] == "0xC00C"
26
27 # Check the fixups
28 kernel_cache.analyze("/symbol-sets-and-codeless-kexts/main.kc", ["-fixups", "-arch", "arm64"])
29 assert len(kernel_cache.dictionary()["fixups"]) == 2
30 assert kernel_cache.dictionary()["fixups"]["0x14000"] == "kc(0) + 0xC000"
31 assert kernel_cache.dictionary()["fixups"]["0x14008"] == "kc(0) + 0xC00C"
32 assert len(kernel_cache.dictionary()["dylibs"]) == 2
33 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
34 assert kernel_cache.dictionary()["dylibs"][0]["fixups"] == "none"
35 assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.foo"
36 assert kernel_cache.dictionary()["dylibs"][1]["fixups"] == "none"
37
38 # [~]> 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 main.c -o main.kernel -Wl,-sectcreate,__LINKINFO,__symbolsets,SymbolSets.plist -Wl,-segprot,__LINKINFO,r--,r--
39 # [~]> xcrun -sdk iphoneos.internal cc -arch arm64 -Wl,-kext -mkernel -nostdlib -Wl,-add_split_seg_info foo.c -o extensions/foo.kext/foo
40 # [~]> rm -r extensions/foo.kext/*.ld
41