dyld-832.7.1.tar.gz
[apple/dyld.git] / testing / kernel-cache-tests / symbol-sets / test.py
1 #!/usr/bin/python2.7
2
3 import os
4 import KernelCollection
5
6 # This verifies that we use the symbol set when resolving symbols in to the kernel
7 # Note symbol sets are the plist which is embedded in to the kernel
8
9 def check(kernel_cache):
10 kernel_cache.buildKernelCollection("arm64", "/symbol-sets/main.kc", "/symbol-sets/main.kernel", "/symbol-sets/extensions", ["com.apple.foo"], [])
11 kernel_cache.analyze("/symbol-sets/main.kc", ["-layout", "-arch", "arm64"])
12
13 assert len(kernel_cache.dictionary()["dylibs"]) == 2
14 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
15 assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.foo"
16 assert kernel_cache.dictionary()["dylibs"][1]["segments"][2]["name"] == "__DATA_CONST"
17 assert kernel_cache.dictionary()["dylibs"][1]["segments"][2]["vmAddr"] == "0x14000"
18
19 # Find the address of the symbols to bind to
20 kernel_cache.analyze("/symbol-sets/main.kc", ["-symbols", "-arch", "arm64"])
21 assert len(kernel_cache.dictionary()["dylibs"]) == 2
22 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
23 assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][2]["name"] == "_symbol_from_xnu"
24 assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][2]["vmAddr"] == "0xC000"
25 assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][3]["name"] == "_symbol_from_xnu_no_alias"
26 assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][3]["vmAddr"] == "0xC00C"
27
28 # Check the fixups
29 kernel_cache.analyze("/symbol-sets/main.kc", ["-fixups", "-arch", "arm64"])
30 assert len(kernel_cache.dictionary()["fixups"]) == 2
31 assert kernel_cache.dictionary()["fixups"]["0x14000"] == "kc(0) + 0xC000"
32 assert kernel_cache.dictionary()["fixups"]["0x14008"] == "kc(0) + 0xC00C"
33 assert len(kernel_cache.dictionary()["dylibs"]) == 2
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.foo"
37 assert kernel_cache.dictionary()["dylibs"][1]["fixups"] == "none"
38
39 # [~]> 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--
40 # [~]> xcrun -sdk iphoneos.internal cc -arch arm64 -Wl,-kext -mkernel -nostdlib -Wl,-add_split_seg_info foo.c -o extensions/foo.kext/foo
41 # [~]> rm -r extensions/foo.kext/*.ld
42