From fac0622ae0a59659a5969a137a724008547be697 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 16 Nov 2020 20:02:25 -0800 Subject: [PATCH] ELFAsmParser: Remove non-SHF_ALLOC or non-executable sections' line info/address ranges contribution for -g I filed the issue https://sourceware.org/bugzilla/show_bug.cgi?id=26850 , which was acknowledged and fixed in GNU binutils 2.36 This patch adds the similar behavior to MC. Reviewed By: #debug-info, dblaikie Differential Revision: https://reviews.llvm.org/D91505 --- llvm/lib/MC/MCParser/ELFAsmParser.cpp | 4 +++- llvm/test/MC/ARM/dwarf-asm-multiple-sections.s | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cpp index 440d3a3..78fee5a 100644 --- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp +++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp @@ -659,7 +659,9 @@ EndStmt: Error(loc, "changed section entsize for " + SectionName + ", expected: " + Twine(Section->getEntrySize())); - if (getContext().getGenDwarfForAssembly()) { + if (getContext().getGenDwarfForAssembly() && + (Section->getFlags() & ELF::SHF_ALLOC) && + (Section->getFlags() & ELF::SHF_EXECINSTR)) { bool InsertResult = getContext().addGenDwarfSection(Section); if (InsertResult) { if (getContext().getDwarfVersion() <= 2) diff --git a/llvm/test/MC/ARM/dwarf-asm-multiple-sections.s b/llvm/test/MC/ARM/dwarf-asm-multiple-sections.s index abe7507..72115cc 100644 --- a/llvm/test/MC/ARM/dwarf-asm-multiple-sections.s +++ b/llvm/test/MC/ARM/dwarf-asm-multiple-sections.s @@ -20,6 +20,16 @@ a: b: mov r1, r1 +// Non-executable sections do not contribute address ranges. + .section .rodata, "a" +c: + mov r2, r2 + +// Non-SHF_ALLOC sections do not contribute address ranges. + .section nonalloc, "x" +d: + mov r3, r3 + // DWARF: .debug_abbrev contents: // DWARF: Abbrev table for offset: 0x00000000 // DWARF: [1] DW_TAG_compile_unit DW_CHILDREN_yes -- 2.7.4