]> git.saurik.com Git - apple/dyld.git/blob - testing/kernel-cache-tests/symbol-sets-prefix/test.py
dyld-851.27.tar.gz
[apple/dyld.git] / testing / kernel-cache-tests / symbol-sets-prefix / test.py
1 #!/usr/bin/python2.7
2
3 import os
4 import KernelCollection
5
6 # Symbol sets can have a prefix with an implicit * wildcard on the end which re-exports anything from xnu with that name
7
8 def check(kernel_cache):
9 kernel_cache.buildKernelCollection("arm64", "/symbol-sets-prefix/main.kc", "/symbol-sets-prefix/main.kernel", "/symbol-sets-prefix/extensions", ["com.apple.foo"], [])
10 kernel_cache.analyze("/symbol-sets-prefix/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 # Check the symbols
19 kernel_cache.analyze("/symbol-sets-prefix/main.kc", ["-symbols", "-arch", "arm64"])
20 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
21 assert len(kernel_cache.dictionary()["dylibs"][0]["global-symbols"]) == 6
22 assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][0]["name"] == "__mh_execute_header"
23 assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][1]["name"] == "__start"
24 assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][2]["name"] == "_symbol_from_xnu0"
25 assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][2]["vmAddr"] == "0xC000"
26 assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][3]["name"] == "_symbol_from_xnu1"
27 assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][3]["vmAddr"] == "0xC00C"
28 assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][4]["name"] == "_symbol_from_xnu2"
29 assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][4]["vmAddr"] == "0xC018"
30 assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][5]["name"] == "_symbol_from_xnu3"
31 assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][5]["vmAddr"] == "0xC024"
32
33 # Check the fixups
34 kernel_cache.analyze("/symbol-sets-prefix/main.kc", ["-fixups", "-arch", "arm64"])
35 assert len(kernel_cache.dictionary()["fixups"]) == 4
36 assert kernel_cache.dictionary()["fixups"]["0x14000"] == "kc(0) + 0xC000"
37 assert kernel_cache.dictionary()["fixups"]["0x14008"] == "kc(0) + 0xC00C"
38 assert kernel_cache.dictionary()["fixups"]["0x14010"] == "kc(0) + 0xC018"
39 assert kernel_cache.dictionary()["fixups"]["0x14018"] == "kc(0) + 0xC024"
40 assert len(kernel_cache.dictionary()["dylibs"]) == 2
41 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
42 assert kernel_cache.dictionary()["dylibs"][0]["fixups"] == "none"
43 assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.foo"
44 assert kernel_cache.dictionary()["dylibs"][1]["fixups"] == "none"
45
46 # [~]> 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--
47 # [~]> xcrun -sdk iphoneos.internal cc -arch arm64 -Wl,-kext -mkernel -nostdlib -Wl,-add_split_seg_info foo.c -o extensions/foo.kext/foo
48 # [~]> rm -r extensions/foo.kext/*.ld
49