-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lld-macho] Handle user-provided dtrace symbols to avoid linking failure
This fixes #56238. ld64.lld currently does not generate __dof section in Mach-O, and -no_dtrace_dof option is on by default. However when there are user-defined dtrace symbols, ld64.lld will treat them as undefined symbols, which causes the linking to fail because lld cannot find their definitions. This patch allows ld64.lld to rewrite the instructions calling dtrace symbols to instructions like nop as what ld64 does; therefore, when encountered with user-provided dtrace probes, the linking can still succeed. I'm not sure whether support for dtrace is expected in lld, so for now I didn't add codes to make lld emit __dof section like ld64, and only made it possible to link with dtrace symbols provided. If this feature is needed, I can add that part in Dtrace.cpp & Dtrace.h. Reviewed By: int3, #lld-macho Differential Revision: https://reviews.llvm.org/D129062
- Loading branch information
1 parent
f18de76
commit 6c641d0
Showing
11 changed files
with
217 additions
and
0 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# REQUIRES: arm | ||
# RUN: rm -rf %t; split-file %s %t | ||
|
||
# RUN: llvm-mc -filetype=obj -triple=armv4t-apple-darwin %t/armv4t-dtrace.s -o %t/armv4t-dtrace.o | ||
# RUN: %lld -arch armv4t -o %t/armv4t-dtrace %t/armv4t-dtrace.o | ||
|
||
## If references of dtrace symbols are handled by lld, their relocation should be replaced with the following instructions | ||
# RUN: llvm-objdump --macho -D %t/armv4t-dtrace | FileCheck %s --check-prefix=CHECK-armv4t | ||
|
||
# CHECK-armv4t: 00 00 20 e0 eor r0, r0, r0 | ||
|
||
# CHECK-armv4t: 00 00 a0 e1 mov r0, r0 | ||
|
||
# RUN: llvm-mc -filetype=obj -triple=thumbv7-apple-darwin %t/armv7-dtrace.s -o %t/armv7-dtrace.o | ||
# RUN: %lld -arch armv7 -o %t/armv7-dtrace %t/armv7-dtrace.o | ||
|
||
## If references of dtrace symbols are handled by lld, their relocation should be replaced with the following instructions | ||
# RUN: llvm-objdump --macho -D %t/armv7-dtrace | FileCheck %s --check-prefix=CHECK-armv7 | ||
|
||
# CHECK-armv7: 40 40 eors r0, r0 | ||
# CHECK-armv7-NEXT: c0 46 mov r8, r8 | ||
|
||
# CHECK-armv7: c0 46 mov r8, r8 | ||
# CHECK-armv7-NEXT: c0 46 mov r8, r8 | ||
|
||
;--- armv4t-dtrace.s | ||
.globl _main | ||
_main: | ||
bl ___dtrace_isenabled$Foo$added$v1 | ||
.reference ___dtrace_typedefs$Foo$v2 | ||
bl ___dtrace_probe$Foo$added$v1$696e74 | ||
.reference ___dtrace_stability$Foo$v1$1_1_0_1_1_0_1_1_0_1_1_0_1_1_0 | ||
|
||
.subsections_via_symbols | ||
|
||
;--- armv7-dtrace.s | ||
.globl _main | ||
.thumb_func _main | ||
_main: | ||
bl ___dtrace_isenabled$Foo$added$v1 | ||
.reference ___dtrace_typedefs$Foo$v2 | ||
bl ___dtrace_probe$Foo$added$v1$696e74 | ||
.reference ___dtrace_stability$Foo$v1$1_1_0_1_1_0_1_1_0_1_1_0_1_1_0 | ||
|
||
.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# REQUIRES: aarch64 | ||
# RUN: rm -rf %t; split-file %s %t | ||
|
||
# RUN: llvm-mc -filetype=obj -triple=arm64_32-apple-darwin %t/arm64-32-dtrace.s -o %t/arm64-32-dtrace.o | ||
# RUN: %lld -arch arm64_32 -o %t/arm64-32-dtrace %t/arm64-32-dtrace.o | ||
|
||
## If references of dtrace symbols are handled by lld, their relocation should be replaced with the following instructions | ||
# RUN: llvm-objdump --macho -D %t/arm64-32-dtrace | FileCheck %s --check-prefix=CHECK | ||
|
||
# CHECK: 00 00 80 d2 mov x0, #0 | ||
|
||
# CHECK: 1f 20 03 d5 nop | ||
|
||
#--- arm64-32-dtrace.s | ||
.globl _main | ||
_main: | ||
bl ___dtrace_isenabled$Foo$added$v1 | ||
.reference ___dtrace_typedefs$Foo$v2 | ||
bl ___dtrace_probe$Foo$added$v1$696e74 | ||
.reference ___dtrace_stability$Foo$v1$1_1_0_1_1_0_1_1_0_1_1_0_1_1_0 | ||
ret | ||
|
||
.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# REQUIRES: aarch64 | ||
# RUN: rm -rf %t; split-file %s %t | ||
|
||
# RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin %t/arm64-dtrace.s -o %t/arm64-dtrace.o | ||
# RUN: %lld -arch arm64 -o %t/arm64-dtrace %t/arm64-dtrace.o | ||
|
||
## If references of dtrace symbols are handled by lld, their relocation should be replaced with the following instructions | ||
# RUN: llvm-objdump --macho -D %t/arm64-dtrace | FileCheck %s --check-prefix=CHECK | ||
|
||
# CHECK: 00 00 80 d2 mov x0, #0 | ||
|
||
# CHECK: 1f 20 03 d5 nop | ||
|
||
#--- arm64-dtrace.s | ||
.globl _main | ||
_main: | ||
bl ___dtrace_isenabled$Foo$added$v1 | ||
.reference ___dtrace_typedefs$Foo$v2 | ||
bl ___dtrace_probe$Foo$added$v1$696e74 | ||
.reference ___dtrace_stability$Foo$v1$1_1_0_1_1_0_1_1_0_1_1_0_1_1_0 | ||
ret | ||
|
||
.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# REQUIRES: x86 | ||
# RUN: rm -rf %t; split-file %s %t | ||
|
||
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/x86_64-dtrace.s -o %t/x86_64-dtrace.o | ||
# RUN: %lld -arch x86_64 -o %t/x86_64-dtrace %t/x86_64-dtrace.o | ||
|
||
## If references of dtrace symbols are handled by lld, their relocation should be replaced with the following instructions | ||
# RUN: llvm-objdump --macho -D %t/x86_64-dtrace | FileCheck %s --check-prefix=CHECK | ||
|
||
# CHECK: 33 c0 xorl %eax, %eax | ||
# CHECK-NEXT: 90 nop | ||
# CHECK-NEXT: 90 nop | ||
# CHECK-NEXT: 90 nop | ||
|
||
# CHECK: 90 nop | ||
# CHECK-NEXT: 0f 1f 40 00 nopl (%rax) | ||
|
||
#--- x86_64-dtrace.s | ||
.globl _main | ||
_main: | ||
callq ___dtrace_isenabled$Foo$added$v1 | ||
.reference ___dtrace_typedefs$Foo$v2 | ||
callq ___dtrace_probe$Foo$added$v1$696e74 | ||
.reference ___dtrace_stability$Foo$v1$1_1_0_1_1_0_1_1_0_1_1_0_1_1_0 | ||
retq | ||
|
||
.subsections_via_symbols |