Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BOLT] Fix sign issue when validating X86 relocations
Summary: In analyzeRelocations, we extract the result of the relocation from binary code to recreate the target of it in a few special cases. For R_X86_64_32S relocations, however, we were neglecting the possibility of the encoded value in the instruction to be negative. (cherry picked from FBD24096347)
- Loading branch information
1 parent
2808c80
commit d7fb998
Showing
4 changed files
with
58 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# This reproduces a bug triggered by a relocation referencing a section symbol | ||
# plus a negative reloc. BOLT handles such cases specially, but while doing so, | ||
# it was failing to sign extend a negative result for the relocation (encoded | ||
# in the immediate operand of an LEA instruction). | ||
# Originally triggered by https://fossies.org/linux/glib/glib/guniprop.c | ||
# Line 550: const gchar *p = special_case_table + val - 0x1000000; | ||
|
||
# REQUIRES: system-linux | ||
|
||
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown \ | ||
# RUN: %s -o %t.o | ||
# Delete our BB symbols so BOLT doesn't mark them as entry points | ||
# RUN: strip --strip-unneeded %t.o | ||
# RUN: %host_cc %t.o -o %t.exe -Wl,-q | ||
|
||
# RUN: llvm-bolt %t.exe -relocs=1 -print-finalized -print-only=main -o %t.out | ||
|
||
# RUN: %t.out 1 2 | ||
|
||
.text | ||
.globl main | ||
.type main, %function | ||
.p2align 4 | ||
main: | ||
pushq %rbp | ||
movq %rsp, %rbp | ||
subq $0x18, %rsp | ||
cmpl $0x2, %edi | ||
jb .BBend | ||
.BB2: | ||
leaq .data-0x1000000, %rsi # Use a large negative addend to cause a | ||
# negative result to be encoded in LEA | ||
addq $0x1000000, %rsi # Eventually program logic compensates to get | ||
# a real address | ||
movq $2, %rbx | ||
xorq %rax, %rax | ||
movb (%rsi), %al | ||
addq %rbx, %rax | ||
movb %al, (%rsi) | ||
leaq mystring, %rdi | ||
callq puts | ||
|
||
.BBend: | ||
xorq %rax, %rax | ||
leaveq | ||
retq | ||
.size main, .-main | ||
|
||
.data | ||
mystring: .asciz "0 is rbx mod 10 contents in decimal\n" |