[lld] r334392 - [ELF] Pass a pointer to InputFile to the getRelocTargetVA to escape dereferencing of nullptr. NFC
Simon Atanasyan via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 11 01:37:19 PDT 2018
Author: atanasyan
Date: Mon Jun 11 01:37:19 2018
New Revision: 334392
URL: http://llvm.org/viewvc/llvm-project?rev=334392&view=rev
Log:
[ELF] Pass a pointer to InputFile to the getRelocTargetVA to escape dereferencing of nullptr. NFC
Modified:
lld/trunk/ELF/InputSection.cpp
lld/trunk/ELF/SyntheticSections.cpp
lld/trunk/ELF/SyntheticSections.h
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=334392&r1=334391&r2=334392&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Mon Jun 11 01:37:19 2018
@@ -477,7 +477,7 @@ static uint64_t getARMStaticBase(const S
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 I
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 I
// 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 I
// 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 I
// 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(uin
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) {
Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=334392&r1=334391&r2=334392&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Mon Jun 11 01:37:19 2018
@@ -708,10 +708,10 @@ MipsGotSection::FileGot &MipsGotSection:
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::getPageEntryOff
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::getSymEntryOffs
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;
}
Modified: lld/trunk/ELF/SyntheticSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.h?rev=334392&r1=334391&r2=334392&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.h (original)
+++ lld/trunk/ELF/SyntheticSections.h Mon Jun 11 01:37:19 2018
@@ -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
More information about the llvm-commits
mailing list