Skip to content

Commit

Permalink
[ELF] SHF_MERGE: avoid Fatal
Browse files Browse the repository at this point in the history
In LLD_IN_TEST=2 mode, when a thread calls Fatal, there will be no
output even if the process exits with code 1.
  • Loading branch information
MaskRay committed Jan 25, 2025
1 parent d2c7cab commit 4f48048
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
11 changes: 5 additions & 6 deletions lld/ELF/InputFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,13 +700,12 @@ bool ObjFile<ELFT>::shouldMerge(const Elf_Shdr &sec, StringRef name) {
if (entSize == 0)
return false;
if (sec.sh_size % entSize)
Fatal(ctx) << this << ":(" << name << "): SHF_MERGE section size ("
<< uint64_t(sec.sh_size)
<< ") must be a multiple of sh_entsize (" << entSize << ")";

ErrAlways(ctx) << this << ":(" << name << "): SHF_MERGE section size ("
<< uint64_t(sec.sh_size)
<< ") must be a multiple of sh_entsize (" << entSize << ")";
if (sec.sh_flags & SHF_WRITE)
Fatal(ctx) << this << ":(" << name
<< "): writable SHF_MERGE section is not supported";
Err(ctx) << this << ":(" << name
<< "): writable SHF_MERGE section is not supported";

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/invalid/merge-invalid-size.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// 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 2>&1 | FileCheck %s
// RUN: not ld.lld %t.o -o /dev/null --noinhibit-exec 2>&1 | FileCheck %s
// CHECK: merge-invalid-size.s.tmp.o:(.foo): SHF_MERGE section size (2) must be a multiple of sh_entsize (4)

.section .foo,"aM",@progbits,4
Expand Down
1 change: 1 addition & 0 deletions lld/test/ELF/invalid/merge-writable.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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 2>&1 | FileCheck %s
// RUN: ld.lld %t.o -o /dev/null --noinhibit-exec 2>&1 | FileCheck %s
// CHECK: merge-writable.s.tmp.o:(.foo): writable SHF_MERGE section is not supported

.section .foo,"awM",@progbits,4
Expand Down

0 comments on commit 4f48048

Please sign in to comment.