[lld] r308003 - [ELF] Fix writing the content of the .got section in a wrong place.

Igor Kudrin via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 14 01:10:45 PDT 2017


Author: ikudrin
Date: Fri Jul 14 01:10:45 2017
New Revision: 308003

URL: http://llvm.org/viewvc/llvm-project?rev=308003&view=rev
Log:
[ELF] Fix writing the content of the .got section in a wrong place.

In filling the .got sections, InputSection::OutSecOff was added twice
when finding the position to apply a relocation: first time in
InputSection::writeTo() and then in SectionBase::getOffset().

Differential revision: https://reviews.llvm.org/D34232

Added:
    lld/trunk/test/ELF/linkerscript/got-write-offset.s
Modified:
    lld/trunk/ELF/SyntheticSections.cpp

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=308003&r1=308002&r2=308003&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Fri Jul 14 01:10:45 2017
@@ -662,7 +662,12 @@ bool GotSection::empty() const {
   return NumEntries == 0 && !HasGotOffRel;
 }
 
-void GotSection::writeTo(uint8_t *Buf) { relocateAlloc(Buf, Buf + Size); }
+void GotSection::writeTo(uint8_t *Buf) {
+  // Buf points to the start of this section's buffer,
+  // whereas InputSectionBase::relocateAlloc() expects its argument
+  // to point to the start of the output section.
+  relocateAlloc(Buf - OutSecOff, Buf - OutSecOff + Size);
+}
 
 MipsGotSection::MipsGotSection()
     : SyntheticSection(SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL, SHT_PROGBITS, 16,

Added: lld/trunk/test/ELF/linkerscript/got-write-offset.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/got-write-offset.s?rev=308003&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/got-write-offset.s (added)
+++ lld/trunk/test/ELF/linkerscript/got-write-offset.s Fri Jul 14 01:10:45 2017
@@ -0,0 +1,23 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux-gnu %s -o %t
+# RUN: echo "SECTIONS { \
+# RUN:   .data 0x1000 : { *(.data) } \
+# RUN:   .got 0x2000 : { \
+# RUN:     LONG(0) \
+# RUN:     *(.got) \
+# RUN:   } \
+# RUN:  };" > %t.script
+# RUN: ld.lld -shared -o %t.out --script %t.script %t
+# RUN: llvm-objdump -s %t.out | FileCheck %s
+.text
+.global foo
+foo:
+	movl bar at GOT, %eax
+.data
+.local bar
+bar:
+	.zero 4
+# CHECK:      Contents of section .data:
+# CHECK-NEXT:  1000 00000000
+# CHECK:      Contents of section .got:
+# CHECK-NEXT:  2000 00000000 00100000




More information about the llvm-commits mailing list