Skip to content

Commit

Permalink
[ELF] De-template InputSectionBase::getLocation. NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
MaskRay committed Jan 19, 2022
1 parent d230848 commit 5f404a7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
16 changes: 5 additions & 11 deletions lld/ELF/InputSection.cpp
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 *);
Expand Down
2 changes: 1 addition & 1 deletion lld/ELF/InputSection.h
Expand Up @@ -184,7 +184,7 @@ class InputSectionBase : public SectionBase {
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);

Expand Down
2 changes: 1 addition & 1 deletion lld/ELF/Target.cpp
Expand Up @@ -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);
Expand Down

0 comments on commit 5f404a7

Please sign in to comment.