[PATCH] D111803: [LLD][TEST] Add a test case for negative addends for R_X86_64_PC32 relocations

Owen Reynolds via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 14 06:53:06 PDT 2021


gbreynoo created this revision.
gbreynoo added reviewers: MaskRay, peter.smith.
Herald added a subscriber: emaste.
gbreynoo requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This test is derived from a test case we have locally but I could not see an equivalent in LLD's testing.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111803

Files:
  lld/test/ELF/x86-64-pc32-negative-addend.s


Index: lld/test/ELF/x86-64-pc32-negative-addend.s
===================================================================
--- /dev/null
+++ lld/test/ELF/x86-64-pc32-negative-addend.s
@@ -0,0 +1,23 @@
+# REQUIRES: x86
+## Check patching of negative addends for R_X86_64_PC32 relocations.
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64 -defsym ADDEND=1 %s -o %t1.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64 -defsym ADDEND=2147483648 %s -o %t2.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64 -defsym ADDEND=2147483649 %s -o %t3.o
+
+# RUN: ld.lld --section-start=.text=0x0 %t1.o -o %t1out
+# RUN: ld.lld --section-start=.text=0x0 %t2.o -o %t2out
+# RUN: not ld.lld --section-start=.text=0x0 %t3.o -o /dev/null 2>&1 | FileCheck %s --check-prefix ERROR
+
+# ERROR: relocation R_X86_64_PC32 out of range
+
+# RUN: llvm-readelf --hex-dump=.text %t1out | FileCheck %s -DADDEND=ffffffff --check-prefix DUMP
+# RUN: llvm-readelf --hex-dump=.text %t2out | FileCheck %s -DADDEND=00000080 --check-prefix DUMP
+
+# DUMP:  0x00000000 [[ADDEND]]
+
+.text
+.globl _start
+_start:
+    .reloc ., R_X86_64_PC32, .text-ADDEND
+    .space 4


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111803.379695.patch
Type: text/x-patch
Size: 1141 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211014/ad488608/attachment.bin>


More information about the llvm-commits mailing list