Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[llvm-jitlink] Add -harness option to llvm-jitlink.
The -harness option enables new testing use-cases for llvm-jitlink. It takes a list of objects to treat as a test harness for any regular objects passed to llvm-jitlink. If any files are passed using the -harness option then the following transformations are applied to all other files: (1) Symbols definitions that are referenced by the harness files are promoted to default scope. (This enables access to statics from test harness). (2) Symbols definitions that clash with definitions in the harness files are deleted. (This enables interposition by test harness). (3) All other definitions in regular files are demoted to local scope. (This causes untested code to be dead stripped, reducing memory cost and eliminating spurious unresolved symbol errors from untested code). These transformations allow the harness files to reference and interpose symbols in the regular object files, which can be used to support execution tests (including fuzz tests) of functions in relocatable objects produced by a build.
- Loading branch information
Showing
6 changed files
with
320 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
llvm/test/ExecutionEngine/JITLink/X86/Inputs/MachO_test_harness_test.s
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
.section __TEXT,__text,regular,pure_instructions | ||
.globl _unused_public_function | ||
.p2align 4, 0x90 | ||
_unused_public_function: | ||
jmp _unresolvable_external | ||
|
||
.p2align 4, 0x90 | ||
_unused_private_function: | ||
jmp _unresolvable_external | ||
|
||
.globl _public_func_to_interpose | ||
.p2align 4, 0x90 | ||
_public_func_to_interpose: | ||
retq | ||
|
||
.p2align 4, 0x90 | ||
_private_func_to_interpose: | ||
retq | ||
|
||
.globl _public_func_to_test | ||
.p2align 4, 0x90 | ||
_public_func_to_test: | ||
jmp _public_func_to_interpose | ||
|
||
.p2align 4, 0x90 | ||
_private_func_to_test: | ||
jmp _private_func_to_interpose | ||
|
||
.section __DATA,__data | ||
.globl _public_func_to_interpose_as_seen_by_test | ||
.p2align 3 | ||
_public_func_to_interpose_as_seen_by_test: | ||
.quad _public_func_to_interpose | ||
|
||
.globl _private_func_to_interpose_as_seen_by_test | ||
.p2align 3 | ||
_private_func_to_interpose_as_seen_by_test: | ||
.quad _private_func_to_interpose | ||
|
||
.subsections_via_symbols |
65 changes: 65 additions & 0 deletions
65
llvm/test/ExecutionEngine/JITLink/X86/MachO_test_harness_harness.s
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# RUN: rm -rf %t && mkdir -p %t | ||
# RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj \ | ||
# RUN: -o %t/file_to_test.o %S/Inputs/MachO_test_harness_test.s | ||
# RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj \ | ||
# RUN: -o %t/test_harness.o %s | ||
# RUN: llvm-jitlink -noexec -check %s %t/file_to_test.o \ | ||
# RUN: -harness %t/test_harness.o | ||
# | ||
# Check that we | ||
# (1) Can call global symbols in the test object. | ||
# (2) Can call private symbols in the test object. | ||
# (3) Can interpose global symbols in the test object. | ||
# (4) Can interpose private symbols in the test object. | ||
# (5) Don't need to resolve unused externals in the test object. | ||
|
||
.section __TEXT,__text,regular,pure_instructions | ||
|
||
.globl _public_func_to_interpose | ||
.p2align 4, 0x90 | ||
_public_func_to_interpose: | ||
retq | ||
|
||
.globl _private_func_to_interpose | ||
.p2align 4, 0x90 | ||
_private_func_to_interpose: | ||
retq | ||
|
||
.globl _main | ||
.p2align 4, 0x90 | ||
_main: | ||
callq _public_func_to_test | ||
callq _private_func_to_test | ||
xorl %eax, %eax | ||
retq | ||
|
||
.section __DATA,__data | ||
|
||
# Check that the harness and test file agree on the address of the addresses | ||
# of the interposes: | ||
|
||
# jitlink-check: *{8}_public_func_to_interpose_as_seen_by_harness = \ | ||
# jitlink-check: *{8}_public_func_to_interpose_as_seen_by_test | ||
|
||
# jitlink-check: *{8}_private_func_to_interpose_as_seen_by_harness = \ | ||
# jitlink-check: *{8}_private_func_to_interpose_as_seen_by_test | ||
|
||
.globl _public_func_to_interpose_as_seen_by_harness | ||
.p2align 3 | ||
_public_func_to_interpose_as_seen_by_harness: | ||
.quad _public_func_to_interpose | ||
|
||
.globl _private_func_to_interpose_as_seen_by_harness | ||
.p2align 3 | ||
_private_func_to_interpose_as_seen_by_harness: | ||
.quad _private_func_to_interpose | ||
|
||
# We need to reference the *_as_seen_by_test pointers used above to ensure | ||
# that they're not dead-stripped as unused. | ||
.globl _anchor_test_case_pointers | ||
.p2align 3 | ||
_anchor_test_case_pointers: | ||
.quad _public_func_to_interpose_as_seen_by_test | ||
.quad _private_func_to_interpose_as_seen_by_test | ||
|
||
.subsections_via_symbols |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.