dyld-832.7.1.tar.gz
[apple/dyld.git] / testing / kernel-cache-tests / kext-receipts / test.py
1 #!/usr/bin/python2.7
2
3 import os
4 import KernelCollection
5
6
7 def check(kernel_cache):
8 kernel_cache.buildKernelCollection("arm64", "/kext-receipts/main.kc", "/kext-receipts/main.kernel", None, [],
9 ["-sectcreate", "__SMALL", "", "$PWD/kext-receipts/small.txt",
10 "-sectcreate", "__SIXTEEN_CHARSS", "__sixteen_chaars", "$PWD/kext-receipts/large.txt",
11 "-sectcreate", "__SIXTEEN_CHARSS", "__large2", "$PWD/kext-receipts/large2.txt"])
12
13 # Check the layout
14 kernel_cache.analyze("/kext-receipts/main.kc", ["-layout", "-arch", "arm64"])
15
16 assert len(kernel_cache.dictionary()["cache-segments"]) == 8
17 assert kernel_cache.dictionary()["cache-segments"][0]["name"] == "__TEXT"
18 assert kernel_cache.dictionary()["cache-segments"][0]["vmAddr"] == "0x0"
19 assert kernel_cache.dictionary()["cache-segments"][1]["name"] == "__PRELINK_TEXT"
20 assert kernel_cache.dictionary()["cache-segments"][1]["vmAddr"] == "0x4000"
21 assert kernel_cache.dictionary()["cache-segments"][2]["name"] == "__TEXT_EXEC"
22 assert kernel_cache.dictionary()["cache-segments"][2]["vmAddr"] == "0x4000"
23
24 # small.txt
25 assert kernel_cache.dictionary()["cache-segments"][3]["name"] == "__SMALL"
26 assert kernel_cache.dictionary()["cache-segments"][3]["vmAddr"] == "0xC000"
27 assert not "sections" in kernel_cache.dictionary()["cache-segments"][3]
28
29 # large.txt, then large2.txt
30 assert kernel_cache.dictionary()["cache-segments"][4]["name"] == "__SIXTEEN_CHARSS"
31 assert kernel_cache.dictionary()["cache-segments"][4]["vmAddr"] == "0x10000"
32 assert kernel_cache.dictionary()["cache-segments"][4]["vmSize"] == "0x4000"
33 assert len(kernel_cache.dictionary()["cache-segments"][4]["sections"]) == 2
34 assert kernel_cache.dictionary()["cache-segments"][4]["sections"][0]["name"] == "__sixteen_chaars";
35 assert kernel_cache.dictionary()["cache-segments"][4]["sections"][0]["vmAddr"] == "0x10000";
36 assert kernel_cache.dictionary()["cache-segments"][4]["sections"][0]["vmEnd"] == "0x10124";
37 assert kernel_cache.dictionary()["cache-segments"][4]["sections"][0]["vmSize"] == "0x124";
38 assert kernel_cache.dictionary()["cache-segments"][4]["sections"][1]["name"] == "__large2";
39 assert kernel_cache.dictionary()["cache-segments"][4]["sections"][1]["vmAddr"] == "0x10124";
40 assert kernel_cache.dictionary()["cache-segments"][4]["sections"][1]["vmEnd"] == "0x1012E";
41 assert kernel_cache.dictionary()["cache-segments"][4]["sections"][1]["vmSize"] == "0xA";
42
43 assert kernel_cache.dictionary()["cache-segments"][5]["name"] == "__PRELINK_INFO"
44 assert kernel_cache.dictionary()["cache-segments"][5]["vmAddr"] == "0x14000"
45 assert kernel_cache.dictionary()["cache-segments"][6]["name"] == "__DATA"
46 assert kernel_cache.dictionary()["cache-segments"][6]["vmAddr"] == "0x18000"
47 assert kernel_cache.dictionary()["cache-segments"][7]["name"] == "__LINKEDIT"
48 assert kernel_cache.dictionary()["cache-segments"][7]["vmAddr"] == "0x20000"
49
50 assert len(kernel_cache.dictionary()["dylibs"]) == 1
51 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
52 assert len(kernel_cache.dictionary()["dylibs"][0]["segments"]) == 4
53 assert kernel_cache.dictionary()["dylibs"][0]["segments"][0]["name"] == "__TEXT"
54 assert kernel_cache.dictionary()["dylibs"][0]["segments"][0]["vmAddr"] == "0x4000"
55 assert kernel_cache.dictionary()["dylibs"][0]["segments"][1]["name"] == "__DATA"
56 assert kernel_cache.dictionary()["dylibs"][0]["segments"][1]["vmAddr"] == "0x18000"
57 assert kernel_cache.dictionary()["dylibs"][0]["segments"][2]["name"] == "__TEXT_EXEC"
58 assert kernel_cache.dictionary()["dylibs"][0]["segments"][2]["vmAddr"] == "0x8000"
59 assert kernel_cache.dictionary()["dylibs"][0]["segments"][3]["name"] == "__LINKEDIT"
60 assert kernel_cache.dictionary()["dylibs"][0]["segments"][3]["vmAddr"] == "0x20000"
61
62 # Check the entry point
63 kernel_cache.analyze("/kext-receipts/main.kc", ["-entrypoint", "-arch", "arm64"])
64 assert kernel_cache.dictionary()["entrypoint"] == "0x8000"
65
66 # Check the fixups
67 kernel_cache.analyze("/kext-receipts/main.kc", ["-fixups", "-arch", "arm64"])
68 assert len(kernel_cache.dictionary()["fixups"]) == 4
69 assert kernel_cache.dictionary()["fixups"]["0x18000"] == "kc(0) + 0x18028"
70 assert kernel_cache.dictionary()["fixups"]["0x18008"] == "kc(0) + 0x18028"
71 assert kernel_cache.dictionary()["fixups"]["0x18018"] == "kc(0) + 0x1802C"
72 assert kernel_cache.dictionary()["fixups"]["0x18020"] == "kc(0) + 0x1802D"
73 assert len(kernel_cache.dictionary()["dylibs"]) == 1
74 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
75 assert kernel_cache.dictionary()["dylibs"][0]["fixups"] == "none"
76
77 # [~]> xcrun -sdk iphoneos.internal cc -arch arm64 -Wl,-static -mkernel -nostdlib -Wl,-add_split_seg_info -Wl,-e,__start -Wl,-pie main.c -Wl,-pagezero_size,0x0 -Wl,-rename_section,__TEXT,__text,__TEXT_EXEC,__text -o main.kernel -Wl,-install_name,/usr/lib/swift/split.seg.v2.hack
78