]> git.saurik.com Git - apple/dyld.git/blob - testing/kernel-cache-tests/hello-world-auxkc/test.py
dyld-851.27.tar.gz
[apple/dyld.git] / testing / kernel-cache-tests / hello-world-auxkc / test.py
1 #!/usr/bin/python2.7
2
3 import os
4 import KernelCollection
5
6 # Verify that an auxKC has a reverse vmAddr order
7
8 def check(kernel_cache):
9 # First build a kernel collection
10 kernel_cache.buildKernelCollection("arm64", "/hello-world-auxkc/main.kc", "/hello-world-auxkc/main.kernel", "/hello-world-auxkc/extensions", [], [])
11 kernel_cache.analyze("/hello-world-auxkc/main.kc", ["-layout", "-arch", "arm64"])
12
13 assert len(kernel_cache.dictionary()["cache-segments"]) == 5
14 assert kernel_cache.dictionary()["cache-segments"][0]["name"] == "__TEXT"
15 assert kernel_cache.dictionary()["cache-segments"][0]["vmAddr"] == "0x0"
16 assert kernel_cache.dictionary()["cache-segments"][1]["name"] == "__PRELINK_TEXT"
17 assert kernel_cache.dictionary()["cache-segments"][1]["vmAddr"] == "0x4000"
18 assert kernel_cache.dictionary()["cache-segments"][2]["name"] == "__TEXT_EXEC"
19 assert kernel_cache.dictionary()["cache-segments"][2]["vmAddr"] == "0x4000"
20 assert kernel_cache.dictionary()["cache-segments"][3]["name"] == "__PRELINK_INFO"
21 assert kernel_cache.dictionary()["cache-segments"][3]["vmAddr"] == "0xC000"
22 assert kernel_cache.dictionary()["cache-segments"][4]["name"] == "__LINKEDIT"
23 assert kernel_cache.dictionary()["cache-segments"][4]["vmAddr"] == "0x10000"
24
25 assert len(kernel_cache.dictionary()["dylibs"]) == 1
26 # main.kernel
27 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
28 assert len(kernel_cache.dictionary()["dylibs"][0]["segments"]) == 3
29 assert kernel_cache.dictionary()["dylibs"][0]["segments"][0]["name"] == "__TEXT"
30 assert kernel_cache.dictionary()["dylibs"][0]["segments"][0]["vmAddr"] == "0x4000"
31 assert kernel_cache.dictionary()["dylibs"][0]["segments"][1]["name"] == "__TEXT_EXEC"
32 assert kernel_cache.dictionary()["dylibs"][0]["segments"][1]["vmAddr"] == "0x8000"
33 assert kernel_cache.dictionary()["dylibs"][0]["segments"][2]["name"] == "__LINKEDIT"
34 assert kernel_cache.dictionary()["dylibs"][0]["segments"][2]["vmAddr"] == "0x10000"
35
36 # Now build an aux cache using the baseline kernel collection
37 kernel_cache.buildAuxKernelCollection("arm64", "/hello-world-auxkc/aux.kc", "/hello-world-auxkc/main.kc", "", "/hello-world-auxkc/extensions", ["com.apple.foo", "com.apple.bar"], [])
38 kernel_cache.analyze("/hello-world-auxkc/aux.kc", ["-layout", "-arch", "arm64"])
39
40 assert len(kernel_cache.dictionary()["cache-segments"]) == 6
41 assert kernel_cache.dictionary()["cache-segments"][0]["name"] == "__TEXT"
42 assert kernel_cache.dictionary()["cache-segments"][0]["vmAddr"] == "0x8000"
43 assert kernel_cache.dictionary()["cache-segments"][1]["name"] == "__PRELINK_TEXT"
44 assert kernel_cache.dictionary()["cache-segments"][1]["vmAddr"] == "0xC000"
45 assert kernel_cache.dictionary()["cache-segments"][2]["name"] == "__TEXT_EXEC"
46 assert kernel_cache.dictionary()["cache-segments"][2]["vmAddr"] == "0x14000"
47 assert kernel_cache.dictionary()["cache-segments"][3]["name"] == "__PRELINK_INFO"
48 assert kernel_cache.dictionary()["cache-segments"][3]["vmAddr"] == "0x0"
49 assert kernel_cache.dictionary()["cache-segments"][4]["name"] == "__DATA"
50 assert kernel_cache.dictionary()["cache-segments"][4]["vmAddr"] == "0x4000"
51 assert kernel_cache.dictionary()["cache-segments"][5]["name"] == "__LINKEDIT"
52 assert kernel_cache.dictionary()["cache-segments"][5]["vmAddr"] == "0x18000"
53
54 assert len(kernel_cache.dictionary()["dylibs"]) == 2
55 # bar.kext
56 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.bar"
57 assert len(kernel_cache.dictionary()["dylibs"][0]["segments"]) == 4
58 assert kernel_cache.dictionary()["dylibs"][0]["segments"][0]["name"] == "__TEXT"
59 assert kernel_cache.dictionary()["dylibs"][0]["segments"][0]["vmAddr"] == "0xC000"
60 assert kernel_cache.dictionary()["dylibs"][0]["segments"][1]["name"] == "__TEXT_EXEC"
61 assert kernel_cache.dictionary()["dylibs"][0]["segments"][1]["vmAddr"] == "0x14000"
62 assert kernel_cache.dictionary()["dylibs"][0]["segments"][2]["name"] == "__DATA"
63 assert kernel_cache.dictionary()["dylibs"][0]["segments"][2]["vmAddr"] == "0x4000"
64 assert kernel_cache.dictionary()["dylibs"][0]["segments"][3]["name"] == "__LINKEDIT"
65 assert kernel_cache.dictionary()["dylibs"][0]["segments"][3]["vmAddr"] == "0x18000"
66 # foo.kext
67 assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.foo"
68 assert len(kernel_cache.dictionary()["dylibs"][1]["segments"]) == 3
69 assert kernel_cache.dictionary()["dylibs"][1]["segments"][0]["name"] == "__TEXT"
70 assert kernel_cache.dictionary()["dylibs"][1]["segments"][0]["vmAddr"] == "0x10000"
71 assert kernel_cache.dictionary()["dylibs"][1]["segments"][1]["name"] == "__TEXT_EXEC"
72 assert kernel_cache.dictionary()["dylibs"][1]["segments"][1]["vmAddr"] == "0x14020"
73 assert kernel_cache.dictionary()["dylibs"][1]["segments"][2]["name"] == "__LINKEDIT"
74 assert kernel_cache.dictionary()["dylibs"][1]["segments"][2]["vmAddr"] == "0x18000"
75
76 # Check the fixups
77 kernel_cache.analyze("/hello-world-auxkc/aux.kc", ["-fixups", "-arch", "arm64"])
78 assert len(kernel_cache.dictionary()["fixups"]) == 1
79 assert kernel_cache.dictionary()["fixups"]["0x4000"] == "kc(3) + 0x14020"
80 assert len(kernel_cache.dictionary()["dylibs"]) == 2
81 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.bar"
82 assert kernel_cache.dictionary()["dylibs"][0]["fixups"] == "none"
83 assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.foo"
84 assert kernel_cache.dictionary()["dylibs"][1]["fixups"] == "none"
85
86
87 # [~]> 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
88 # [~]> xcrun -sdk iphoneos.internal cc -arch arm64 -Wl,-kext -mkernel -nostdlib -Wl,-add_split_seg_info -Wl,-no_data_const foo.c -o extensions/foo.kext/foo
89 # [~]> xcrun -sdk iphoneos.internal cc -arch arm64 -Wl,-kext -mkernel -nostdlib -Wl,-add_split_seg_info -Wl,-no_data_const bar.c -o extensions/bar.kext/bar
90 # [~]> rm -r extensions/*.kext/*.ld
91