diff --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cpp --- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp +++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp @@ -659,7 +659,9 @@ 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 --- a/llvm/test/MC/ARM/dwarf-asm-multiple-sections.s +++ b/llvm/test/MC/ARM/dwarf-asm-multiple-sections.s @@ -20,6 +20,16 @@ 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