[PATCH] D68758: Improve error message for bad SHF_MERGE sections

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 9 21:25:53 PDT 2019


ruiu created this revision.
ruiu added reviewers: MaskRay, grimar.
Herald added subscribers: arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

This patch adds a section name to error messages.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68758

Files:
  lld/ELF/InputFiles.cpp
  lld/ELF/InputFiles.h
  lld/test/ELF/merge-bad-input1.s
  lld/test/ELF/merge-bad-input2.s


Index: lld/test/ELF/merge-bad-input2.s
===================================================================
--- /dev/null
+++ 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", at progbits,1
+.zero 16
Index: lld/test/ELF/merge-bad-input1.s
===================================================================
--- /dev/null
+++ 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", at progbits,16
+.align 16
+.zero 24
Index: lld/ELF/InputFiles.h
===================================================================
--- lld/ELF/InputFiles.h
+++ 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
Index: lld/ELF/InputFiles.cpp
===================================================================
--- lld/ELF/InputFiles.cpp
+++ lld/ELF/InputFiles.cpp
@@ -483,7 +483,8 @@
   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,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<EhInputSection>(*this, sec, name);
 
-  if (shouldMerge(sec))
+  if (shouldMerge(sec, name))
     return make<MergeInputSection>(*this, sec, name);
   return make<InputSection>(*this, sec, name);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68758.224243.patch
Type: text/x-patch
Size: 2906 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191010/805b13b5/attachment.bin>


More information about the llvm-commits mailing list