[BOLT] Fix references in ignored functions in CFG state (#140678)
When we call setIgnored() on functions that already have CFG built, these functions are not going to get emitted and we risk missing external function references being updated. To mitigate the potential issues, run scanExternalRefs() on such functions to create patches/relocations. Since scanExternalRefs() relies on function relocations, we have to preserve relocations until the function is emitted. As a result, the memory overhead without debug info update could reach up to 2%.
This commit is contained in:
33
bolt/test/AArch64/patch-ignored.s
Normal file
33
bolt/test/AArch64/patch-ignored.s
Normal file
@@ -0,0 +1,33 @@
|
||||
## Check that llvm-bolt patches functions that are getting ignored after their
|
||||
## CFG was constructed.
|
||||
|
||||
# RUN: %clang %cflags %s -o %t.exe -Wl,-q
|
||||
# RUN: llvm-bolt %t.exe -o %t.bolt --force-patch 2>&1 | FileCheck %s
|
||||
# RUN: llvm-objdump -d %t.bolt | FileCheck %s --check-prefix=CHECK-OBJDUMP
|
||||
|
||||
.text
|
||||
|
||||
## The function is too small to be patched and BOLT is forced to ignore it under
|
||||
## --force-patch. Check that the reference to _start is updated.
|
||||
# CHECK: BOLT-WARNING: failed to patch entries in unpatchable
|
||||
.globl unpatchable
|
||||
.type unpatchable, %function
|
||||
unpatchable:
|
||||
.cfi_startproc
|
||||
# CHECK-OBJDUMP: <unpatchable>:
|
||||
# CHECK-OBJDUMP-NEXT: bl {{.*}} <_start>
|
||||
bl _start
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size unpatchable, .-unpatchable
|
||||
|
||||
.globl _start
|
||||
.type _start, %function
|
||||
_start:
|
||||
.cfi_startproc
|
||||
cmp x0, 1
|
||||
b.eq .L0
|
||||
.L0:
|
||||
ret x30
|
||||
.cfi_endproc
|
||||
.size _start, .-_start
|
||||
44
bolt/test/X86/patch-ignored.s
Normal file
44
bolt/test/X86/patch-ignored.s
Normal file
@@ -0,0 +1,44 @@
|
||||
## Check that llvm-bolt patches functions that are getting ignored after their
|
||||
## CFG was constructed.
|
||||
|
||||
# RUN: %clang %cflags %s -o %t.exe -Wl,-q
|
||||
# RUN: llvm-bolt %t.exe -o %t.bolt 2>&1 | FileCheck %s
|
||||
# RUN: llvm-objdump -d %t.bolt | FileCheck %s --check-prefix=CHECK-OBJDUMP
|
||||
|
||||
.text
|
||||
|
||||
## After the CFG is built, the following function will be marked as ignored
|
||||
## due to the presence of the internal call.
|
||||
# CHECK: BOLT-WARNING: will skip the following function
|
||||
# CHECK-NEXT: internal_call
|
||||
.globl internal_call
|
||||
.type internal_call, %function
|
||||
internal_call:
|
||||
.cfi_startproc
|
||||
# CHECK-OBJDUMP: <internal_call>:
|
||||
call .L1
|
||||
jmp .L2
|
||||
# CHECK-OBJDUMP: jmp
|
||||
.L1:
|
||||
jmp _start
|
||||
# CHECK-OBJDUMP: jmp
|
||||
# CHECK-OBJDUMP-SAME: <_start>
|
||||
ret
|
||||
.L2:
|
||||
jmp _start
|
||||
# CHECK-OBJDUMP: jmp
|
||||
# CHECK-OBJDUMP-SAME: <_start>
|
||||
.cfi_endproc
|
||||
.size internal_call, .-internal_call
|
||||
|
||||
.globl _start
|
||||
.type _start, %function
|
||||
_start:
|
||||
.cfi_startproc
|
||||
cmpq %rdi, 1
|
||||
jne .L0
|
||||
movq %rdi, %rax
|
||||
.L0:
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size _start, .-_start
|
||||
Reference in New Issue
Block a user