[lld] r374290 - Improve error message for bad SHF_MERGE sections
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 10 01:32:12 PDT 2019
Author: ruiu
Date: Thu Oct 10 01:32:12 2019
New Revision: 374290
URL: http://llvm.org/viewvc/llvm-project?rev=374290&view=rev
Log:
Improve error message for bad SHF_MERGE sections
This patch adds a section name to error messages.
Differential Revision: https://reviews.llvm.org/D68758
Added:
lld/trunk/test/ELF/invalid/merge-writable.s
Removed:
lld/trunk/test/ELF/writable-merge.s
Modified:
lld/trunk/ELF/InputFiles.cpp
lld/trunk/ELF/InputFiles.h
lld/trunk/test/ELF/invalid/merge-invalid-size.s
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=374290&r1=374289&r2=374290&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Thu Oct 10 01:32:12 2019
@@ -483,7 +483,8 @@ StringRef ObjFile<ELFT>::getShtGroupSign
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>
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>::createI
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);
}
Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=374290&r1=374289&r2=374290&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Thu Oct 10 01:32:12 2019
@@ -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
Modified: lld/trunk/test/ELF/invalid/merge-invalid-size.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid/merge-invalid-size.s?rev=374290&r1=374289&r2=374290&view=diff
==============================================================================
--- lld/trunk/test/ELF/invalid/merge-invalid-size.s (original)
+++ lld/trunk/test/ELF/invalid/merge-invalid-size.s Thu Oct 10 01:32:12 2019
@@ -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", at progbits,4
.short 42
Added: lld/trunk/test/ELF/invalid/merge-writable.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid/merge-writable.s?rev=374290&view=auto
==============================================================================
--- lld/trunk/test/ELF/invalid/merge-writable.s (added)
+++ lld/trunk/test/ELF/invalid/merge-writable.s Thu Oct 10 01:32:12 2019
@@ -0,0 +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: merge-writable.s.tmp.o:(.foo): writable SHF_MERGE section is not supported
+
+.section .foo,"awM", at progbits,4
+.quad 0
Removed: lld/trunk/test/ELF/writable-merge.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/writable-merge.s?rev=374289&view=auto
==============================================================================
--- lld/trunk/test/ELF/writable-merge.s (original)
+++ lld/trunk/test/ELF/writable-merge.s (removed)
@@ -1,7 +0,0 @@
-// 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
-
-.section .foo,"awM", at progbits,4
-.quad 0
More information about the llvm-commits
mailing list