Index: lld/trunk/COFF/Chunks.h =================================================================== --- lld/trunk/COFF/Chunks.h +++ lld/trunk/COFF/Chunks.h @@ -188,6 +188,9 @@ return SectionName == ".debug" || SectionName.startswith(".debug$"); } + // True if this is a DWARF debug info chunk. + bool isDWARF() const { return SectionName.startswith(".debug_"); } + // Allow iteration over the bodies of this chunk's relocated symbols. llvm::iterator_range symbols() const { return llvm::make_range(symbol_iterator(File, Relocs.begin()), Index: lld/trunk/COFF/Chunks.cpp =================================================================== --- lld/trunk/COFF/Chunks.cpp +++ lld/trunk/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(Sym) && !isa(Sym)) { - if (isCodeView()) + if (isCodeView() || isDWARF()) continue; fatal("relocation against symbol in discarded section: " + Sym->getName()); Index: lld/trunk/test/COFF/reloc-discarded-dwarf.s =================================================================== --- lld/trunk/test/COFF/reloc-discarded-dwarf.s +++ lld/trunk/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