[lld] r313788 - Fix assigning to _gp in linker scripts.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 20 11:30:57 PDT 2017
Author: rafael
Date: Wed Sep 20 11:30:57 2017
New Revision: 313788
URL: http://llvm.org/viewvc/llvm-project?rev=313788&view=rev
Log:
Fix assigning to _gp in linker scripts.
The previous logic was to try to detect if a linker script defined _gp
by checking !ElfSym::MipsGp->Value. That doesn't work in all cases as
the assigned value can be 0.
We now just always defined it Writer.cpp and always overwrite it
afterwards if needed.
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/Writer.cpp
lld/trunk/test/ELF/mips-gp-ext.s
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=313788&r1=313787&r2=313788&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Wed Sep 20 11:30:57 2017
@@ -148,6 +148,7 @@ void LinkerScript::assignSymbol(SymbolAs
ExprValue V = Cmd->Expression();
if (V.isAbsolute()) {
Sym->Value = V.getValue();
+ Sym->Section = nullptr;
} else {
Sym->Section = V.Sec;
Sym->Value = V.getSectionOffset();
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=313788&r1=313787&r2=313788&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Sep 20 11:30:57 2017
@@ -964,7 +964,7 @@ template <class ELFT> void Writer<ELFT>:
// 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) {
Modified: lld/trunk/test/ELF/mips-gp-ext.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-gp-ext.s?rev=313788&r1=313787&r2=313788&view=diff
==============================================================================
--- lld/trunk/test/ELF/mips-gp-ext.s (original)
+++ lld/trunk/test/ELF/mips-gp-ext.s Wed Sep 20 11:30:57 2017
@@ -12,6 +12,13 @@
# 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; \
# RUN: .got : { *(.got) } }" > %t.abs.script
# RUN: ld.lld -shared -o %t.abs.so --script %t.abs.script %t.o
More information about the llvm-commits
mailing list