<div dir="ltr">The commit message indicates that a file name should be included in a diagnostic, but the test case doesn't seem to verify any file name - is there something missing there?</div><br><div class="gmail_quote"><div dir="ltr">On Fri, Jul 15, 2016 at 1:45 PM Rui Ueyama via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: ruiu<br>
Date: Fri Jul 15 15:38:28 2016<br>
New Revision: 275608<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=275608&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=275608&view=rev</a><br>
Log:<br>
ELF: Include filenames in error messages.<br>
<br>
Modified:<br>
    lld/trunk/ELF/InputFiles.cpp<br>
    lld/trunk/ELF/InputFiles.h<br>
    lld/trunk/test/ELF/writable-merge.s<br>
<br>
Modified: lld/trunk/ELF/InputFiles.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=275608&r1=275607&r2=275608&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=275608&r1=275607&r2=275608&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/InputFiles.cpp (original)<br>
+++ lld/trunk/ELF/InputFiles.cpp Fri Jul 15 15:38:28 2016<br>
@@ -29,7 +29,7 @@ using namespace lld;<br>
 using namespace lld::elf;<br>
<br>
 // Returns "(internal)", "foo.a(bar.o)" or "baz.o".<br>
-std::string elf::getFilename(InputFile *F) {<br>
+std::string elf::getFilename(const InputFile *F) {<br>
   if (!F)<br>
     return "(internal)";<br>
   if (!F->ArchiveName.empty())<br>
@@ -67,7 +67,7 @@ typename ELFT::SymRange ELFFileBase<ELFT<br>
   uint32_t NumSymbols = std::distance(Syms.begin(), Syms.end());<br>
   uint32_t FirstNonLocal = Symtab->sh_info;<br>
   if (FirstNonLocal > NumSymbols)<br>
-    fatal("invalid sh_info in symbol table");<br>
+    fatal(getFilename(this) + ": invalid sh_info in symbol table");<br>
<br>
   if (OnlyGlobals)<br>
     return makeArrayRef(Syms.begin() + FirstNonLocal, Syms.end());<br>
@@ -151,13 +151,12 @@ elf::ObjectFile<ELFT>::getShtGroupEntrie<br>
   ArrayRef<Elf_Word> Entries =<br>
       check(Obj.template getSectionContentsAsArray<Elf_Word>(&Sec));<br>
   if (Entries.empty() || Entries[0] != GRP_COMDAT)<br>
-    fatal("unsupported SHT_GROUP format");<br>
+    fatal(getFilename(this) + ": unsupported SHT_GROUP format");<br>
   return Entries.slice(1);<br>
 }<br>
<br>
-template <class ELFT> static bool shouldMerge(const typename ELFT::Shdr &Sec) {<br>
-  typedef typename ELFT::uint uintX_t;<br>
-<br>
+template <class ELFT><br>
+bool elf::ObjectFile<ELFT>::shouldMerge(const Elf_Shdr &Sec) {<br>
   // We don't merge sections if -O0 (default is -O1). This makes sometimes<br>
   // the linker significantly faster, although the output will be bigger.<br>
   if (Config->Optimize == 0)<br>
@@ -167,10 +166,11 @@ template <class ELFT> static bool should<br>
   if (!(Flags & SHF_MERGE))<br>
     return false;<br>
   if (Flags & SHF_WRITE)<br>
-    fatal("writable SHF_MERGE sections are not supported");<br>
+    fatal(getFilename(this) + ": writable SHF_MERGE section is not supported");<br>
   uintX_t EntSize = Sec.sh_entsize;<br>
   if (!EntSize || Sec.sh_size % EntSize)<br>
-    fatal("SHF_MERGE section size must be a multiple of sh_entsize");<br>
+    fatal(getFilename(this) +<br>
+          ": SHF_MERGE section size must be a multiple of sh_entsize");<br>
<br>
   // Don't try to merge if the alignment is larger than the sh_entsize and this<br>
   // is not SHF_STRINGS.<br>
@@ -203,7 +203,8 @@ void elf::ObjectFile<ELFT>::initializeSe<br>
         continue;<br>
       for (uint32_t SecIndex : getShtGroupEntries(Sec)) {<br>
         if (SecIndex >= Size)<br>
-          fatal("invalid section index in group");<br>
+          fatal(getFilename(this) + ": invalid section index in group: " +<br>
+                Twine(SecIndex));<br>
         Sections[SecIndex] = &InputSection<ELFT>::Discarded;<br>
       }<br>
       break;<br>
@@ -237,11 +238,14 @@ void elf::ObjectFile<ELFT>::initializeSe<br>
       }<br>
       if (auto *S = dyn_cast<EhInputSection<ELFT>>(Target)) {<br>
         if (S->RelocSection)<br>
-          fatal("multiple relocation sections to .eh_frame are not supported");<br>
+          fatal(<br>
+              getFilename(this) +<br>
+              ": multiple relocation sections to .eh_frame are not supported");<br>
         S->RelocSection = &Sec;<br>
         break;<br>
       }<br>
-      fatal("relocations pointing to SHF_MERGE are not supported");<br>
+      fatal(getFilename(this) +<br>
+            ": relocations pointing to SHF_MERGE are not supported");<br>
     }<br>
     case SHT_ARM_ATTRIBUTES:<br>
       // FIXME: ARM meta-data section. At present attributes are ignored,<br>
@@ -259,7 +263,8 @@ InputSectionBase<ELFT> *<br>
 elf::ObjectFile<ELFT>::getRelocTarget(const Elf_Shdr &Sec) {<br>
   uint32_t Idx = Sec.sh_info;<br>
   if (Idx >= Sections.size())<br>
-    fatal("invalid relocated section index");<br>
+    fatal(getFilename(this) + ": invalid relocated section index: " +<br>
+          Twine(Idx));<br>
   InputSectionBase<ELFT> *Target = Sections[Idx];<br>
<br>
   // Strictly speaking, a relocation section must be included in the<br>
@@ -269,7 +274,7 @@ elf::ObjectFile<ELFT>::getRelocTarget(co<br>
     return nullptr;<br>
<br>
   if (!Target)<br>
-    fatal("unsupported relocation reference");<br>
+    fatal(getFilename(this) + ": unsupported relocation reference");<br>
   return Target;<br>
 }<br>
<br>
@@ -312,7 +317,7 @@ elf::ObjectFile<ELFT>::createInputSectio<br>
   if (Name == ".eh_frame" && !Config->Relocatable)<br>
     return new (EHAlloc.Allocate()) EhInputSection<ELFT>(this, &Sec);<br>
<br>
-  if (shouldMerge<ELFT>(Sec))<br>
+  if (shouldMerge(Sec))<br>
     return new (MAlloc.Allocate()) MergeInputSection<ELFT>(this, &Sec);<br>
   return new (IAlloc.Allocate()) InputSection<ELFT>(this, &Sec);<br>
 }<br>
@@ -333,7 +338,7 @@ elf::ObjectFile<ELFT>::getSection(const<br>
   if (Index == 0)<br>
     return nullptr;<br>
   if (Index >= Sections.size() || !Sections[Index])<br>
-    fatal("invalid section index");<br>
+    fatal(getFilename(this) + ": invalid section index: " + Twine(Index));<br>
   InputSectionBase<ELFT> *S = Sections[Index];<br>
   if (S == &InputSectionBase<ELFT>::Discarded)<br>
     return S;<br>
@@ -342,7 +347,7 @@ elf::ObjectFile<ELFT>::getSection(const<br>
<br>
 template <class ELFT><br>
 SymbolBody *elf::ObjectFile<ELFT>::createSymbolBody(const Elf_Sym *Sym) {<br>
-  unsigned char Binding = Sym->getBinding();<br>
+  int Binding = Sym->getBinding();<br>
   InputSectionBase<ELFT> *Sec = getSection(*Sym);<br>
   if (Binding == STB_LOCAL) {<br>
     if (Sym->st_shndx == SHN_UNDEF)<br>
@@ -373,7 +378,7 @@ SymbolBody *elf::ObjectFile<ELFT>::creat<br>
<br>
   switch (Binding) {<br>
   default:<br>
-    fatal("unexpected binding");<br>
+    fatal(getFilename(this) + ": unexpected binding: " + Twine(Binding));<br>
   case STB_GLOBAL:<br>
   case STB_WEAK:<br>
   case STB_GNU_UNIQUE:<br>
@@ -471,7 +476,7 @@ template <class ELFT> void SharedFile<EL<br>
     if (Dyn.d_tag == DT_SONAME) {<br>
       uintX_t Val = Dyn.getVal();<br>
       if (Val >= this->StringTable.size())<br>
-        fatal("invalid DT_SONAME entry");<br>
+        fatal(getFilename(this) + ": invalid DT_SONAME entry");<br>
       SoName = StringRef(this->StringTable.data() + Val);<br>
       return;<br>
     }<br>
@@ -581,7 +586,9 @@ static uint8_t getMachineKind(MemoryBuff<br>
   case Triple::x86_64:<br>
     return EM_X86_64;<br>
   default:<br>
-    fatal("could not infer e_machine from bitcode target triple " + TripleStr);<br>
+    fatal(MB.getBufferIdentifier() +<br>
+          ": could not infer e_machine from bitcode target triple " +<br>
+          TripleStr);<br>
   }<br>
 }<br>
<br>
<br>
Modified: lld/trunk/ELF/InputFiles.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=275608&r1=275607&r2=275608&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=275608&r1=275607&r2=275608&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/InputFiles.h (original)<br>
+++ lld/trunk/ELF/InputFiles.h Fri Jul 15 15:38:28 2016<br>
@@ -69,7 +69,7 @@ private:<br>
 };<br>
<br>
 // Returns "(internal)", "foo.a(bar.o)" or "baz.o".<br>
-std::string getFilename(InputFile *F);<br>
+std::string getFilename(const InputFile *F);<br>
<br>
 template <typename ELFT> class ELFFileBase : public InputFile {<br>
 public:<br>
@@ -162,6 +162,7 @@ private:<br>
   InputSectionBase<ELFT> *getRelocTarget(const Elf_Shdr &Sec);<br>
   InputSectionBase<ELFT> *createInputSection(const Elf_Shdr &Sec);<br>
<br>
+  bool shouldMerge(const Elf_Shdr &Sec);<br>
   SymbolBody *createSymbolBody(const Elf_Sym *Sym);<br>
<br>
   // List of all sections defined by this file.<br>
<br>
Modified: lld/trunk/test/ELF/writable-merge.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/writable-merge.s?rev=275608&r1=275607&r2=275608&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/writable-merge.s?rev=275608&r1=275607&r2=275608&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/test/ELF/writable-merge.s (original)<br>
+++ lld/trunk/test/ELF/writable-merge.s Fri Jul 15 15:38:28 2016<br>
@@ -1,6 +1,6 @@<br>
 // REQUIRES: x86<br>
 // RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux<br>
 // RUN: not ld.lld %t.o -o %t 2>&1 | FileCheck %s<br>
-// CHECK: writable SHF_MERGE sections are not supported<br>
+// CHECK: writable SHF_MERGE section is not supported<br>
<br>
-        .section       .foo,"awM",@progbits,4<br>
+.section .foo,"awM",@progbits,4<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>