[PATCH] D54240: [COFF] Improve relocation against discarded section error

Reid Kleckner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 8 10:41:57 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rLLD346427: [COFF] Improve relocation against discarded section error (authored by rnk, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D54240?vs=173091&id=173196#toc

Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D54240

Files:
  COFF/Chunks.cpp
  COFF/SymbolTable.cpp
  COFF/SymbolTable.h
  test/COFF/reloc-discarded.s


Index: test/COFF/reloc-discarded.s
===================================================================
--- test/COFF/reloc-discarded.s
+++ 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
Index: COFF/Chunks.cpp
===================================================================
--- COFF/Chunks.cpp
+++ 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 @@
       // 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 @@
       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();
Index: COFF/SymbolTable.h
===================================================================
--- COFF/SymbolTable.h
+++ COFF/SymbolTable.h
@@ -123,6 +123,8 @@
 
 extern SymbolTable *Symtab;
 
+std::string getSymbolLocations(ObjFile *File, uint32_t SymIndex);
+
 } // namespace coff
 } // namespace lld
 
Index: COFF/SymbolTable.cpp
===================================================================
--- COFF/SymbolTable.cpp
+++ COFF/SymbolTable.cpp
@@ -84,7 +84,7 @@
   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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54240.173196.patch
Type: text/x-patch
Size: 2385 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181108/4661783f/attachment.bin>


More information about the llvm-commits mailing list