[lld] r270328 - [ELF] Take into account offset in the output section when read addends for a non-alloc input section

Simon Atanasyan via llvm-commits llvm-commits at lists.llvm.org
Sat May 21 12:48:54 PDT 2016


Author: atanasyan
Date: Sat May 21 14:48:54 2016
New Revision: 270328

URL: http://llvm.org/viewvc/llvm-project?rev=270328&view=rev
Log:
[ELF] Take into account offset in the output section when read addends for a non-alloc input section

Added:
    lld/trunk/test/ELF/Inputs/mips-nonalloc.s
    lld/trunk/test/ELF/mips-nonalloc.s
Modified:
    lld/trunk/ELF/InputSection.cpp

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=270328&r1=270327&r2=270328&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Sat May 21 14:48:54 2016
@@ -269,9 +269,11 @@ void InputSection<ELFT>::relocateNonAllo
   const unsigned Bits = sizeof(uintX_t) * 8;
   for (const RelTy &Rel : Rels) {
     uint32_t Type = Rel.getType(Config->Mips64EL);
+    uintX_t Offset = this->getOffset(Rel.r_offset);
+    uint8_t *BufLoc = Buf + Offset;
     uintX_t Addend = getAddend<ELFT>(Rel);
     if (!RelTy::IsRela)
-      Addend += Target->getImplicitAddend(Buf + Rel.r_offset, Type);
+      Addend += Target->getImplicitAddend(BufLoc, Type);
 
     SymbolBody &Sym = this->File->getRelocTargetSym(Rel);
     if (Target->getRelExpr(Type, Sym) != R_ABS) {
@@ -279,8 +281,6 @@ void InputSection<ELFT>::relocateNonAllo
       return;
     }
 
-    uintX_t Offset = this->getOffset(Rel.r_offset);
-    uint8_t *BufLoc = Buf + Offset;
     uintX_t AddrLoc = this->OutSec->getVA() + Offset;
     uint64_t SymVA = SignExtend64<Bits>(getSymVA<ELFT>(
         Type, Addend, AddrLoc, Sym, BufLoc, *this->File, R_ABS));

Added: lld/trunk/test/ELF/Inputs/mips-nonalloc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/mips-nonalloc.s?rev=270328&view=auto
==============================================================================
--- lld/trunk/test/ELF/Inputs/mips-nonalloc.s (added)
+++ lld/trunk/test/ELF/Inputs/mips-nonalloc.s Sat May 21 14:48:54 2016
@@ -0,0 +1,2 @@
+  .section .debug_info
+  .word __start

Added: lld/trunk/test/ELF/mips-nonalloc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-nonalloc.s?rev=270328&view=auto
==============================================================================
--- lld/trunk/test/ELF/mips-nonalloc.s (added)
+++ lld/trunk/test/ELF/mips-nonalloc.s Sat May 21 14:48:54 2016
@@ -0,0 +1,21 @@
+# Check reading addends for relocations in non-allocatable sections.
+
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t1.o
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \
+# RUN:         %S/Inputs/mips-nonalloc.s -o %t2.o
+# RUN: ld.lld %t1.o %t2.o -o %t.exe
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+# REQUIRES: mips
+
+# CHECK:      Contents of section .debug_info:
+# CHECK-NEXT:  0000 ffffffff 00020000 00020000
+#                            ^--------^-- __start
+
+  .global __start
+__start:
+  nop
+
+.section .debug_info
+  .word 0xffffffff
+  .word __start




More information about the llvm-commits mailing list