]> git.saurik.com Git - apple/dyld.git/blob - testing/kernel-cache-tests/kext-bind-to-kext-old-section-type/test.py
dyld-832.7.1.tar.gz
[apple/dyld.git] / testing / kernel-cache-tests / kext-bind-to-kext-old-section-type / test.py
1 #!/usr/bin/python2.7
2
3 import os
4 import KernelCollection
5
6 # This tests that the very old bar.kext can be parsed. It's __got section has a S_NON_LAZY_SYMBOL_POINTERS type,
7 # but newer linkers changed to just S_REGULAR.
8
9 def check(kernel_cache):
10 kernel_cache.buildKernelCollection("x86_64", "/kext-bind-to-kext-old-section-type/main.kc", "/kext-bind-to-kext-old-section-type/main.kernel", "/kext-bind-to-kext-old-section-type/extensions", ["com.apple.foo", "com.apple.bar"], [])
11 kernel_cache.analyze("/kext-bind-to-kext-old-section-type/main.kc", ["-layout", "-arch", "x86_64"])
12
13 assert len(kernel_cache.dictionary()["dylibs"]) == 3
14 # main.kernel
15 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
16 # foo.kext
17 assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.foo"
18 # bar.kext
19 assert kernel_cache.dictionary()["dylibs"][2]["name"] == "com.apple.bar"
20 assert len(kernel_cache.dictionary()["dylibs"][2]["segments"]) == 3
21 assert kernel_cache.dictionary()["dylibs"][2]["segments"][1]["name"] == "__DATA"
22 assert kernel_cache.dictionary()["dylibs"][2]["segments"][1]["vmAddr"] == "0x19000"
23
24 kernel_cache.analyze("/kext-bind-to-kext-old-section-type/main.kc", ["-symbols", "-arch", "x86_64"])
25 assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.foo"
26 assert kernel_cache.dictionary()["dylibs"][1]["global-symbols"][0]["name"] == "_foo"
27 assert kernel_cache.dictionary()["dylibs"][1]["global-symbols"][0]["vmAddr"] == "0x14000"
28
29 # Check the fixups
30 kernel_cache.analyze("/kext-bind-to-kext-old-section-type/main.kc", ["-fixups", "-arch", "x86_64"])
31 assert len(kernel_cache.dictionary()["fixups"]) == 1
32 assert kernel_cache.dictionary()["fixups"]["0x15000"] == "kc(0) + 0x14000"
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.foo"
37 assert kernel_cache.dictionary()["dylibs"][1]["fixups"] == "none"
38 assert kernel_cache.dictionary()["dylibs"][2]["name"] == "com.apple.bar"
39 assert kernel_cache.dictionary()["dylibs"][2]["fixups"] == "none"
40
41
42 # Note, bar.kext has to be linked with a very old linker from 10.7 to get the __got section with S_NON_LAZY_SYMBOL_POINTERS.
43 # [~]> xcrun -sdk macosx.internal cc -arch x86_64 -Wl,-static -Wl,-kernel -mkernel -nostdlib -Wl,-add_split_seg_info -Wl,-rename_section,__TEXT,__text,__HIB,__text -Wl,-e,__start -Wl,-pagezero_size,0x0 -Wl,-pie main.c -o main.kernel -Wl,-install_name,/usr/lib/swift/split.seg.v2.hack -Wl,-segprot,__HIB,r-x,r-x -Wl,-image_base,0x8000 -Wl,-segaddr,__HIB,0x4000
44 # [~]> xcrun -sdk macosx.internal cc -arch x86_64 -Wl,-kext -mkernel -nostdlib -Wl,-add_split_seg_info -Wl,-no_data_const foo.c -o extensions/foo.kext/foo
45 # [~]> xcrun -sdk macosx.internal cc -arch x86_64 -Wl,-kext -mkernel -nostdlib -Wl,-add_split_seg_info -Wl,-no_data_const bar.c -o extensions/bar.kext/bar -fuse-ld=...
46