[PATCH] D93502: DebugInfo: Make -no-dwarf-ranges-section just emit no address range rather than a bogus/partial one

David Blaikie via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 17 17:25:05 PST 2020


dblaikie created this revision.
dblaikie added a reviewer: ABataev.
Herald added a subscriber: hiraditya.
dblaikie requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

First implemented in r328030 / 858a7dd6d70bfed500e0e2a5137f25dd71b90f19 and I
speculated in this review about what exactly we should be doing here - and now
I've come across some changes I'm making that trip over the somewhat arbitrary
behavior we chose here & deciding to revisit it for more correctness/less
arbitrariness.

With that previous commit, we made a single contiguous range (high/low_pc) from
the first and last entry in the range list - that's not correct, especially at
the CU level where this address range might then span multiple sections (maybe
even not sections that would all be unified by the linker, even - if you have
functions in special sections). Instead, just don't emit any addresses (ranges
or low/high) for such an entity.

I made the change for nested constructs (not just the CU) as well, though there
doesn't seem to be test coverage for that - I can add that if folks think it's
worthwhile. (probably should, I'm just being lazy) This could still hit the
multiple different sections issue in cases like -fbasic-block-sections.

Alexey - a question I had on the orginal patch: Any idea what other compilers
have done in this case? Is it the original behavior implemented here (beginning
of the first range to the end of the last, sort of paving over any address
holes).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93502

Files:
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  llvm/test/DebugInfo/X86/no_debug_ranges.ll


Index: llvm/test/DebugInfo/X86/no_debug_ranges.ll
===================================================================
--- llvm/test/DebugInfo/X86/no_debug_ranges.ll
+++ llvm/test/DebugInfo/X86/no_debug_ranges.ll
@@ -1,12 +1,17 @@
-; RUN: llc -filetype=asm -mtriple=x86_64-pc-linux-gnu < %s -o - -dwarf-version=2 -no-dwarf-ranges-section | FileCheck %s --check-prefix=DISABLED
+; RUN: llc -filetype=asm -mtriple=x86_64-pc-linux-gnu < %s -o - -dwarf-version=2 -no-dwarf-ranges-section \
+; RUN:     | FileCheck %s --check-prefix=DISABLED "--implicit-check-not={{DW_AT_ranges|.debug_ranges}}"
 ; RUN: llc -filetype=asm -mtriple=x86_64-pc-linux-gnu < %s -o - -dwarf-version=2 | FileCheck %s
 
-; DISABLED-NOT:  {{DW_AT_ranges|.debug_ranges}}
-; DISABLED:      .section .debug_info
-; DISABLED-NOT:  {{DW_AT_ranges|.section}}
-; DISABLED:      .quad .Lfunc_begin0 # DW_AT_low_pc
+; DISABLED: .section .debug_info
+; DISABLED-NOT: {{DW_AT_low_pc|DW_AT_high_pc}}
+; DISABLED: .quad 0 # DW_AT_low_pc
+; DISABLED-NOT: {{DW_AT_low_pc|DW_AT_high_pc}}
+; DISABLED: .quad .Lfunc_begin0 # DW_AT_low_pc
+; DISABLED-NEXT: .quad .Lfunc_end0   # DW_AT_high_pc
+; DISABLED-NOT: {{DW_AT_low_pc|DW_AT_high_pc}}
+; DISABLED: .quad .Lfunc_begin1 # DW_AT_low_pc
 ; DISABLED-NEXT: .quad .Lfunc_end1   # DW_AT_high_pc
-; DISABLED-NOT:  {{DW_AT_ranges|.debug_ranges}}
+; DISABLED-NOT: {{DW_AT_low_pc|DW_AT_high_pc}}
 
 ; .debug_ranges section must be emitted by default
 ; CHECK: .section .debug_info
Index: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -1316,7 +1316,7 @@
     DwarfCompileUnit &U = SkCU ? *SkCU : TheCU;
 
     if (unsigned NumRanges = TheCU.getRanges().size()) {
-      if (NumRanges > 1 && useRangesSection())
+      if (NumRanges > 1)
         // A DW_AT_low_pc attribute may also be specified in combination with
         // DW_AT_ranges to specify the default base address for use in
         // location lists (see Section 2.6.2) and range lists (see Section
@@ -1324,7 +1324,8 @@
         U.addUInt(U.getUnitDie(), dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, 0);
       else
         U.setBaseAddress(TheCU.getRanges().front().Begin);
-      U.attachRangesOrLowHighPC(U.getUnitDie(), TheCU.takeRanges());
+      if (useRangesSection())
+        U.attachRangesOrLowHighPC(U.getUnitDie(), TheCU.takeRanges());
     }
 
     // We don't keep track of which addresses are used in which CU so this
Index: llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -558,11 +558,10 @@
 
 void DwarfCompileUnit::attachRangesOrLowHighPC(
     DIE &Die, SmallVector<RangeSpan, 2> Ranges) {
-  if (Ranges.size() == 1 || !DD->useRangesSection()) {
+  if (Ranges.size() == 1) {
     const RangeSpan &Front = Ranges.front();
-    const RangeSpan &Back = Ranges.back();
-    attachLowHighPC(Die, Front.Begin, Back.End);
-  } else
+    attachLowHighPC(Die, Front.Begin, Front.End);
+  } else if (DD->useRangesSection())
     addScopeRangeList(Die, std::move(Ranges));
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93502.312652.patch
Type: text/x-patch
Size: 3282 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201218/770a56f6/attachment.bin>


More information about the llvm-commits mailing list