forked from OSchip/llvm-project
				
			[ELF] Pass a pointer to InputFile to the getRelocTargetVA to escape dereferencing of nullptr. NFC
llvm-svn: 334392
This commit is contained in:
		
							parent
							
								
									f4f6899cdf
								
							
						
					
					
						commit
						00d8843fa3
					
				| 
						 | 
					@ -477,7 +477,7 @@ static uint64_t getARMStaticBase(const Symbol &Sym) {
 | 
				
			||||||
  return OS->PtLoad->FirstSec->Addr;
 | 
					  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) {
 | 
					                                 uint64_t P, const Symbol &Sym, RelExpr Expr) {
 | 
				
			||||||
  switch (Expr) {
 | 
					  switch (Expr) {
 | 
				
			||||||
  case R_INVALID:
 | 
					  case R_INVALID:
 | 
				
			||||||
| 
						 | 
					@ -516,9 +516,9 @@ static uint64_t getRelocTargetVA(const InputFile &File, RelType Type, int64_t A,
 | 
				
			||||||
  case R_TLSDESC_CALL:
 | 
					  case R_TLSDESC_CALL:
 | 
				
			||||||
    llvm_unreachable("cannot relocate hint relocs");
 | 
					    llvm_unreachable("cannot relocate hint relocs");
 | 
				
			||||||
  case R_MIPS_GOTREL:
 | 
					  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:
 | 
					  case R_MIPS_GOT_GP:
 | 
				
			||||||
    return InX::MipsGot->getGp(&File) + A;
 | 
					    return InX::MipsGot->getGp(File) + A;
 | 
				
			||||||
  case R_MIPS_GOT_GP_PC: {
 | 
					  case R_MIPS_GOT_GP_PC: {
 | 
				
			||||||
    // R_MIPS_LO16 expression has R_MIPS_GOT_GP_PC type iif the target
 | 
					    // 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
 | 
					    // 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
 | 
					    // microMIPS variants of these relocations use slightly different
 | 
				
			||||||
    // expressions: AHL + GP - P + 3 for %lo() and AHL + GP - P - 1 for %hi()
 | 
					    // expressions: AHL + GP - P + 3 for %lo() and AHL + GP - P - 1 for %hi()
 | 
				
			||||||
    // to correctly handle less-sugnificant bit of the microMIPS symbol.
 | 
					    // 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)
 | 
					    if (Type == R_MIPS_LO16 || Type == R_MICROMIPS_LO16)
 | 
				
			||||||
      V += 4;
 | 
					      V += 4;
 | 
				
			||||||
    if (Type == R_MICROMIPS_LO16 || Type == R_MICROMIPS_HI16)
 | 
					    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.
 | 
					    // of sum the symbol's value and the addend.
 | 
				
			||||||
    return InX::MipsGot->getVA() +
 | 
					    return InX::MipsGot->getVA() +
 | 
				
			||||||
           InX::MipsGot->getPageEntryOffset(File, Sym, A) -
 | 
					           InX::MipsGot->getPageEntryOffset(File, Sym, A) -
 | 
				
			||||||
           InX::MipsGot->getGp(&File);
 | 
					           InX::MipsGot->getGp(File);
 | 
				
			||||||
  case R_MIPS_GOT_OFF:
 | 
					  case R_MIPS_GOT_OFF:
 | 
				
			||||||
  case R_MIPS_GOT_OFF32:
 | 
					  case R_MIPS_GOT_OFF32:
 | 
				
			||||||
    // In case of MIPS if a GOT relocation has non-zero addend this addend
 | 
					    // 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.
 | 
					    // That is why we use separate expression type.
 | 
				
			||||||
    return InX::MipsGot->getVA() +
 | 
					    return InX::MipsGot->getVA() +
 | 
				
			||||||
           InX::MipsGot->getSymEntryOffset(File, Sym, A) -
 | 
					           InX::MipsGot->getSymEntryOffset(File, Sym, A) -
 | 
				
			||||||
           InX::MipsGot->getGp(&File);
 | 
					           InX::MipsGot->getGp(File);
 | 
				
			||||||
  case R_MIPS_TLSGD:
 | 
					  case R_MIPS_TLSGD:
 | 
				
			||||||
    return InX::MipsGot->getVA() +
 | 
					    return InX::MipsGot->getVA() + InX::MipsGot->getGlobalDynOffset(File, Sym) -
 | 
				
			||||||
           InX::MipsGot->getGlobalDynOffset(File, Sym) -
 | 
					           InX::MipsGot->getGp(File);
 | 
				
			||||||
           InX::MipsGot->getGp(&File);
 | 
					 | 
				
			||||||
  case R_MIPS_TLSLD:
 | 
					  case R_MIPS_TLSLD:
 | 
				
			||||||
    return InX::MipsGot->getVA() + InX::MipsGot->getTlsIndexOffset(File) -
 | 
					    return InX::MipsGot->getVA() + InX::MipsGot->getTlsIndexOffset(File) -
 | 
				
			||||||
           InX::MipsGot->getGp(&File);
 | 
					           InX::MipsGot->getGp(File);
 | 
				
			||||||
  case R_PAGE_PC:
 | 
					  case R_PAGE_PC:
 | 
				
			||||||
  case R_PLT_PAGE_PC: {
 | 
					  case R_PLT_PAGE_PC: {
 | 
				
			||||||
    uint64_t Dest;
 | 
					    uint64_t Dest;
 | 
				
			||||||
| 
						 | 
					@ -754,7 +753,7 @@ void InputSectionBase::relocateAlloc(uint8_t *Buf, uint8_t *BufEnd) {
 | 
				
			||||||
    uint64_t AddrLoc = getOutputSection()->Addr + Offset;
 | 
					    uint64_t AddrLoc = getOutputSection()->Addr + Offset;
 | 
				
			||||||
    RelExpr Expr = Rel.Expr;
 | 
					    RelExpr Expr = Rel.Expr;
 | 
				
			||||||
    uint64_t TargetVA = SignExtend64(
 | 
					    uint64_t TargetVA = SignExtend64(
 | 
				
			||||||
        getRelocTargetVA(*File, Type, Rel.Addend, AddrLoc, *Rel.Sym, Expr),
 | 
					        getRelocTargetVA(File, Type, Rel.Addend, AddrLoc, *Rel.Sym, Expr),
 | 
				
			||||||
        Bits);
 | 
					        Bits);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    switch (Expr) {
 | 
					    switch (Expr) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -708,10 +708,10 @@ MipsGotSection::FileGot &MipsGotSection::getGot(InputFile &F) {
 | 
				
			||||||
  return Gots[*F.MipsGotIndex];
 | 
					  return Gots[*F.MipsGotIndex];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
uint64_t MipsGotSection::getPageEntryOffset(const InputFile &F,
 | 
					uint64_t MipsGotSection::getPageEntryOffset(const InputFile *F,
 | 
				
			||||||
                                            const Symbol &Sym,
 | 
					                                            const Symbol &Sym,
 | 
				
			||||||
                                            int64_t Addend) const {
 | 
					                                            int64_t Addend) const {
 | 
				
			||||||
  const FileGot &G = Gots[*F.MipsGotIndex];
 | 
					  const FileGot &G = Gots[*F->MipsGotIndex];
 | 
				
			||||||
  uint64_t Index = 0;
 | 
					  uint64_t Index = 0;
 | 
				
			||||||
  if (const OutputSection *OutSec = Sym.getOutputSection()) {
 | 
					  if (const OutputSection *OutSec = Sym.getOutputSection()) {
 | 
				
			||||||
    uint64_t SecAddr = getMipsPageAddr(OutSec->Addr);
 | 
					    uint64_t SecAddr = getMipsPageAddr(OutSec->Addr);
 | 
				
			||||||
| 
						 | 
					@ -723,9 +723,9 @@ uint64_t MipsGotSection::getPageEntryOffset(const InputFile &F,
 | 
				
			||||||
  return Index * Config->Wordsize;
 | 
					  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 {
 | 
					                                           int64_t Addend) const {
 | 
				
			||||||
  const FileGot &G = Gots[*F.MipsGotIndex];
 | 
					  const FileGot &G = Gots[*F->MipsGotIndex];
 | 
				
			||||||
  Symbol *Sym = const_cast<Symbol *>(&S);
 | 
					  Symbol *Sym = const_cast<Symbol *>(&S);
 | 
				
			||||||
  if (Sym->isTls())
 | 
					  if (Sym->isTls())
 | 
				
			||||||
    return G.Tls.find(Sym)->second * Config->Wordsize;
 | 
					    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;
 | 
					  return G.Local16.find({Sym, Addend})->second * Config->Wordsize;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
uint64_t MipsGotSection::getTlsIndexOffset(const InputFile &F) const {
 | 
					uint64_t MipsGotSection::getTlsIndexOffset(const InputFile *F) const {
 | 
				
			||||||
  const FileGot &G = Gots[*F.MipsGotIndex];
 | 
					  const FileGot &G = Gots[*F->MipsGotIndex];
 | 
				
			||||||
  return G.DynTlsSymbols.find(nullptr)->second * Config->Wordsize;
 | 
					  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 Symbol &S) const {
 | 
				
			||||||
  const FileGot &G = Gots[*F.MipsGotIndex];
 | 
					  const FileGot &G = Gots[*F->MipsGotIndex];
 | 
				
			||||||
  Symbol *Sym = const_cast<Symbol *>(&S);
 | 
					  Symbol *Sym = const_cast<Symbol *>(&S);
 | 
				
			||||||
  return G.DynTlsSymbols.find(Sym)->second * Config->Wordsize;
 | 
					  return G.DynTlsSymbols.find(Sym)->second * Config->Wordsize;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -187,12 +187,12 @@ public:
 | 
				
			||||||
  void addDynTlsEntry(InputFile &File, Symbol &Sym);
 | 
					  void addDynTlsEntry(InputFile &File, Symbol &Sym);
 | 
				
			||||||
  void addTlsIndex(InputFile &File);
 | 
					  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;
 | 
					                              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;
 | 
					                             int64_t Addend) const;
 | 
				
			||||||
  uint64_t getGlobalDynOffset(const InputFile &F, const Symbol &S) const;
 | 
					  uint64_t getGlobalDynOffset(const InputFile *F, const Symbol &S) const;
 | 
				
			||||||
  uint64_t getTlsIndexOffset(const InputFile &F) const;
 | 
					  uint64_t getTlsIndexOffset(const InputFile *F) const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Returns the symbol which corresponds to the first entry of the global part
 | 
					  // 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
 | 
					  // of GOT on MIPS platform. It is required to fill up MIPS-specific dynamic
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue