Skip to content

Commit 7db789b

Browse files
committed
[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.
1 parent c7579bf commit 7db789b

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

lld/ELF/InputSection.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ InputSectionBase::InputSectionBase(InputFile *file, StringRef name,
7171
// The ELF spec states that a value of 0 means the section has
7272
// no alignment constraints.
7373
uint32_t v = std::max<uint32_t>(addralign, 1);
74-
if (!isPowerOf2_64(v))
75-
Fatal(getCtx()) << this << ": sh_addralign is not a power of 2";
74+
if (!isPowerOf2_64(v)) {
75+
Err(getCtx()) << this << ": sh_addralign is not a power of 2";
76+
v = 1;
77+
}
7678
this->addralign = v;
7779

7880
// If SHF_COMPRESSED is set, parse the header. The legacy .zdebug format is no
@@ -104,8 +106,10 @@ InputSectionBase::InputSectionBase(ObjFile<ELFT> &file,
104106
// We reject object files having insanely large alignments even though
105107
// they are allowed by the spec. I think 4GB is a reasonable limitation.
106108
// We might want to relax this in the future.
107-
if (hdr.sh_addralign > UINT32_MAX)
108-
Fatal(getCtx()) << &file << ": section sh_addralign is too large";
109+
if (hdr.sh_addralign > UINT32_MAX) {
110+
Err(getCtx()) << &file << ": section sh_addralign is too large";
111+
addralign = 1;
112+
}
109113
}
110114

111115
size_t InputSectionBase::getSize() const {
@@ -123,7 +127,7 @@ static void decompressAux(Ctx &ctx, const InputSectionBase &sec, uint8_t *out,
123127
if (Error e = hdr->ch_type == ELFCOMPRESS_ZLIB
124128
? compression::zlib::decompress(compressed, out, size)
125129
: compression::zstd::decompress(compressed, out, size))
126-
Fatal(ctx) << &sec << ": decompress failed: " << std::move(e);
130+
Err(ctx) << &sec << ": decompress failed: " << std::move(e);
127131
}
128132

129133
void InputSectionBase::decompress() const {
@@ -649,9 +653,11 @@ static uint64_t getRISCVUndefinedRelativeWeakVA(uint64_t type, uint64_t p) {
649653
// of the RW segment.
650654
static uint64_t getARMStaticBase(const Symbol &sym) {
651655
OutputSection *os = sym.getOutputSection();
652-
if (!os || !os->ptLoad || !os->ptLoad->firstSec)
653-
Fatal(os->ctx) << "SBREL relocation to " << sym.getName()
654-
<< " without static base";
656+
if (!os || !os->ptLoad || !os->ptLoad->firstSec) {
657+
Err(os->ctx) << "SBREL relocation to " << sym.getName()
658+
<< " without static base";
659+
return 0;
660+
}
655661
return os->ptLoad->firstSec->addr;
656662
}
657663

@@ -1304,7 +1310,7 @@ template <class ELFT> void InputSection::writeTo(Ctx &ctx, uint8_t *buf) {
13041310
if (Error e = hdr->ch_type == ELFCOMPRESS_ZLIB
13051311
? compression::zlib::decompress(compressed, buf, size)
13061312
: compression::zstd::decompress(compressed, buf, size))
1307-
Fatal(ctx) << this << ": decompress failed: " << std::move(e);
1313+
Err(ctx) << this << ": decompress failed: " << std::move(e);
13081314
uint8_t *bufEnd = buf + size;
13091315
relocate<ELFT>(ctx, buf, bufEnd);
13101316
return;

lld/test/ELF/compressed-input-err.s

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
# RUN: yaml2obj --docnum=3 %s -o %t3.o
1111
# RUN: not ld.lld %t3.o -o /dev/null -shared 2>&1 | FileCheck %s
12+
# RUN: ld.lld %t3.o -o /dev/null -shared --noinhibit-exec
1213

1314
## Check we are able to report zlib decompress errors.
1415
# CHECK: error: {{.*}}.o:(.debug_info): decompress failed: zlib error: Z_DATA_ERROR

lld/test/ELF/invalid/section-alignment.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# RUN: yaml2obj %s -o %t
22
# RUN: not ld.lld %t -o /dev/null 2>&1 | FileCheck %s
3+
# RUN: ld.lld %t -o /dev/null --noinhibit-exec 2>&1 | FileCheck %s
34

45
## In current lld implementation, we do not accept sh_addralign
56
## larger than UINT32_MAX.

lld/test/ELF/invalid/section-alignment2.s

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# RUN: yaml2obj %s -o %t.o
22
# RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s
3+
# RUN: ld.lld %t.o -o /dev/null --noinhibit-exec
34

45
# CHECK: error: {{.*}}.o:(.text): sh_addralign is not a power of 2
56

0 commit comments

Comments
 (0)