forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BOLT] Support input binaries that use R_X86_GOTPC64
In large code model, the address of GOT is calculated by the static linker via R_X86_GOTPC64 reloc applied against a MOVABSQ instruction. In the final binary, it can be disassembled as a regular immediate, but because such immediate is the result of PC-relative pointer arithmetic, we need to parse this relocation and update this calculation whenever we move code, otherwise we break the code trying to read GOT. A test case showing how GOT is accessed was provided. Reviewed By: #bolt, maksfb Differential Revision: https://reviews.llvm.org/D158911
- Loading branch information
1 parent
a29e8ef
commit 853e126
Showing
11 changed files
with
207 additions
and
1 deletion.
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
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,57 @@ | ||
# A variation of gotoff-large-code-model.s that accesses GOT value | ||
# with a slightly different code sequence. | ||
|
||
# REQUIRES: system-linux | ||
|
||
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown \ | ||
# RUN: %s -o %t.o | ||
# RUN: %clang %cflags -no-pie %t.o -o %t.exe -Wl,-q | ||
|
||
# RUN: llvm-bolt %t.exe --funcs init_impls --lite \ | ||
# RUN: -o %t.bolted | ||
# RUN: %t.bolted | FileCheck %s | ||
|
||
.section .rodata.str1.1,"aMS",@progbits,1 | ||
.LC2: | ||
.string "Hello, world\n" | ||
.text | ||
.p2align 4 | ||
.globl init_impls | ||
.type init_impls, @function | ||
init_impls: | ||
.cfi_startproc | ||
push %rbp | ||
mov %rsp,%rbp | ||
push %r15 | ||
push %rbx | ||
sub $0x8,%rsp | ||
lea 1f(%rip),%rbx | ||
# R_X86_64_GOTPC64 _GLOBAL_OFFSET_TABLE_+0x2 | ||
1: movabsq $_GLOBAL_OFFSET_TABLE_, %r11 | ||
add %r11,%rbx | ||
# R_X86_64_GOTOFF64 .LC2 | ||
movabs $.LC2@gotoff,%rax | ||
lea (%rbx,%rax,1),%rax | ||
mov %rax,%rdi | ||
mov %rbx,%r15 | ||
# R_X86_64_PLTOFF64 puts | ||
movabs $puts@pltoff,%rax | ||
add %rbx,%rax | ||
call *%rax | ||
add $0x8,%rsp | ||
pop %rbx | ||
pop %r15 | ||
pop %rbp | ||
retq | ||
.cfi_endproc | ||
.size init_impls, .-init_impls | ||
|
||
.globl main | ||
.type main, @function | ||
.p2align 4 | ||
main: | ||
callq init_impls | ||
xorq %rax, %rax | ||
ret | ||
|
||
# CHECK: Hello, world |
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,55 @@ | ||
# REQUIRES: system-linux | ||
|
||
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown \ | ||
# RUN: %s -o %t.o | ||
# RUN: %clang %cflags -no-pie %t.o -o %t.exe -Wl,-q | ||
|
||
# RUN: llvm-bolt %t.exe --funcs init_impls --lite \ | ||
# RUN: -o %t.bolted | ||
# RUN: %t.bolted | FileCheck %s | ||
|
||
.section .rodata.str1.1,"aMS",@progbits,1 | ||
.LC2: | ||
.string "Hello, world\n" | ||
.text | ||
.p2align 4 | ||
.globl init_impls | ||
.type init_impls, @function | ||
init_impls: | ||
.cfi_startproc | ||
push %rbp | ||
mov %rsp,%rbp | ||
push %r15 | ||
push %rbx | ||
sub $0x8,%rsp | ||
1: | ||
lea 1b(%rip),%rbx | ||
# R_X86_64_GOTPC64 _GLOBAL_OFFSET_TABLE_+0x9 | ||
movabsq $_GLOBAL_OFFSET_TABLE_-1b, %r11 | ||
add %r11,%rbx | ||
# R_X86_64_GOTOFF64 .LC2 | ||
movabs $.LC2@gotoff,%rax | ||
lea (%rbx,%rax,1),%rax | ||
mov %rax,%rdi | ||
mov %rbx,%r15 | ||
# R_X86_64_PLTOFF64 puts | ||
movabs $puts@pltoff,%rax | ||
add %rbx,%rax | ||
call *%rax | ||
add $0x8,%rsp | ||
pop %rbx | ||
pop %r15 | ||
pop %rbp | ||
retq | ||
.cfi_endproc | ||
.size init_impls, .-init_impls | ||
|
||
.globl main | ||
.type main, @function | ||
.p2align 4 | ||
main: | ||
callq init_impls | ||
xorq %rax, %rax | ||
ret | ||
|
||
# CHECK: Hello, world |