summaryrefslogtreecommitdiffstats
path: root/lld
diff options
context:
space:
mode:
authorSimon Atanasyan <simon@atanasyan.com>2018-06-11 08:37:19 +0000
committerSimon Atanasyan <simon@atanasyan.com>2018-06-11 08:37:19 +0000
commit00d8843fa39e917882023c54f43eb4b77c113e4c (patch)
treea66a700907988c60ec55851f0a33b7dd8a22c7eb /lld
parentf4f6899cdf0d7dff6d06e26ac71d782ae9d18292 (diff)
downloadbcm5719-llvm-00d8843fa39e917882023c54f43eb4b77c113e4c.tar.gz
bcm5719-llvm-00d8843fa39e917882023c54f43eb4b77c113e4c.zip
[ELF] Pass a pointer to InputFile to the getRelocTargetVA to escape dereferencing of nullptr. NFC
llvm-svn: 334392
Diffstat (limited to 'lld')
-rw-r--r--lld/ELF/InputSection.cpp21
-rw-r--r--lld/ELF/SyntheticSections.cpp16
-rw-r--r--lld/ELF/SyntheticSections.h8
3 files changed, 22 insertions, 23 deletions
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index b8e4659b921..33f4f25658f 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -477,7 +477,7 @@ static uint64_t getARMStaticBase(const Symbol &Sym) {
return OS->PtLoad->FirstSec->Addr;
}
-static uint64_t getRelocTargetVA(const InputFile &File, RelType Type, int64_t A,
+static uint64_t getRelocTargetVA(const InputFile *File, RelType Type, int64_t A,
uint64_t P, const Symbol &Sym, RelExpr Expr) {
switch (Expr) {
case R_INVALID:
@@ -516,9 +516,9 @@ static uint64_t getRelocTargetVA(const InputFile &File, RelType Type, int64_t A,
case R_TLSDESC_CALL:
llvm_unreachable("cannot relocate hint relocs");
case R_MIPS_GOTREL:
- return Sym.getVA(A) - InX::MipsGot->getGp(&File);
+ return Sym.getVA(A) - InX::MipsGot->getGp(File);
case R_MIPS_GOT_GP:
- return InX::MipsGot->getGp(&File) + A;
+ return InX::MipsGot->getGp(File) + A;
case R_MIPS_GOT_GP_PC: {
// R_MIPS_LO16 expression has R_MIPS_GOT_GP_PC type iif the target
// is _gp_disp symbol. In that case we should use the following
@@ -527,7 +527,7 @@ static uint64_t getRelocTargetVA(const InputFile &File, RelType Type, int64_t A,
// microMIPS variants of these relocations use slightly different
// expressions: AHL + GP - P + 3 for %lo() and AHL + GP - P - 1 for %hi()
// to correctly handle less-sugnificant bit of the microMIPS symbol.
- uint64_t V = InX::MipsGot->getGp(&File) + A - P;
+ uint64_t V = InX::MipsGot->getGp(File) + A - P;
if (Type == R_MIPS_LO16 || Type == R_MICROMIPS_LO16)
V += 4;
if (Type == R_MICROMIPS_LO16 || Type == R_MICROMIPS_HI16)
@@ -540,7 +540,7 @@ static uint64_t getRelocTargetVA(const InputFile &File, RelType Type, int64_t A,
// of sum the symbol's value and the addend.
return InX::MipsGot->getVA() +
InX::MipsGot->getPageEntryOffset(File, Sym, A) -
- InX::MipsGot->getGp(&File);
+ InX::MipsGot->getGp(File);
case R_MIPS_GOT_OFF:
case R_MIPS_GOT_OFF32:
// In case of MIPS if a GOT relocation has non-zero addend this addend
@@ -548,14 +548,13 @@ static uint64_t getRelocTargetVA(const InputFile &File, RelType Type, int64_t A,
// That is why we use separate expression type.
return InX::MipsGot->getVA() +
InX::MipsGot->getSymEntryOffset(File, Sym, A) -
- InX::MipsGot->getGp(&File);
+ InX::MipsGot->getGp(File);
case R_MIPS_TLSGD:
- return InX::MipsGot->getVA() +
- InX::MipsGot->getGlobalDynOffset(File, Sym) -
- InX::MipsGot->getGp(&File);
+ return InX::MipsGot->getVA() + InX::MipsGot->getGlobalDynOffset(File, Sym) -
+ InX::MipsGot->getGp(File);
case R_MIPS_TLSLD:
return InX::MipsGot->getVA() + InX::MipsGot->getTlsIndexOffset(File) -
- InX::MipsGot->getGp(&File);
+ InX::MipsGot->getGp(File);
case R_PAGE_PC:
case R_PLT_PAGE_PC: {
uint64_t Dest;
@@ -754,7 +753,7 @@ void InputSectionBase::relocateAlloc(uint8_t *Buf, uint8_t *BufEnd) {
uint64_t AddrLoc = getOutputSection()->Addr + Offset;
RelExpr Expr = Rel.Expr;
uint64_t TargetVA = SignExtend64(
- getRelocTargetVA(*File, Type, Rel.Addend, AddrLoc, *Rel.Sym, Expr),
+ getRelocTargetVA(File, Type, Rel.Addend, AddrLoc, *Rel.Sym, Expr),
Bits);
switch (Expr) {
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index cd0d3fe525c..4195ed9a2e8 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -708,10 +708,10 @@ MipsGotSection::FileGot &MipsGotSection::getGot(InputFile &F) {
return Gots[*F.MipsGotIndex];
}
-uint64_t MipsGotSection::getPageEntryOffset(const InputFile &F,
+uint64_t MipsGotSection::getPageEntryOffset(const InputFile *F,
const Symbol &Sym,
int64_t Addend) const {
- const FileGot &G = Gots[*F.MipsGotIndex];
+ const FileGot &G = Gots[*F->MipsGotIndex];
uint64_t Index = 0;
if (const OutputSection *OutSec = Sym.getOutputSection()) {
uint64_t SecAddr = getMipsPageAddr(OutSec->Addr);
@@ -723,9 +723,9 @@ uint64_t MipsGotSection::getPageEntryOffset(const InputFile &F,
return Index * Config->Wordsize;
}
-uint64_t MipsGotSection::getSymEntryOffset(const InputFile &F, const Symbol &S,
+uint64_t MipsGotSection::getSymEntryOffset(const InputFile *F, const Symbol &S,
int64_t Addend) const {
- const FileGot &G = Gots[*F.MipsGotIndex];
+ const FileGot &G = Gots[*F->MipsGotIndex];
Symbol *Sym = const_cast<Symbol *>(&S);
if (Sym->isTls())
return G.Tls.find(Sym)->second * Config->Wordsize;
@@ -734,14 +734,14 @@ uint64_t MipsGotSection::getSymEntryOffset(const InputFile &F, const Symbol &S,
return G.Local16.find({Sym, Addend})->second * Config->Wordsize;
}
-uint64_t MipsGotSection::getTlsIndexOffset(const InputFile &F) const {
- const FileGot &G = Gots[*F.MipsGotIndex];
+uint64_t MipsGotSection::getTlsIndexOffset(const InputFile *F) const {
+ const FileGot &G = Gots[*F->MipsGotIndex];
return G.DynTlsSymbols.find(nullptr)->second * Config->Wordsize;
}
-uint64_t MipsGotSection::getGlobalDynOffset(const InputFile &F,
+uint64_t MipsGotSection::getGlobalDynOffset(const InputFile *F,
const Symbol &S) const {
- const FileGot &G = Gots[*F.MipsGotIndex];
+ const FileGot &G = Gots[*F->MipsGotIndex];
Symbol *Sym = const_cast<Symbol *>(&S);
return G.DynTlsSymbols.find(Sym)->second * Config->Wordsize;
}
diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h
index 9776f2a32d0..b2a609b1813 100644
--- a/lld/ELF/SyntheticSections.h
+++ b/lld/ELF/SyntheticSections.h
@@ -187,12 +187,12 @@ public:
void addDynTlsEntry(InputFile &File, Symbol &Sym);
void addTlsIndex(InputFile &File);
- uint64_t getPageEntryOffset(const InputFile &F, const Symbol &S,
+ uint64_t getPageEntryOffset(const InputFile *F, const Symbol &S,
int64_t Addend) const;
- uint64_t getSymEntryOffset(const InputFile &F, const Symbol &S,
+ uint64_t getSymEntryOffset(const InputFile *F, const Symbol &S,
int64_t Addend) const;
- uint64_t getGlobalDynOffset(const InputFile &F, const Symbol &S) const;
- uint64_t getTlsIndexOffset(const InputFile &F) const;
+ uint64_t getGlobalDynOffset(const InputFile *F, const Symbol &S) const;
+ uint64_t getTlsIndexOffset(const InputFile *F) const;
// Returns the symbol which corresponds to the first entry of the global part
// of GOT on MIPS platform. It is required to fill up MIPS-specific dynamic
OpenPOWER on IntegriCloud