ELFAsmParser: Remove non-SHF_ALLOC or non-executable sections' line info/address...
authorFangrui Song <i@maskray.me>
Tue, 17 Nov 2020 04:02:25 +0000 (20:02 -0800)
committerFangrui Song <i@maskray.me>
Tue, 17 Nov 2020 04:02:25 +0000 (20:02 -0800)
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
llvm/test/MC/ARM/dwarf-asm-multiple-sections.s

index 440d3a3..78fee5a 100644 (file)
@@ -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)
index abe7507..72115cc 100644 (file)
@@ -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