]>
git.saurik.com Git - apple/dyld.git/blob - testing/kernel-cache-tests/hello-world-pageablekc/test.py
4 import KernelCollection
6 # Verify that pageableKC has nothing packed on the same page
8 def check(kernel_cache
):
9 # First build a kernel collection
10 kernel_cache
.buildKernelCollection("arm64", "/hello-world-pageablekc/main.kc", "/hello-world-pageablekc/main.kernel", "/hello-world-pageablekc/extensions", [], [])
11 kernel_cache
.analyze("/hello-world-pageablekc/main.kc", ["-layout", "-arch", "arm64"])
13 assert len(kernel_cache
.dictionary()["cache-segments"]) == 6
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"] == "__DATA"
23 assert kernel_cache
.dictionary()["cache-segments"][4]["vmAddr"] == "0x10000"
24 assert kernel_cache
.dictionary()["cache-segments"][5]["name"] == "__LINKEDIT"
25 assert kernel_cache
.dictionary()["cache-segments"][5]["vmAddr"] == "0x14000"
27 assert len(kernel_cache
.dictionary()["dylibs"]) == 1
29 assert kernel_cache
.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
30 assert len(kernel_cache
.dictionary()["dylibs"][0]["segments"]) == 4
31 assert kernel_cache
.dictionary()["dylibs"][0]["segments"][0]["name"] == "__TEXT"
32 assert kernel_cache
.dictionary()["dylibs"][0]["segments"][0]["vmAddr"] == "0x4000"
33 assert kernel_cache
.dictionary()["dylibs"][0]["segments"][1]["name"] == "__DATA"
34 assert kernel_cache
.dictionary()["dylibs"][0]["segments"][1]["vmAddr"] == "0x10000"
35 assert kernel_cache
.dictionary()["dylibs"][0]["segments"][2]["name"] == "__TEXT_EXEC"
36 assert kernel_cache
.dictionary()["dylibs"][0]["segments"][2]["vmAddr"] == "0x8000"
37 assert kernel_cache
.dictionary()["dylibs"][0]["segments"][3]["name"] == "__LINKEDIT"
38 assert kernel_cache
.dictionary()["dylibs"][0]["segments"][3]["vmAddr"] == "0x14000"
40 # Now build an pageable cache using the baseline kernel collection
41 kernel_cache
.buildPageableKernelCollection("arm64", "/hello-world-pageablekc/pageable.kc", "/hello-world-pageablekc/main.kc", "/hello-world-pageablekc/extensions", ["com.apple.foo", "com.apple.bar"], [])
42 kernel_cache
.analyze("/hello-world-pageablekc/pageable.kc", ["-layout", "-arch", "arm64"])
44 assert len(kernel_cache
.dictionary()["cache-segments"]) == 6
45 assert kernel_cache
.dictionary()["cache-segments"][0]["name"] == "__TEXT"
46 assert kernel_cache
.dictionary()["cache-segments"][0]["vmAddr"] == "0x0"
47 assert kernel_cache
.dictionary()["cache-segments"][1]["name"] == "__PRELINK_TEXT"
48 assert kernel_cache
.dictionary()["cache-segments"][1]["vmAddr"] == "0x4000"
49 assert kernel_cache
.dictionary()["cache-segments"][2]["name"] == "__TEXT_EXEC"
50 assert kernel_cache
.dictionary()["cache-segments"][2]["vmAddr"] == "0xC000"
51 assert kernel_cache
.dictionary()["cache-segments"][3]["name"] == "__PRELINK_INFO"
52 assert kernel_cache
.dictionary()["cache-segments"][3]["vmAddr"] == "0x14000"
53 assert kernel_cache
.dictionary()["cache-segments"][4]["name"] == "__DATA"
54 assert kernel_cache
.dictionary()["cache-segments"][4]["vmAddr"] == "0x18000"
55 assert kernel_cache
.dictionary()["cache-segments"][5]["name"] == "__LINKEDIT"
56 assert kernel_cache
.dictionary()["cache-segments"][5]["vmAddr"] == "0x20000"
58 assert len(kernel_cache
.dictionary()["dylibs"]) == 2
60 assert kernel_cache
.dictionary()["dylibs"][0]["name"] == "com.apple.bar"
61 assert len(kernel_cache
.dictionary()["dylibs"][0]["segments"]) == 4
62 assert kernel_cache
.dictionary()["dylibs"][0]["segments"][0]["name"] == "__TEXT"
63 assert kernel_cache
.dictionary()["dylibs"][0]["segments"][0]["vmAddr"] == "0x4000"
64 assert kernel_cache
.dictionary()["dylibs"][0]["segments"][1]["name"] == "__TEXT_EXEC"
65 assert kernel_cache
.dictionary()["dylibs"][0]["segments"][1]["vmAddr"] == "0xC000"
66 assert kernel_cache
.dictionary()["dylibs"][0]["segments"][2]["name"] == "__DATA"
67 assert kernel_cache
.dictionary()["dylibs"][0]["segments"][2]["vmAddr"] == "0x18000"
68 assert kernel_cache
.dictionary()["dylibs"][0]["segments"][3]["name"] == "__LINKEDIT"
69 assert kernel_cache
.dictionary()["dylibs"][0]["segments"][3]["vmAddr"] == "0x20000"
71 assert kernel_cache
.dictionary()["dylibs"][1]["name"] == "com.apple.foo"
72 assert len(kernel_cache
.dictionary()["dylibs"][1]["segments"]) == 4
73 assert kernel_cache
.dictionary()["dylibs"][1]["segments"][0]["name"] == "__TEXT"
74 assert kernel_cache
.dictionary()["dylibs"][1]["segments"][0]["vmAddr"] == "0x8000"
75 assert kernel_cache
.dictionary()["dylibs"][1]["segments"][1]["name"] == "__TEXT_EXEC"
76 assert kernel_cache
.dictionary()["dylibs"][1]["segments"][1]["vmAddr"] == "0x10000"
77 assert kernel_cache
.dictionary()["dylibs"][1]["segments"][2]["name"] == "__DATA"
78 assert kernel_cache
.dictionary()["dylibs"][1]["segments"][2]["vmAddr"] == "0x1C000"
79 assert kernel_cache
.dictionary()["dylibs"][1]["segments"][3]["name"] == "__LINKEDIT"
80 assert kernel_cache
.dictionary()["dylibs"][1]["segments"][3]["vmAddr"] == "0x20000"
83 kernel_cache
.analyze("/hello-world-pageablekc/pageable.kc", ["-fixups", "-arch", "arm64"])
84 assert kernel_cache
.dictionary()["fixups"] == ""
85 assert len(kernel_cache
.dictionary()["dylibs"]) == 2
88 assert kernel_cache
.dictionary()["dylibs"][0]["name"] == "com.apple.bar"
89 assert len(kernel_cache
.dictionary()["dylibs"][0]["fixups"]) == 2
91 assert kernel_cache
.dictionary()["dylibs"][0]["fixups"]["0x14000"] == "kc(1) + 0x10000"
93 assert kernel_cache
.dictionary()["dylibs"][0]["fixups"]["0x14008"] == "kc(1) + 0x18010"
96 assert kernel_cache
.dictionary()["dylibs"][1]["name"] == "com.apple.foo"
97 assert len(kernel_cache
.dictionary()["dylibs"][1]["fixups"]) == 1
99 assert kernel_cache
.dictionary()["dylibs"][1]["fixups"]["0x14000"] == "kc(1) + 0x1C008"
102 # [~]> 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
103 # [~]> 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
104 # [~]> 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
105 # [~]> rm -r extensions/*.kext/*.ld