Skip to content

Commit 6b87f01

Browse files
committed
[ELF] MergeInputSection: replace 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 7db789b commit 6b87f01

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

lld/ELF/InputSection.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,8 +1433,11 @@ static size_t findNull(StringRef s, size_t entSize) {
14331433
void MergeInputSection::splitStrings(StringRef s, size_t entSize) {
14341434
const bool live = !(flags & SHF_ALLOC) || !getCtx().arg.gcSections;
14351435
const char *p = s.data(), *end = s.data() + s.size();
1436-
if (!std::all_of(end - entSize, end, [](char c) { return c == 0; }))
1437-
Fatal(getCtx()) << this << ": string is not null terminated";
1436+
if (!std::all_of(end - entSize, end, [](char c) { return c == 0; })) {
1437+
Err(getCtx()) << this << ": string is not null terminated";
1438+
pieces.emplace_back(entSize, 0, false);
1439+
return;
1440+
}
14381441
if (entSize == 1) {
14391442
// Optimize the common case.
14401443
do {
@@ -1494,8 +1497,10 @@ void MergeInputSection::splitIntoPieces() {
14941497
}
14951498

14961499
SectionPiece &MergeInputSection::getSectionPiece(uint64_t offset) {
1497-
if (content().size() <= offset)
1498-
Fatal(getCtx()) << this << ": offset is outside the section";
1500+
if (content().size() <= offset) {
1501+
Err(getCtx()) << this << ": offset is outside the section";
1502+
return pieces[0];
1503+
}
14991504
return partition_point(
15001505
pieces, [=](SectionPiece p) { return p.inputOff <= offset; })[-1];
15011506
}

lld/test/ELF/merge-string-error.s

Lines changed: 0 additions & 11 deletions
This file was deleted.

lld/test/ELF/mergeable-errors.s

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# REQUIRES: x86
22
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
33
# RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s
4+
# RUN: ld.lld %t.o -o /dev/null --noinhibit-exec
45

56
# CHECK: error: {{.*}}.o:(.mergeable): string is not null terminated
67

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
// REQUIRES: x86
22
// RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux
33
// RUN: not ld.lld %t.o -o /dev/null -shared 2>&1 | FileCheck %s
4-
// CHECK: relocation-past-merge-end.s.tmp.o:(.foo): offset is outside the section
4+
// RUN: ld.lld %t.o -o /dev/null -shared --noinhibit-exec 2>&1 | FileCheck %s
5+
// CHECK: .o:(.foo): offset is outside the section
6+
// CHECCK: .o:(.rodata.str1.1): offset is outside the section
57

68
.data
79
.quad .foo + 10
10+
.quad .rodata.str1.1 + 4
11+
812
.section .foo,"aM",@progbits,4
913
.quad 0
14+
15+
.section .rodata.str1.1,"aMS",@progbits,1
16+
.asciz "abc"

0 commit comments

Comments
 (0)