summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/Config.h2
-rw-r--r--lld/ELF/InputSection.cpp10
-rw-r--r--lld/ELF/Symbols.h5
-rw-r--r--lld/ELF/Writer.cpp16
4 files changed, 20 insertions, 13 deletions
diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index 792a42febf0e..8295e7379be5 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -38,8 +38,6 @@ enum class BuildIdKind { None, Fnv1, Md5, Sha1 };
// Most fields are initialized by the driver.
struct Configuration {
SymbolBody *EntrySym = nullptr;
- SymbolBody *MipsGpDisp = nullptr;
- SymbolBody *MipsLocalGp = nullptr;
InputFile *FirstElf = nullptr;
llvm::StringRef DynamicLinker;
llvm::StringRef Entry;
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index c641957c6d4e..ba77b3e9d0d6 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -206,12 +206,10 @@ template <class ELFT, class uintX_t>
static uintX_t adjustMipsSymVA(uint32_t Type, const elf::ObjectFile<ELFT> &File,
const SymbolBody &Body, uintX_t AddrLoc,
uintX_t SymVA) {
- if (Type == R_MIPS_HI16 && &Body == Config->MipsGpDisp)
- return getMipsGpAddr<ELFT>() - AddrLoc;
- if (Type == R_MIPS_LO16 && &Body == Config->MipsGpDisp)
- return getMipsGpAddr<ELFT>() - AddrLoc + 4;
- if (&Body == Config->MipsLocalGp)
- return getMipsGpAddr<ELFT>();
+ if (Type == R_MIPS_HI16 && &Body == ElfSym<ELFT>::MipsGpDisp)
+ return SymVA - AddrLoc;
+ if (Type == R_MIPS_LO16 && &Body == ElfSym<ELFT>::MipsGpDisp)
+ return SymVA - AddrLoc + 4;
if (Body.isLocal() && (Type == R_MIPS_GPREL16 || Type == R_MIPS_GPREL32))
// We need to adjust SymVA value in case of R_MIPS_GPREL16/32
// relocations because they use the following expression to calculate
diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h
index 6e22131c4621..b5ade14715c6 100644
--- a/lld/ELF/Symbols.h
+++ b/lld/ELF/Symbols.h
@@ -405,6 +405,9 @@ template <class ELFT> struct ElfSym {
// The content for _gp symbol for MIPS target.
static DefinedRegular<ELFT> *MipsGp;
+ static DefinedRegular<ELFT> *MipsLocalGp;
+ static DefinedRegular<ELFT> *MipsGpDisp;
+
// __rel_iplt_start/__rel_iplt_end for signaling
// where R_[*]_IRELATIVE relocations do live.
static SymbolBody *RelaIpltStart;
@@ -418,6 +421,8 @@ template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::Edata2;
template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::End;
template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::End2;
template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::MipsGp;
+template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::MipsLocalGp;
+template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::MipsGpDisp;
template <class ELFT> SymbolBody *ElfSym<ELFT>::RelaIpltStart;
template <class ELFT> SymbolBody *ElfSym<ELFT>::RelaIpltEnd;
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index b46b0786d3ea..483c069bb9db 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -454,8 +454,8 @@ void Writer<ELFT>::scanRelocs(InputSectionBase<ELFT> &C, ArrayRef<RelTy> Rels) {
// pointer into GOT. __gnu_local_gp is equal to the current value of
// the 'gp'. Therefore any relocations against them do not require
// dynamic relocation.
- if (Config->EMachine == EM_MIPS &&
- (&Body == Config->MipsGpDisp || &Body == Config->MipsLocalGp))
+ if (Config->EMachine == EM_MIPS && (&Body == ElfSym<ELFT>::MipsGpDisp ||
+ &Body == ElfSym<ELFT>::MipsLocalGp))
continue;
if (Preemptible) {
@@ -930,12 +930,12 @@ template <class ELFT> void Writer<ELFT>::addReservedSymbols() {
if (Config->EMachine == EM_MIPS) {
// On MIPS O32 ABI, _gp_disp is a magic symbol designates offset between
// start of function and 'gp' pointer into GOT.
- Config->MipsGpDisp = Symtab.addIgnored("_gp_disp");
+ ElfSym<ELFT>::MipsGpDisp = Symtab.addIgnored("_gp_disp");
// The __gnu_local_gp is a magic symbol equal to the current value of 'gp'
// pointer. This symbol is used in the code generated by .cpload pseudo-op
// in case of using -mno-shared option.
// https://sourceware.org/ml/binutils/2004-12/msg00094.html
- Config->MipsLocalGp = Symtab.addIgnored("__gnu_local_gp");
+ ElfSym<ELFT>::MipsLocalGp = Symtab.addIgnored("__gnu_local_gp");
}
// In the assembly for 32 bit x86 the _GLOBAL_OFFSET_TABLE_ symbol
@@ -1510,8 +1510,14 @@ static uint16_t getELFType() {
// symbol values that depend on section address and size.
template <class ELFT> void Writer<ELFT>::fixAbsoluteSymbols() {
// Update MIPS _gp absolute symbol so that it points to the static data.
- if (Config->EMachine == EM_MIPS)
+
+ if (Config->EMachine == EM_MIPS) {
ElfSym<ELFT>::MipsGp->Value = getMipsGpAddr<ELFT>();
+ if (ElfSym<ELFT>::MipsLocalGp)
+ ElfSym<ELFT>::MipsLocalGp->Value = getMipsGpAddr<ELFT>();
+ if (ElfSym<ELFT>::MipsGpDisp)
+ ElfSym<ELFT>::MipsGpDisp->Value = getMipsGpAddr<ELFT>();
+ }
// _etext is the first location after the last read-only loadable segment.
// _edata is the first location after the last read-write loadable segment.