From 7a44fe956a249585187cd5f82a0683dc117e0ae8 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Thu, 8 Nov 2018 18:38:17 +0000 Subject: [PATCH] [COFF] Improve relocation against discarded section error Summary: Reuse the "referenced by" note diagnostic code that we already use for undefined symbols. In my case, it turned this: lld-link: error: relocation against symbol in discarded section: .text lld-link: error: relocation against symbol in discarded section: .text ... Into this: lld-link: error: relocation against symbol in discarded section: .text >>> referenced by libANGLE.lib(CompilerGL.obj):(.SCOVP$M) >>> referenced by libANGLE.lib(CompilerGL.obj):(.SCOVP$M) ... lld-link: error: relocation against symbol in discarded section: .text >>> referenced by obj/third_party/angle/libGLESv2/entry_points_egl_ext.obj:(.SCOVP$M) >>> referenced by obj/third_party/angle/libGLESv2/entry_points_egl_ext.obj:(.SCOVP$M) ... I think the new output is more useful. Reviewers: ruiu, pcc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D54240 llvm-svn: 346427 --- lld/COFF/Chunks.cpp | 6 ++++-- lld/COFF/SymbolTable.cpp | 2 +- lld/COFF/SymbolTable.h | 2 ++ lld/test/COFF/reloc-discarded.s | 1 + 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lld/COFF/Chunks.cpp b/lld/COFF/Chunks.cpp index 9808c8be6b30..321bfeb04060 100644 --- a/lld/COFF/Chunks.cpp +++ b/lld/COFF/Chunks.cpp @@ -11,6 +11,7 @@ #include "InputFiles.h" #include "Symbols.h" #include "Writer.h" +#include "SymbolTable.h" #include "lld/Common/ErrorHandler.h" #include "llvm/ADT/Twine.h" #include "llvm/BinaryFormat/COFF.h" @@ -356,7 +357,8 @@ void SectionChunk::writeTo(uint8_t *Buf) const { // with relocations against discarded comdat sections. Such sections // are left as is, with relocations untouched. if (!Config->MinGW) - error("relocation against symbol in discarded section: " + Name); + error("relocation against symbol in discarded section: " + Name + + getSymbolLocations(File, Rel.SymbolTableIndex)); continue; } // Get the output section of the symbol for this relocation. The output @@ -374,7 +376,7 @@ void SectionChunk::writeTo(uint8_t *Buf) const { if (isCodeView() || isDWARF()) continue; error("relocation against symbol in discarded section: " + - Sym->getName()); + Sym->getName() + getSymbolLocations(File, Rel.SymbolTableIndex)); continue; } uint64_t S = Sym->getRVA(); diff --git a/lld/COFF/SymbolTable.cpp b/lld/COFF/SymbolTable.cpp index 3edd98febeeb..4a50e30e1098 100644 --- a/lld/COFF/SymbolTable.cpp +++ b/lld/COFF/SymbolTable.cpp @@ -84,7 +84,7 @@ static Symbol *getSymbol(SectionChunk *SC, uint32_t Addr) { return Candidate; } -static std::string getSymbolLocations(ObjFile *File, uint32_t SymIndex) { +std::string lld::coff::getSymbolLocations(ObjFile *File, uint32_t SymIndex) { struct Location { Symbol *Sym; std::pair FileLine; diff --git a/lld/COFF/SymbolTable.h b/lld/COFF/SymbolTable.h index dc40b14ff47e..00e55dbb7a02 100644 --- a/lld/COFF/SymbolTable.h +++ b/lld/COFF/SymbolTable.h @@ -123,6 +123,8 @@ private: extern SymbolTable *Symtab; +std::string getSymbolLocations(ObjFile *File, uint32_t SymIndex); + } // namespace coff } // namespace lld diff --git a/lld/test/COFF/reloc-discarded.s b/lld/test/COFF/reloc-discarded.s index aa8fb3c3447a..378804b62312 100644 --- a/lld/test/COFF/reloc-discarded.s +++ b/lld/test/COFF/reloc-discarded.s @@ -10,6 +10,7 @@ # RUN: not lld-link -entry:main -nodefaultlib %t1.obj %t2.obj -out:%t.exe -opt:noref 2>&1 | FileCheck %s # CHECK: error: relocation against symbol in discarded section: assoc_global +# CHECK: >>> referenced by {{.*}}reloc-discarded{{.*}}.obj:(main) .section .bss,"bw",discard,main_global .globl main_global