[llvm] [LLVM][DWARF] Add support for monolithic types in .debug_names (PR #70515)

Alexander Yermolovich via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 17 21:19:49 PST 2023


================
@@ -267,28 +277,66 @@ class DWARF5AccelTableData : public AccelTableData {
   }
   unsigned getDieTag() const { return DieTag; }
   unsigned getUnitID() const { return UnitID; }
+  bool isTU() const { return IsTU; }
   void normalizeDIEToOffset() {
     assert(std::holds_alternative<const DIE *>(OffsetVal) &&
            "Accessing offset after normalizing.");
     OffsetVal = std::get<const DIE *>(OffsetVal)->getOffset();
   }
+  bool isNormalized() const {
+    return std::holds_alternative<uint64_t>(OffsetVal);
+  }
 
 protected:
   std::variant<const DIE *, uint64_t> OffsetVal;
-  unsigned DieTag;
-  unsigned UnitID;
+  uint32_t DieTag : 16;
+  uint32_t UnitID : 15;
+  uint32_t IsTU : 1;
 
   uint64_t order() const override { return getDieOffset(); }
 };
 
+struct TypeUnitMetaInfo {
+  // Symbol for start of the TU section.
+  MCSymbol *Label;
+  // Unique ID of Type Unit.
+  unsigned UniqueID;
+};
+using TUVectorTy = SmallVector<TypeUnitMetaInfo, 1>;
 class DWARF5AccelTable : public AccelTable<DWARF5AccelTableData> {
+  // Symbols to start of all the TU sections that were generated.
+  TUVectorTy TUSymbols;
+
 public:
+  struct UnitIndexAndEncoding {
+    unsigned Index;
+    DWARF5AccelTableData::AttributeEncoding Endoding;
+  };
+  /// Returns type units that were constructed.
+  const TUVectorTy &getTypeUnitsSymbols() { return TUSymbols; }
+  /// Add a type unit start symbol.
+  void addTypeUnitSymbol(DwarfTypeUnit &U);
   /// Convert DIE entries to explicit offset.
   /// Needs to be called after DIE offsets are computed.
   void convertDieToOffset() {
     for (auto &Entry : Entries) {
       for (AccelTableData *Value : Entry.second.Values) {
-        static_cast<DWARF5AccelTableData *>(Value)->normalizeDIEToOffset();
+        DWARF5AccelTableData *Data = static_cast<DWARF5AccelTableData *>(Value);
+        // For TU we normalize as each Unit is emitted.
+        // So when this is invoked after CU construction we will be in mixed
+        // state.
+        if (!Data->isNormalized())
----------------
ayermolo wrote:

Ah IC. 
So when we normalize in CU it will be in mix state. The TU DIEs will be normalized because we do it as we write them out. The CU DIEs will not be. Without the check it will runtime assert in:

```
void normalizeDIEToOffset() {
    assert(std::holds_alternative<const DIE *>(OffsetVal) &&
           "Accessing offset after normalizing.");
    OffsetVal = std::get<const DIE *>(OffsetVal)->getOffset();
  }
```

https://github.com/llvm/llvm-project/pull/70515


More information about the llvm-commits mailing list