[lld] 63c6fe4 - [ELF] Replace fatal(...) with Fatal or Err
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 6 21:17:32 PST 2024
Author: Fangrui Song
Date: 2024-11-06T21:17:26-08:00
New Revision: 63c6fe4a0b18d5eaa50c002185cd270f20cf131b
URL: https://github.com/llvm/llvm-project/commit/63c6fe4a0b18d5eaa50c002185cd270f20cf131b
DIFF: https://github.com/llvm/llvm-project/commit/63c6fe4a0b18d5eaa50c002185cd270f20cf131b.diff
LOG: [ELF] Replace fatal(...) with Fatal or Err
Added:
Modified:
lld/ELF/Arch/ARM.cpp
lld/ELF/Arch/LoongArch.cpp
lld/ELF/Arch/RISCV.cpp
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/EhFrame.cpp
lld/ELF/InputFiles.cpp
lld/ELF/InputSection.cpp
lld/ELF/InputSection.h
lld/ELF/Relocations.cpp
lld/ELF/Symbols.cpp
lld/ELF/Symbols.h
lld/ELF/SyntheticSections.cpp
lld/ELF/Target.cpp
lld/ELF/Thunks.cpp
lld/ELF/Writer.cpp
Removed:
################################################################################
diff --git a/lld/ELF/Arch/ARM.cpp b/lld/ELF/Arch/ARM.cpp
index 271e2e27a26949..0df644c61babdd 100644
--- a/lld/ELF/Arch/ARM.cpp
+++ b/lld/ELF/Arch/ARM.cpp
@@ -1542,8 +1542,8 @@ template <typename ELFT> void elf::writeARMCmseImportLib(Ctx &ctx) {
}
if (auto e = buffer->commit())
- fatal("failed to write output '" + buffer->getPath() +
- "': " + toString(std::move(e)));
+ Fatal(ctx) << "failed to write output '" << buffer->getPath()
+ << "': " << std::move(e);
}
void elf::setARMTargetInfo(Ctx &ctx) { ctx.target.reset(new ARM(ctx)); }
diff --git a/lld/ELF/Arch/LoongArch.cpp b/lld/ELF/Arch/LoongArch.cpp
index 876aadcb91511b..79ad0d60051592 100644
--- a/lld/ELF/Arch/LoongArch.cpp
+++ b/lld/ELF/Arch/LoongArch.cpp
@@ -808,7 +808,7 @@ static bool relax(Ctx &ctx, InputSection &sec) {
}
// Inform assignAddresses that the size has changed.
if (!isUInt<32>(delta))
- fatal("section size decrease is too large: " + Twine(delta));
+ Fatal(ctx) << "section size decrease is too large: " << Twine(delta);
sec.bytesDropped = delta;
return changed;
}
diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index e80dfbd4351b1e..888495962d9762 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -901,7 +901,7 @@ static bool relax(Ctx &ctx, InputSection &sec) {
}
// Inform assignAddresses that the size has changed.
if (!isUInt<32>(delta))
- fatal("section size decrease is too large: " + Twine(delta));
+ Fatal(ctx) << "section size decrease is too large: " << Twine(delta);
sec.bytesDropped = delta;
return changed;
}
diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index aebccc020030d3..91555573307b74 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -695,6 +695,11 @@ operator<<(const ELFSyncStream &s, T &&v) {
return s;
}
+inline const ELFSyncStream &operator<<(const ELFSyncStream &s, const char *v) {
+ s.os << v;
+ return s;
+}
+
// Report a log if --verbose is specified.
ELFSyncStream Log(Ctx &ctx);
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index aa123e9d11e5cf..75d7f934a990d6 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -265,8 +265,8 @@ std::vector<std::pair<MemoryBufferRef, uint64_t>> static getArchiveMembers(
v.push_back(std::make_pair(mbref, c.getChildOffset()));
}
if (err)
- fatal(mb.getBufferIdentifier() + ": Archive::children failed: " +
- toString(std::move(err)));
+ Fatal(ctx) << mb.getBufferIdentifier()
+ << ": Archive::children failed: " << std::move(err);
// Take ownership of memory buffers created for members of thin archives.
std::vector<std::unique_ptr<MemoryBuffer>> mbs = file->takeThinBuffers();
@@ -1064,7 +1064,7 @@ template <class ELFT> static void readCallGraphsFromObjectFiles(Ctx &ctx) {
continue;
if (symbolIndices.size() != cgProfile.size() * 2)
- fatal("number of relocations doesn't match Weights");
+ Fatal(ctx) << "number of relocations doesn't match Weights";
for (uint32_t i = 0, size = cgProfile.size(); i < size; ++i) {
const Elf_CGProfile_Impl<ELFT> &cgpe = cgProfile[i];
@@ -2445,7 +2445,7 @@ static void findKeepUniqueSections(Ctx &ctx, opt::InputArgList &args) {
const char *err = nullptr;
uint64_t symIndex = decodeULEB128(cur, &size, contents.end(), &err);
if (err)
- fatal(toString(f) + ": could not decode addrsig section: " + err);
+ Fatal(ctx) << f << ": could not decode addrsig section: " << err;
markAddrsig(icfSafe, syms[symIndex]);
cur += size;
}
@@ -2507,7 +2507,7 @@ static void readSymbolPartitionSection(Ctx &ctx, InputSectionBase *s) {
// sizes of the Partition fields in InputSectionBase and Symbol, as well as
// the amount of space devoted to the partition number in RankFlags.
if (ctx.partitions.size() == 254)
- fatal("may not have more than 254 partitions");
+ Fatal(ctx) << "may not have more than 254 partitions";
ctx.partitions.emplace_back(ctx);
Partition &newPart = ctx.partitions.back();
diff --git a/lld/ELF/EhFrame.cpp b/lld/ELF/EhFrame.cpp
index f4c788fe610ae6..9539585d5ecea8 100644
--- a/lld/ELF/EhFrame.cpp
+++ b/lld/ELF/EhFrame.cpp
@@ -41,8 +41,9 @@ class EhReader {
private:
template <class P> void failOn(const P *loc, const Twine &msg) {
- fatal("corrupted .eh_frame: " + msg + "\n>>> defined in " +
- isec->getObjMsg((const uint8_t *)loc - isec->content().data()));
+ Fatal(ctx) << "corrupted .eh_frame: " << msg << "\n>>> defined in "
+ << isec->getObjMsg((const uint8_t *)loc -
+ isec->content().data());
}
uint8_t readByte();
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index e9a75b37026fd2..f9bf90bdc0a6a2 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -68,8 +68,7 @@ std::string lld::toString(const InputFile *f) {
const ELFSyncStream &elf::operator<<(const ELFSyncStream &s,
const InputFile *f) {
- s << toString(f);
- return s;
+ return s << toString(f);
}
static ELFKind getELFKind(MemoryBufferRef mb, StringRef archiveName) {
@@ -80,9 +79,9 @@ static ELFKind getELFKind(MemoryBufferRef mb, StringRef archiveName) {
auto report = [&](StringRef msg) {
StringRef filename = mb.getBufferIdentifier();
if (archiveName.empty())
- fatal(filename + ": " + msg);
+ Fatal(ctx) << filename << ": " << msg;
else
- fatal(archiveName + "(" + filename + "): " + msg);
+ Fatal(ctx) << archiveName << "(" << filename << "): " << msg;
};
if (!mb.getBuffer().starts_with(ElfMagic))
@@ -573,7 +572,7 @@ template <class ELFT> void ELFFileBase::init(InputFile::Kind k) {
ArrayRef<Elf_Sym> eSyms = CHECK(obj.symbols(symtabSec), this);
if (firstGlobal == 0 || firstGlobal > eSyms.size())
- fatal(toString(this) + ": invalid sh_info in symbol table");
+ Fatal(ctx) << this << ": invalid sh_info in symbol table";
elfSyms = reinterpret_cast<const void *>(eSyms.data());
numELFSyms = uint32_t(eSyms.size());
@@ -666,11 +665,11 @@ template <class ELFT> void ObjFile<ELFT>::parse(bool ignoreComdats) {
ArrayRef<Elf_Word> entries =
CHECK(obj.template getSectionContentsAsArray<Elf_Word>(sec), this);
if (entries.empty())
- fatal(toString(this) + ": empty SHT_GROUP");
+ Fatal(ctx) << this << ": empty SHT_GROUP";
Elf_Word flag = entries[0];
if (flag && flag != GRP_COMDAT)
- fatal(toString(this) + ": unsupported SHT_GROUP format");
+ Fatal(ctx) << this << ": unsupported SHT_GROUP format";
bool keepGroup = (flag & GRP_COMDAT) == 0 || ignoreComdats ||
ctx.symtab->comdatGroups
@@ -686,8 +685,8 @@ template <class ELFT> void ObjFile<ELFT>::parse(bool ignoreComdats) {
// Otherwise, discard group members.
for (uint32_t secIndex : entries.slice(1)) {
if (secIndex >= size)
- fatal(toString(this) +
- ": invalid section index in group: " + Twine(secIndex));
+ Fatal(ctx) << this
+ << ": invalid section index in group: " << Twine(secIndex);
this->sections[secIndex] = &InputSection::discarded;
}
}
@@ -704,7 +703,7 @@ StringRef ObjFile<ELFT>::getShtGroupSignature(ArrayRef<Elf_Shdr> sections,
const Elf_Shdr &sec) {
typename ELFT::SymRange symbols = this->getELFSyms<ELFT>();
if (sec.sh_info >= symbols.size())
- fatal(toString(this) + ": invalid symbol index");
+ Fatal(ctx) << this << ": invalid symbol index";
const typename ELFT::Sym &sym = symbols[sec.sh_info];
return CHECK(sym.getName(this->stringTable), this);
}
@@ -742,13 +741,13 @@ bool ObjFile<ELFT>::shouldMerge(const Elf_Shdr &sec, StringRef name) {
if (entSize == 0)
return false;
if (sec.sh_size % entSize)
- fatal(toString(this) + ":(" + name + "): SHF_MERGE section size (" +
- Twine(sec.sh_size) + ") must be a multiple of sh_entsize (" +
- Twine(entSize) + ")");
+ Fatal(ctx) << this << ":(" << name << "): SHF_MERGE section size ("
+ << Twine(sec.sh_size) << ") must be a multiple of sh_entsize ("
+ << Twine(entSize) << ")";
if (sec.sh_flags & SHF_WRITE)
- fatal(toString(this) + ":(" + name +
- "): writable SHF_MERGE section is not supported");
+ Fatal(ctx) << this << ":(" << name
+ << "): writable SHF_MERGE section is not supported";
return true;
}
@@ -934,7 +933,7 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats,
if (sec.sh_link < size)
linkSec = this->sections[sec.sh_link];
if (!linkSec)
- fatal(toString(this) + ": invalid sh_link index: " + Twine(sec.sh_link));
+ Fatal(ctx) << this << ": invalid sh_link index: " << Twine(sec.sh_link);
// A SHF_LINK_ORDER section is discarded if its linked-to section is
// discarded.
@@ -963,8 +962,9 @@ static void readGnuProperty(Ctx &ctx, const InputSection &sec,
ArrayRef<uint8_t> data = sec.content();
auto reportFatal = [&](const uint8_t *place, const Twine &msg) {
- fatal(toString(sec.file) + ":(" + sec.name + "+0x" +
- Twine::utohexstr(place - sec.content().data()) + "): " + msg);
+ Fatal(ctx) << sec.file << ":(" << sec.name << "+0x"
+ << Twine::utohexstr(place - sec.content().data())
+ << "): " << msg;
};
while (!data.empty()) {
// Read one NOTE record.
@@ -1159,8 +1159,8 @@ void ObjFile<ELFT>::initializeSymbols(const object::ELFFile<ELFT> &obj) {
sym->isUsedInRegularObj = true;
if (LLVM_UNLIKELY(eSym.st_shndx == SHN_COMMON)) {
if (value == 0 || value >= UINT32_MAX)
- fatal(toString(this) + ": common symbol '" + sym->getName() +
- "' has invalid alignment: " + Twine(value));
+ Fatal(ctx) << this << ": common symbol '" << sym->getName()
+ << "' has invalid alignment: " << Twine(value);
hasCommonSyms = true;
sym->resolve(ctx, CommonSymbol{ctx, this, StringRef(), binding, stOther,
type, value, size});
@@ -1207,7 +1207,7 @@ void ObjFile<ELFT>::initSectionsAndLocalSyms(bool ignoreComdats) {
else if (secIdx >= SHN_LORESERVE)
secIdx = 0;
if (LLVM_UNLIKELY(secIdx >= sections.size()))
- fatal(toString(this) + ": invalid section index: " + Twine(secIdx));
+ Fatal(ctx) << this << ": invalid section index: " << Twine(secIdx);
if (LLVM_UNLIKELY(eSym.getBinding() != STB_LOCAL))
error(toString(this) + ": non-local symbol (" + Twine(i) +
") found at index < .symtab's sh_info (" + Twine(end) + ")");
@@ -1217,7 +1217,7 @@ void ObjFile<ELFT>::initSectionsAndLocalSyms(bool ignoreComdats) {
if (type == STT_FILE)
sourceFile = CHECK(eSym.getName(stringTable), this);
if (LLVM_UNLIKELY(stringTable.size() <= eSym.st_name))
- fatal(toString(this) + ": invalid symbol name offset");
+ Fatal(ctx) << this << ": invalid symbol name offset";
StringRef name(stringTable.data() + eSym.st_name);
symbols[i] = reinterpret_cast<Symbol *>(locals + i);
@@ -1267,7 +1267,7 @@ template <class ELFT> void ObjFile<ELFT>::postParse() {
else if (secIdx >= SHN_LORESERVE)
secIdx = 0;
if (LLVM_UNLIKELY(secIdx >= sections.size()))
- fatal(toString(this) + ": invalid section index: " + Twine(secIdx));
+ Fatal(ctx) << this << ": invalid section index: " << Twine(secIdx);
InputSectionBase *sec = sections[secIdx];
if (sec == &InputSection::discarded) {
if (sym.traced) {
@@ -1405,15 +1405,15 @@ std::vector<uint32_t> SharedFile::parseVerneed(const ELFFile<ELFT> &obj,
const uint8_t *verneedBuf = data.begin();
for (unsigned i = 0; i != sec->sh_info; ++i) {
if (verneedBuf + sizeof(typename ELFT::Verneed) > data.end())
- fatal(toString(this) + " has an invalid Verneed");
+ Fatal(ctx) << this << " has an invalid Verneed";
auto *vn = reinterpret_cast<const typename ELFT::Verneed *>(verneedBuf);
const uint8_t *vernauxBuf = verneedBuf + vn->vn_aux;
for (unsigned j = 0; j != vn->vn_cnt; ++j) {
if (vernauxBuf + sizeof(typename ELFT::Vernaux) > data.end())
- fatal(toString(this) + " has an invalid Vernaux");
+ Fatal(ctx) << this << " has an invalid Vernaux";
auto *aux = reinterpret_cast<const typename ELFT::Vernaux *>(vernauxBuf);
if (aux->vna_name >= this->stringTable.size())
- fatal(toString(this) + " has a Vernaux with an invalid vna_name");
+ Fatal(ctx) << this << " has a Vernaux with an invalid vna_name";
uint16_t version = aux->vna_other & VERSYM_VERSION;
if (version >= verneeds.size())
verneeds.resize(version + 1);
@@ -1501,12 +1501,12 @@ template <class ELFT> void SharedFile::parse() {
if (dyn.d_tag == DT_NEEDED) {
uint64_t val = dyn.getVal();
if (val >= this->stringTable.size())
- fatal(toString(this) + ": invalid DT_NEEDED entry");
+ Fatal(ctx) << this << ": invalid DT_NEEDED entry";
dtNeeded.push_back(this->stringTable.data() + val);
} else if (dyn.d_tag == DT_SONAME) {
uint64_t val = dyn.getVal();
if (val >= this->stringTable.size())
- fatal(toString(this) + ": invalid DT_SONAME entry");
+ Fatal(ctx) << this << ": invalid DT_SONAME entry";
soName = this->stringTable.data() + val;
}
}
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 3b48fbe07bb082..f4a5304d4f251f 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -39,6 +39,11 @@ std::string lld::toString(const InputSectionBase *sec) {
return (toString(sec->file) + ":(" + sec->name + ")").str();
}
+const ELFSyncStream &elf::operator<<(const ELFSyncStream &s,
+ const InputSectionBase *sec) {
+ return s << toString(sec);
+}
+
template <class ELFT>
static ArrayRef<uint8_t> getSectionContents(ObjFile<ELFT> &file,
const typename ELFT::Shdr &hdr) {
@@ -65,7 +70,7 @@ InputSectionBase::InputSectionBase(InputFile *file, uint64_t flags,
// no alignment constraints.
uint32_t v = std::max<uint32_t>(addralign, 1);
if (!isPowerOf2_64(v))
- fatal(toString(this) + ": sh_addralign is not a power of 2");
+ Fatal(ctx) << this << ": sh_addralign is not a power of 2";
this->addralign = v;
// If SHF_COMPRESSED is set, parse the header. The legacy .zdebug format is no
@@ -98,7 +103,7 @@ InputSectionBase::InputSectionBase(ObjFile<ELFT> &file,
// they are allowed by the spec. I think 4GB is a reasonable limitation.
// We might want to relax this in the future.
if (hdr.sh_addralign > UINT32_MAX)
- fatal(toString(&file) + ": section sh_addralign is too large");
+ Fatal(ctx) << &file << ": section sh_addralign is too large";
}
size_t InputSectionBase::getSize() const {
@@ -116,8 +121,8 @@ static void decompressAux(const InputSectionBase &sec, uint8_t *out,
if (Error e = hdr->ch_type == ELFCOMPRESS_ZLIB
? compression::zlib::decompress(compressed, out, size)
: compression::zstd::decompress(compressed, out, size))
- fatal(toString(&sec) +
- ": decompress failed: " + llvm::toString(std::move(e)));
+ Fatal(ctx) << &sec
+ << ": decompress failed: " << llvm::toString(std::move(e));
}
void InputSectionBase::decompress() const {
@@ -621,7 +626,8 @@ static uint64_t getRISCVUndefinedRelativeWeakVA(uint64_t type, uint64_t p) {
static uint64_t getARMStaticBase(const Symbol &sym) {
OutputSection *os = sym.getOutputSection();
if (!os || !os->ptLoad || !os->ptLoad->firstSec)
- fatal("SBREL relocation to " + sym.getName() + " without static base");
+ Fatal(ctx) << "SBREL relocation to " << sym.getName()
+ << " without static base";
return os->ptLoad->firstSec->addr;
}
@@ -1269,8 +1275,8 @@ template <class ELFT> void InputSection::writeTo(Ctx &ctx, uint8_t *buf) {
if (Error e = hdr->ch_type == ELFCOMPRESS_ZLIB
? compression::zlib::decompress(compressed, buf, size)
: compression::zstd::decompress(compressed, buf, size))
- fatal(toString(this) +
- ": decompress failed: " + llvm::toString(std::move(e)));
+ Fatal(ctx) << this
+ << ": decompress failed: " << llvm::toString(std::move(e));
uint8_t *bufEnd = buf + size;
relocate<ELFT>(ctx, buf, bufEnd);
return;
@@ -1394,7 +1400,7 @@ void MergeInputSection::splitStrings(StringRef s, size_t entSize) {
const bool live = !(flags & SHF_ALLOC) || !getCtx().arg.gcSections;
const char *p = s.data(), *end = s.data() + s.size();
if (!std::all_of(end - entSize, end, [](char c) { return c == 0; }))
- fatal(toString(this) + ": string is not null terminated");
+ Fatal(ctx) << this << ": string is not null terminated";
if (entSize == 1) {
// Optimize the common case.
do {
@@ -1454,7 +1460,7 @@ void MergeInputSection::splitIntoPieces() {
SectionPiece &MergeInputSection::getSectionPiece(uint64_t offset) {
if (content().size() <= offset)
- fatal(toString(this) + ": offset is outside the section");
+ Fatal(ctx) << this << ": offset is outside the section";
return partition_point(
pieces, [=](SectionPiece p) { return p.inputOff <= offset; })[-1];
}
diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h
index dfcc7c8bc852a9..5511bb5e2c44d5 100644
--- a/lld/ELF/InputSection.h
+++ b/lld/ELF/InputSection.h
@@ -501,6 +501,9 @@ inline bool isDebugSection(const InputSectionBase &sec) {
return (sec.flags & llvm::ELF::SHF_ALLOC) == 0 &&
sec.name.starts_with(".debug");
}
+
+const ELFSyncStream &operator<<(const ELFSyncStream &,
+ const InputSectionBase *);
} // namespace elf
std::string toString(const elf::InputSectionBase *);
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index d40348a7b30d8f..6553ff9b06bb1e 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -376,7 +376,7 @@ template <class ELFT> static void addCopyRelSymbol(Ctx &ctx, SharedSymbol &ss) {
// Copy relocation against zero-sized symbol doesn't make sense.
uint64_t symSize = ss.getSize();
if (symSize == 0 || ss.alignment == 0)
- fatal("cannot create a copy relocation for symbol " + toString(ss));
+ Err(ctx) << "cannot create a copy relocation for symbol " << &ss;
// See if this symbol is in a read-only segment. If so, preserve the symbol's
// memory protection by reserving space in the .bss.rel.ro section.
@@ -441,7 +441,7 @@ class OffsetGetter {
while (i != cies.end() && i->inputOff <= off)
++i;
if (i == cies.begin() || i[-1].inputOff + i[-1].size <= off)
- fatal(".eh_frame: relocation is not in any piece");
+ Fatal(ctx) << ".eh_frame: relocation is not in any piece";
it = i;
}
@@ -2097,8 +2097,8 @@ ThunkSection *ThunkCreator::getISDThunkSec(OutputSection *os,
thunkSecOff = isec->outSecOff + isec->getSize();
if (!ctx.target->inBranchRange(rel.type, src,
os->addr + thunkSecOff + rel.addend))
- fatal("InputSection too large for range extension thunk " +
- isec->getObjMsg(src - (os->addr + isec->outSecOff)));
+ Fatal(ctx) << "InputSection too large for range extension thunk "
+ << isec->getObjMsg(src - (os->addr << isec->outSecOff));
}
return addThunkSection(os, isd, thunkSecOff);
}
diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp
index da35bf858cb371..40f54ea7a2507b 100644
--- a/lld/ELF/Symbols.cpp
+++ b/lld/ELF/Symbols.cpp
@@ -58,6 +58,11 @@ std::string lld::toString(const elf::Symbol &sym) {
return ret;
}
+const ELFSyncStream &elf::operator<<(const ELFSyncStream &s,
+ const Symbol *sym) {
+ return s << toString(*sym);
+}
+
static uint64_t getSymVA(Ctx &ctx, const Symbol &sym, int64_t addend) {
switch (sym.kind()) {
case Symbol::DefinedKind: {
diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h
index 8c9c9a56cfbc72..a0ebd4adee8b62 100644
--- a/lld/ELF/Symbols.h
+++ b/lld/ELF/Symbols.h
@@ -40,6 +40,8 @@ class Undefined;
class LazySymbol;
class InputFile;
+const ELFSyncStream &operator<<(const ELFSyncStream &, const Symbol *);
+
void printTraceSymbol(const Symbol &sym, StringRef name);
enum {
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 7a344635a1cb53..745112164edd6f 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -210,7 +210,7 @@ MipsOptionsSection<ELFT>::create(Ctx &ctx) {
}
if (!opt->size)
- fatal(filename + ": zero option descriptor size");
+ Fatal(ctx) << filename << ": zero option descriptor size";
d = d.slice(opt->size);
}
};
@@ -449,7 +449,7 @@ void EhFrameSection::addRecords(EhInputSection *sec, ArrayRef<RelTy> rels) {
uint32_t id = endian::read32<ELFT::Endianness>(fde.data().data() + 4);
CieRecord *rec = offsetToCie[fde.inputOff + 4 - id];
if (!rec)
- fatal(toString(sec) + ": invalid CIE reference");
+ Fatal(ctx) << sec << ": invalid CIE reference";
if (!isFdeLive<ELFT>(fde, rels))
continue;
@@ -609,7 +609,8 @@ static uint64_t readFdeAddr(Ctx &ctx, uint8_t *buf, int size) {
case DW_EH_PE_absptr:
return readUint(ctx, buf);
}
- fatal("unknown FDE size encoding");
+ Err(ctx) << "unknown FDE size encoding";
+ return 0;
}
// Returns the VA to which a given FDE (on a mmap'ed buffer) is applied to.
@@ -625,7 +626,8 @@ uint64_t EhFrameSection::getFdePc(uint8_t *buf, size_t fdeOff,
return ctx.arg.is64 ? addr : uint32_t(addr);
if ((enc & 0x70) == DW_EH_PE_pcrel)
return addr + getParent()->addr + off + outSecOff;
- fatal("unknown FDE size relative encoding");
+ Err(ctx) << "unknown FDE size relative encoding";
+ return 0;
}
void EhFrameSection::writeTo(uint8_t *buf) {
diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp
index 5d487b1673d925..49dcb3d0758a61 100644
--- a/lld/ELF/Target.cpp
+++ b/lld/ELF/Target.cpp
@@ -88,7 +88,7 @@ void elf::setTarget(Ctx &ctx) {
case EM_X86_64:
return setX86_64TargetInfo(ctx);
default:
- fatal("unsupported e_machine value: " + Twine(ctx.arg.emachine));
+ Fatal(ctx) << "unsupported e_machine value: " << Twine(ctx.arg.emachine);
}
}
@@ -137,7 +137,8 @@ bool TargetInfo::needsThunk(RelExpr expr, RelType type, const InputFile *file,
bool TargetInfo::adjustPrologueForCrossSplitStack(uint8_t *loc, uint8_t *end,
uint8_t stOther) const {
- fatal("target doesn't support split stacks");
+ Err(ctx) << "target doesn't support split stacks";
+ return false;
}
bool TargetInfo::inBranchRange(RelType type, uint64_t src, uint64_t dst) const {
diff --git a/lld/ELF/Thunks.cpp b/lld/ELF/Thunks.cpp
index 94c0b2409c6c7c..4cb4d22cac0c27 100644
--- a/lld/ELF/Thunks.cpp
+++ b/lld/ELF/Thunks.cpp
@@ -1375,7 +1375,7 @@ Thunk::~Thunk() = default;
static Thunk *addThunkAArch64(Ctx &ctx, RelType type, Symbol &s, int64_t a) {
if (type != R_AARCH64_CALL26 && type != R_AARCH64_JUMP26 &&
type != R_AARCH64_PLT32)
- fatal("unrecognized relocation type");
+ Fatal(ctx) << "unrecognized relocation type";
bool mayNeedLandingPad =
(ctx.arg.andFeatures & GNU_PROPERTY_AARCH64_FEATURE_1_BTI) &&
!isAArch64BTILandingPad(ctx, s, a);
@@ -1418,8 +1418,9 @@ static Thunk *addThunkArmv4(Ctx &ctx, RelType reloc, Symbol &s, int64_t a) {
return make<ThumbV4ABSLongThunk>(ctx, s, a);
return make<ThumbV4ABSLongBXThunk>(ctx, s, a);
}
- fatal("relocation " + toString(reloc) + " to " + toString(s) +
- " not supported for Armv4 or Armv4T target");
+ Fatal(ctx) << "relocation " << reloc << " to " << &s
+ << " not supported for Armv4 or Armv4T target";
+ llvm_unreachable("");
}
// Creates a thunk for Thumb-ARM interworking compatible with Armv5 and Armv6.
@@ -1438,8 +1439,9 @@ static Thunk *addThunkArmv5v6(Ctx &ctx, RelType reloc, Symbol &s, int64_t a) {
return make<ARMV4PILongBXThunk>(ctx, s, a);
return make<ARMV5LongLdrPcThunk>(ctx, s, a);
}
- fatal("relocation " + toString(reloc) + " to " + toString(s) +
- " not supported for Armv5 or Armv6 targets");
+ Fatal(ctx) << "relocation " << reloc << " to " << &s
+ << " not supported for Armv5 or Armv6 targets";
+ llvm_unreachable("");
}
// Create a thunk for Thumb long branch on V6-M.
@@ -1458,16 +1460,19 @@ static Thunk *addThunkV6M(Ctx &ctx, const InputSection &isec, RelType reloc,
if (!isPureCode)
return make<ThumbV6MPILongThunk>(ctx, s, a);
- fatal("relocation " + toString(reloc) + " to " + toString(s) +
- " not supported for Armv6-M targets for position independent"
- " and execute only code");
+ Fatal(ctx)
+ << "relocation " << reloc << " to " << &s
+ << " not supported for Armv6-M targets for position independent"
+ " and execute only code";
+ llvm_unreachable("");
}
if (isPureCode)
return make<ThumbV6MABSXOLongThunk>(ctx, s, a);
return make<ThumbV6MABSLongThunk>(ctx, s, a);
}
- fatal("relocation " + toString(reloc) + " to " + toString(s) +
- " not supported for Armv6-M targets");
+ Fatal(ctx) << "relocation " << reloc << " to " << &s
+ << " not supported for Armv6-M targets";
+ llvm_unreachable("");
}
// Creates a thunk for Thumb-ARM interworking or branch range extension.
@@ -1513,7 +1518,7 @@ static Thunk *addThunkArm(Ctx &ctx, const InputSection &isec, RelType reloc,
return make<ThumbV7PILongThunk>(ctx, s, a);
return make<ThumbV7ABSLongThunk>(ctx, s, a);
}
- fatal("unrecognized relocation type");
+ llvm_unreachable("");
}
static Thunk *addThunkAVR(Ctx &ctx, RelType type, Symbol &s, int64_t a) {
@@ -1522,7 +1527,7 @@ static Thunk *addThunkAVR(Ctx &ctx, RelType type, Symbol &s, int64_t a) {
case R_AVR_HI8_LDI_GS:
return make<AVRThunk>(ctx, s, a);
default:
- fatal("unrecognized relocation type " + toString(type));
+ llvm_unreachable("");
}
}
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index ecd4f5e470833c..12d51b828710d2 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -374,8 +374,8 @@ template <class ELFT> void Writer<ELFT>::run() {
return;
if (auto e = buffer->commit())
- fatal("failed to write output '" + buffer->getPath() +
- "': " + toString(std::move(e)));
+ Err(ctx) << "failed to write output '" << buffer->getPath()
+ << "': " << std::move(e);
if (!ctx.arg.cmseOutputLib.empty())
writeARMCmseImportLib<ELFT>(ctx);
More information about the llvm-commits
mailing list