summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/COFF/InputFiles.cpp4
-rw-r--r--lld/ELF/InputFiles.cpp70
-rw-r--r--lld/include/lld/Common/ErrorHandler.h6
3 files changed, 34 insertions, 46 deletions
diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp
index df20f0c6193..a8f52e0391f 100644
--- a/lld/COFF/InputFiles.cpp
+++ b/lld/COFF/InputFiles.cpp
@@ -63,7 +63,7 @@ ArchiveFile::ArchiveFile(MemoryBufferRef M) : InputFile(ArchiveKind, M) {}
void ArchiveFile::parse() {
// Parse a MemoryBufferRef as an archive file.
- File = CHECK(Archive::create(MB), toString(this));
+ File = CHECK(Archive::create(MB), this);
// Read the symbol table to construct Lazy objects.
for (const Archive::Symbol &Sym : File->symbols())
@@ -104,7 +104,7 @@ std::vector<MemoryBufferRef> getArchiveMembers(Archive *File) {
void ObjFile::parse() {
// Parse a memory buffer as a COFF file.
- std::unique_ptr<Binary> Bin = CHECK(createBinary(MB), toString(this));
+ std::unique_ptr<Binary> Bin = CHECK(createBinary(MB), this);
if (auto *Obj = dyn_cast<COFFObjectFile>(Bin.get())) {
Bin.release();
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 2eed28a0406..3813990952c 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -209,20 +209,19 @@ typename ELFT::SymRange ELFFileBase<ELFT>::getGlobalELFSyms() {
template <class ELFT>
uint32_t ELFFileBase<ELFT>::getSectionIndex(const Elf_Sym &Sym) const {
- return CHECK(getObj().getSectionIndex(&Sym, ELFSyms, SymtabSHNDX),
- toString(this));
+ return CHECK(getObj().getSectionIndex(&Sym, ELFSyms, SymtabSHNDX), this);
}
template <class ELFT>
void ELFFileBase<ELFT>::initSymtab(ArrayRef<Elf_Shdr> Sections,
const Elf_Shdr *Symtab) {
FirstNonLocal = Symtab->sh_info;
- ELFSyms = CHECK(getObj().symbols(Symtab), toString(this));
+ ELFSyms = CHECK(getObj().symbols(Symtab), this);
if (FirstNonLocal == 0 || FirstNonLocal > ELFSyms.size())
fatal(toString(this) + ": invalid sh_info in symbol table");
- StringTable = CHECK(getObj().getStringTableForSymtab(*Symtab, Sections),
- toString(this));
+ StringTable =
+ CHECK(getObj().getStringTableForSymtab(*Symtab, Sections), this);
}
template <class ELFT>
@@ -254,12 +253,11 @@ StringRef ObjFile<ELFT>::getShtGroupSignature(ArrayRef<Elf_Shdr> Sections,
// sh_info contains a symbol index, so we fetch a symbol and read its name.
if (this->ELFSyms.empty())
this->initSymtab(
- Sections,
- CHECK(object::getSection<ELFT>(Sections, Sec.sh_link), toString(this)));
+ Sections, CHECK(object::getSection<ELFT>(Sections, Sec.sh_link), this));
- const Elf_Sym *Sym = CHECK(
- object::getSymbol<ELFT>(this->ELFSyms, Sec.sh_info), toString(this));
- StringRef Signature = CHECK(Sym->getName(this->StringTable), toString(this));
+ const Elf_Sym *Sym =
+ CHECK(object::getSymbol<ELFT>(this->ELFSyms, Sec.sh_info), this);
+ StringRef Signature = CHECK(Sym->getName(this->StringTable), this);
// As a special case, if a symbol is a section symbol and has no name,
// we use a section name as a signature.
@@ -277,8 +275,8 @@ template <class ELFT>
ArrayRef<typename ObjFile<ELFT>::Elf_Word>
ObjFile<ELFT>::getShtGroupEntries(const Elf_Shdr &Sec) {
const ELFFile<ELFT> &Obj = this->getObj();
- ArrayRef<Elf_Word> Entries = CHECK(
- Obj.template getSectionContentsAsArray<Elf_Word>(&Sec), toString(this));
+ ArrayRef<Elf_Word> Entries =
+ CHECK(Obj.template getSectionContentsAsArray<Elf_Word>(&Sec), this);
if (Entries.empty() || Entries[0] != GRP_COMDAT)
fatal(toString(this) + ": unsupported SHT_GROUP format");
return Entries.slice(1);
@@ -323,12 +321,11 @@ void ObjFile<ELFT>::initializeSections(
DenseSet<CachedHashStringRef> &ComdatGroups) {
const ELFFile<ELFT> &Obj = this->getObj();
- ArrayRef<Elf_Shdr> ObjSections =
- CHECK(this->getObj().sections(), toString(this));
+ ArrayRef<Elf_Shdr> ObjSections = CHECK(this->getObj().sections(), this);
uint64_t Size = ObjSections.size();
this->Sections.resize(Size);
this->SectionStringTable =
- CHECK(Obj.getSectionStringTable(ObjSections), toString(this));
+ CHECK(Obj.getSectionStringTable(ObjSections), this);
for (size_t I = 0, E = ObjSections.size(); I < E; I++) {
if (this->Sections[I] == &InputSection::Discarded)
@@ -374,8 +371,7 @@ void ObjFile<ELFT>::initializeSections(
this->initSymtab(ObjSections, &Sec);
break;
case SHT_SYMTAB_SHNDX:
- this->SymtabSHNDX =
- CHECK(Obj.getSHNDXTable(Sec, ObjSections), toString(this));
+ this->SymtabSHNDX = CHECK(Obj.getSHNDXTable(Sec, ObjSections), this);
break;
case SHT_STRTAB:
case SHT_NULL:
@@ -520,13 +516,12 @@ InputSectionBase *ObjFile<ELFT>::createInputSection(const Elf_Shdr &Sec) {
size_t NumRelocations;
if (Sec.sh_type == SHT_RELA) {
- ArrayRef<Elf_Rela> Rels =
- CHECK(this->getObj().relas(&Sec), toString(this));
+ ArrayRef<Elf_Rela> Rels = CHECK(this->getObj().relas(&Sec), this);
Target->FirstRelocation = Rels.begin();
NumRelocations = Rels.size();
Target->AreRelocsRela = true;
} else {
- ArrayRef<Elf_Rel> Rels = CHECK(this->getObj().rels(&Sec), toString(this));
+ ArrayRef<Elf_Rel> Rels = CHECK(this->getObj().rels(&Sec), this);
Target->FirstRelocation = Rels.begin();
NumRelocations = Rels.size();
Target->AreRelocsRela = false;
@@ -595,8 +590,7 @@ InputSectionBase *ObjFile<ELFT>::createInputSection(const Elf_Shdr &Sec) {
template <class ELFT>
StringRef ObjFile<ELFT>::getSectionName(const Elf_Shdr &Sec) {
- return CHECK(this->getObj().getSectionName(&Sec, SectionStringTable),
- toString(this));
+ return CHECK(this->getObj().getSectionName(&Sec, SectionStringTable), this);
}
template <class ELFT> void ObjFile<ELFT>::initializeSymbols() {
@@ -628,7 +622,7 @@ template <class ELFT> Symbol *ObjFile<ELFT>::createSymbol(const Elf_Sym *Sym) {
if (Binding == STB_LOCAL) {
if (Sym->getType() == STT_FILE)
- SourceFile = CHECK(Sym->getName(this->StringTable), toString(this));
+ SourceFile = CHECK(Sym->getName(this->StringTable), this);
if (this->StringTable.size() <= Sym->st_name)
fatal(toString(this) + ": invalid symbol name offset");
@@ -640,7 +634,7 @@ template <class ELFT> Symbol *ObjFile<ELFT>::createSymbol(const Elf_Sym *Sym) {
return make<Defined>(this, Name, Binding, StOther, Type, Value, Size, Sec);
}
- StringRef Name = CHECK(Sym->getName(this->StringTable), toString(this));
+ StringRef Name = CHECK(Sym->getName(this->StringTable), this);
switch (Sym->st_shndx) {
case SHN_UNDEF:
@@ -695,8 +689,7 @@ ArchiveFile::getMember(const Archive::Symbol *Sym) {
Sym->getName());
if (C.getParent()->isThin() && Tar)
- Tar->append(relativeToRoot(CHECK(C.getFullName(), toString(this))),
- Ret.getBuffer());
+ Tar->append(relativeToRoot(CHECK(C.getFullName(), this)), Ret.getBuffer());
if (C.getParent()->isThin())
return {Ret, 0};
return {Ret, C.getChildOffset()};
@@ -712,7 +705,7 @@ SharedFile<ELFT>::SharedFile(MemoryBufferRef M, StringRef DefaultSoName)
template <class ELFT> void SharedFile<ELFT>::parseSoName() {
const Elf_Shdr *DynamicSec = nullptr;
const ELFFile<ELFT> Obj = this->getObj();
- ArrayRef<Elf_Shdr> Sections = CHECK(Obj.sections(), toString(this));
+ ArrayRef<Elf_Shdr> Sections = CHECK(Obj.sections(), this);
// Search for .dynsym, .dynamic, .symtab, .gnu.version and .gnu.version_d.
for (const Elf_Shdr &Sec : Sections) {
@@ -726,8 +719,7 @@ template <class ELFT> void SharedFile<ELFT>::parseSoName() {
DynamicSec = &Sec;
break;
case SHT_SYMTAB_SHNDX:
- this->SymtabSHNDX =
- CHECK(Obj.getSHNDXTable(Sec, Sections), toString(this));
+ this->SymtabSHNDX = CHECK(Obj.getSHNDXTable(Sec, Sections), this);
break;
case SHT_GNU_versym:
this->VersymSec = &Sec;
@@ -745,8 +737,7 @@ template <class ELFT> void SharedFile<ELFT>::parseSoName() {
if (!DynamicSec)
return;
ArrayRef<Elf_Dyn> Arr =
- CHECK(Obj.template getSectionContentsAsArray<Elf_Dyn>(DynamicSec),
- toString(this));
+ CHECK(Obj.template getSectionContentsAsArray<Elf_Dyn>(DynamicSec), this);
for (const Elf_Dyn &Dyn : Arr) {
if (Dyn.d_tag == DT_SONAME) {
uint64_t Val = Dyn.getVal();
@@ -805,8 +796,7 @@ template <class ELFT> void SharedFile<ELFT>::parseRest() {
const Elf_Versym *Versym = nullptr;
std::vector<const Elf_Verdef *> Verdefs = parseVerdefs(Versym);
- ArrayRef<Elf_Shdr> Sections =
- CHECK(this->getObj().sections(), toString(this));
+ ArrayRef<Elf_Shdr> Sections = CHECK(this->getObj().sections(), this);
// Add symbols to the symbol table.
Elf_Sym_Range Syms = this->getGlobalELFSyms();
@@ -819,7 +809,7 @@ template <class ELFT> void SharedFile<ELFT>::parseRest() {
bool Hidden = VersymIndex & VERSYM_HIDDEN;
VersymIndex = VersymIndex & ~VERSYM_HIDDEN;
- StringRef Name = CHECK(Sym.getName(this->StringTable), toString(this));
+ StringRef Name = CHECK(Sym.getName(this->StringTable), this);
if (Sym.isUndefined()) {
Undefs.push_back(Name);
continue;
@@ -916,7 +906,7 @@ BitcodeFile::BitcodeFile(MemoryBufferRef MB, StringRef ArchiveName,
MemoryBufferRef MBRef(MB.getBuffer(),
Saver.save(ArchiveName + MB.getBufferIdentifier() +
utostr(OffsetInArchive)));
- Obj = CHECK(lto::InputFile::create(MBRef), toString(this));
+ Obj = CHECK(lto::InputFile::create(MBRef), this);
Triple T(Obj->getTargetTriple());
EKind = getBitcodeELFKind(T);
@@ -1081,20 +1071,20 @@ template <class ELFT> std::vector<StringRef> LazyObjFile::getElfSymbols() {
typedef typename ELFT::SymRange Elf_Sym_Range;
ELFFile<ELFT> Obj = check(ELFFile<ELFT>::create(this->MB.getBuffer()));
- ArrayRef<Elf_Shdr> Sections = CHECK(Obj.sections(), toString(this));
+ ArrayRef<Elf_Shdr> Sections = CHECK(Obj.sections(), this);
for (const Elf_Shdr &Sec : Sections) {
if (Sec.sh_type != SHT_SYMTAB)
continue;
- Elf_Sym_Range Syms = CHECK(Obj.symbols(&Sec), toString(this));
+ Elf_Sym_Range Syms = CHECK(Obj.symbols(&Sec), this);
uint32_t FirstNonLocal = Sec.sh_info;
StringRef StringTable =
- CHECK(Obj.getStringTableForSymtab(Sec, Sections), toString(this));
+ CHECK(Obj.getStringTableForSymtab(Sec, Sections), this);
std::vector<StringRef> V;
for (const Elf_Sym &Sym : Syms.slice(FirstNonLocal))
if (Sym.st_shndx != SHN_UNDEF)
- V.push_back(CHECK(Sym.getName(StringTable), toString(this)));
+ V.push_back(CHECK(Sym.getName(StringTable), this));
return V;
}
return {};
@@ -1102,7 +1092,7 @@ template <class ELFT> std::vector<StringRef> LazyObjFile::getElfSymbols() {
std::vector<StringRef> LazyObjFile::getBitcodeSymbols() {
std::unique_ptr<lto::InputFile> Obj =
- CHECK(lto::InputFile::create(this->MB), toString(this));
+ CHECK(lto::InputFile::create(this->MB), this);
std::vector<StringRef> V;
for (const lto::InputFile::Symbol &Sym : Obj->symbols())
if (!Sym.isUndefined())
diff --git a/lld/include/lld/Common/ErrorHandler.h b/lld/include/lld/Common/ErrorHandler.h
index 5f544b88155..8ae6f46ac59 100644
--- a/lld/include/lld/Common/ErrorHandler.h
+++ b/lld/include/lld/Common/ErrorHandler.h
@@ -102,12 +102,10 @@ T check2(Expected<T> E, llvm::function_ref<std::string()> Prefix) {
return std::move(*E);
}
-inline std::string checkToString(const Twine &S) { return S.str(); }
-inline std::string checkToString(std::string S) { return S; }
-inline std::string checkToString(const char *S) { return S; }
+inline std::string toString(const Twine &S) { return S.str(); }
// To evaluate the second argument lazily, we use C macro.
-#define CHECK(E, S) check2(E, [&] { return checkToString(S); })
+#define CHECK(E, S) check2(E, [&] { return toString(S); })
} // namespace lld
OpenPOWER on IntegriCloud