[PATCH] D35526: [COFF] Accept discarded relocations in DWARF debug sections

Shoaib Meenai via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 17 18:39:29 PDT 2017


smeenai created this revision.
Herald added a subscriber: aprantl.

DWARF debug sections can also contain relocations against symbols in
discared segments. LLD should accept such relocations.


https://reviews.llvm.org/D35526

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


Index: test/COFF/reloc-discarded-dwarf.s
===================================================================
--- /dev/null
+++ test/COFF/reloc-discarded-dwarf.s
@@ -0,0 +1,15 @@
+# RUN: llvm-mc -triple=x86_64-windows-msvc -filetype=obj -o %t1.obj %s
+# RUN: llvm-mc -triple=x86_64-windows-msvc -filetype=obj -o %t2.obj %s
+
+# LLD should not error on relocations in DWARF debug sections against symbols in
+# discarded sections.
+# RUN: lld-link -entry:main -debug %t1.obj %t2.obj
+
+	.section	.text,"xr",discard,main
+	.globl	main
+main:
+f:
+	retq
+
+	.section	.debug_info,"dr"
+	.quad	f
Index: COFF/Chunks.h
===================================================================
--- COFF/Chunks.h
+++ COFF/Chunks.h
@@ -188,6 +188,10 @@
     return SectionName == ".debug" || SectionName.startswith(".debug$");
   }
 
+  bool isDWARF() const {
+    return SectionName.startswith(".debug_");
+  }
+
   // Allow iteration over the bodies of this chunk's relocated symbols.
   llvm::iterator_range<symbol_iterator> symbols() const {
     return llvm::make_range(symbol_iterator(File, Relocs.begin()),
Index: COFF/Chunks.cpp
===================================================================
--- COFF/Chunks.cpp
+++ COFF/Chunks.cpp
@@ -235,7 +235,7 @@
     // sections are not GC roots and can end up with these kinds of relocations.
     // Skip these relocations.
     if (!OS && !isa<DefinedAbsolute>(Sym) && !isa<DefinedSynthetic>(Sym)) {
-      if (isCodeView())
+      if (isCodeView() || isDWARF())
         continue;
       fatal("relocation against symbol in discarded section: " +
             Sym->getName());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35526.107005.patch
Type: text/x-patch
Size: 1617 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170718/35f1510b/attachment.bin>


More information about the llvm-commits mailing list