diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h --- a/lld/ELF/InputFiles.h +++ b/lld/ELF/InputFiles.h @@ -259,7 +259,7 @@ InputSectionBase *createInputSection(const Elf_Shdr &sec); StringRef getSectionName(const Elf_Shdr &sec); - bool shouldMerge(const Elf_Shdr &sec); + bool shouldMerge(const Elf_Shdr &sec, StringRef name); // Each ELF symbol contains a section index which the symbol belongs to. // However, because the number of bits dedicated for that is limited, a diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -483,7 +483,8 @@ return signature; } -template bool ObjFile::shouldMerge(const Elf_Shdr &sec) { +template +bool ObjFile::shouldMerge(const Elf_Shdr &sec, StringRef name) { // On a regular link we don't merge sections if -O0 (default is -O1). This // sometimes makes the linker significantly faster, although the output will // be bigger. @@ -515,14 +516,15 @@ if (entSize == 0) return false; if (sec.sh_size % entSize) - fatal(toString(this) + - ": SHF_MERGE section size must be a multiple of sh_entsize"); + fatal(toString(this) + ":(" + name + + "): SHF_MERGE section size must be a multiple of sh_entsize"); uint64_t flags = sec.sh_flags; if (!(flags & SHF_MERGE)) return false; if (flags & SHF_WRITE) - fatal(toString(this) + ": writable SHF_MERGE section is not supported"); + fatal(toString(this) + ":(" + name + + "): writable SHF_MERGE section is not supported"); return true; } @@ -1033,7 +1035,7 @@ if (name == ".eh_frame" && !config->relocatable) return make(*this, sec, name); - if (shouldMerge(sec)) + if (shouldMerge(sec, name)) return make(*this, sec, name); return make(*this, sec, name); } diff --git a/lld/test/ELF/merge-bad-input1.s b/lld/test/ELF/merge-bad-input1.s new file mode 100644 --- /dev/null +++ b/lld/test/ELF/merge-bad-input1.s @@ -0,0 +1,9 @@ +# 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 2>&1 | FileCheck %s + +# CHECK: merge-bad-input1.s.tmp.o:(.foo): SHF_MERGE section size must be a multiple of sh_entsize + +.section .foo,"aM",@progbits,16 +.align 16 +.zero 24 diff --git a/lld/test/ELF/merge-bad-input2.s b/lld/test/ELF/merge-bad-input2.s new file mode 100644 --- /dev/null +++ b/lld/test/ELF/merge-bad-input2.s @@ -0,0 +1,8 @@ +# 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 2>&1 | FileCheck %s + +# CHECK: merge-bad-input2.s.tmp.o:(.foo): writable SHF_MERGE section is not supported + +.section .foo,"awM",@progbits,1 +.zero 16