]> git.saurik.com Git - apple/dyld.git/blob - testing/kernel-cache-tests/auxkc-bind-to-pageablekc/test.py
dyld-851.27.tar.gz
[apple/dyld.git] / testing / kernel-cache-tests / auxkc-bind-to-pageablekc / test.py
1 #!/usr/bin/python2.7
2
3 import os
4 import KernelCollection
5
6 # This verifies that a kext can bind to another kext
7 # foo.kext exports foo and bar.kext uses it
8
9 def check(kernel_cache):
10 kernel_cache.buildKernelCollection("arm64", "/auxkc-bind-to-pageablekc/main.kc", "/auxkc-bind-to-pageablekc/main.kernel", "", [], [])
11 kernel_cache.analyze("/auxkc-bind-to-pageablekc/main.kc", ["-layout", "-arch", "arm64"])
12
13 # Now build an pageable cache using the baseline kernel collection
14 kernel_cache.buildPageableKernelCollection("arm64", "/auxkc-bind-to-pageablekc/pageable.kc", "/auxkc-bind-to-pageablekc/main.kc", "/auxkc-bind-to-pageablekc/extensions", ["com.apple.foo"], [])
15 kernel_cache.analyze("/auxkc-bind-to-pageablekc/pageable.kc", ["-symbols", "-arch", "arm64"])
16
17 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.foo"
18 assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][0]["name"] == "_foo"
19 assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][0]["vmAddr"] == "0x8000"
20
21 # Now build an aux cache using the baseline and pageable kernel collections
22 kernel_cache.buildAuxKernelCollection("arm64", "/auxkc-bind-to-pageablekc/aux.kc", "/auxkc-bind-to-pageablekc/main.kc", "/auxkc-bind-to-pageablekc/pageable.kc", "/auxkc-bind-to-pageablekc/extensions", ["com.apple.bar"], [])
23 kernel_cache.analyze("/auxkc-bind-to-pageablekc/aux.kc", ["-fixups", "-arch", "arm64"])
24
25 # bar.kext
26 assert len(kernel_cache.dictionary()["fixups"]) == 1
27 # extern int foo()
28 assert kernel_cache.dictionary()["fixups"]["0x4000"] == "kc(1) + 0x8000"
29
30
31 # [~]> 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
32 # [~]> 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
33 # [~]> 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
34 # [~]> rm -r extensions/*.kext/*.ld
35