[lld] r259692 - Fix addend computation for IRELATIVE relocations.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 3 13:02:50 PST 2016


Author: rafael
Date: Wed Feb  3 15:02:48 2016
New Revision: 259692

URL: http://llvm.org/viewvc/llvm-project?rev=259692&view=rev
Log:
Fix addend computation for IRELATIVE relocations.

Added:
    lld/trunk/test/ELF/gnu-ifunc-relative.s
Modified:
    lld/trunk/ELF/OutputSections.cpp

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=259692&r1=259691&r2=259692&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Wed Feb  3 15:02:48 2016
@@ -285,6 +285,18 @@ template <class ELFT> void RelocationSec
     bool NeedsGot = Body && Target->needsGot(Type, *Body);
     bool CBP = canBePreempted(Body, NeedsGot);
 
+    if (IsRela) {
+      auto R = static_cast<const Elf_Rela &>(RI);
+      auto S = static_cast<Elf_Rela *>(P);
+      uintX_t A = NeedsGot ? 0 : R.r_addend;
+      if (CBP)
+        S->r_addend = A;
+      else if (Body)
+        S->r_addend = Body->getVA<ELFT>() + A;
+      else
+        S->r_addend = getLocalRelTarget(File, R, A);
+    }
+
     // For a symbol with STT_GNU_IFUNC type, we always create a PLT and
     // a GOT entry for the symbol, and emit an IRELATIVE reloc rather than
     // the usual JUMP_SLOT reloc for the GOT entry. For the details, you
@@ -318,19 +330,6 @@ template <class ELFT> void RelocationSec
       P->r_offset = Body->getGotVA<ELFT>();
     else
       P->r_offset = C.getOffset(RI.r_offset) + C.OutSec->getVA();
-
-    if (!IsRela)
-      continue;
-
-    auto R = static_cast<const Elf_Rela &>(RI);
-    auto S = static_cast<Elf_Rela *>(P);
-    uintX_t A = NeedsGot ? 0 : R.r_addend;
-    if (CBP)
-      S->r_addend = A;
-    else if (Body)
-      S->r_addend = Body->getVA<ELFT>() + A;
-    else
-      S->r_addend = getLocalRelTarget(File, R, A);
   }
 }
 

Added: lld/trunk/test/ELF/gnu-ifunc-relative.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/gnu-ifunc-relative.s?rev=259692&view=auto
==============================================================================
--- lld/trunk/test/ELF/gnu-ifunc-relative.s (added)
+++ lld/trunk/test/ELF/gnu-ifunc-relative.s Wed Feb  3 15:02:48 2016
@@ -0,0 +1,24 @@
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+// RUN: ld.lld -static %t.o -o %tout
+// RUN: llvm-readobj -r -t %tout | FileCheck %s
+// REQUIRES: x86
+
+.type foo STT_GNU_IFUNC
+.globl foo
+.type foo, @function
+foo:
+ ret
+
+.globl _start
+_start:
+ call foo
+
+// CHECK:      Section ({{.*}}) .rela.plt {
+// CHECK-NEXT:   R_X86_64_IRELATIVE - 0x[[ADDR:.*]]
+// CHECK-NEXT: }
+
+// CHECK:      Name: foo
+// CHECK-NEXT: Value: 0x[[ADDR]]
+// CHECK-NEXT: Size: 0
+// CHECK-NEXT: Binding: Global
+// CHECK-NEXT: Type: GNU_IFunc




More information about the llvm-commits mailing list