Skip to content

Commit 19a6ac1

Browse files
committed
[ELF] EhFrame: replace failOn with errOn
These diagnostics are mostly reported by a thread during writeSections. In LLD_IN_TEST=2 mode, when a thread calls Fatal, there will be no output even if the process exits with code 1.
1 parent 04d5608 commit 19a6ac1

File tree

4 files changed

+34
-21
lines changed

4 files changed

+34
-21
lines changed

lld/ELF/EhFrame.cpp

+31-21
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@ class EhReader {
4141
bool hasLSDA();
4242

4343
private:
44-
template <class P> void failOn(const P *loc, const Twine &msg) {
44+
template <class P> void errOn(const P *loc, const Twine &msg) {
4545
Ctx &ctx = isec->file->ctx;
46-
Fatal(ctx) << "corrupted .eh_frame: " << msg << "\n>>> defined in "
47-
<< isec->getObjMsg((const uint8_t *)loc -
48-
isec->content().data());
46+
Err(ctx) << "corrupted .eh_frame: " << msg << "\n>>> defined in "
47+
<< isec->getObjMsg((const uint8_t *)loc - isec->content().data());
4948
}
5049

5150
uint8_t readByte();
@@ -62,24 +61,29 @@ class EhReader {
6261

6362
// Read a byte and advance D by one byte.
6463
uint8_t EhReader::readByte() {
65-
if (d.empty())
66-
failOn(d.data(), "unexpected end of CIE");
64+
if (d.empty()) {
65+
errOn(d.data(), "unexpected end of CIE");
66+
return 0;
67+
}
6768
uint8_t b = d.front();
6869
d = d.slice(1);
6970
return b;
7071
}
7172

7273
void EhReader::skipBytes(size_t count) {
7374
if (d.size() < count)
74-
failOn(d.data(), "CIE is too small");
75-
d = d.slice(count);
75+
errOn(d.data(), "CIE is too small");
76+
else
77+
d = d.slice(count);
7678
}
7779

7880
// Read a null-terminated string.
7981
StringRef EhReader::readString() {
8082
const uint8_t *end = llvm::find(d, '\0');
81-
if (end == d.end())
82-
failOn(d.data(), "corrupted CIE (failed to read string)");
83+
if (end == d.end()) {
84+
errOn(d.data(), "corrupted CIE (failed to read string)");
85+
return {};
86+
}
8387
StringRef s = toStringRef(d.slice(0, end - d.begin()));
8488
d = d.slice(s.size() + 1);
8589
return s;
@@ -97,7 +101,7 @@ void EhReader::skipLeb128() {
97101
if ((val & 0x80) == 0)
98102
return;
99103
}
100-
failOn(errPos, "corrupted CIE (failed to read LEB128)");
104+
errOn(errPos, "corrupted CIE (failed to read LEB128)");
101105
}
102106

103107
static size_t getAugPSize(Ctx &ctx, unsigned enc) {
@@ -121,12 +125,12 @@ static size_t getAugPSize(Ctx &ctx, unsigned enc) {
121125
void EhReader::skipAugP() {
122126
uint8_t enc = readByte();
123127
if ((enc & 0xf0) == DW_EH_PE_aligned)
124-
failOn(d.data() - 1, "DW_EH_PE_aligned encoding is not supported");
128+
return errOn(d.data() - 1, "DW_EH_PE_aligned encoding is not supported");
125129
size_t size = getAugPSize(isec->getCtx(), enc);
126130
if (size == 0)
127-
failOn(d.data() - 1, "unknown FDE encoding");
131+
return errOn(d.data() - 1, "unknown FDE encoding");
128132
if (size >= d.size())
129-
failOn(d.data() - 1, "corrupted CIE");
133+
return errOn(d.data() - 1, "corrupted CIE");
130134
d = d.slice(size);
131135
}
132136

@@ -141,9 +145,11 @@ bool elf::hasLSDA(const EhSectionPiece &p) {
141145
StringRef EhReader::getAugmentation() {
142146
skipBytes(8);
143147
int version = readByte();
144-
if (version != 1 && version != 3)
145-
failOn(d.data() - 1,
146-
"FDE version 1 or 3 expected, but got " + Twine(version));
148+
if (version != 1 && version != 3) {
149+
errOn(d.data() - 1,
150+
"FDE version 1 or 3 expected, but got " + Twine(version));
151+
return {};
152+
}
147153

148154
StringRef aug = readString();
149155

@@ -174,8 +180,10 @@ uint8_t EhReader::getFdeEncoding() {
174180
readByte();
175181
else if (c == 'P')
176182
skipAugP();
177-
else if (c != 'B' && c != 'S' && c != 'G')
178-
failOn(aug.data(), "unknown .eh_frame augmentation string: " + aug);
183+
else if (c != 'B' && c != 'S' && c != 'G') {
184+
errOn(aug.data(), "unknown .eh_frame augmentation string: " + aug);
185+
break;
186+
}
179187
}
180188
return DW_EH_PE_absptr;
181189
}
@@ -191,8 +199,10 @@ bool EhReader::hasLSDA() {
191199
skipAugP();
192200
else if (c == 'R')
193201
readByte();
194-
else if (c != 'B' && c != 'S' && c != 'G')
195-
failOn(aug.data(), "unknown .eh_frame augmentation string: " + aug);
202+
else if (c != 'B' && c != 'S' && c != 'G') {
203+
errOn(aug.data(), "unknown .eh_frame augmentation string: " + aug);
204+
break;
205+
}
196206
}
197207
return false;
198208
}

lld/test/ELF/invalid-eh-frame2.s

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
44
# RUN: not ld.lld --eh-frame-hdr %t -o /dev/null 2>&1 | FileCheck %s
5+
# RUN: ld.lld --eh-frame-hdr %t -o /dev/null --noinhibit-exec
56

67
# CHECK: error: corrupted .eh_frame: corrupted CIE (failed to read string)
78
# CHECK-NEXT: >>> defined in {{.*}}:(.eh_frame+0x9)

lld/test/ELF/invalid-eh-frame4.s

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
44
# RUN: not ld.lld --eh-frame-hdr %t -o /dev/null 2>&1 | FileCheck %s
5+
# RUN: ld.lld --eh-frame-hdr %t -o /dev/null --noinhibit-exec 2>&1 | FileCheck %s
56

67
# CHECK: corrupted .eh_frame: unknown .eh_frame augmentation string:
78

lld/test/ELF/invalid-eh-frame6.s

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
44
# RUN: not ld.lld --eh-frame-hdr %t -o /dev/null 2>&1 | FileCheck %s
5+
# RUN: ld.lld --eh-frame-hdr %t -o /dev/null --noinhibit-exec
56

67
# CHECK: error: corrupted .eh_frame: unknown FDE encoding
78
# CHECK-NEXT: >>> defined in {{.*}}:(.eh_frame+0xe)

0 commit comments

Comments
 (0)