diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index af8398290e67..3ed6ad090938 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -148,6 +148,7 @@ void LinkerScript::assignSymbol(SymbolAssignment *Cmd, bool InSec) { ExprValue V = Cmd->Expression(); if (V.isAbsolute()) { Sym->Value = V.getValue(); + Sym->Section = nullptr; } else { Sym->Section = V.Sec; Sym->Value = V.getSectionOffset(); diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 6dd3d9f92418..b4342a93c560 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -964,7 +964,7 @@ template void Writer::setReservedSymbolSections() { // Setup MIPS _gp_disp/__gnu_local_gp symbols which should // be equal to the _gp symbol's value. - if (ElfSym::MipsGp && !ElfSym::MipsGp->Value) { + if (ElfSym::MipsGp) { // Find GP-relative section with the lowest address // and use this address to calculate default _gp value. for (OutputSection *OS : OutputSections) { diff --git a/lld/test/ELF/mips-gp-ext.s b/lld/test/ELF/mips-gp-ext.s index 98b9cbc06d28..2fd21b7a9818 100644 --- a/lld/test/ELF/mips-gp-ext.s +++ b/lld/test/ELF/mips-gp-ext.s @@ -10,6 +10,13 @@ # RUN: ld.lld -shared -o %t.rel.so --script %t.rel.script %t.o # RUN: llvm-objdump -s -t %t.rel.so | FileCheck --check-prefix=REL %s +# RUN: echo "SECTIONS { \ +# RUN: .text : { *(.text) } \ +# RUN: _gp = 0x100 + ABSOLUTE(.); \ +# RUN: .got : { *(.got) } }" > %t.rel.script +# RUN: ld.lld -shared -o %t.rel.so --script %t.rel.script %t.o +# RUN: llvm-objdump -s -t %t.rel.so | FileCheck --check-prefix=REL %s + # RUN: echo "SECTIONS { \ # RUN: .text : { *(.text) } \ # RUN: _gp = 0x200; \