Index: COFF/InputFiles.cpp =================================================================== --- COFF/InputFiles.cpp +++ COFF/InputFiles.cpp @@ -63,7 +63,7 @@ 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 @@ void ObjFile::parse() { // Parse a memory buffer as a COFF file. - std::unique_ptr Bin = CHECK(createBinary(MB), toString(this)); + std::unique_ptr Bin = CHECK(createBinary(MB), this); if (auto *Obj = dyn_cast(Bin.get())) { Bin.release(); Index: ELF/InputFiles.cpp =================================================================== --- ELF/InputFiles.cpp +++ ELF/InputFiles.cpp @@ -209,20 +209,19 @@ template uint32_t ELFFileBase::getSectionIndex(const Elf_Sym &Sym) const { - return CHECK(getObj().getSectionIndex(&Sym, ELFSyms, SymtabSHNDX), - toString(this)); + return CHECK(getObj().getSectionIndex(&Sym, ELFSyms, SymtabSHNDX), this); } template void ELFFileBase::initSymtab(ArrayRef 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 @@ -254,12 +253,11 @@ // 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(Sections, Sec.sh_link), toString(this))); + Sections, CHECK(object::getSection(Sections, Sec.sh_link), this)); - const Elf_Sym *Sym = CHECK( - object::getSymbol(this->ELFSyms, Sec.sh_info), toString(this)); - StringRef Signature = CHECK(Sym->getName(this->StringTable), toString(this)); + const Elf_Sym *Sym = + CHECK(object::getSymbol(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 @@ ArrayRef::Elf_Word> ObjFile::getShtGroupEntries(const Elf_Shdr &Sec) { const ELFFile &Obj = this->getObj(); - ArrayRef Entries = CHECK( - Obj.template getSectionContentsAsArray(&Sec), toString(this)); + ArrayRef Entries = + CHECK(Obj.template getSectionContentsAsArray(&Sec), this); if (Entries.empty() || Entries[0] != GRP_COMDAT) fatal(toString(this) + ": unsupported SHT_GROUP format"); return Entries.slice(1); @@ -323,12 +321,11 @@ DenseSet &ComdatGroups) { const ELFFile &Obj = this->getObj(); - ArrayRef ObjSections = - CHECK(this->getObj().sections(), toString(this)); + ArrayRef 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 @@ 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 @@ size_t NumRelocations; if (Sec.sh_type == SHT_RELA) { - ArrayRef Rels = - CHECK(this->getObj().relas(&Sec), toString(this)); + ArrayRef Rels = CHECK(this->getObj().relas(&Sec), this); Target->FirstRelocation = Rels.begin(); NumRelocations = Rels.size(); Target->AreRelocsRela = true; } else { - ArrayRef Rels = CHECK(this->getObj().rels(&Sec), toString(this)); + ArrayRef Rels = CHECK(this->getObj().rels(&Sec), this); Target->FirstRelocation = Rels.begin(); NumRelocations = Rels.size(); Target->AreRelocsRela = false; @@ -595,8 +590,7 @@ template StringRef ObjFile::getSectionName(const Elf_Shdr &Sec) { - return CHECK(this->getObj().getSectionName(&Sec, SectionStringTable), - toString(this)); + return CHECK(this->getObj().getSectionName(&Sec, SectionStringTable), this); } template void ObjFile::initializeSymbols() { @@ -628,7 +622,7 @@ 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 @@ return make(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 @@ 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 @@ template void SharedFile::parseSoName() { const Elf_Shdr *DynamicSec = nullptr; const ELFFile Obj = this->getObj(); - ArrayRef Sections = CHECK(Obj.sections(), toString(this)); + ArrayRef 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 @@ 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 @@ if (!DynamicSec) return; ArrayRef Arr = - CHECK(Obj.template getSectionContentsAsArray(DynamicSec), - toString(this)); + CHECK(Obj.template getSectionContentsAsArray(DynamicSec), this); for (const Elf_Dyn &Dyn : Arr) { if (Dyn.d_tag == DT_SONAME) { uint64_t Val = Dyn.getVal(); @@ -805,8 +796,7 @@ const Elf_Versym *Versym = nullptr; std::vector Verdefs = parseVerdefs(Versym); - ArrayRef Sections = - CHECK(this->getObj().sections(), toString(this)); + ArrayRef Sections = CHECK(this->getObj().sections(), this); // Add symbols to the symbol table. Elf_Sym_Range Syms = this->getGlobalELFSyms(); @@ -819,7 +809,7 @@ 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 @@ 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 @@ typedef typename ELFT::SymRange Elf_Sym_Range; ELFFile Obj = check(ELFFile::create(this->MB.getBuffer())); - ArrayRef Sections = CHECK(Obj.sections(), toString(this)); + ArrayRef 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 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 @@ std::vector LazyObjFile::getBitcodeSymbols() { std::unique_ptr Obj = - CHECK(lto::InputFile::create(this->MB), toString(this)); + CHECK(lto::InputFile::create(this->MB), this); std::vector V; for (const lto::InputFile::Symbol &Sym : Obj->symbols()) if (!Sym.isUndefined()) Index: include/lld/Common/ErrorHandler.h =================================================================== --- include/lld/Common/ErrorHandler.h +++ include/lld/Common/ErrorHandler.h @@ -102,12 +102,10 @@ 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