[lld] 7db789b - [ELF] Replace a few Fatal with Err
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 25 16:01:18 PST 2025
Author: Fangrui Song
Date: 2025-01-25T16:00:51-08:00
New Revision: 7db789b5702714ffb6c96ad53c3136ca0a4300b2
URL: https://github.com/llvm/llvm-project/commit/7db789b5702714ffb6c96ad53c3136ca0a4300b2
DIFF: https://github.com/llvm/llvm-project/commit/7db789b5702714ffb6c96ad53c3136ca0a4300b2.diff
LOG: [ELF] Replace a few Fatal with Err
In LLD_IN_TEST=2 mode, when a thread calls Fatal, there will be no
output even if the process exits with code 1. Change a few Fatal to
recoverable Err.
Added:
Modified:
lld/ELF/InputSection.cpp
lld/test/ELF/compressed-input-err.s
lld/test/ELF/invalid/section-alignment.test
lld/test/ELF/invalid/section-alignment2.s
Removed:
################################################################################
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 42ef530b79d898..56928b7c9547bf 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -71,8 +71,10 @@ InputSectionBase::InputSectionBase(InputFile *file, StringRef name,
// The ELF spec states that a value of 0 means the section has
// no alignment constraints.
uint32_t v = std::max<uint32_t>(addralign, 1);
- if (!isPowerOf2_64(v))
- Fatal(getCtx()) << this << ": sh_addralign is not a power of 2";
+ if (!isPowerOf2_64(v)) {
+ Err(getCtx()) << this << ": sh_addralign is not a power of 2";
+ v = 1;
+ }
this->addralign = v;
// If SHF_COMPRESSED is set, parse the header. The legacy .zdebug format is no
@@ -104,8 +106,10 @@ InputSectionBase::InputSectionBase(ObjFile<ELFT> &file,
// We reject object files having insanely large alignments even though
// 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(getCtx()) << &file << ": section sh_addralign is too large";
+ if (hdr.sh_addralign > UINT32_MAX) {
+ Err(getCtx()) << &file << ": section sh_addralign is too large";
+ addralign = 1;
+ }
}
size_t InputSectionBase::getSize() const {
@@ -123,7 +127,7 @@ static void decompressAux(Ctx &ctx, 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(ctx) << &sec << ": decompress failed: " << std::move(e);
+ Err(ctx) << &sec << ": decompress failed: " << std::move(e);
}
void InputSectionBase::decompress() const {
@@ -649,9 +653,11 @@ static uint64_t getRISCVUndefinedRelativeWeakVA(uint64_t type, uint64_t p) {
// of the RW segment.
static uint64_t getARMStaticBase(const Symbol &sym) {
OutputSection *os = sym.getOutputSection();
- if (!os || !os->ptLoad || !os->ptLoad->firstSec)
- Fatal(os->ctx) << "SBREL relocation to " << sym.getName()
- << " without static base";
+ if (!os || !os->ptLoad || !os->ptLoad->firstSec) {
+ Err(os->ctx) << "SBREL relocation to " << sym.getName()
+ << " without static base";
+ return 0;
+ }
return os->ptLoad->firstSec->addr;
}
@@ -1304,7 +1310,7 @@ 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(ctx) << this << ": decompress failed: " << std::move(e);
+ Err(ctx) << this << ": decompress failed: " << std::move(e);
uint8_t *bufEnd = buf + size;
relocate<ELFT>(ctx, buf, bufEnd);
return;
diff --git a/lld/test/ELF/compressed-input-err.s b/lld/test/ELF/compressed-input-err.s
index 83b1f62d7e4957..7251585ed5d709 100644
--- a/lld/test/ELF/compressed-input-err.s
+++ b/lld/test/ELF/compressed-input-err.s
@@ -9,6 +9,7 @@
# RUN: yaml2obj --docnum=3 %s -o %t3.o
# RUN: not ld.lld %t3.o -o /dev/null -shared 2>&1 | FileCheck %s
+# RUN: ld.lld %t3.o -o /dev/null -shared --noinhibit-exec
## Check we are able to report zlib decompress errors.
# CHECK: error: {{.*}}.o:(.debug_info): decompress failed: zlib error: Z_DATA_ERROR
diff --git a/lld/test/ELF/invalid/section-alignment.test b/lld/test/ELF/invalid/section-alignment.test
index 8099ec01849b6b..32e673f82992bd 100644
--- a/lld/test/ELF/invalid/section-alignment.test
+++ b/lld/test/ELF/invalid/section-alignment.test
@@ -1,5 +1,6 @@
# RUN: yaml2obj %s -o %t
# RUN: not ld.lld %t -o /dev/null 2>&1 | FileCheck %s
+# RUN: ld.lld %t -o /dev/null --noinhibit-exec 2>&1 | FileCheck %s
## In current lld implementation, we do not accept sh_addralign
## larger than UINT32_MAX.
diff --git a/lld/test/ELF/invalid/section-alignment2.s b/lld/test/ELF/invalid/section-alignment2.s
index c130bbbaa071fc..c180860ca41276 100644
--- a/lld/test/ELF/invalid/section-alignment2.s
+++ b/lld/test/ELF/invalid/section-alignment2.s
@@ -1,5 +1,6 @@
# RUN: yaml2obj %s -o %t.o
# RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s
+# RUN: ld.lld %t.o -o /dev/null --noinhibit-exec
# CHECK: error: {{.*}}.o:(.text): sh_addralign is not a power of 2
More information about the llvm-commits
mailing list