[lld] r265453 - Don't omit dynamic relocations for the GOT.

Ed Schouten via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 5 13:17:35 PDT 2016


Author: ed
Date: Tue Apr  5 15:17:33 2016
New Revision: 265453

URL: http://llvm.org/viewvc/llvm-project?rev=265453&view=rev
Log:
Don't omit dynamic relocations for the GOT.

Where Clang's AArch64 backend seems to differ from the X86 backend is
that it tends to use the GOT more aggressively.

After getting CloudABI PIEs working on x86-64, I noticed that accessing
global variables would still crash on aarch64. Tracing it down, it turns
out that the GOT was filled with entries assuming the base address was
zero.

It turns out that we skip generating relocations for GOT entries in case
the relocation pointing towards the GOT is relative. Whether the thing
pointing to the GOT is absolute or relative shouldn't make any
difference; the GOT entry itself should contain the absolute address,
thus needs a relocation regardless.

Approved by:	rafael
Differential Revision:	http://reviews.llvm.org/D18739

Added:
    lld/trunk/test/ELF/aarch64-got-relocations.s
Modified:
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=265453&r1=265452&r2=265453&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue Apr  5 15:17:33 2016
@@ -432,9 +432,7 @@ void Writer<ELFT>::scanRelocs(InputSecti
         // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
         continue;
 
-      bool Dynrel = Config->Pic && !Target->isRelRelative(Type) &&
-                    !Target->isSizeRel(Type);
-      if (Preemptible || Dynrel) {
+      if (Preemptible || Config->Pic) {
         uint32_t DynType;
         if (Body.isTls())
           DynType = Target->TlsGotRel;

Added: lld/trunk/test/ELF/aarch64-got-relocations.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/aarch64-got-relocations.s?rev=265453&view=auto
==============================================================================
--- lld/trunk/test/ELF/aarch64-got-relocations.s (added)
+++ lld/trunk/test/ELF/aarch64-got-relocations.s Tue Apr  5 15:17:33 2016
@@ -0,0 +1,21 @@
+# REQUIRES: aarch64
+# RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-cloudabi %s -o %t.o
+# RUN: ld.lld -pie %t.o -o %t
+# RUN: llvm-readobj -r %t | FileCheck %s
+
+# If we're addressing a global relatively through the GOT, we still need to
+# emit a relocation for the entry in the GOT itself.
+# CHECK: Relocations [
+# CHECK:   Section (4) .rela.dyn {
+# CHECK:     0x{{[0-9A-F]+}} R_AARCH64_RELATIVE - 0x{{[0-9A-F]+}}
+# CHECK:   }
+# CHECK: ]
+
+	.globl	_start
+	.type	_start, at function
+_start:
+	adrp	x8, :got:i
+	ldr	x8, [x8, :got_lo12:i]
+
+	.type	i, at object
+	.comm	i,4,4




More information about the llvm-commits mailing list