From: Rui Ueyama Date: Fri, 15 Jul 2016 20:38:28 +0000 (+0000) Subject: ELF: Include filenames in error messages. X-Git-Tag: llvmorg-3.9.0-rc1~270 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=429ef2af6a1f6a3d4fc017d43cff14f056228eb3;p=platform%2Fupstream%2Fllvm.git ELF: Include filenames in error messages. llvm-svn: 275608 --- diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 3fd889e..e5311e6 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -29,7 +29,7 @@ using namespace lld; using namespace lld::elf; // Returns "(internal)", "foo.a(bar.o)" or "baz.o". -std::string elf::getFilename(InputFile *F) { +std::string elf::getFilename(const InputFile *F) { if (!F) return "(internal)"; if (!F->ArchiveName.empty()) @@ -67,7 +67,7 @@ typename ELFT::SymRange ELFFileBase::getElfSymbols(bool OnlyGlobals) { uint32_t NumSymbols = std::distance(Syms.begin(), Syms.end()); uint32_t FirstNonLocal = Symtab->sh_info; if (FirstNonLocal > NumSymbols) - fatal("invalid sh_info in symbol table"); + fatal(getFilename(this) + ": invalid sh_info in symbol table"); if (OnlyGlobals) return makeArrayRef(Syms.begin() + FirstNonLocal, Syms.end()); @@ -151,13 +151,12 @@ elf::ObjectFile::getShtGroupEntries(const Elf_Shdr &Sec) { ArrayRef Entries = check(Obj.template getSectionContentsAsArray(&Sec)); if (Entries.empty() || Entries[0] != GRP_COMDAT) - fatal("unsupported SHT_GROUP format"); + fatal(getFilename(this) + ": unsupported SHT_GROUP format"); return Entries.slice(1); } -template static bool shouldMerge(const typename ELFT::Shdr &Sec) { - typedef typename ELFT::uint uintX_t; - +template +bool elf::ObjectFile::shouldMerge(const Elf_Shdr &Sec) { // We don't merge sections if -O0 (default is -O1). This makes sometimes // the linker significantly faster, although the output will be bigger. if (Config->Optimize == 0) @@ -167,10 +166,11 @@ template static bool shouldMerge(const typename ELFT::Shdr &Sec) { if (!(Flags & SHF_MERGE)) return false; if (Flags & SHF_WRITE) - fatal("writable SHF_MERGE sections are not supported"); + fatal(getFilename(this) + ": writable SHF_MERGE section is not supported"); uintX_t EntSize = Sec.sh_entsize; if (!EntSize || Sec.sh_size % EntSize) - fatal("SHF_MERGE section size must be a multiple of sh_entsize"); + fatal(getFilename(this) + + ": SHF_MERGE section size must be a multiple of sh_entsize"); // Don't try to merge if the alignment is larger than the sh_entsize and this // is not SHF_STRINGS. @@ -203,7 +203,8 @@ void elf::ObjectFile::initializeSections( continue; for (uint32_t SecIndex : getShtGroupEntries(Sec)) { if (SecIndex >= Size) - fatal("invalid section index in group"); + fatal(getFilename(this) + ": invalid section index in group: " + + Twine(SecIndex)); Sections[SecIndex] = &InputSection::Discarded; } break; @@ -237,11 +238,14 @@ void elf::ObjectFile::initializeSections( } if (auto *S = dyn_cast>(Target)) { if (S->RelocSection) - fatal("multiple relocation sections to .eh_frame are not supported"); + fatal( + getFilename(this) + + ": multiple relocation sections to .eh_frame are not supported"); S->RelocSection = &Sec; break; } - fatal("relocations pointing to SHF_MERGE are not supported"); + fatal(getFilename(this) + + ": relocations pointing to SHF_MERGE are not supported"); } case SHT_ARM_ATTRIBUTES: // FIXME: ARM meta-data section. At present attributes are ignored, @@ -259,7 +263,8 @@ InputSectionBase * elf::ObjectFile::getRelocTarget(const Elf_Shdr &Sec) { uint32_t Idx = Sec.sh_info; if (Idx >= Sections.size()) - fatal("invalid relocated section index"); + fatal(getFilename(this) + ": invalid relocated section index: " + + Twine(Idx)); InputSectionBase *Target = Sections[Idx]; // Strictly speaking, a relocation section must be included in the @@ -269,7 +274,7 @@ elf::ObjectFile::getRelocTarget(const Elf_Shdr &Sec) { return nullptr; if (!Target) - fatal("unsupported relocation reference"); + fatal(getFilename(this) + ": unsupported relocation reference"); return Target; } @@ -312,7 +317,7 @@ elf::ObjectFile::createInputSection(const Elf_Shdr &Sec) { if (Name == ".eh_frame" && !Config->Relocatable) return new (EHAlloc.Allocate()) EhInputSection(this, &Sec); - if (shouldMerge(Sec)) + if (shouldMerge(Sec)) return new (MAlloc.Allocate()) MergeInputSection(this, &Sec); return new (IAlloc.Allocate()) InputSection(this, &Sec); } @@ -333,7 +338,7 @@ elf::ObjectFile::getSection(const Elf_Sym &Sym) const { if (Index == 0) return nullptr; if (Index >= Sections.size() || !Sections[Index]) - fatal("invalid section index"); + fatal(getFilename(this) + ": invalid section index: " + Twine(Index)); InputSectionBase *S = Sections[Index]; if (S == &InputSectionBase::Discarded) return S; @@ -342,7 +347,7 @@ elf::ObjectFile::getSection(const Elf_Sym &Sym) const { template SymbolBody *elf::ObjectFile::createSymbolBody(const Elf_Sym *Sym) { - unsigned char Binding = Sym->getBinding(); + int Binding = Sym->getBinding(); InputSectionBase *Sec = getSection(*Sym); if (Binding == STB_LOCAL) { if (Sym->st_shndx == SHN_UNDEF) @@ -373,7 +378,7 @@ SymbolBody *elf::ObjectFile::createSymbolBody(const Elf_Sym *Sym) { switch (Binding) { default: - fatal("unexpected binding"); + fatal(getFilename(this) + ": unexpected binding: " + Twine(Binding)); case STB_GLOBAL: case STB_WEAK: case STB_GNU_UNIQUE: @@ -471,7 +476,7 @@ template void SharedFile::parseSoName() { if (Dyn.d_tag == DT_SONAME) { uintX_t Val = Dyn.getVal(); if (Val >= this->StringTable.size()) - fatal("invalid DT_SONAME entry"); + fatal(getFilename(this) + ": invalid DT_SONAME entry"); SoName = StringRef(this->StringTable.data() + Val); return; } @@ -581,7 +586,9 @@ static uint8_t getMachineKind(MemoryBufferRef MB) { case Triple::x86_64: return EM_X86_64; default: - fatal("could not infer e_machine from bitcode target triple " + TripleStr); + fatal(MB.getBufferIdentifier() + + ": could not infer e_machine from bitcode target triple " + + TripleStr); } } diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h index 416e7ce..79cb751 100644 --- a/lld/ELF/InputFiles.h +++ b/lld/ELF/InputFiles.h @@ -69,7 +69,7 @@ private: }; // Returns "(internal)", "foo.a(bar.o)" or "baz.o". -std::string getFilename(InputFile *F); +std::string getFilename(const InputFile *F); template class ELFFileBase : public InputFile { public: @@ -162,6 +162,7 @@ private: InputSectionBase *getRelocTarget(const Elf_Shdr &Sec); InputSectionBase *createInputSection(const Elf_Shdr &Sec); + bool shouldMerge(const Elf_Shdr &Sec); SymbolBody *createSymbolBody(const Elf_Sym *Sym); // List of all sections defined by this file. diff --git a/lld/test/ELF/writable-merge.s b/lld/test/ELF/writable-merge.s index 6375573..431cb628 100644 --- a/lld/test/ELF/writable-merge.s +++ b/lld/test/ELF/writable-merge.s @@ -1,6 +1,6 @@ // REQUIRES: x86 // RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux // RUN: not ld.lld %t.o -o %t 2>&1 | FileCheck %s -// CHECK: writable SHF_MERGE sections are not supported +// CHECK: writable SHF_MERGE section is not supported - .section .foo,"awM",@progbits,4 +.section .foo,"awM",@progbits,4