Revert "[DWARF] Fix PR51087 Extraneous enum record in DWARF with type units"

Causes invalid debug_gnu_pubnames (& I think non-gnu pubnames too) -
visible as 0 values for the offset in gnu pubnames. More details on the
original review in D115325.

This reverts commit 78d15a112c.
This reverts commit 54586582d3.
This commit is contained in:
David Blaikie 2021-12-23 20:28:37 -08:00
parent f3d4e168db
commit b05df0287b
3 changed files with 18 additions and 49 deletions

View File

@ -1141,21 +1141,6 @@ sortGlobalExprs(SmallVectorImpl<DwarfCompileUnit::GlobalExpr> &GVEs) {
return GVEs;
}
/// Create a DIE for \p Ty if it doesn't already exist. If type units are
/// enabled, try to emit a type unit without a CU skeleton DIE.
static void createMaybeUnusedType(DwarfDebug &DD, DwarfCompileUnit &CU,
DIType &Ty) {
// Try to generate a type unit without creating a skeleton DIE in this CU.
if (DICompositeType const *CTy = dyn_cast<DICompositeType>(&Ty)) {
MDString const *TypeId = CTy->getRawIdentifier();
if (DD.generateTypeUnits() && TypeId && !Ty.isForwardDecl())
if (DD.getOrCreateDwarfTypeUnit(CU, TypeId->getString(), CTy))
return;
}
// We couldn't or shouldn't add a type unit so create the DIE normally.
CU.getOrCreateTypeDIE(&Ty);
}
// Emit all Dwarf sections that should come prior to the content. Create
// global DIEs and emit initial debug info sections. This is invoked by
// the target AsmPrinter.
@ -1239,17 +1224,15 @@ void DwarfDebug::beginModule(Module *M) {
CU.getOrCreateGlobalVariableDIE(GV, sortGlobalExprs(GVMap[GV]));
}
for (auto *Ty : CUNode->getEnumTypes()) {
// The enum types array by design contains pointers to
// MDNodes rather than DIRefs. Unique them here.
createMaybeUnusedType(*this, CU, *Ty);
}
for (auto *Ty : CUNode->getEnumTypes())
CU.getOrCreateTypeDIE(cast<DIType>(Ty));
for (auto *Ty : CUNode->getRetainedTypes()) {
// The retained types array by design contains pointers to
// MDNodes rather than DIRefs. Unique them here.
if (DIType *RT = dyn_cast<DIType>(Ty))
// There is no point in force-emitting a forward declaration.
createMaybeUnusedType(*this, CU, *RT);
CU.getOrCreateTypeDIE(RT);
}
// Emit imported_modules last so that the relevant context is already
// available.
@ -1420,7 +1403,6 @@ void DwarfDebug::finalizeModuleInfo() {
SkeletonHolder.computeSizeAndOffsets();
}
// Emit all Dwarf sections that should come after the content.
void DwarfDebug::endModule() {
// Terminate the pending line table.
@ -3384,30 +3366,17 @@ uint64_t DwarfDebug::makeTypeSignature(StringRef Identifier) {
void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU,
StringRef Identifier, DIE &RefDie,
const DICompositeType *CTy) {
bool TopLevelType = TypeUnitsUnderConstruction.empty();
if (auto Signature = getOrCreateDwarfTypeUnit(CU, Identifier, CTy)) {
CU.addDIETypeSignature(RefDie, *Signature);
} else if (TopLevelType) {
// Construct this type in the CU directly.
// This is inefficient because all the dependent types will be rebuilt
// from scratch, including building them in type units, discovering that
// they depend on addresses, throwing them out and rebuilding them.
CU.constructTypeDIE(RefDie, cast<DICompositeType>(CTy));
}
}
Optional<uint64_t>
DwarfDebug::getOrCreateDwarfTypeUnit(DwarfCompileUnit &CU, StringRef Identifier,
const DICompositeType *CTy) {
// Fast path if we're building some type units and one has already used the
// address pool we know we're going to throw away all this work anyway, so
// don't bother building dependent types.
if (!TypeUnitsUnderConstruction.empty() && AddrPool.hasBeenUsed())
return None;
return;
auto Ins = TypeSignatures.insert(std::make_pair(CTy, 0));
if (!Ins.second)
return Ins.first->second;
if (!Ins.second) {
CU.addDIETypeSignature(RefDie, Ins.first->second);
return;
}
bool TopLevelType = TypeUnitsUnderConstruction.empty();
AddrPool.resetUsedFlag();
@ -3461,7 +3430,13 @@ DwarfDebug::getOrCreateDwarfTypeUnit(DwarfCompileUnit &CU, StringRef Identifier,
// the type that used an address.
for (const auto &TU : TypeUnitsToAdd)
TypeSignatures.erase(TU.second);
return None;
// Construct this type in the CU directly.
// This is inefficient because all the dependent types will be rebuilt
// from scratch, including building them in type units, discovering that
// they depend on addresses, throwing them out and rebuilding them.
CU.constructTypeDIE(RefDie, cast<DICompositeType>(CTy));
return;
}
// If the type wasn't dependent on fission addresses, finish adding the type
@ -3471,7 +3446,7 @@ DwarfDebug::getOrCreateDwarfTypeUnit(DwarfCompileUnit &CU, StringRef Identifier,
InfoHolder.emitUnit(TU.first.get(), useSplitDwarf());
}
}
return Signature;
CU.addDIETypeSignature(RefDie, Signature);
}
DwarfDebug::NonTypeUnitContext::NonTypeUnitContext(DwarfDebug *DD)

View File

@ -667,12 +667,6 @@ public:
void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier,
DIE &Die, const DICompositeType *CTy);
/// Return the type unit signature of \p CTy after finding or creating its
/// type unit. Return None if a type unit cannot be created for \p CTy.
Optional<uint64_t> getOrCreateDwarfTypeUnit(DwarfCompileUnit &CU,
StringRef Identifier,
const DICompositeType *CTy);
class NonTypeUnitContext {
DwarfDebug *DD;
decltype(DwarfDebug::TypeUnitsUnderConstruction) TypeUnitsUnderConstruction;

View File

@ -1,4 +1,4 @@
; RUN: llc %s -mtriple=x86_64-linux-gnu -generate-type-units -o - -filetype=obj \
; RUN: %llc_dwarf %s -generate-type-units -o - -filetype=obj \
; RUN: | llvm-dwarfdump -o - - \
; RUN: | FileCheck %s