]> git.saurik.com Git - apple/dyld.git/blob - testing/kernel-cache-tests/text-fixups-x86_64-auxkc/test.py
dyld-832.7.1.tar.gz
[apple/dyld.git] / testing / kernel-cache-tests / text-fixups-x86_64-auxkc / test.py
1 #!/usr/bin/python2.7
2
3 import os
4 import KernelCollection
5
6
7 def findGlobalSymbolVMAddr(kernel_cache, dylib_index, symbol_name):
8 for symbol_and_addr in kernel_cache.dictionary()["dylibs"][dylib_index]["global-symbols"]:
9 if symbol_and_addr["name"] == symbol_name:
10 return symbol_and_addr["vmAddr"]
11 return None
12
13 def check(kernel_cache):
14 kernel_cache.buildKernelCollection("x86_64", "/text-fixups-x86_64-auxkc/main.kc", "/text-fixups-x86_64-auxkc/main.kernel", "/text-fixups-x86_64-auxkc/extensions", [], [])
15 kernel_cache.analyze("/text-fixups-x86_64-auxkc/main.kc", ["-layout", "-arch", "x86_64"])
16
17 assert len(kernel_cache.dictionary()["dylibs"]) == 1
18 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
19
20 # Now build an aux cache using the baseline kernel collection
21 kernel_cache.buildAuxKernelCollection("x86_64", "/text-fixups-x86_64-auxkc/aux.kc", "/text-fixups-x86_64-auxkc/main.kc", "", "/text-fixups-x86_64-auxkc/extensions", ["com.apple.foo", "com.apple.bar"], [])
22 kernel_cache.analyze("/text-fixups-x86_64-auxkc/aux.kc", ["-layout", "-arch", "x86_64"])
23 assert len(kernel_cache.dictionary()["dylibs"]) == 2
24 # bar.kext
25 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.bar"
26 assert len(kernel_cache.dictionary()["dylibs"][0]["segments"]) == 3
27 assert kernel_cache.dictionary()["dylibs"][0]["segments"][0]["name"] == "__TEXT"
28 assert kernel_cache.dictionary()["dylibs"][0]["segments"][0]["vmAddr"] == "0x8000"
29 assert kernel_cache.dictionary()["dylibs"][0]["segments"][1]["name"] == "__DATA"
30 assert kernel_cache.dictionary()["dylibs"][0]["segments"][1]["vmAddr"] == "0x9000"
31 assert kernel_cache.dictionary()["dylibs"][0]["segments"][2]["name"] == "__LINKEDIT"
32 assert kernel_cache.dictionary()["dylibs"][0]["segments"][2]["vmAddr"] == "0xC000"
33 # foo.kext
34 assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.foo"
35 assert len(kernel_cache.dictionary()["dylibs"][1]["segments"]) == 3
36 assert kernel_cache.dictionary()["dylibs"][1]["segments"][0]["name"] == "__TEXT"
37 assert kernel_cache.dictionary()["dylibs"][1]["segments"][0]["vmAddr"] == "0xA000"
38 assert kernel_cache.dictionary()["dylibs"][1]["segments"][1]["name"] == "__DATA"
39 assert kernel_cache.dictionary()["dylibs"][1]["segments"][1]["vmAddr"] == "0xB000"
40 assert kernel_cache.dictionary()["dylibs"][1]["segments"][2]["name"] == "__LINKEDIT"
41 assert kernel_cache.dictionary()["dylibs"][1]["segments"][2]["vmAddr"] == "0xC000"
42
43 # Find the sybmols the fixups point to
44 kernel_cache.analyze("/text-fixups-x86_64-auxkc/aux.kc", ["-symbols", "-arch", "x86_64"])
45 barAddress = findGlobalSymbolVMAddr(kernel_cache, 0, "_bar")
46 gAddress = findGlobalSymbolVMAddr(kernel_cache, 1, "_g")
47
48 # Check the fixups
49 kernel_cache.analyze("/text-fixups-x86_64-auxkc/aux.kc", ["-fixups", "-arch", "x86_64"])
50 assert len(kernel_cache.dictionary()["dylibs"]) == 2
51
52 # bar.kext
53 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.bar"
54 assert len(kernel_cache.dictionary()["dylibs"][0]["fixups"]) == 1
55 assert kernel_cache.dictionary()["dylibs"][0]["fixups"]["0x4FF0"] == "kc(3) + " + barAddress
56
57 # foo.kext
58 assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.foo"
59
60 assert len(kernel_cache.dictionary()["dylibs"][1]["fixups"]) == 1
61 assert kernel_cache.dictionary()["dylibs"][1]["fixups"]["0x4FF0"] == "kc(3) + " + gAddress
62
63 # [~]> 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,0xffffff8000200000 -Wl,-segaddr,__HIB,0xffffff8000100000 -Wl,-add_split_seg_info -Wl,-read_only_relocs,suppress -Wl,-install_name,/usr/lib/swift/split.seg.v2.hack
64 # [~]> xcrun -sdk macosx.internal cc -arch x86_64 -Wl,-kext -mkernel -nostdlib foo.c -o extensions/foo.kext/foo
65 # [~]> xcrun -sdk macosx.internal cc -arch x86_64 -Wl,-kext -mkernel -nostdlib bar.c -o extensions/bar.kext/bar
66