[lld] 84af3ee - [ELF] Replace Fatal with Err
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 26 16:13:57 PST 2025
Author: Fangrui Song
Date: 2025-01-26T16:13:52-08:00
New Revision: 84af3ee5124de3385b829c3a9980fd734f0d92e8
URL: https://github.com/llvm/llvm-project/commit/84af3ee5124de3385b829c3a9980fd734f0d92e8
DIFF: https://github.com/llvm/llvm-project/commit/84af3ee5124de3385b829c3a9980fd734f0d92e8.diff
LOG: [ELF] Replace Fatal with Err
Added:
Modified:
lld/ELF/Arch/ARM.cpp
lld/ELF/Arch/RISCV.cpp
lld/ELF/InputFiles.cpp
Removed:
################################################################################
diff --git a/lld/ELF/Arch/ARM.cpp b/lld/ELF/Arch/ARM.cpp
index de6e45c6cc65c6..7d2953ddf64f07 100644
--- a/lld/ELF/Arch/ARM.cpp
+++ b/lld/ELF/Arch/ARM.cpp
@@ -1536,8 +1536,8 @@ template <typename ELFT> void elf::writeARMCmseImportLib(Ctx &ctx) {
}
if (auto e = buffer->commit())
- Fatal(ctx) << "failed to write output '" << buffer->getPath()
- << "': " << std::move(e);
+ Err(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/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index 36ae31be6ed2a2..4d8989a21b5018 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -885,7 +885,7 @@ static bool relax(Ctx &ctx, InputSection &sec) {
}
// Inform assignAddresses that the size has changed.
if (!isUInt<32>(delta))
- Fatal(ctx) << "section size decrease is too large: " << delta;
+ Err(ctx) << "section size decrease is too large: " << delta;
sec.bytesDropped = delta;
return changed;
}
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index eba4c234d3f167..42d0e4c202ec61 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -1131,8 +1131,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(ctx) << this << ": common symbol '" << sym->getName()
- << "' has invalid alignment: " << value;
+ Err(ctx) << this << ": common symbol '" << sym->getName()
+ << "' has invalid alignment: " << value;
hasCommonSyms = true;
sym->resolve(ctx, CommonSymbol{ctx, this, StringRef(), binding, stOther,
type, value, size});
@@ -1384,16 +1384,22 @@ std::vector<uint32_t> SharedFile::parseVerneed(const ELFFile<ELFT> &obj,
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())
- Fatal(ctx) << this << " has an invalid Verneed";
+ if (verneedBuf + sizeof(typename ELFT::Verneed) > data.end()) {
+ Err(ctx) << this << " has an invalid Verneed";
+ break;
+ }
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(ctx) << this << " has an invalid Vernaux";
+ if (vernauxBuf + sizeof(typename ELFT::Vernaux) > data.end()) {
+ Err(ctx) << this << " has an invalid Vernaux";
+ break;
+ }
auto *aux = reinterpret_cast<const typename ELFT::Vernaux *>(vernauxBuf);
- if (aux->vna_name >= this->stringTable.size())
- Fatal(ctx) << this << " has a Vernaux with an invalid vna_name";
+ if (aux->vna_name >= this->stringTable.size()) {
+ Err(ctx) << this << " has a Vernaux with an invalid vna_name";
+ break;
+ }
uint16_t version = aux->vna_other & VERSYM_VERSION;
if (version >= verneeds.size())
verneeds.resize(version + 1);
@@ -1481,13 +1487,17 @@ template <class ELFT> void SharedFile::parse() {
for (const Elf_Dyn &dyn : dynamicTags) {
if (dyn.d_tag == DT_NEEDED) {
uint64_t val = dyn.getVal();
- if (val >= this->stringTable.size())
- Fatal(ctx) << this << ": invalid DT_NEEDED entry";
+ if (val >= this->stringTable.size()) {
+ Err(ctx) << this << ": invalid DT_NEEDED entry";
+ return;
+ }
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(ctx) << this << ": invalid DT_SONAME entry";
+ if (val >= this->stringTable.size()) {
+ Err(ctx) << this << ": invalid DT_SONAME entry";
+ return;
+ }
soName = this->stringTable.data() + val;
}
}
More information about the llvm-commits
mailing list