From 6b87f01aaaa9d7c6eef8b66e48f13eb8492c7503 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 25 Jan 2025 16:20:27 -0800 Subject: [PATCH] [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. --- lld/ELF/InputSection.cpp | 13 +++++++++---- lld/test/ELF/merge-string-error.s | 11 ----------- lld/test/ELF/mergeable-errors.s | 1 + lld/test/ELF/relocation-past-merge-end.s | 9 ++++++++- 4 files changed, 18 insertions(+), 16 deletions(-) delete mode 100644 lld/test/ELF/merge-string-error.s diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 56928b7c9547..52c472bb89ca 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -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]; } diff --git a/lld/test/ELF/merge-string-error.s b/lld/test/ELF/merge-string-error.s deleted file mode 100644 index bd77a4c1dce8..000000000000 --- a/lld/test/ELF/merge-string-error.s +++ /dev/null @@ -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 diff --git a/lld/test/ELF/mergeable-errors.s b/lld/test/ELF/mergeable-errors.s index d67cd91c97fb..b155d581046a 100644 --- a/lld/test/ELF/mergeable-errors.s +++ b/lld/test/ELF/mergeable-errors.s @@ -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 diff --git a/lld/test/ELF/relocation-past-merge-end.s b/lld/test/ELF/relocation-past-merge-end.s index 15214a5a4fc0..1dced95c49ac 100644 --- a/lld/test/ELF/relocation-past-merge-end.s +++ b/lld/test/ELF/relocation-past-merge-end.s @@ -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"