dyld-832.7.1.tar.gz
[apple/dyld.git] / testing / kernel-cache-tests / vtable-patching-metaclass-alias / test.py
1 #!/usr/bin/python2.7
2
3 import os
4 import KernelCollection
5
6 # kxld has an implicit alias for a metaclass vtable entry. Test that we also rewrite that alias
7
8 def check(kernel_cache):
9 kernel_cache.buildKernelCollection("arm64", "/vtable-patching-metaclass-alias/main.kc", "/vtable-patching-metaclass-alias/main.kernel", "/vtable-patching-metaclass-alias/extensions", ["com.apple.foo"], [])
10 kernel_cache.analyze("/vtable-patching-metaclass-alias/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("/vtable-patching-metaclass-alias/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"][0]["name"] == "__ZN15OSMetaClassBase8DispatchE5IORPC"
23 assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][0]["vmAddr"] == "0xC000"
24
25 # Check the fixups
26 kernel_cache.analyze("/vtable-patching-metaclass-alias/main.kc", ["-fixups", "-arch", "arm64"])
27 assert len(kernel_cache.dictionary()["fixups"]) == 2
28 assert kernel_cache.dictionary()["fixups"]["0x14000"] == "kc(0) + 0xC000"
29 assert kernel_cache.dictionary()["fixups"]["0x14008"] == "kc(0) + 0xC000"
30 assert len(kernel_cache.dictionary()["dylibs"]) == 2
31 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
32 assert kernel_cache.dictionary()["dylibs"][0]["fixups"] == "none"
33 assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.foo"
34 assert kernel_cache.dictionary()["dylibs"][1]["fixups"] == "none"
35
36 # [~]> 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--
37 # [~]> xcrun -sdk iphoneos.internal cc -arch arm64 -Wl,-kext -mkernel -nostdlib -Wl,-add_split_seg_info foo.c -o extensions/foo.kext/foo
38 # [~]> rm -r extensions/foo.kext/*.ld
39