diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2017-09-20 18:30:57 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2017-09-20 18:30:57 +0000 |
commit | 9be24cf516c79322e53d2d7b3a391117c4460883 (patch) | |
tree | f1bf36758ce7bdd7597d8884265f6d2ff67ab294 | |
parent | 1b30d63aeb3a7dec4084cc6d0a2de91a4be7f805 (diff) | |
download | bcm5719-llvm-9be24cf516c79322e53d2d7b3a391117c4460883.tar.gz bcm5719-llvm-9be24cf516c79322e53d2d7b3a391117c4460883.zip |
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.
llvm-svn: 313788
-rw-r--r-- | lld/ELF/LinkerScript.cpp | 1 | ||||
-rw-r--r-- | lld/ELF/Writer.cpp | 2 | ||||
-rw-r--r-- | lld/test/ELF/mips-gp-ext.s | 7 |
3 files changed, 9 insertions, 1 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index af8398290e6..3ed6ad09093 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 6dd3d9f9241..b4342a93c56 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -964,7 +964,7 @@ template <class ELFT> void Writer<ELFT>::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 98b9cbc06d2..2fd21b7a981 100644 --- a/lld/test/ELF/mips-gp-ext.s +++ b/lld/test/ELF/mips-gp-ext.s @@ -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 |