[lld] r279264 - [ELF] - Fix for PR28976 - Corrupted section contents when using linker scripts
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 19 08:46:29 PDT 2016
Author: grimar
Date: Fri Aug 19 10:46:28 2016
New Revision: 279264
URL: http://llvm.org/viewvc/llvm-project?rev=279264&view=rev
Log:
[ELF] - Fix for PR28976 - Corrupted section contents when using linker scripts
This is fix for PR28976.
Problem was that in scanRelocs, we computed relocation offset too early
for case when linkerscript was used. Patch fixes the issue
delaying the calculation.
Differential revision: https://reviews.llvm.org/D23655
Added:
lld/trunk/test/ELF/linkerscript/Inputs/linkerscript-merge-sections-reloc.s
lld/trunk/test/ELF/linkerscript/linkerscript-merge-sections-reloc.s
Modified:
lld/trunk/ELF/InputSection.cpp
lld/trunk/ELF/OutputSections.cpp
lld/trunk/ELF/Relocations.cpp
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=279264&r1=279263&r2=279264&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Fri Aug 19 10:46:28 2016
@@ -351,7 +351,7 @@ void InputSectionBase<ELFT>::relocate(ui
const unsigned Bits = sizeof(uintX_t) * 8;
for (const Relocation<ELFT> &Rel : Relocations) {
- uintX_t Offset = Rel.Offset;
+ uintX_t Offset = getOffset(Rel.Offset);
uint8_t *BufLoc = Buf + Offset;
uint32_t Type = Rel.Type;
uintX_t A = Rel.Addend;
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=279264&r1=279263&r2=279264&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Fri Aug 19 10:46:28 2016
@@ -1274,7 +1274,7 @@ template <class ELFT>
typename ELFT::uint DynamicReloc<ELFT>::getOffset() const {
if (OutputSec)
return OutputSec->getVA() + OffsetInSec;
- return InputSec->OutSec->getVA() + OffsetInSec;
+ return InputSec->OutSec->getVA() + InputSec->getOffset(OffsetInSec);
}
template <class ELFT>
Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=279264&r1=279263&r2=279264&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Fri Aug 19 10:46:28 2016
@@ -566,7 +566,7 @@ static void scanRelocs(InputSectionBase<
continue;
Offset = PieceI->OutputOff + RI.r_offset - PieceI->InputOff;
} else {
- Offset = C.getOffset(RI.r_offset);
+ Offset = RI.r_offset;
}
// This relocation does not require got entry, but it is relative to got and
Added: lld/trunk/test/ELF/linkerscript/Inputs/linkerscript-merge-sections-reloc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/Inputs/linkerscript-merge-sections-reloc.s?rev=279264&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/Inputs/linkerscript-merge-sections-reloc.s (added)
+++ lld/trunk/test/ELF/linkerscript/Inputs/linkerscript-merge-sections-reloc.s Fri Aug 19 10:46:28 2016
@@ -0,0 +1,3 @@
+.globl _start
+_start:
+ .quad 0x11223344
Added: lld/trunk/test/ELF/linkerscript/linkerscript-merge-sections-reloc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/linkerscript-merge-sections-reloc.s?rev=279264&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/linkerscript-merge-sections-reloc.s (added)
+++ lld/trunk/test/ELF/linkerscript/linkerscript-merge-sections-reloc.s Fri Aug 19 10:46:28 2016
@@ -0,0 +1,16 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/linkerscript-merge-sections-reloc.s -o %t1.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t2.o
+# RUN: echo "SECTIONS {}" > %t.script
+# RUN: ld.lld -o %t --script %t.script %t1.o %t2.o
+# RUN: llvm-objdump -s %t | FileCheck %s
+
+## Check that sections content is not corrupted.
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 44332211 00000000 44332211 00000000
+# CHECK-NEXT: f0ffffff ffffffff
+
+.globl _start
+_foo:
+ .quad 0x11223344
+ .quad _start - .
More information about the llvm-commits
mailing list