Skip to content

Commit

Permalink
[COFF] Accept discarded relocations in DWARF debug sections
Browse files Browse the repository at this point in the history
DWARF debug sections can also contain relocations against symbols in
discared segments. LLD should accept such relocations.

Differential Revision: https://reviews.llvm.org/D35526

llvm-svn: 308315
  • Loading branch information
smeenai committed Jul 18, 2017
1 parent a253e4c commit 9a61a79
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lld/COFF/Chunks.cpp
Expand Up @@ -235,7 +235,7 @@ void SectionChunk::writeTo(uint8_t *Buf) const {
// 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());
Expand Down
3 changes: 3 additions & 0 deletions lld/COFF/Chunks.h
Expand Up @@ -188,6 +188,9 @@ class SectionChunk final : public Chunk {
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<symbol_iterator> symbols() const {
return llvm::make_range(symbol_iterator(File, Relocs.begin()),
Expand Down
15 changes: 15 additions & 0 deletions lld/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

0 comments on commit 9a61a79

Please sign in to comment.