aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Atanasyan <simon@atanasyan.com>2016-05-21 19:48:54 +0000
committerSimon Atanasyan <simon@atanasyan.com>2016-05-21 19:48:54 +0000
commitc23cb216df75f354752259e63aba9c3f643939af (patch)
treea657efea3daa486fd350d90d4ba52a87c868255d
parentdeb6c0aefc34ec77daab2d038ddd7673c730326b (diff)
[ELF] Take into account offset in the output section when read addends for a non-alloc input section
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@270328 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--ELF/InputSection.cpp6
-rw-r--r--test/ELF/Inputs/mips-nonalloc.s2
-rw-r--r--test/ELF/mips-nonalloc.s21
3 files changed, 26 insertions, 3 deletions
diff --git a/ELF/InputSection.cpp b/ELF/InputSection.cpp
index c4b506252..835e8c512 100644
--- a/ELF/InputSection.cpp
+++ b/ELF/InputSection.cpp
@@ -269,9 +269,11 @@ void InputSection<ELFT>::relocateNonAlloc(uint8_t *Buf, ArrayRef<RelTy> Rels) {
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>::relocateNonAlloc(uint8_t *Buf, ArrayRef<RelTy> Rels) {
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));
diff --git a/test/ELF/Inputs/mips-nonalloc.s b/test/ELF/Inputs/mips-nonalloc.s
new file mode 100644
index 000000000..72bfd2743
--- /dev/null
+++ b/test/ELF/Inputs/mips-nonalloc.s
@@ -0,0 +1,2 @@
+ .section .debug_info
+ .word __start
diff --git a/test/ELF/mips-nonalloc.s b/test/ELF/mips-nonalloc.s
new file mode 100644
index 000000000..7b0aa9469
--- /dev/null
+++ b/test/ELF/mips-nonalloc.s
@@ -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