xref: /llvm-project/bolt/test/X86/gotpcrelx.s (revision 887f7002b65f7376c7a5004535bd08c95bdaa8f8)
1# REQUIRES: system-linux
2
3## Check that BOLT correctly handles different types of instructions with
4## R_X86_64_GOTPCRELX or R_X86_64_REX_GOTPCRELX relocations and different
5## kinds of handling of the relocation by the linker (no relaxation, pic, and
6## non-pic).
7
8# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-linux %s -o %t.o
9# RUN: ld.lld %t.o -o %t.exe -q
10# RUN: ld.lld %t.o -o %t.pie.exe -q -pie
11# RUN: ld.lld %t.o -o %t.no-relax.exe -q --no-relax
12# RUN: llvm-bolt %t.exe --relocs -o %t.out --print-cfg --print-only=_start \
13# RUN:   2>&1 | FileCheck --check-prefix=BOLT %s
14# RUN: llvm-bolt %t.pie.exe -o %t.null --print-cfg --print-only=_start \
15# RUN:   2>&1 | FileCheck --check-prefix=PIE-BOLT %s
16# RUN: llvm-bolt %t.no-relax.exe -o %t.null --print-cfg --print-only=_start \
17# RUN:   2>&1 | FileCheck --check-prefix=NO-RELAX-BOLT %s
18# RUN: llvm-objdump -d --no-show-raw-insn --print-imm-hex \
19# RUN:   %t.out | FileCheck --check-prefix=DISASM %s
20
21## Relocate foo only and check that code references from _start (that is
22## otherwise preserved) are updated.
23
24# RUN: llvm-bolt %t.exe --relocs -o %t.lite.out --funcs=foo
25# RUN: llvm-objdump -d --no-show-raw-insn --print-imm-hex \
26# RUN:   %t.lite.out | FileCheck --check-prefix=DISASM %s
27
28  .text
29  .globl _start
30  .type _start, %function
31_start:
32  .cfi_startproc
33# DISASM: <_start>:
34
35                      call *foo@GOTPCREL(%rip)
36# NO-RELAX-BOLT:      callq *{{.*}}(%rip)
37# BOLT:               callq foo
38# PIE-BOLT:           callq foo
39# DISASM-NEXT:        callq 0x[[#%x,ADDR:]]
40
41                      movq foo@GOTPCREL(%rip), %rdi
42# NO-RELAX-BOLT-NEXT: movq {{.*}}(%rip), %rdi
43# BOLT-NEXT:          leaq foo(%rip), %rdi
44# PIE-BOLT-NEXT:      leaq foo(%rip), %rdi
45# DISASM-NEXT:        leaq {{.*}}(%rip), %rdi # 0x[[#ADDR]]
46
47                      movl foo@GOTPCREL+4(%rip), %edi
48# NO-RELAX-BOLT-NEXT: movl {{.*}}(%rip), %edi
49# BOLT-NEXT:          movl {{.*}}(%rip), %edi
50# PIE-BOLT-NEXT:      movl {{.*}}(%rip), %edi
51# DISASM-NEXT:        movl {{.*}}(%rip), %edi
52
53                      test %rdi, foo@GOTPCREL(%rip)
54# NO-RELAX-BOLT-NEXT: testq %rdi, DATA{{.*}}(%rip)
55# BOLT-NEXT:          testq $foo, %rdi
56# PIE-BOLT-NEXT:      testq %rdi, DATA{{.*}}(%rip)
57# DISASM-NEXT:        testq $0x[[#ADDR]], %rdi
58
59                      cmpq foo@GOTPCREL(%rip), %rax
60# NO-RELAX-BOLT-NEXT: cmpq DATA{{.*}}(%rip), %rax
61# BOLT-NEXT:          cmpq $foo, %rax
62# PIE-BOLT-NEXT:      cmpq DATA{{.*}}(%rip), %rax
63# DISASM-NEXT:        cmpq $0x[[#ADDR]], %rax
64
65                      jmp *foo@GOTPCREL(%rip)
66# NO-RELAX-BOLT-NEXT: jmpq *DATA{{.*}}(%rip)
67# BOLT-NEXT:          jmp foo
68# PIE-BOLT-NEXT:      jmp foo
69# DISASM-NEXT:        jmp 0x[[#ADDR]]
70
71# DISASM: [[#ADDR]] <foo>:
72
73  ret
74  .cfi_endproc
75  .size _start, .-_start
76
77  .globl foo
78  .type foo, %function
79foo:
80  .cfi_startproc
81  ret
82  .cfi_endproc
83  .size foo, .-foo
84