[ELF] Improve error message for incompatible section types
authorRui Ueyama <ruiu@google.com>
Wed, 10 May 2017 16:57:50 +0000 (16:57 +0000)
committerRui Ueyama <ruiu@google.com>
Wed, 10 May 2017 16:57:50 +0000 (16:57 +0000)
Previously we were not printing out the type of the incompatible section
which made it difficult to determine what the problem was.

The error message format has been change to the following:

  error: section type mismatch for .shstrtab
  >>> <internal>:(.shstrtab): SHT_STRTAB
  >>> output section .shstrtab: Unknown

Patch by Alexander Richardson.

Differential Revision: https://reviews.llvm.org/D32488

llvm-svn: 302694

lld/ELF/OutputSections.cpp
lld/test/ELF/incompatible-section-types2.s

index 9cbbd468e8ff373ce70cf8529267010738924568..b25aa0683655fc1294aa9762ef06024f9b375a7c 100644 (file)
@@ -429,8 +429,11 @@ void OutputSectionFactory::addInputSec(InputSectionBase *IS,
       if (canMergeToProgbits(Sec->Type) && canMergeToProgbits(IS->Type))
         Sec->Type = SHT_PROGBITS;
       else
-        error("Section has different type from others with the same name " +
-              toString(IS));
+        error("section type mismatch for " + IS->Name +
+              "\n>>> " + toString(IS) + ": " +
+              getELFSectionTypeName(Config->EMachine, IS->Type) +
+              "\n>>> output section " + Sec->Name + ": " +
+              getELFSectionTypeName(Config->EMachine, Sec->Type));
     }
     Sec->Flags |= Flags;
   } else {
index 2cf9b8548aa113b37fa1d96584eeb98ff9428f02..146e680ab2713c0e7aff65c59196af49621f13d3 100644 (file)
@@ -1,7 +1,9 @@
 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
 // RUN: not ld.lld %t.o -o %t 2>&1 | FileCheck %s
 
-// CHECK: error: Section has different type from others with the same name <internal>:(.shstrtab)
+// CHECK:      error: section type mismatch for .shstrtab
+// CHECK-NEXT: >>> <internal>:(.shstrtab): SHT_STRTAB
+// CHECK-NEXT: >>> output section .shstrtab: Unknown
 
-.section .shstrtab,""
+.section .shstrtab,"",@12345
 .short 20