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,16 @@ if (entSize == 0) return false; if (sec.sh_size % entSize) - fatal(toString(this) + ": SHF_MERGE section size (" + Twine(sec.sh_size) + - ")must be a multiple of sh_entsize (" + Twine(entSize) + ")"); + fatal(toString(this) + ":(" + name + "): SHF_MERGE section size (" + + Twine(sec.sh_size) + ") must be a multiple of sh_entsize (" + + Twine(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 +1036,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/invalid/merge-invalid-size.s b/lld/test/ELF/invalid/merge-invalid-size.s --- a/lld/test/ELF/invalid/merge-invalid-size.s +++ b/lld/test/ELF/invalid/merge-invalid-size.s @@ -1,7 +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 -// CHECK: SHF_MERGE section size must be a multiple of sh_entsize +// 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 .short 42 diff --git a/lld/test/ELF/invalid/merge-writable.s b/lld/test/ELF/invalid/merge-writable.s new file mode 100644 --- /dev/null +++ b/lld/test/ELF/invalid/merge-writable.s @@ -0,0 +1,7 @@ +// 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-writable.s.tmp.o:(.foo): writable SHF_MERGE section is not supported + +.section .foo,"awM",@progbits,1 +.zero 16