[lld] r346427 - [COFF] Improve relocation against discarded section error
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 8 10:38:17 PST 2018
Author: rnk
Date: Thu Nov 8 10:38:17 2018
New Revision: 346427
URL: http://llvm.org/viewvc/llvm-project?rev=346427&view=rev
Log:
[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
Modified:
lld/trunk/COFF/Chunks.cpp
lld/trunk/COFF/SymbolTable.cpp
lld/trunk/COFF/SymbolTable.h
lld/trunk/test/COFF/reloc-discarded.s
Modified: lld/trunk/COFF/Chunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.cpp?rev=346427&r1=346426&r2=346427&view=diff
==============================================================================
--- lld/trunk/COFF/Chunks.cpp (original)
+++ lld/trunk/COFF/Chunks.cpp Thu Nov 8 10:38:17 2018
@@ -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)
// 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)
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();
Modified: lld/trunk/COFF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=346427&r1=346426&r2=346427&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.cpp (original)
+++ lld/trunk/COFF/SymbolTable.cpp Thu Nov 8 10:38:17 2018
@@ -84,7 +84,7 @@ static Symbol *getSymbol(SectionChunk *S
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<StringRef, uint32_t> FileLine;
Modified: lld/trunk/COFF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.h?rev=346427&r1=346426&r2=346427&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.h (original)
+++ lld/trunk/COFF/SymbolTable.h Thu Nov 8 10:38:17 2018
@@ -123,6 +123,8 @@ private:
extern SymbolTable *Symtab;
+std::string getSymbolLocations(ObjFile *File, uint32_t SymIndex);
+
} // namespace coff
} // namespace lld
Modified: lld/trunk/test/COFF/reloc-discarded.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/reloc-discarded.s?rev=346427&r1=346426&r2=346427&view=diff
==============================================================================
--- lld/trunk/test/COFF/reloc-discarded.s (original)
+++ lld/trunk/test/COFF/reloc-discarded.s Thu Nov 8 10:38:17 2018
@@ -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
More information about the llvm-commits
mailing list