[lld] 6b87f01 - [ELF] MergeInputSection: replace Fatal with Err

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 25 16:21:01 PST 2025


Author: Fangrui Song
Date: 2025-01-25T16:20:27-08:00
New Revision: 6b87f01aaaa9d7c6eef8b66e48f13eb8492c7503

URL: https://github.com/llvm/llvm-project/commit/6b87f01aaaa9d7c6eef8b66e48f13eb8492c7503
DIFF: https://github.com/llvm/llvm-project/commit/6b87f01aaaa9d7c6eef8b66e48f13eb8492c7503.diff

LOG: [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.

Added: 
    

Modified: 
    lld/ELF/InputSection.cpp
    lld/test/ELF/mergeable-errors.s
    lld/test/ELF/relocation-past-merge-end.s

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


################################################################################
diff  --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 56928b7c9547bf..52c472bb89caf1 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 bd77a4c1dce875..00000000000000
--- 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", at 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 d67cd91c97fbf8..b155d581046a88 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 15214a5a4fc05d..1dced95c49ac20 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", at progbits,4
 .quad 0
+
+.section	.rodata.str1.1,"aMS", at progbits,1
+.asciz	"abc"


        


More information about the llvm-commits mailing list