Skip to content

Commit 202a9f6

Browse files
committedJul 14, 2017
[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 llvm-svn: 308003
1 parent 3544b3e commit 202a9f6

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed
 

‎lld/ELF/SyntheticSections.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,12 @@ bool GotSection::empty() const {
662662
return NumEntries == 0 && !HasGotOffRel;
663663
}
664664

665-
void GotSection::writeTo(uint8_t *Buf) { relocateAlloc(Buf, Buf + Size); }
665+
void GotSection::writeTo(uint8_t *Buf) {
666+
// Buf points to the start of this section's buffer,
667+
// whereas InputSectionBase::relocateAlloc() expects its argument
668+
// to point to the start of the output section.
669+
relocateAlloc(Buf - OutSecOff, Buf - OutSecOff + Size);
670+
}
666671

667672
MipsGotSection::MipsGotSection()
668673
: SyntheticSection(SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL, SHT_PROGBITS, 16,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# REQUIRES: x86
2+
# RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux-gnu %s -o %t
3+
# RUN: echo "SECTIONS { \
4+
# RUN: .data 0x1000 : { *(.data) } \
5+
# RUN: .got 0x2000 : { \
6+
# RUN: LONG(0) \
7+
# RUN: *(.got) \
8+
# RUN: } \
9+
# RUN: };" > %t.script
10+
# RUN: ld.lld -shared -o %t.out --script %t.script %t
11+
# RUN: llvm-objdump -s %t.out | FileCheck %s
12+
.text
13+
.global foo
14+
foo:
15+
movl bar@GOT, %eax
16+
.data
17+
.local bar
18+
bar:
19+
.zero 4
20+
# CHECK: Contents of section .data:
21+
# CHECK-NEXT: 1000 00000000
22+
# CHECK: Contents of section .got:
23+
# CHECK-NEXT: 2000 00000000 00100000

0 commit comments

Comments
 (0)
Please sign in to comment.