[PATCH] D27678: [LLD][ARM] Add R_ARM_RELATIVE to relocations that can be applied to GotSection

Peter Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 12 09:26:55 PST 2016


peter.smith created this revision.
peter.smith added reviewers: ruiu, rafael.
peter.smith added a subscriber: llvm-commits.
Herald added subscribers: rengolin, aemerson.

When compiling -fpie and linking with the --pie option the R_ARM_GOTBREL relocation to D is resolved by writing the value of D into the .got slot and emitting an R_ARM_RELATIVE relocation for it.

Unfortunately R_ARM_RELATIVE is missing from relocateOne() leading to an unsupported relocation error (and then a segfault by the error handling system as it tries to look up the source for the GotSection.

The simple fix is to add R_ARM_RELATIVE to relocateOne() as R_ABS.

The R_ARM_GOTBREL relocation is present in the glibc library startup code so this problem will affect all --pie applications.


https://reviews.llvm.org/D27678

Files:
  ELF/Target.cpp
  test/ELF/arm-pie-relative.s


Index: test/ELF/arm-pie-relative.s
===================================================================
--- /dev/null
+++ test/ELF/arm-pie-relative.s
@@ -0,0 +1,25 @@
+// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t
+// RUN: ld.lld %t --pie -o %t2
+// RUN: llvm-readobj -r %t2
+// RUN: llvm-objdump -s %t2
+// REQUIRES: arm
+
+// Test that a R_ARM_GOT_BREL relocation with PIE results in a R_ARM_RELATIVE
+// dynamic relocation
+ .syntax unified
+ .text
+ .global _start
+_start:
+ .word sym(GOT)
+
+ .data
+ .global sym
+sym:
+ .word 0
+
+// CHECK:      Relocations [
+// CHECK-NEXT:   Section (4) .rel.dyn {
+// CHECK-NEXT:     0x2058 R_ARM_RELATIVE
+
+// GOT: Contents of section .got:
+// GOT-NEXT:  2058 00300000
Index: ELF/Target.cpp
===================================================================
--- ELF/Target.cpp
+++ ELF/Target.cpp
@@ -1739,6 +1739,7 @@
   case R_ARM_GOT_BREL:
   case R_ARM_GOT_PREL:
   case R_ARM_REL32:
+  case R_ARM_RELATIVE:
   case R_ARM_TARGET1:
   case R_ARM_TARGET2:
   case R_ARM_TLS_GD32:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27678.81096.patch
Type: text/x-patch
Size: 1055 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161212/66d846d9/attachment.bin>


More information about the llvm-commits mailing list