[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.
This commit is contained in:
Fangrui Song 2025-01-25 16:20:27 -08:00
parent 7db789b570
commit 6b87f01aaa
4 changed files with 18 additions and 16 deletions

View File

@ -1433,8 +1433,11 @@ static size_t findNull(StringRef s, size_t entSize) {
void MergeInputSection::splitStrings(StringRef s, size_t entSize) {
const bool live = !(flags & SHF_ALLOC) || !getCtx().arg.gcSections;
const char *p = s.data(), *end = s.data() + s.size();
if (!std::all_of(end - entSize, end, [](char c) { return c == 0; }))
Fatal(getCtx()) << this << ": string is not null terminated";
if (!std::all_of(end - entSize, end, [](char c) { return c == 0; })) {
Err(getCtx()) << this << ": string is not null terminated";
pieces.emplace_back(entSize, 0, false);
return;
}
if (entSize == 1) {
// Optimize the common case.
do {
@ -1494,8 +1497,10 @@ void MergeInputSection::splitIntoPieces() {
}
SectionPiece &MergeInputSection::getSectionPiece(uint64_t offset) {
if (content().size() <= offset)
Fatal(getCtx()) << this << ": offset is outside the section";
if (content().size() <= offset) {
Err(getCtx()) << this << ": offset is outside the section";
return pieces[0];
}
return partition_point(
pieces, [=](SectionPiece p) { return p.inputOff <= offset; })[-1];
}

View File

@ -1,11 +0,0 @@
// REQUIRES: x86
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
// RUN: not ld.lld %t.o -o /dev/null -shared 2>&1 | FileCheck %s
.section .rodata.str1.1,"aMS",@progbits,1
.asciz "abc"
.data
.quad .rodata.str1.1 + 4
// CHECK: merge-string-error.s.tmp.o:(.rodata.str1.1): offset is outside the section

View File

@ -1,6 +1,7 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %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:(.mergeable): string is not null terminated

View File

@ -1,9 +1,16 @@
// REQUIRES: x86
// RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux
// RUN: not ld.lld %t.o -o /dev/null -shared 2>&1 | FileCheck %s
// CHECK: relocation-past-merge-end.s.tmp.o:(.foo): offset is outside the section
// RUN: ld.lld %t.o -o /dev/null -shared --noinhibit-exec 2>&1 | FileCheck %s
// CHECK: .o:(.foo): offset is outside the section
// CHECCK: .o:(.rodata.str1.1): offset is outside the section
.data
.quad .foo + 10
.quad .rodata.str1.1 + 4
.section .foo,"aM",@progbits,4
.quad 0
.section .rodata.str1.1,"aMS",@progbits,1
.asciz "abc"