[lld] 58a971f - [ELF] Replace contex-less toString(x) with toStr(ctx, x)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 16 11:58:15 PST 2024
Author: Fangrui Song
Date: 2024-11-16T11:58:10-08:00
New Revision: 58a971f42f1f2b2e25995c8cad439f4aa07c024d
URL: https://github.com/llvm/llvm-project/commit/58a971f42f1f2b2e25995c8cad439f4aa07c024d
DIFF: https://github.com/llvm/llvm-project/commit/58a971f42f1f2b2e25995c8cad439f4aa07c024d.diff
LOG: [ELF] Replace contex-less toString(x) with toStr(ctx, x)
so that we can remove the global `ctx` from toString implementations.
Rename lld::toString (to lld::elf::toStr) to simplify name lookup (we
have many llvm::toString and another lld::toString(const llvm::opt::Arg
&)).
Added:
Modified:
lld/ELF/Arch/AArch64.cpp
lld/ELF/Arch/AMDGPU.cpp
lld/ELF/Arch/ARM.cpp
lld/ELF/Arch/Hexagon.cpp
lld/ELF/Arch/LoongArch.cpp
lld/ELF/Arch/Mips.cpp
lld/ELF/Arch/PPC.cpp
lld/ELF/Arch/PPC64.cpp
lld/ELF/Arch/RISCV.cpp
lld/ELF/Arch/SystemZ.cpp
lld/ELF/Arch/X86.cpp
lld/ELF/Arch/X86_64.cpp
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/ICF.cpp
lld/ELF/InputFiles.cpp
lld/ELF/InputFiles.h
lld/ELF/InputSection.cpp
lld/ELF/InputSection.h
lld/ELF/MapFile.cpp
lld/ELF/MarkLive.cpp
lld/ELF/OutputSections.cpp
lld/ELF/Relocations.cpp
lld/ELF/Symbols.cpp
lld/ELF/Symbols.h
lld/ELF/SyntheticSections.cpp
lld/ELF/Target.cpp
lld/ELF/Target.h
Removed:
################################################################################
diff --git a/lld/ELF/Arch/AArch64.cpp b/lld/ELF/Arch/AArch64.cpp
index c4334a6b1a1012..3d048e81fa7fb4 100644
--- a/lld/ELF/Arch/AArch64.cpp
+++ b/lld/ELF/Arch/AArch64.cpp
@@ -349,7 +349,8 @@ int64_t AArch64::getImplicitAddend(const uint8_t *buf, RelType type) const {
default:
internalLinkerError(getErrorLoc(ctx, buf),
- "cannot read addend for relocation " + toString(type));
+ "cannot read addend for relocation " +
+ toStr(ctx, type));
return 0;
}
}
diff --git a/lld/ELF/Arch/AMDGPU.cpp b/lld/ELF/Arch/AMDGPU.cpp
index fb567085de3719..4dd085d2f719f3 100644
--- a/lld/ELF/Arch/AMDGPU.cpp
+++ b/lld/ELF/Arch/AMDGPU.cpp
@@ -214,7 +214,8 @@ int64_t AMDGPU::getImplicitAddend(const uint8_t *buf, RelType type) const {
return read64(ctx, buf);
default:
internalLinkerError(getErrorLoc(ctx, buf),
- "cannot read addend for relocation " + toString(type));
+ "cannot read addend for relocation " +
+ toStr(ctx, type));
return 0;
}
}
diff --git a/lld/ELF/Arch/ARM.cpp b/lld/ELF/Arch/ARM.cpp
index 27986ddafeeb48..b797be9359c077 100644
--- a/lld/ELF/Arch/ARM.cpp
+++ b/lld/ELF/Arch/ARM.cpp
@@ -876,7 +876,8 @@ int64_t ARM::getImplicitAddend(const uint8_t *buf, RelType type) const {
switch (type) {
default:
internalLinkerError(getErrorLoc(ctx, buf),
- "cannot read addend for relocation " + toString(type));
+ "cannot read addend for relocation " +
+ toStr(ctx, type));
return 0;
case R_ARM_ABS32:
case R_ARM_BASE_PREL:
@@ -1199,7 +1200,7 @@ template <class ELFT> void ObjFile<ELFT>::importCmseSymbols() {
ArrayRef<Elf_Sym> eSyms = getELFSyms<ELFT>();
// Error for local symbols. The symbol at index 0 is LOCAL. So skip it.
for (size_t i = 1, end = firstGlobal; i != end; ++i) {
- Err(ctx) << "CMSE symbol '" << CHECK(eSyms[i].getName(stringTable), this)
+ Err(ctx) << "CMSE symbol '" << CHECK2(eSyms[i].getName(stringTable), this)
<< "' in import library '" << this << "' is not global";
}
@@ -1209,7 +1210,7 @@ template <class ELFT> void ObjFile<ELFT>::importCmseSymbols() {
// Initialize symbol fields.
memset(static_cast<void *>(sym), 0, sizeof(Symbol));
- sym->setName(CHECK(eSyms[i].getName(stringTable), this));
+ sym->setName(CHECK2(eSyms[i].getName(stringTable), this));
sym->value = eSym.st_value;
sym->size = eSym.st_size;
sym->type = eSym.getType();
@@ -1248,15 +1249,16 @@ template <class ELFT> void ObjFile<ELFT>::importCmseSymbols() {
// Check symbol attributes of the acleSeSym, sym pair.
// Both symbols should be global/weak Thumb code symbol definitions.
-static std::string checkCmseSymAttributes(Symbol *acleSeSym, Symbol *sym) {
- auto check = [](Symbol *s, StringRef type) -> std::optional<std::string> {
+static std::string checkCmseSymAttributes(Ctx &ctx, Symbol *acleSeSym,
+ Symbol *sym) {
+ auto check = [&](Symbol *s, StringRef type) -> std::optional<std::string> {
auto d = dyn_cast_or_null<Defined>(s);
if (!(d && d->isFunc() && (d->value & 1)))
- return (Twine(toString(s->file)) + ": cmse " + type + " symbol '" +
+ return (Twine(toStr(ctx, s->file)) + ": cmse " + type + " symbol '" +
s->getName() + "' is not a Thumb function definition")
.str();
if (!d->section)
- return (Twine(toString(s->file)) + ": cmse " + type + " symbol '" +
+ return (Twine(toStr(ctx, s->file)) + ": cmse " + type + " symbol '" +
s->getName() + "' cannot be an absolute symbol")
.str();
return std::nullopt;
@@ -1305,7 +1307,7 @@ void elf::processArmCmseSymbols(Ctx &ctx) {
continue;
}
- std::string errMsg = checkCmseSymAttributes(acleSeSym, sym);
+ std::string errMsg = checkCmseSymAttributes(ctx, acleSeSym, sym);
if (!errMsg.empty()) {
ErrAlways(ctx) << errMsg;
continue;
diff --git a/lld/ELF/Arch/Hexagon.cpp b/lld/ELF/Arch/Hexagon.cpp
index 84b1bfb5662ced..9657c5d098a690 100644
--- a/lld/ELF/Arch/Hexagon.cpp
+++ b/lld/ELF/Arch/Hexagon.cpp
@@ -412,7 +412,8 @@ int64_t Hexagon::getImplicitAddend(const uint8_t *buf, RelType type) const {
return SignExtend64<32>(read32(ctx, buf));
default:
internalLinkerError(getErrorLoc(ctx, buf),
- "cannot read addend for relocation " + toString(type));
+ "cannot read addend for relocation " +
+ toStr(ctx, type));
return 0;
}
}
diff --git a/lld/ELF/Arch/LoongArch.cpp b/lld/ELF/Arch/LoongArch.cpp
index 328e6bab244413..669cd6103e1da9 100644
--- a/lld/ELF/Arch/LoongArch.cpp
+++ b/lld/ELF/Arch/LoongArch.cpp
@@ -280,7 +280,8 @@ int64_t LoongArch::getImplicitAddend(const uint8_t *buf, RelType type) const {
switch (type) {
default:
internalLinkerError(getErrorLoc(ctx, buf),
- "cannot read addend for relocation " + toString(type));
+ "cannot read addend for relocation " +
+ toStr(ctx, type));
return 0;
case R_LARCH_32:
case R_LARCH_TLS_DTPMOD32:
diff --git a/lld/ELF/Arch/Mips.cpp b/lld/ELF/Arch/Mips.cpp
index fb6355cd19b62c..6e8be75da5cc77 100644
--- a/lld/ELF/Arch/Mips.cpp
+++ b/lld/ELF/Arch/Mips.cpp
@@ -476,7 +476,8 @@ int64_t MIPS<ELFT>::getImplicitAddend(const uint8_t *buf, RelType type) const {
return 0;
default:
internalLinkerError(getErrorLoc(ctx, buf),
- "cannot read addend for relocation " + toString(type));
+ "cannot read addend for relocation " +
+ toStr(ctx, type));
return 0;
}
}
diff --git a/lld/ELF/Arch/PPC.cpp b/lld/ELF/Arch/PPC.cpp
index 8b0af6c4a49d70..4af2aed73bc456 100644
--- a/lld/ELF/Arch/PPC.cpp
+++ b/lld/ELF/Arch/PPC.cpp
@@ -297,7 +297,8 @@ int64_t PPC::getImplicitAddend(const uint8_t *buf, RelType type) const {
return SignExtend64<32>(read32(ctx, buf));
default:
internalLinkerError(getErrorLoc(ctx, buf),
- "cannot read addend for relocation " + toString(type));
+ "cannot read addend for relocation " +
+ toStr(ctx, type));
return 0;
}
}
diff --git a/lld/ELF/Arch/PPC64.cpp b/lld/ELF/Arch/PPC64.cpp
index a7188e2e858402..e5be461fcfacbb 100644
--- a/lld/ELF/Arch/PPC64.cpp
+++ b/lld/ELF/Arch/PPC64.cpp
@@ -1131,7 +1131,8 @@ int64_t PPC64::getImplicitAddend(const uint8_t *buf, RelType type) const {
return read64(ctx, buf);
default:
internalLinkerError(getErrorLoc(ctx, buf),
- "cannot read addend for relocation " + toString(type));
+ "cannot read addend for relocation " +
+ toStr(ctx, type));
return 0;
}
}
@@ -1618,7 +1619,7 @@ void PPC64::relocateAlloc(InputSectionBase &sec, uint8_t *buf) const {
rel.sym->file != sec.file) {
// Use substr(6) to remove the "__plt_" prefix.
Err(ctx) << getErrorLoc(ctx, loc) << "call to "
- << lld::toString(*rel.sym).substr(6)
+ << toStr(ctx, *rel.sym).substr(6)
<< " lacks nop, can't restore toc";
break;
}
diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index 146a875a65c270..581c0c16da3004 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -173,7 +173,8 @@ int64_t RISCV::getImplicitAddend(const uint8_t *buf, RelType type) const {
switch (type) {
default:
internalLinkerError(getErrorLoc(ctx, buf),
- "cannot read addend for relocation " + toString(type));
+ "cannot read addend for relocation " +
+ toStr(ctx, type));
return 0;
case R_RISCV_32:
case R_RISCV_TLS_DTPMOD32:
diff --git a/lld/ELF/Arch/SystemZ.cpp b/lld/ELF/Arch/SystemZ.cpp
index 3b78ce14aa1224..50534808487932 100644
--- a/lld/ELF/Arch/SystemZ.cpp
+++ b/lld/ELF/Arch/SystemZ.cpp
@@ -262,7 +262,8 @@ int64_t SystemZ::getImplicitAddend(const uint8_t *buf, RelType type) const {
return 0;
default:
internalLinkerError(getErrorLoc(ctx, buf),
- "cannot read addend for relocation " + toString(type));
+ "cannot read addend for relocation " +
+ toStr(ctx, type));
return 0;
}
}
diff --git a/lld/ELF/Arch/X86.cpp b/lld/ELF/Arch/X86.cpp
index ac69d032e2fbff..2d6b6c80da683e 100644
--- a/lld/ELF/Arch/X86.cpp
+++ b/lld/ELF/Arch/X86.cpp
@@ -281,7 +281,8 @@ int64_t X86::getImplicitAddend(const uint8_t *buf, RelType type) const {
return 0;
default:
internalLinkerError(getErrorLoc(ctx, buf),
- "cannot read addend for relocation " + toString(type));
+ "cannot read addend for relocation " +
+ toStr(ctx, type));
return 0;
}
}
diff --git a/lld/ELF/Arch/X86_64.cpp b/lld/ELF/Arch/X86_64.cpp
index 8c183c021cd8af..f4f5b1f077edf7 100644
--- a/lld/ELF/Arch/X86_64.cpp
+++ b/lld/ELF/Arch/X86_64.cpp
@@ -769,7 +769,8 @@ int64_t X86_64::getImplicitAddend(const uint8_t *buf, RelType type) const {
return 0;
default:
internalLinkerError(getErrorLoc(ctx, buf),
- "cannot read addend for relocation " + toString(type));
+ "cannot read addend for relocation " +
+ toStr(ctx, type));
return 0;
}
}
diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index 227f87e2dd01b9..f7da272ab9bc4e 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -721,6 +721,8 @@ ELFSyncStream Fatal(Ctx &ctx);
uint64_t errCount(Ctx &ctx);
+#define CHECK2(E, S) lld::check2((E), [&] { return toStr(ctx, S); })
+
} // namespace lld::elf
#endif
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index b108ce3aa7035a..d913ffd8f0b6aa 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -2307,15 +2307,15 @@ static void writeWhyExtract(Ctx &ctx) {
os << "reference\textracted\tsymbol\n";
for (auto &entry : ctx.whyExtractRecords) {
- os << std::get<0>(entry) << '\t' << toString(std::get<1>(entry)) << '\t'
- << toString(std::get<2>(entry)) << '\n';
+ os << std::get<0>(entry) << '\t' << toStr(ctx, std::get<1>(entry)) << '\t'
+ << toStr(ctx, std::get<2>(entry)) << '\n';
}
}
static void reportBackrefs(Ctx &ctx) {
for (auto &ref : ctx.backwardReferences) {
const Symbol &sym = *ref.first;
- std::string to = toString(ref.second.second);
+ std::string to = toStr(ctx, ref.second.second);
// Some libraries have known problems and can cause noise. Filter them out
// with --warn-backrefs-exclude=. The value may look like (for --start-lib)
// *.o or (archive member) *.a(*.o).
@@ -2807,23 +2807,23 @@ static void readSecurityNotes(Ctx &ctx) {
checkAndReportMissingFeature(
ctx, ctx.arg.zBtiReport, features, GNU_PROPERTY_AARCH64_FEATURE_1_BTI,
- toString(f) + ": -z bti-report: file does not have "
- "GNU_PROPERTY_AARCH64_FEATURE_1_BTI property");
+ toStr(ctx, f) + ": -z bti-report: file does not have "
+ "GNU_PROPERTY_AARCH64_FEATURE_1_BTI property");
checkAndReportMissingFeature(
ctx, ctx.arg.zGcsReport, features, GNU_PROPERTY_AARCH64_FEATURE_1_GCS,
- toString(f) + ": -z gcs-report: file does not have "
- "GNU_PROPERTY_AARCH64_FEATURE_1_GCS property");
+ toStr(ctx, f) + ": -z gcs-report: file does not have "
+ "GNU_PROPERTY_AARCH64_FEATURE_1_GCS property");
checkAndReportMissingFeature(
ctx, ctx.arg.zCetReport, features, GNU_PROPERTY_X86_FEATURE_1_IBT,
- toString(f) + ": -z cet-report: file does not have "
- "GNU_PROPERTY_X86_FEATURE_1_IBT property");
+ toStr(ctx, f) + ": -z cet-report: file does not have "
+ "GNU_PROPERTY_X86_FEATURE_1_IBT property");
checkAndReportMissingFeature(
ctx, ctx.arg.zCetReport, features, GNU_PROPERTY_X86_FEATURE_1_SHSTK,
- toString(f) + ": -z cet-report: file does not have "
- "GNU_PROPERTY_X86_FEATURE_1_SHSTK property");
+ toStr(ctx, f) + ": -z cet-report: file does not have "
+ "GNU_PROPERTY_X86_FEATURE_1_SHSTK property");
if (ctx.arg.zForceBti && !(features & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)) {
features |= GNU_PROPERTY_AARCH64_FEATURE_1_BTI;
@@ -2854,7 +2854,7 @@ static void readSecurityNotes(Ctx &ctx) {
if (f->aarch64PauthAbiCoreInfo.empty()) {
reportMissingFeature(ctx, ctx.arg.zPauthReport,
- toString(f) +
+ toStr(ctx, f) +
": -z pauth-report: file does not have AArch64 "
"PAuth core info while '" +
referenceFileName + "' has one");
diff --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp
index f58e072334638d..0bf55177113044 100644
--- a/lld/ELF/ICF.cpp
+++ b/lld/ELF/ICF.cpp
@@ -548,9 +548,9 @@ template <class ELFT> void ICF<ELFT>::run() {
forEachClassRange(0, sections.size(), [&](size_t begin, size_t end) {
if (end - begin == 1)
return;
- print(ctx, "selected section " + toString(sections[begin]));
+ print(ctx, "selected section " + toStr(ctx, sections[begin]));
for (size_t i = begin + 1; i < end; ++i) {
- print(ctx, " removing identical section " + toString(sections[i]));
+ print(ctx, " removing identical section " + toStr(ctx, sections[i]));
sections[begin]->replace(sections[i]);
// At this point we know sections merged are fully identical and hence
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 769081fa71a449..15737650be4c68 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -49,7 +49,7 @@ extern template void ObjFile<ELF64LE>::importCmseSymbols();
extern template void ObjFile<ELF64BE>::importCmseSymbols();
// Returns "<internal>", "foo.a(bar.o)" or "baz.o".
-std::string lld::toString(const InputFile *f) {
+std::string elf::toStr(Ctx &ctx, const InputFile *f) {
static std::mutex mu;
if (!f)
return "<internal>";
@@ -68,7 +68,7 @@ std::string lld::toString(const InputFile *f) {
const ELFSyncStream &elf::operator<<(const ELFSyncStream &s,
const InputFile *f) {
- return s << toString(f);
+ return s << toStr(s.ctx, f);
}
static ELFKind getELFKind(Ctx &ctx, MemoryBufferRef mb, StringRef archiveName) {
@@ -295,7 +295,7 @@ static bool isCompatible(Ctx &ctx, InputFile *file) {
existing = ctx.bitcodeFiles[0];
std::string with;
if (existing)
- with = " with " + toString(existing);
+ with = " with " + toStr(ctx, existing);
ErrAlways(ctx) << file << " is incompatible" << with;
return false;
}
@@ -316,7 +316,7 @@ template <class ELFT> static void doParseFile(Ctx &ctx, InputFile *file) {
}
if (ctx.arg.trace)
- message(toString(file));
+ message(toStr(ctx, file));
if (file->kind() == InputFile::ObjKind) {
ctx.objectFiles.push_back(cast<ELFFileBase>(file));
@@ -557,7 +557,7 @@ template <class ELFT> void ELFFileBase::init(InputFile::Kind k) {
osabi = obj.getHeader().e_ident[llvm::ELF::EI_OSABI];
abiVersion = obj.getHeader().e_ident[llvm::ELF::EI_ABIVERSION];
- ArrayRef<Elf_Shdr> sections = CHECK(obj.sections(), this);
+ ArrayRef<Elf_Shdr> sections = CHECK2(obj.sections(), this);
elfShdrs = sections.data();
numELFShdrs = sections.size();
@@ -571,18 +571,18 @@ template <class ELFT> void ELFFileBase::init(InputFile::Kind k) {
// Initialize members corresponding to a symbol table.
firstGlobal = symtabSec->sh_info;
- ArrayRef<Elf_Sym> eSyms = CHECK(obj.symbols(symtabSec), this);
+ ArrayRef<Elf_Sym> eSyms = CHECK2(obj.symbols(symtabSec), this);
if (firstGlobal == 0 || firstGlobal > eSyms.size())
Fatal(ctx) << this << ": invalid sh_info in symbol table";
elfSyms = reinterpret_cast<const void *>(eSyms.data());
numELFSyms = uint32_t(eSyms.size());
- stringTable = CHECK(obj.getStringTableForSymtab(*symtabSec, sections), this);
+ stringTable = CHECK2(obj.getStringTableForSymtab(*symtabSec, sections), this);
}
template <class ELFT>
uint32_t ObjFile<ELFT>::getSectionIndex(const Elf_Sym &sym) const {
- return CHECK(
+ return CHECK2(
this->getObj().getSectionIndex(sym, getELFSyms<ELFT>(), shndxTable),
this);
}
@@ -599,14 +599,14 @@ template <class ELFT> void ObjFile<ELFT>::parse(bool ignoreComdats) {
// Handle dependent libraries and selection of section groups as these are not
// done in parallel.
ArrayRef<Elf_Shdr> objSections = getELFShdrs<ELFT>();
- StringRef shstrtab = CHECK(obj.getSectionStringTable(objSections), this);
+ StringRef shstrtab = CHECK2(obj.getSectionStringTable(objSections), this);
uint64_t size = objSections.size();
sections.resize(size);
for (size_t i = 0; i != size; ++i) {
const Elf_Shdr &sec = objSections[i];
if (sec.sh_type == SHT_LLVM_DEPENDENT_LIBRARIES && !ctx.arg.relocatable) {
StringRef name = check(obj.getSectionName(sec, shstrtab));
- ArrayRef<char> data = CHECK(
+ ArrayRef<char> data = CHECK2(
this->getObj().template getSectionContentsAsArray<char>(sec), this);
if (!data.empty() && data.back() != '\0') {
ErrAlways(ctx)
@@ -664,7 +664,7 @@ template <class ELFT> void ObjFile<ELFT>::parse(bool ignoreComdats) {
continue;
StringRef signature = getShtGroupSignature(objSections, sec);
ArrayRef<Elf_Word> entries =
- CHECK(obj.template getSectionContentsAsArray<Elf_Word>(sec), this);
+ CHECK2(obj.template getSectionContentsAsArray<Elf_Word>(sec), this);
if (entries.empty())
Fatal(ctx) << this << ": empty SHT_GROUP";
@@ -706,7 +706,7 @@ StringRef ObjFile<ELFT>::getShtGroupSignature(ArrayRef<Elf_Shdr> sections,
if (sec.sh_info >= symbols.size())
Fatal(ctx) << this << ": invalid symbol index";
const typename ELFT::Sym &sym = symbols[sec.sh_info];
- return CHECK(sym.getName(this->stringTable), this);
+ return CHECK2(sym.getName(this->stringTable), this);
}
template <class ELFT>
@@ -779,7 +779,7 @@ template <class ELFT>
void ObjFile<ELFT>::initializeSections(bool ignoreComdats,
const llvm::object::ELFFile<ELFT> &obj) {
ArrayRef<Elf_Shdr> objSections = getELFShdrs<ELFT>();
- StringRef shstrtab = CHECK(obj.getSectionStringTable(objSections), this);
+ StringRef shstrtab = CHECK2(obj.getSectionStringTable(objSections), this);
uint64_t size = objSections.size();
SmallVector<ArrayRef<Elf_Word>, 0> selectedGroups;
for (size_t i = 0; i != size; ++i) {
@@ -828,7 +828,7 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats,
break;
}
case SHT_SYMTAB_SHNDX:
- shndxTable = CHECK(obj.getSHNDXTable(sec, objSections), this);
+ shndxTable = CHECK2(obj.getSHNDXTable(sec, objSections), this);
break;
case SHT_SYMTAB:
case SHT_STRTAB:
@@ -1139,7 +1139,7 @@ void ObjFile<ELFT>::initializeSymbols(const object::ELFFile<ELFT> &obj) {
auto *symtab = ctx.symtab.get();
for (size_t i = firstGlobal, end = eSyms.size(); i != end; ++i)
if (!symbols[i])
- symbols[i] = symtab->insert(CHECK(eSyms[i].getName(stringTable), this));
+ symbols[i] = symtab->insert(CHECK2(eSyms[i].getName(stringTable), this));
// Perform symbol resolution on non-local symbols.
SmallVector<unsigned, 32> undefineds;
@@ -1218,7 +1218,7 @@ void ObjFile<ELFT>::initSectionsAndLocalSyms(bool ignoreComdats) {
InputSectionBase *sec = sections[secIdx];
uint8_t type = eSym.getType();
if (type == STT_FILE)
- sourceFile = CHECK(eSym.getName(stringTable), this);
+ sourceFile = CHECK2(eSym.getName(stringTable), this);
if (LLVM_UNLIKELY(stringTable.size() <= eSym.st_name))
Fatal(ctx) << this << ": invalid symbol name offset";
StringRef name(stringTable.data() + eSym.st_name);
@@ -1404,7 +1404,7 @@ std::vector<uint32_t> SharedFile::parseVerneed(const ELFFile<ELFT> &obj,
if (!sec)
return {};
std::vector<uint32_t> verneeds;
- ArrayRef<uint8_t> data = CHECK(obj.getSectionContents(*sec), this);
+ ArrayRef<uint8_t> data = CHECK2(obj.getSectionContents(*sec), this);
const uint8_t *verneedBuf = data.begin();
for (unsigned i = 0; i != sec->sh_info; ++i) {
if (verneedBuf + sizeof(typename ELFT::Verneed) > data.end())
@@ -1480,7 +1480,7 @@ template <class ELFT> void SharedFile::parse() {
continue;
case SHT_DYNAMIC:
dynamicTags =
- CHECK(obj.template getSectionContentsAsArray<Elf_Dyn>(sec), this);
+ CHECK2(obj.template getSectionContentsAsArray<Elf_Dyn>(sec), this);
break;
case SHT_GNU_versym:
versymSec = &sec;
@@ -1540,8 +1540,8 @@ template <class ELFT> void SharedFile::parse() {
std::vector<uint16_t> versyms(size, VER_NDX_GLOBAL);
if (versymSec) {
ArrayRef<Elf_Versym> versym =
- CHECK(obj.template getSectionContentsAsArray<Elf_Versym>(*versymSec),
- this)
+ CHECK2(obj.template getSectionContentsAsArray<Elf_Versym>(*versymSec),
+ this)
.slice(firstGlobal);
for (size_t i = 0; i < size; ++i)
versyms[i] = versym[i].vs_index;
@@ -1561,7 +1561,7 @@ template <class ELFT> void SharedFile::parse() {
// symbols in each symbol table, and the index of first non-local symbol
// is stored to sh_info. If a local symbol appears after some non-local
// symbol, that's a violation of the spec.
- StringRef name = CHECK(sym.getName(stringTable), this);
+ StringRef name = CHECK2(sym.getName(stringTable), this);
if (sym.getBinding() == STB_LOCAL) {
Err(ctx) << this << ": invalid local symbol '" << name
<< "' in global part of symbol table";
@@ -1729,7 +1729,7 @@ BitcodeFile::BitcodeFile(Ctx &ctx, MemoryBufferRef mb, StringRef archiveName,
" at " + utostr(offsetInArchive) + ")");
MemoryBufferRef mbref(mb.getBuffer(), name);
- obj = CHECK(lto::InputFile::create(mbref), this);
+ obj = CHECK2(lto::InputFile::create(mbref), this);
Triple t(obj->getTargetTriple());
ekind = getBitcodeELFKind(t);
@@ -1917,7 +1917,7 @@ template <class ELFT> void ObjFile<ELFT>::parseLazy() {
for (size_t i = firstGlobal, end = eSyms.size(); i != end; ++i) {
if (eSyms[i].st_shndx == SHN_UNDEF)
continue;
- symbols[i] = symtab->insert(CHECK(eSyms[i].getName(stringTable), this));
+ symbols[i] = symtab->insert(CHECK2(eSyms[i].getName(stringTable), this));
symbols[i]->resolve(ctx, LazySymbol{*this});
if (!lazy)
break;
diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h
index e00e2c83d017c2..1dff172c901045 100644
--- a/lld/ELF/InputFiles.h
+++ b/lld/ELF/InputFiles.h
@@ -31,14 +31,13 @@ class InputFile;
namespace lld {
class DWARFCache;
-// Returns "<internal>", "foo.a(bar.o)" or "baz.o".
-std::string toString(const elf::InputFile *f);
-
namespace elf {
-
class InputSection;
class Symbol;
+// Returns "<internal>", "foo.a(bar.o)" or "baz.o".
+std::string toStr(Ctx &, const InputFile *f);
+
// Opens a given file.
std::optional<MemoryBufferRef> readFile(Ctx &, StringRef path);
@@ -102,7 +101,7 @@ class InputFile {
Symbol &getSymbol(uint32_t symbolIndex) const {
assert(fileKind == ObjKind);
if (symbolIndex >= numSymbols)
- fatal(toString(this) + ": invalid symbol index");
+ fatal(toStr(ctx, this) + ": invalid symbol index");
return *this->symbols[symbolIndex];
}
@@ -168,7 +167,8 @@ class InputFile {
// If not empty, this stores the name of the archive containing this file.
// We use this string for creating error messages.
SmallString<0> archiveName;
- // Cache for toString(). Only toString() should use this member.
+ // Cache for toStr(Ctx &, const InputFile *). Only toStr should use this
+ // member.
mutable SmallString<0> toStringCache;
private:
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 89ffa69d858e64..6114f570df3228 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -35,13 +35,13 @@ using namespace lld;
using namespace lld::elf;
// Returns a string to construct an error message.
-std::string lld::toString(const InputSectionBase *sec) {
- return (toString(sec->file) + ":(" + sec->name + ")").str();
+std::string elf::toStr(Ctx &ctx, const InputSectionBase *sec) {
+ return (toStr(ctx, sec->file) + ":(" + sec->name + ")").str();
}
const ELFSyncStream &elf::operator<<(const ELFSyncStream &s,
const InputSectionBase *sec) {
- return s << toString(sec);
+ return s << toStr(s.ctx, sec);
}
template <class ELFT>
@@ -309,9 +309,9 @@ std::string InputSectionBase::getLocation(uint64_t offset) const {
std::string secAndOffset =
(name + "+0x" + Twine::utohexstr(offset) + ")").str();
- std::string filename = toString(file);
+ std::string filename = toStr(ctx, file);
if (Defined *d = getEnclosingFunction(offset))
- return filename + ":(function " + toString(*d) + ": " + secAndOffset;
+ return filename + ":(function " + toStr(getCtx(), *d) + ": " + secAndOffset;
return filename + ":(" + secAndOffset;
}
@@ -347,7 +347,7 @@ std::string InputSectionBase::getObjMsg(uint64_t off) const {
// before ObjFile::initSectionsAndLocalSyms where local symbols are
// initialized.
if (Defined *d = getEnclosingSymbol(off))
- return filename + ":(" + toString(*d) + ")" + archive;
+ return filename + ":(" + toStr(ctx, *d) + ")" + archive;
// If there's no symbol, print out the offset in the section.
return (filename + ":(" + name + "+0x" + utohexstr(off) + ")" + archive)
@@ -487,7 +487,7 @@ void InputSection::copyRelocations(Ctx &ctx, uint8_t *buf,
uint32_t secIdx = cast<Undefined>(sym).discardedSecIdx;
Elf_Shdr_Impl<ELFT> sec = file->template getELFShdrs<ELFT>()[secIdx];
Warn(ctx) << "relocation refers to a discarded section: "
- << CHECK(file->getObj().getSectionName(sec), file)
+ << CHECK2(file->getObj().getSectionName(sec), file)
<< "\n>>> referenced by " << getObjMsg(p->r_offset);
}
p->setSymbolAndType(0, 0, false);
@@ -1106,7 +1106,7 @@ void InputSection::relocateNonAlloc(Ctx &ctx, uint8_t *buf,
}
std::string msg = getLocation(offset) + ": has non-ABS relocation " +
- toString(type) + " against symbol '" + toString(sym) +
+ toStr(ctx, type) + " against symbol '" + toStr(ctx, sym) +
"'";
if (expr != R_PC && !(emachine == EM_386 && type == R_386_GOTPC)) {
Err(ctx) << msg;
diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h
index 482d63cfb610af..303452fed60d86 100644
--- a/lld/ELF/InputSection.h
+++ b/lld/ELF/InputSection.h
@@ -501,11 +501,10 @@ inline bool isDebugSection(const InputSectionBase &sec) {
sec.name.starts_with(".debug");
}
+std::string toStr(elf::Ctx &, const elf::InputSectionBase *);
const ELFSyncStream &operator<<(const ELFSyncStream &,
const InputSectionBase *);
} // namespace elf
-
-std::string toString(const elf::InputSectionBase *);
} // namespace lld
#endif
diff --git a/lld/ELF/MapFile.cpp b/lld/ELF/MapFile.cpp
index caf386ad2d6278..f18d799a8c4e4b 100644
--- a/lld/ELF/MapFile.cpp
+++ b/lld/ELF/MapFile.cpp
@@ -87,7 +87,7 @@ static SymbolMapTy getSectionSyms(Ctx &ctx, ArrayRef<Defined *> syms) {
}
// Construct a map from symbols to their stringified representations.
-// Demangling symbols (which is what toString() does) is slow, so
+// Demangling symbols (which is what toStr(ctx, ) does) is slow, so
// we do that in batch using parallel-for.
static DenseMap<Symbol *, std::string>
getSymbolStrings(Ctx &ctx, ArrayRef<Defined *> syms) {
@@ -98,7 +98,7 @@ getSymbolStrings(Ctx &ctx, ArrayRef<Defined *> syms) {
uint64_t vma = syms[i]->getVA(ctx);
uint64_t lma = osec ? osec->getLMA() + vma - osec->getVA(0) : 0;
writeHeader(ctx, os, vma, lma, syms[i]->getSize(), 1);
- os << indent16 << toString(*syms[i]);
+ os << indent16 << toStr(ctx, *syms[i]);
});
DenseMap<Symbol *, std::string> ret;
@@ -141,7 +141,7 @@ static void printEhFrame(Ctx &ctx, raw_ostream &os, const EhFrameSection *sec) {
for (EhSectionPiece &p : pieces) {
writeHeader(ctx, os, osec->addr + p.outputOff, osec->getLMA() + p.outputOff,
p.size, 1);
- os << indent8 << toString(p.sec->file) << ":(" << p.sec->name << "+0x"
+ os << indent8 << toStr(ctx, p.sec->file) << ":(" << p.sec->name << "+0x"
<< Twine::utohexstr(p.inputOff) + ")\n";
}
}
@@ -186,7 +186,7 @@ static void writeMapFile(Ctx &ctx, raw_fd_ostream &os) {
writeHeader(ctx, os, isec->getVA(), osec->getLMA() + isec->outSecOff,
isec->getSize(), isec->addralign);
- os << indent8 << toString(isec) << '\n';
+ os << indent8 << toStr(ctx, isec) << '\n';
for (Symbol *sym : llvm::make_first_range(sectionSyms[isec]))
os << symStr[sym] << '\n';
}
@@ -250,10 +250,10 @@ static void writeCref(Ctx &ctx, raw_fd_ostream &os) {
Symbol *sym = kv.first;
SetVector<InputFile *> &files = kv.second;
- print(toString(*sym), toString(sym->file));
+ print(toStr(ctx, *sym), toStr(ctx, sym->file));
for (InputFile *file : files)
if (file != sym->file)
- print("", toString(file));
+ print("", toStr(ctx, file));
}
}
diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp
index 9b6aa1982b577e..ab61b8be0ad669 100644
--- a/lld/ELF/MarkLive.cpp
+++ b/lld/ELF/MarkLive.cpp
@@ -391,7 +391,7 @@ template <class ELFT> void elf::markLive(Ctx &ctx) {
if (ctx.arg.printGcSections)
for (InputSectionBase *sec : ctx.inputSections)
if (!sec->isLive())
- message("removing unused section " + toString(sec));
+ message("removing unused section " + toStr(ctx, sec));
}
template void elf::markLive<ELF32LE>(Ctx &);
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index 9eff2a42ccc285..bb785ab9bbcc21 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -912,9 +912,9 @@ void OutputSection::checkDynRelAddends(Ctx &ctx) {
getErrorLoc(ctx, relocTarget),
"wrote incorrect addend value 0x" + utohexstr(writtenAddend) +
" instead of 0x" + utohexstr(addend) +
- " for dynamic relocation " + toString(rel.type) +
+ " for dynamic relocation " + toStr(ctx, rel.type) +
" at offset 0x" + utohexstr(rel.getOffset()) +
- (rel.sym ? " against symbol " + toString(*rel.sym) : ""));
+ (rel.sym ? " against symbol " + toStr(ctx, *rel.sym) : ""));
}
});
}
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 697e04d21aab09..56b654ae510191 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -77,7 +77,7 @@ static std::optional<std::string> getLinkerScriptLocation(Ctx &ctx,
static std::string getDefinedLocation(Ctx &ctx, const Symbol &sym) {
const char msg[] = "\n>>> defined in ";
if (sym.file)
- return msg + toString(sym.file);
+ return msg + toStr(ctx, sym.file);
if (std::optional<std::string> loc = getLinkerScriptLocation(ctx, sym))
return msg + *loc;
return "";
@@ -103,7 +103,7 @@ void elf::reportRangeError(Ctx &ctx, uint8_t *loc, const Relocation &rel,
std::string hint;
if (rel.sym) {
if (!rel.sym->isSection())
- hint = "; references '" + lld::toString(*rel.sym) + '\'';
+ hint = "; references '" + toStr(ctx, *rel.sym) + '\'';
else if (auto *d = dyn_cast<Defined>(rel.sym))
hint = ("; references section '" + d->section->name + "'").str();
@@ -133,7 +133,7 @@ void elf::reportRangeError(Ctx &ctx, uint8_t *loc, int64_t v, int n,
ErrorPlace errPlace = getErrorPlace(ctx, loc);
std::string hint;
if (!sym.getName().empty())
- hint = "; references '" + lld::toString(sym) + '\'' +
+ hint = "; references '" + toStr(ctx, sym) + '\'' +
getDefinedLocation(ctx, sym);
Err(ctx) << errPlace.loc << msg << " is out of range: " << Twine(v)
<< " is not in [" << Twine(llvm::minIntN(n)) << ", "
@@ -535,13 +535,13 @@ static std::string maybeReportDiscarded(Ctx &ctx, Undefined &sym) {
std::string msg;
if (sym.type == ELF::STT_SECTION) {
msg = "relocation refers to a discarded section: ";
- msg += CHECK(
+ msg += CHECK2(
file->getObj().getSectionName(objSections[sym.discardedSecIdx]), file);
} else {
msg = "relocation refers to a symbol in a discarded section: " +
- toString(sym);
+ toStr(ctx, sym);
}
- msg += "\n>>> defined in " + toString(file);
+ msg += "\n>>> defined in " + toStr(ctx, file);
Elf_Shdr_Impl<ELFT> elfSec = objSections[sym.discardedSecIdx - 1];
if (elfSec.sh_type != SHT_GROUP)
@@ -552,7 +552,7 @@ static std::string maybeReportDiscarded(Ctx &ctx, Undefined &sym) {
if (const InputFile *prevailing =
ctx.symtab->comdatGroups.lookup(CachedHashStringRef(signature))) {
msg += "\n>>> section group signature: " + signature.str() +
- "\n>>> prevailing definition is in " + toString(prevailing);
+ "\n>>> prevailing definition is in " + toStr(ctx, prevailing);
if (sym.nonPrevailing) {
msg += "\n>>> or the symbol in the prevailing group had STB_WEAK "
"binding and the symbol in a non-prevailing group had STB_GLOBAL "
@@ -748,7 +748,7 @@ static void reportUndefinedSymbol(Ctx &ctx, const UndefinedDiag &undef,
llvm_unreachable("");
}
if (msg.empty())
- msg = "undefined " + visibility() + "symbol: " + toString(sym);
+ msg = "undefined " + visibility() + "symbol: " + toStr(ctx, sym);
const size_t maxUndefReferences = 3;
size_t i = 0;
@@ -777,9 +777,10 @@ static void reportUndefinedSymbol(Ctx &ctx, const UndefinedDiag &undef,
std::string pre_hint = ": ", post_hint;
if (const Symbol *corrected =
getAlternativeSpelling(ctx, sym, pre_hint, post_hint)) {
- msg += "\n>>> did you mean" + pre_hint + toString(*corrected) + post_hint;
+ msg +=
+ "\n>>> did you mean" + pre_hint + toStr(ctx, *corrected) + post_hint;
if (corrected->file)
- msg += "\n>>> defined in: " + toString(corrected->file);
+ msg += "\n>>> defined in: " + toStr(ctx, corrected->file);
}
}
@@ -1267,7 +1268,7 @@ void RelocationScanner::processAux(RelExpr expr, RelType type, uint64_t offset,
Err(ctx) << "relocation " << type << " cannot be used against "
<< (sym.getName().empty() ? "local symbol"
- : ("symbol '" + toString(sym) + "'"))
+ : ("symbol '" + toStr(ctx, sym) + "'"))
<< "; recompile with -fPIC" << getLocation(ctx, *sec, sym, offset);
}
@@ -2472,7 +2473,7 @@ static void scanCrossRefs(Ctx &ctx, const NoCrossRefCommand &cmd,
std::string toSymName;
if (!sym.isSection())
- toSymName = toString(sym);
+ toSymName = toStr(ctx, sym);
else if (auto *d = dyn_cast<Defined>(&sym))
toSymName = d->section->name;
Err(ctx) << sec->getLocation(r.r_offset)
diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp
index cfaa1a1ec1637f..2d17ce36e1e459 100644
--- a/lld/ELF/Symbols.cpp
+++ b/lld/ELF/Symbols.cpp
@@ -48,7 +48,7 @@ static std::string maybeDemangleSymbol(Ctx &ctx, StringRef symName) {
return ctx.arg.demangle ? demangle(symName.str()) : symName.str();
}
-std::string lld::toString(const elf::Symbol &sym) {
+std::string elf::toStr(Ctx &ctx, const elf::Symbol &sym) {
StringRef name = sym.getName();
std::string ret = maybeDemangleSymbol(ctx, name);
@@ -60,7 +60,7 @@ std::string lld::toString(const elf::Symbol &sym) {
const ELFSyncStream &elf::operator<<(const ELFSyncStream &s,
const Symbol *sym) {
- return s << toString(*sym);
+ return s << toStr(s.ctx, *sym);
}
static uint64_t getSymVA(Ctx &ctx, const Symbol &sym, int64_t addend) {
@@ -295,12 +295,12 @@ void elf::printTraceSymbol(const Symbol &sym, StringRef name) {
else
s = ": definition of ";
- message(toString(sym.file) + s + name);
+ message(toStr(ctx, sym.file) + s + name);
}
static void recordWhyExtract(Ctx &ctx, const InputFile *reference,
const InputFile &extracted, const Symbol &sym) {
- ctx.whyExtractRecords.emplace_back(toString(reference), &extracted, sym);
+ ctx.whyExtractRecords.emplace_back(toStr(ctx, reference), &extracted, sym);
}
void elf::maybeWarnUnorderableSymbol(Ctx &ctx, const Symbol *sym) {
@@ -320,7 +320,9 @@ void elf::maybeWarnUnorderableSymbol(Ctx &ctx, const Symbol *sym) {
const InputFile *file = sym->file;
auto *d = dyn_cast<Defined>(sym);
- auto report = [&](StringRef s) { warn(toString(file) + s + sym->getName()); };
+ auto report = [&](StringRef s) {
+ warn(toStr(ctx, file) + s + sym->getName());
+ };
if (sym->isUndefined()) {
if (cast<Undefined>(sym)->discardedSecIdx)
@@ -548,7 +550,8 @@ void elf::reportDuplicate(Ctx &ctx, const Symbol &sym, const InputFile *newFile,
std::string src2 = errSec->getSrcMsg(sym, errOffset);
std::string obj2 = errSec->getObjMsg(errOffset);
- std::string msg = "duplicate symbol: " + toString(sym) + "\n>>> defined at ";
+ std::string msg =
+ "duplicate symbol: " + toStr(ctx, sym) + "\n>>> defined at ";
if (!src1.empty())
msg += src1 + "\n>>> ";
msg += obj1 + "\n>>> defined at ";
diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h
index a0ebd4adee8b62..18d078c58fa55c 100644
--- a/lld/ELF/Symbols.h
+++ b/lld/ELF/Symbols.h
@@ -21,14 +21,7 @@
#include "llvm/Support/Compiler.h"
#include <tuple>
-namespace lld {
-namespace elf {
-class Symbol;
-}
-// Returns a string representation for a symbol for diagnostics.
-std::string toString(const elf::Symbol &);
-
-namespace elf {
+namespace lld::elf {
class CommonSymbol;
class Defined;
class OutputSection;
@@ -40,6 +33,8 @@ class Undefined;
class LazySymbol;
class InputFile;
+// Returns a string representation for a symbol for diagnostics.
+std::string toStr(Ctx &, const Symbol &);
const ELFSyncStream &operator<<(const ELFSyncStream &, const Symbol *);
void printTraceSymbol(const Symbol &sym, StringRef name);
@@ -533,7 +528,6 @@ void reportDuplicate(Ctx &, const Symbol &sym, const InputFile *newFile,
void maybeWarnUnorderableSymbol(Ctx &, const Symbol *sym);
bool computeIsPreemptible(Ctx &, const Symbol &sym);
-} // namespace elf
-} // namespace lld
+} // namespace lld::elf
#endif
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index ba77fbf6adcef2..1af7200beb4b71 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -119,7 +119,7 @@ MipsAbiFlagsSection<ELFT>::create(Ctx &ctx) {
sec->markDead();
create = true;
- std::string filename = toString(sec->file);
+ std::string filename = toStr(ctx, sec->file);
const size_t size = sec->content().size();
// Older version of BFD (such as the default FreeBSD linker) concatenate
// .MIPS.abiflags instead of merging. To allow for this case (or potential
@@ -196,7 +196,7 @@ MipsOptionsSection<ELFT>::create(Ctx &ctx) {
for (InputSectionBase *sec : sections) {
sec->markDead();
- std::string filename = toString(sec->file);
+ std::string filename = toStr(ctx, sec->file);
ArrayRef<uint8_t> d = sec->content();
while (!d.empty()) {
@@ -2793,7 +2793,7 @@ readEntry(uint64_t &offset, const DWARFDebugNames::NameIndex &ni,
if (err)
return createStringError(inconvertibleErrorCode(),
"invalid abbrev code: %s",
- toString(std::move(err)).c_str());
+ llvm::toString(std::move(err)).c_str());
if (!isUInt<32>(ulebVal))
return createStringError(inconvertibleErrorCode(),
"abbrev code too large for DWARF32: %" PRIu64,
@@ -2844,7 +2844,7 @@ readEntry(uint64_t &offset, const DWARFDebugNames::NameIndex &ni,
if (err)
return createStringError(inconvertibleErrorCode(),
"error while reading attributes: %s",
- toString(std::move(err)).c_str());
+ llvm::toString(std::move(err)).c_str());
if (a.Index == DW_IDX_compile_unit)
cuAttr = attr;
else if (a.Form != DW_FORM_flag_present)
diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp
index 49dcb3d0758a61..d9c40385f2b987 100644
--- a/lld/ELF/Target.cpp
+++ b/lld/ELF/Target.cpp
@@ -38,8 +38,8 @@ using namespace llvm::ELF;
using namespace lld;
using namespace lld::elf;
-std::string lld::toString(RelType type) {
- StringRef s = getELFRelocationTypeName(elf::ctx.arg.emachine, type);
+std::string elf::toStr(Ctx &ctx, RelType type) {
+ StringRef s = getELFRelocationTypeName(ctx.arg.emachine, type);
if (s == "Unknown")
return ("Unknown (" + Twine(type) + ")").str();
return std::string(s);
@@ -123,7 +123,7 @@ TargetInfo::~TargetInfo() {}
int64_t TargetInfo::getImplicitAddend(const uint8_t *buf, RelType type) const {
internalLinkerError(getErrorLoc(ctx, buf),
- "cannot read addend for relocation " + toString(type));
+ "cannot read addend for relocation " + toStr(ctx, type));
return 0;
}
diff --git a/lld/ELF/Target.h b/lld/ELF/Target.h
index af6024ef054a3f..2277537a4e357a 100644
--- a/lld/ELF/Target.h
+++ b/lld/ELF/Target.h
@@ -20,13 +20,13 @@
#include <array>
namespace lld {
-std::string toString(elf::RelType type);
-
namespace elf {
class Defined;
class InputFile;
class Symbol;
+std::string toStr(Ctx &, RelType type);
+
class TargetInfo {
public:
TargetInfo(Ctx &ctx) : ctx(ctx) {}
More information about the llvm-commits
mailing list