Index: ELF/OutputSections.cpp =================================================================== --- ELF/OutputSections.cpp +++ ELF/OutputSections.cpp @@ -393,6 +393,13 @@ IS->File->getName()); } +static std::string getElfSectionType(unsigned Type) { + StringRef S = object::getELFSectionTypeName(Config->EMachine, Type); + if (!S.empty()) + return S; + return "0x" + utohexstr(Type); +} + void OutputSectionFactory::addInputSec(InputSectionBase *IS, StringRef OutsecName) { if (!IS->Live) { @@ -411,8 +418,10 @@ 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) + ": " + getElfSectionType(IS->Type) + + "\n>>> output section " + Sec->Name + ": " + + getElfSectionType(Sec->Type)); } Sec->Flags |= Flags; } else { Index: test/ELF/incompatible-section-types2.s =================================================================== --- test/ELF/incompatible-section-types2.s +++ test/ELF/incompatible-section-types2.s @@ -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 :(.shstrtab) +// CHECK: error: section type mismatch for .shstrtab +// CHECK-NEXT: >>> :(.shstrtab): SHT_STRTAB +// CHECK-NEXT: >>> output section .shstrtab: SHT_PROGBITS .section .shstrtab,"" .short 20