[llvm] a663112 - DWARFv5: Disable DW_OP_convert for configurations that don't yet support it

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 22 12:02:45 PDT 2020


Author: David Blaikie
Date: 2020-10-22T12:02:33-07:00
New Revision: a66311277af3c254cb73a749e8c4478d50a37bb0

URL: https://github.com/llvm/llvm-project/commit/a66311277af3c254cb73a749e8c4478d50a37bb0
DIFF: https://github.com/llvm/llvm-project/commit/a66311277af3c254cb73a749e8c4478d50a37bb0.diff

LOG: DWARFv5: Disable DW_OP_convert for configurations that don't yet support it

Testing reveals that lldb and gdb have some problems with supporting
DW_OP_convert - gdb with Split DWARF tries to resolve the CU-relative
DIE offset relative to the skeleton DIE. lldb tries to treat the offset
as absolute, which judging by the llvm-dsymutil support for
DW_OP_convert, I guess works OK in MachO? (though probably llvm-dsymutil
is producing invalid DWARF by resolving the relative reference to an
absolute one?).

Specifically this disables DW_OP_convert usage in DWARFv5 if:
* Tuning for GDB and using Split DWARF
* Tuning for LLDB and not targeting MachO

Added: 
    

Modified: 
    llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
    llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
    llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
    llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
    llvm/test/DebugInfo/X86/convert-debugloc.ll
    llvm/test/DebugInfo/X86/convert-loclist.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 9c95ed414f2f..f49790551fe6 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -132,6 +132,13 @@ static cl::opt<bool>
                      cl::desc("Emit the GNU .debug_macro format with DWARF <5"),
                      cl::init(false));
 
+static cl::opt<DefaultOnOff> DwarfOpConvert(
+    "dwarf-op-convert", cl::Hidden,
+    cl::desc("Enable use of the DWARFv5 DW_OP_convert operator"),
+    cl::values(clEnumVal(Default, "Default for platform"),
+               clEnumVal(Enable, "Enabled"), clEnumVal(Disable, "Disabled")),
+    cl::init(Default));
+
 enum LinkageNameOption {
   DefaultLinkageNames,
   AllLinkageNames,
@@ -417,6 +424,10 @@ DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
   // for split DWARF. For now, do not allow LLVM to emit it.
   UseDebugMacroSection =
       DwarfVersion >= 5 || (UseGNUDebugMacro && !useSplitDwarf());
+  if (DwarfOpConvert == Default)
+    EnableOpConvert = !((tuneForGDB() && useSplitDwarf()) || (tuneForLLDB() && !TT.isOSBinFormatMachO()));
+  else
+    EnableOpConvert = (DwarfOpConvert == Enable);
 
   Asm->OutStreamer->getContext().setDwarfVersion(DwarfVersion);
   Asm->OutStreamer->getContext().setDwarfFormat(Dwarf64 ? dwarf::DWARF64

diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
index 34c88f1a9c60..b8b9b7e002a2 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
@@ -375,6 +375,9 @@ class DwarfDebug : public DebugHandlerBase {
   /// Emit a .debug_macro section instead of .debug_macinfo.
   bool UseDebugMacroSection;
 
+  /// Avoid using DW_OP_convert due to consumer incompatibilities.
+  bool EnableOpConvert;
+
   /// DWARF5 Experimental Options
   /// @{
   AccelTableKind TheAccelTableKind;
@@ -724,6 +727,10 @@ class DwarfDebug : public DebugHandlerBase {
     return EmitDebugEntryValues;
   }
 
+  bool useOpConvert() const {
+    return EnableOpConvert;
+  }
+
   bool shareAcrossDWOCUs() const;
 
   /// Returns the Dwarf Version.

diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
index 4e551f064bea..d07d261a0653 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
@@ -544,7 +544,7 @@ void DwarfExpression::addExpression(DIExpressionCursor &&ExprCursor,
     case dwarf::DW_OP_LLVM_convert: {
       unsigned BitSize = Op->getArg(0);
       dwarf::TypeKind Encoding = static_cast<dwarf::TypeKind>(Op->getArg(1));
-      if (DwarfVersion >= 5) {
+      if (DwarfVersion >= 5 && CU.getDwarfDebug().useOpConvert()) {
         emitOp(dwarf::DW_OP_convert);
         // If targeting a location-list; simply emit the index into the raw
         // byte stream as ULEB128, DwarfDebug::emitDebugLocEntry has been

diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
index 63a1e5a4780f..b0f2d8b8d873 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
@@ -82,6 +82,7 @@ class DwarfUnit : public DIEUnit {
   MCSymbol *getEndLabel() const { return EndLabel; }
   uint16_t getLanguage() const { return CUNode->getSourceLanguage(); }
   const DICompileUnit *getCUNode() const { return CUNode; }
+  DwarfDebug &getDwarfDebug() const { return *DD; }
 
   /// Return true if this compile unit has something to write out.
   bool hasContent() const { return getUnitDie().hasChildren(); }

diff  --git a/llvm/test/DebugInfo/X86/convert-debugloc.ll b/llvm/test/DebugInfo/X86/convert-debugloc.ll
index 4adb669f15ed..de3c164a3233 100644
--- a/llvm/test/DebugInfo/X86/convert-debugloc.ll
+++ b/llvm/test/DebugInfo/X86/convert-debugloc.ll
@@ -1,47 +1,63 @@
-; RUN: %llc_dwarf -dwarf-version=5 -filetype=obj -O0 < %s | llvm-dwarfdump - \
-; RUN:   | FileCheck %s --check-prefix=DW5 "--implicit-check-not={{DW_TAG|NULL}}"
 ; RUN: %llc_dwarf -dwarf-version=4 -filetype=obj -O0 < %s | llvm-dwarfdump - \
-; RUN:   | FileCheck %s --check-prefix=DW4 "--implicit-check-not={{DW_TAG|NULL}}"
+; RUN:   | FileCheck %s --check-prefix=NOCONV "--implicit-check-not={{DW_TAG|NULL}}"
 
-; DW5: .debug_info contents:
-; DW5: DW_TAG_compile_unit
-; DW5:[[SIG8:.*]]:   DW_TAG_base_type
-; DW5-NEXT:DW_AT_name ("DW_ATE_signed_8")
-; DW5-NEXT:DW_AT_encoding (DW_ATE_signed)
-; DW5-NEXT:DW_AT_byte_size (0x01)
-; DW5-NOT: DW_AT
-; DW5:[[SIG32:.*]]:   DW_TAG_base_type
-; DW5-NEXT:DW_AT_name ("DW_ATE_signed_32")
-; DW5-NEXT:DW_AT_encoding (DW_ATE_signed)
-; DW5-NEXT:DW_AT_byte_size (0x04)
-; DW5-NOT: DW_AT
-; DW5:   DW_TAG_subprogram
-; DW5:     DW_TAG_formal_parameter
-; DW5:     DW_TAG_variable
-; DW5:       DW_AT_location (
-; DW5:         {{.*}}, DW_OP_convert ([[SIG8]]) "DW_ATE_signed_8", DW_OP_convert ([[SIG32]]) "DW_ATE_signed_32", DW_OP_stack_value)
-; DW5:       DW_AT_name ("y")
-; DW5:     NULL
-; DW5:   DW_TAG_base_type
-; DW5:     DW_AT_name ("signed char")
-; DW5:   DW_TAG_base_type
-; DW5:     DW_AT_name ("int")
-; DW5:   NULL
+; Test lldb default: OP_convert is unsupported in general
+; RUN: %llc_dwarf -mtriple=x86_64-apple-darwin -dwarf-version=5 -filetype=obj -O0 < %s -debugger-tune=lldb | llvm-dwarfdump - \
+; RUN:   | FileCheck %s --check-prefix=CONV "--implicit-check-not={{DW_TAG|NULL}}"
+; RUN: %llc_dwarf -mtriple=x86_64-pc-linux-gnu -dwarf-version=5 -filetype=obj -O0 < %s -debugger-tune=lldb | llvm-dwarfdump - \
+; RUN:   | FileCheck %s --check-prefix=NOCONV "--implicit-check-not={{DW_TAG|NULL}}"
 
-; DW4: .debug_info contents:
-; DW4: DW_TAG_compile_unit
-; DW4:   DW_TAG_subprogram
-; DW4:     DW_TAG_formal_parameter
-; DW4:     DW_TAG_variable
-; DW4:       DW_AT_location (
-; DW4:         {{.*}}, DW_OP_dup, DW_OP_constu 0x7, DW_OP_shr, DW_OP_lit0, DW_OP_not, DW_OP_mul, DW_OP_constu 0x8, DW_OP_shl, DW_OP_or, DW_OP_stack_value)
-; DW4:       DW_AT_name ("y")
-; DW4:     NULL
-; DW4:   DW_TAG_base_type
-; DW4:     DW_AT_name ("signed char")
-; DW4:   DW_TAG_base_type
-; DW4:     DW_AT_name ("int")
-; DW4:   NULL
+; Test gdb default: OP_convert is only disabled in split DWARF
+; RUN: %llc_dwarf -dwarf-version=5 -filetype=obj -O0 < %s -debugger-tune=gdb  | llvm-dwarfdump - \
+; RUN:   | FileCheck %s --check-prefix=CONV "--implicit-check-not={{DW_TAG|NULL}}"
+; RUN: %llc_dwarf -dwarf-version=5 -filetype=obj -O0 < %s -debugger-tune=gdb   -split-dwarf-file=baz.dwo | llvm-dwarfdump - \
+; RUN:   | FileCheck %s --check-prefix=NOCONV --check-prefix=SPLIT "--implicit-check-not={{DW_TAG|NULL}}"
+
+; Test the ability to override the platform default in either direction
+; RUN: %llc_dwarf -dwarf-version=5 -filetype=obj -O0 < %s -debugger-tune=gdb  -dwarf-op-convert=Disable | llvm-dwarfdump - \
+; RUN:   | FileCheck %s --check-prefix=NOCONV "--implicit-check-not={{DW_TAG|NULL}}"
+; RUN: %llc_dwarf -dwarf-version=5 -filetype=obj -O0 < %s -debugger-tune=lldb -dwarf-op-convert=Enable | llvm-dwarfdump - \
+; RUN:   | FileCheck %s --check-prefix=CONV "--implicit-check-not={{DW_TAG|NULL}}"
+
+; SPLIT: DW_TAG_skeleton_unit
+
+; CONV: DW_TAG_compile_unit
+; CONV:[[SIG8:.*]]:   DW_TAG_base_type
+; CONV-NEXT:DW_AT_name ("DW_ATE_signed_8")
+; CONV-NEXT:DW_AT_encoding (DW_ATE_signed)
+; CONV-NEXT:DW_AT_byte_size (0x01)
+; CONV-NOT: DW_AT
+; CONV:[[SIG32:.*]]:   DW_TAG_base_type
+; CONV-NEXT:DW_AT_name ("DW_ATE_signed_32")
+; CONV-NEXT:DW_AT_encoding (DW_ATE_signed)
+; CONV-NEXT:DW_AT_byte_size (0x04)
+; CONV-NOT: DW_AT
+; CONV:   DW_TAG_subprogram
+; CONV:     DW_TAG_formal_parameter
+; CONV:     DW_TAG_variable
+; CONV:       DW_AT_location (
+; CONV:         {{.*}}, DW_OP_convert ([[SIG8]]) "DW_ATE_signed_8", DW_OP_convert ([[SIG32]]) "DW_ATE_signed_32", DW_OP_stack_value)
+; CONV:       DW_AT_name ("y")
+; CONV:     NULL
+; CONV:   DW_TAG_base_type
+; CONV:     DW_AT_name ("signed char")
+; CONV:   DW_TAG_base_type
+; CONV:     DW_AT_name ("int")
+; CONV:   NULL
+
+; NOCONV: DW_TAG_compile_unit
+; NOCONV:   DW_TAG_subprogram
+; NOCONV:     DW_TAG_formal_parameter
+; NOCONV:     DW_TAG_variable
+; NOCONV:       DW_AT_location (
+; NOCONV:         {{.*}}, DW_OP_dup, DW_OP_constu 0x7, DW_OP_shr, DW_OP_lit0, DW_OP_not, DW_OP_mul, DW_OP_constu 0x8, DW_OP_shl, DW_OP_or, DW_OP_stack_value)
+; NOCONV:       DW_AT_name ("y")
+; NOCONV:     NULL
+; NOCONV:   DW_TAG_base_type
+; NOCONV:     DW_AT_name ("signed char")
+; NOCONV:   DW_TAG_base_type
+; NOCONV:     DW_AT_name ("int")
+; NOCONV:   NULL
 
 
 ; Function Attrs: noinline nounwind uwtable

diff  --git a/llvm/test/DebugInfo/X86/convert-loclist.ll b/llvm/test/DebugInfo/X86/convert-loclist.ll
index 2421ee1f5e03..06b91cada130 100644
--- a/llvm/test/DebugInfo/X86/convert-loclist.ll
+++ b/llvm/test/DebugInfo/X86/convert-loclist.ll
@@ -1,8 +1,8 @@
 ; RUN: %llc_dwarf -filetype=obj < %s \
 ; RUN:   | llvm-dwarfdump -debug-info -debug-loclists - | FileCheck %s
-; RUN: llc -mtriple x86_64-pc-linux -split-dwarf-file=foo.dwo -filetype=obj < %s \
+; RUN: llc -mtriple x86_64-pc-linux -split-dwarf-file=foo.dwo -filetype=obj -dwarf-op-convert=Enable < %s \
 ; RUN:   | llvm-dwarfdump -debug-info -debug-loclists - | FileCheck --check-prefix=SPLIT --check-prefix=CHECK %s
-; RUN: llc -mtriple x86_64-pc-linux -split-dwarf-file=foo.dwo -filetype=asm < %s \
+; RUN: llc -mtriple x86_64-pc-linux -split-dwarf-file=foo.dwo -filetype=asm -dwarf-op-convert=Enable < %s \
 ; RUN:   | FileCheck --check-prefix=ASM %s
 
 ; A bit of a brittle test - this is testing the specific DWO_id. The


        


More information about the llvm-commits mailing list