Index: lld/trunk/ELF/SyntheticSections.cpp =================================================================== --- lld/trunk/ELF/SyntheticSections.cpp +++ lld/trunk/ELF/SyntheticSections.cpp @@ -662,7 +662,12 @@ 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, Index: lld/trunk/test/ELF/linkerscript/got-write-offset.s =================================================================== --- lld/trunk/test/ELF/linkerscript/got-write-offset.s +++ lld/trunk/test/ELF/linkerscript/got-write-offset.s @@ -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@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