dyld-832.7.1.tar.gz
[apple/dyld.git] / testing / kernel-cache-tests / fixups-x86_64-unaligned / test.py
1 #!/usr/bin/python2.7
2
3 import os
4 import KernelCollection
5
6 # Test unaligned fixups in x86_64 kexts
7
8 def check(kernel_cache):
9 kernel_cache.buildKernelCollection("x86_64", "/fixups-x86_64-unaligned/main.kc", "/fixups-x86_64-unaligned/main.kernel", "/fixups-x86_64-unaligned/extensions", ["com.apple.foo"], [])
10 kernel_cache.analyze("/fixups-x86_64-unaligned/main.kc", ["-symbols", "-arch", "x86_64"])
11
12 assert len(kernel_cache.dictionary()["dylibs"]) == 2
13 # foo.kext
14 assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.foo"
15 # int foo();
16 assert kernel_cache.dictionary()["dylibs"][1]["global-symbols"][0]["name"] == "_foo"
17 foo_vmaddr_foo = kernel_cache.dictionary()["dylibs"][1]["global-symbols"][0]["vmAddr"]
18 # int g;
19 assert kernel_cache.dictionary()["dylibs"][1]["global-symbols"][1]["name"] == "_g"
20 foo_vmaddr_g = kernel_cache.dictionary()["dylibs"][1]["global-symbols"][1]["vmAddr"]
21 # PackedS ps;
22 assert kernel_cache.dictionary()["dylibs"][1]["global-symbols"][2]["name"] == "_ps"
23 assert kernel_cache.dictionary()["dylibs"][1]["global-symbols"][2]["vmAddr"] == "0x20C000"
24 # int func();
25 assert kernel_cache.dictionary()["dylibs"][1]["local-symbols"][0]["name"] == "_func"
26 foo_vmaddr_func = kernel_cache.dictionary()["dylibs"][1]["local-symbols"][0]["vmAddr"]
27
28 # Check the fixups
29 kernel_cache.analyze("/fixups-x86_64-unaligned/main.kc", ["-fixups", "-arch", "x86_64"])
30 assert len(kernel_cache.dictionary()["fixups"]) == 20
31 # foo.kext: PackedS ps = { 0, &func, &func, 0, &g, 0, &g };
32 # _ps is at 0x20C000 which is offset 0x10C000 from __HIB
33 assert kernel_cache.dictionary()["fixups"]["0x10C004"] == "kc(0) + " + foo_vmaddr_func
34 assert kernel_cache.dictionary()["fixups"]["0x10C00C"] == "kc(0) + " + foo_vmaddr_func
35 assert kernel_cache.dictionary()["fixups"]["0x10C018"] == "kc(0) + " + foo_vmaddr_g
36 assert kernel_cache.dictionary()["fixups"]["0x10C021"] == "kc(0) + " + foo_vmaddr_g
37 # foo.kext: PackedS ps_array = { { 0, &func, &func, 0, &g, 0, &g }, ... }
38 # _ps_array[0] is at 0x20D000 which is offset 0x10D000 from __HIB
39 assert kernel_cache.dictionary()["fixups"]["0x10D004"] == "kc(0) + " + foo_vmaddr_func
40 assert kernel_cache.dictionary()["fixups"]["0x10D00C"] == "kc(0) + " + foo_vmaddr_func
41 assert kernel_cache.dictionary()["fixups"]["0x10D018"] == "kc(0) + " + foo_vmaddr_g
42 assert kernel_cache.dictionary()["fixups"]["0x10D021"] == "kc(0) + " + foo_vmaddr_g
43 # _ps_array[1] is at 0x20E000 which is offset 0x10D000 from __HIB
44 assert kernel_cache.dictionary()["fixups"]["0x10E004"] == "kc(0) + " + foo_vmaddr_func
45 assert kernel_cache.dictionary()["fixups"]["0x10E00C"] == "kc(0) + " + foo_vmaddr_func
46 assert kernel_cache.dictionary()["fixups"]["0x10E018"] == "kc(0) + " + foo_vmaddr_g
47 assert kernel_cache.dictionary()["fixups"]["0x10E021"] == "kc(0) + " + foo_vmaddr_g
48 # _ps_array[2] is at 0x20F000 which is offset 0x10D000 from __HIB
49 assert kernel_cache.dictionary()["fixups"]["0x10F004"] == "kc(0) + " + foo_vmaddr_func
50 assert kernel_cache.dictionary()["fixups"]["0x10F00C"] == "kc(0) + " + foo_vmaddr_func
51 assert kernel_cache.dictionary()["fixups"]["0x10F018"] == "kc(0) + " + foo_vmaddr_g
52 assert kernel_cache.dictionary()["fixups"]["0x10F021"] == "kc(0) + " + foo_vmaddr_g
53 # _ps_array[3] is at 0x210000 which is offset 0x10D000 from __HIB
54 assert kernel_cache.dictionary()["fixups"]["0x110004"] == "kc(0) + " + foo_vmaddr_func
55 assert kernel_cache.dictionary()["fixups"]["0x11000C"] == "kc(0) + " + foo_vmaddr_func
56 assert kernel_cache.dictionary()["fixups"]["0x110018"] == "kc(0) + " + foo_vmaddr_g
57 assert kernel_cache.dictionary()["fixups"]["0x110021"] == "kc(0) + " + foo_vmaddr_g
58
59 # [~]> xcrun -sdk macosx.internal cc -arch x86_64 -Wl,-static -mkernel -nostdlib -Wl,-kernel -Wl,-e,__start -Wl,-pie main.cpp -Wl,-pagezero_size,0x0 -o main.kernel -Wl,-image_base,0x200000 -Wl,-segaddr,__HIB,0x100000 -Wl,-add_split_seg_info -Wl,-install_name,/usr/lib/swift/split.seg.v2.hack
60 # [~]> xcrun -sdk macosx.internal cc -arch x86_64 -Wl,-kext -mkernel -nostdlib -Wl,-add_split_seg_info foo.c -o extensions/foo.kext/foo
61