diff options
author | Rui Ueyama <ruiu@google.com> | 2019-10-10 08:32:12 +0000 |
---|---|---|
committer | Rui Ueyama <ruiu@google.com> | 2019-10-10 08:32:12 +0000 |
commit | 2af8248999db1c5e7e58f5914824e6f617fde2c4 (patch) | |
tree | b75302dc858575787e34a3e93eaf99b660b0b90f | |
parent | 472e9b95b43b97efd52b0c19346b379c928b09a7 (diff) |
Improve error message for bad SHF_MERGE sections
This patch adds a section name to error messages.
Differential Revision: https://reviews.llvm.org/D68758
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@374290 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | ELF/InputFiles.cpp | 13 | ||||
-rw-r--r-- | ELF/InputFiles.h | 2 | ||||
-rw-r--r-- | test/ELF/invalid/merge-invalid-size.s | 2 | ||||
-rw-r--r-- | test/ELF/invalid/merge-writable.s (renamed from test/ELF/writable-merge.s) | 2 |
4 files changed, 11 insertions, 8 deletions
diff --git a/ELF/InputFiles.cpp b/ELF/InputFiles.cpp index f8887b111..b0389ccf1 100644 --- a/ELF/InputFiles.cpp +++ b/ELF/InputFiles.cpp @@ -483,7 +483,8 @@ StringRef ObjFile<ELFT>::getShtGroupSignature(ArrayRef<Elf_Shdr> sections, return signature; } -template <class ELFT> bool ObjFile<ELFT>::shouldMerge(const Elf_Shdr &sec) { +template <class ELFT> +bool ObjFile<ELFT>::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 @@ template <class ELFT> bool ObjFile<ELFT>::shouldMerge(const Elf_Shdr &sec) { 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 (" + + 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 @@ InputSectionBase *ObjFile<ELFT>::createInputSection(const Elf_Shdr &sec) { if (name == ".eh_frame" && !config->relocatable) return make<EhInputSection>(*this, sec, name); - if (shouldMerge(sec)) + if (shouldMerge(sec, name)) return make<MergeInputSection>(*this, sec, name); return make<InputSection>(*this, sec, name); } diff --git a/ELF/InputFiles.h b/ELF/InputFiles.h index 3c777ceac..1c78654d0 100644 --- a/ELF/InputFiles.h +++ b/ELF/InputFiles.h @@ -259,7 +259,7 @@ private: 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/test/ELF/invalid/merge-invalid-size.s b/test/ELF/invalid/merge-invalid-size.s index b16889a53..71c3f98e7 100644 --- a/test/ELF/invalid/merge-invalid-size.s +++ b/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/test/ELF/writable-merge.s b/test/ELF/invalid/merge-writable.s index 91a7e07d7..0c5fe9248 100644 --- a/test/ELF/writable-merge.s +++ b/test/ELF/invalid/merge-writable.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: writable SHF_MERGE section is not supported +// CHECK: merge-writable.s.tmp.o:(.foo): writable SHF_MERGE section is not supported .section .foo,"awM",@progbits,4 .quad 0 |