[lld] r250865 - Fix symbol value calculation in SHF_MERGE.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 20 15:08:49 PDT 2015
Author: rafael
Date: Tue Oct 20 17:08:49 2015
New Revision: 250865
URL: http://llvm.org/viewvc/llvm-project?rev=250865&view=rev
Log:
Fix symbol value calculation in SHF_MERGE.
We would get the wrong value if the symbol was in the middle of an entry.
Added:
lld/trunk/test/elf2/merge-sym.s
Modified:
lld/trunk/ELF/InputSection.cpp
lld/trunk/ELF/OutputSections.cpp
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=250865&r1=250864&r2=250865&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Tue Oct 20 17:08:49 2015
@@ -134,10 +134,14 @@ typename MergeInputSection<ELFT>::uintX_
MergeInputSection<ELFT>::getOffset(uintX_t Offset) const {
ArrayRef<uint8_t> Data = this->getSectionData();
uintX_t EntSize = this->Header->sh_entsize;
+ uintX_t Addend = Offset % EntSize;
+ Offset -= Addend;
if (Offset + EntSize > Data.size())
error("Entry is past the end of the section");
Data = Data.slice(Offset, EntSize);
- return static_cast<MergeOutputSection<ELFT> *>(this->OutSec)->getOffset(Data);
+ return static_cast<MergeOutputSection<ELFT> *>(this->OutSec)
+ ->getOffset(Data) +
+ Addend;
}
namespace lld {
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=250865&r1=250864&r2=250865&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Tue Oct 20 17:08:49 2015
@@ -530,8 +530,7 @@ lld::elf2::getLocalRelTarget(const Objec
uintX_t Offset = Sym->st_value;
if (Sym->getType() == STT_SECTION) {
Offset += Addend;
- Addend = Offset % Section->getSectionHdr()->sh_entsize;
- Offset -= Addend;
+ Addend = 0;
}
return VA + cast<MergeInputSection<ELFT>>(Section)->getOffset(Offset) +
Addend;
Added: lld/trunk/test/elf2/merge-sym.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/merge-sym.s?rev=250865&view=auto
==============================================================================
--- lld/trunk/test/elf2/merge-sym.s (added)
+++ lld/trunk/test/elf2/merge-sym.s Tue Oct 20 17:08:49 2015
@@ -0,0 +1,21 @@
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+// RUN: ld.lld2 %t.o -o %t.so -shared
+// RUN: llvm-readobj -t -s %t.so | FileCheck %s
+
+ .section .rodata.cst4,"aM", at progbits,4
+ .short 0
+foo:
+ .short 42
+
+
+// CHECK: Name: .rodata
+// CHECK-NEXT: Type: SHT_PROGBITS
+// CHECK-NEXT: Flags [
+// CHECK-NEXT: SHF_ALLOC
+// CHECK-NEXT: SHF_MERGE
+// CHECK-NEXT: ]
+// CHECK-NEXT: Address: 0x120
+
+// CHECK: Name: foo
+// CHECK-NEXT: Value: 0x122
More information about the llvm-commits
mailing list