[PATCH] D125843: [BOLT] Testcase to repro R_X86_64_REX_GOTPCRELX bug

Rafael Auler via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 18 12:44:55 PDT 2022


rafauler updated this revision to Diff 430478.
rafauler added a comment.

Thanks, I appreciate the suggestions. Adding check for GOTPCRELX.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125843/new/

https://reviews.llvm.org/D125843

Files:
  bolt/test/X86/gotpcrelx.s


Index: bolt/test/X86/gotpcrelx.s
===================================================================
--- /dev/null
+++ bolt/test/X86/gotpcrelx.s
@@ -0,0 +1,54 @@
+# This reproduces a bug with misinterpreting the gotpcrelx reloc
+
+# Here we use llvm-mc -relax-relocations to produce R_X86_64_REX_GOTPCRELX
+# and ld.lld to consume it and optimize it, transforming a CMP <mem, reg>
+# into CMP <imm, reg>.
+# Then we check that BOLT updates correctly the imm operand that references
+# a function address. Currently XFAIL as we do not support it.
+
+# REQUIRES: system-linux
+# XFAIL: *
+
+# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-linux \
+# RUN:   -relax-relocations %s -o %t.o
+# RUN: llvm-strip --strip-unneeded %t.o
+# RUN: ld.lld %t.o -o %t.exe -q
+# RUN: llvm-readobj -r %t.exe | FileCheck --check-prefix=READOBJ %s
+# RUN: llvm-bolt %t.exe -relocs -o %t.out -lite=0
+# RUN: llvm-objdump -d --no-show-raw-insn --print-imm-hex \
+# RUN:   %t.out | FileCheck --check-prefix=DISASM %s
+
+# Check that R_X86_64_REX_GOTPCRELX is present in the input binary
+# READOBJ: 0x[[#%X,]] R_X86_64_REX_GOTPCRELX foo 0x[[#%X,]]
+
+# DISASM:      Disassembly of section .text:
+# DISASM-EMPTY:
+# DISASM-NEXT: <_start>:
+# DISASM-NEXT:                 leaq  0x[[#%x,ADDR:]], %rax
+# DISASM-NEXT:                 cmpq  0x[[#ADDR]], %rax
+
+  .text
+  .globl _start
+  .type _start, %function
+_start:
+  .cfi_startproc
+  leaq foo, %rax
+  cmpq foo at GOTPCREL(%rip), %rax
+  je  b
+c:
+  mov $1, %rdi
+  callq foo
+b:
+  xorq %rdi, %rdi
+  callq foo
+  ret
+  .cfi_endproc
+  .size _start, .-_start
+
+  .globl foo
+  .type foo, %function
+foo:
+  .cfi_startproc
+  ret
+  .cfi_endproc
+  .size foo, .-foo


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125843.430478.patch
Type: text/x-patch
Size: 1703 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220518/97b65a91/attachment.bin>


More information about the llvm-commits mailing list