[ELF] De-template InputSectionBase::getLocation. NFC

This commit is contained in:
Fangrui Song 2022-01-18 17:33:58 -08:00
parent d230848a85
commit 5f404a749a
3 changed files with 7 additions and 13 deletions

View File

@ -278,20 +278,19 @@ Defined *InputSectionBase::getEnclosingFunction(uint64_t offset) {
}
// Returns an object file location string. Used to construct an error message.
template <class ELFT>
std::string InputSectionBase::getLocation(uint64_t offset) {
std::string secAndOffset =
(name + "+0x" + Twine::utohexstr(offset) + ")").str();
// We don't have file for synthetic sections.
if (getFile<ELFT>() == nullptr)
if (file == nullptr)
return (config->outputFile + ":(" + secAndOffset).str();
std::string file = toString(getFile<ELFT>());
std::string filename = toString(file);
if (Defined *d = getEnclosingFunction(offset))
return file + ":(function " + toString(*d) + ": " + secAndOffset;
return filename + ":(function " + toString(*d) + ": " + secAndOffset;
return file + ":(" + secAndOffset;
return filename + ":(" + secAndOffset;
}
// This function is intended to be used for constructing an error message.
@ -948,7 +947,7 @@ void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef<RelTy> rels) {
continue;
}
std::string msg = getLocation<ELFT>(offset) + ": has non-ABS relocation " +
std::string msg = getLocation(offset) + ": has non-ABS relocation " +
toString(type) + " against symbol '" + toString(sym) +
"'";
if (expr != R_PC && expr != R_ARM_PCA) {
@ -1473,11 +1472,6 @@ template InputSection::InputSection(ObjFile<ELF64LE> &, const ELF64LE::Shdr &,
template InputSection::InputSection(ObjFile<ELF64BE> &, const ELF64BE::Shdr &,
StringRef);
template std::string InputSectionBase::getLocation<ELF32LE>(uint64_t);
template std::string InputSectionBase::getLocation<ELF32BE>(uint64_t);
template std::string InputSectionBase::getLocation<ELF64LE>(uint64_t);
template std::string InputSectionBase::getLocation<ELF64BE>(uint64_t);
template void InputSection::writeTo<ELF32LE>(uint8_t *);
template void InputSection::writeTo<ELF32BE>(uint8_t *);
template void InputSection::writeTo<ELF64LE>(uint8_t *);

View File

@ -184,7 +184,7 @@ public:
Defined *getEnclosingFunction(uint64_t offset);
// Returns a source location string. Used to construct an error message.
template <class ELFT> std::string getLocation(uint64_t offset);
std::string getLocation(uint64_t offset);
std::string getSrcMsg(const Symbol &sym, uint64_t offset);
std::string getObjMsg(uint64_t offset);

View File

@ -107,7 +107,7 @@ template <class ELFT> static ErrorPlace getErrPlace(const uint8_t *loc) {
continue;
}
if (isecLoc <= loc && loc < isecLoc + isec->getSize()) {
auto objLoc = isec->template getLocation<ELFT>(loc - isecLoc);
std::string objLoc = isec->getLocation(loc - isecLoc);
// Return object file location and source file location.
// TODO: Refactor getSrcMsg not to take a variable.
Undefined dummy(nullptr, "", STB_LOCAL, 0, 0);