-
Notifications
You must be signed in to change notification settings - Fork 12k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revert "[llvm/DWARF] Recursively resolve DW_AT_signature references" #99444
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-debuginfo Author: Pavel Labath (labath) ChangesReverts llvm/llvm-project#97423 due to a failure in the cross-project-tests. Full diff: https://github.com/llvm/llvm-project/pull/99444.diff 4 Files Affected:
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFDie.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFDie.h
index 497d3bee048ab..421b84d644db6 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFDie.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFDie.h
@@ -181,6 +181,8 @@ class DWARFDie {
DWARFDie getAttributeValueAsReferencedDie(dwarf::Attribute Attr) const;
DWARFDie getAttributeValueAsReferencedDie(const DWARFFormValue &V) const;
+ DWARFDie resolveTypeUnitReference() const;
+
/// Extract the range base attribute from this DIE as absolute section offset.
///
/// This is a utility function that checks for either the DW_AT_rnglists_base
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
index 345a91a6f3585..72e7464b68971 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
@@ -103,6 +103,10 @@ static void dumpLocationExpr(raw_ostream &OS, const DWARFFormValue &FormValue,
.print(OS, DumpOpts, U);
}
+static DWARFDie resolveReferencedType(DWARFDie D, DWARFFormValue F) {
+ return D.getAttributeValueAsReferencedDie(F).resolveTypeUnitReference();
+}
+
static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
const DWARFAttribute &AttrValue, unsigned Indent,
DIDumpOptions DumpOpts) {
@@ -194,8 +198,8 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
DINameKind::LinkageName))
OS << Space << "\"" << Name << '\"';
} else if (Attr == DW_AT_type || Attr == DW_AT_containing_type) {
- if (DWARFDie D = Die.getAttributeValueAsReferencedDie(FormValue);
- D && !D.isNULL()) {
+ DWARFDie D = resolveReferencedType(Die, FormValue);
+ if (D && !D.isNULL()) {
OS << Space << "\"";
dumpTypeQualifiedName(D, OS);
OS << '"';
@@ -287,12 +291,13 @@ DWARFDie::findRecursively(ArrayRef<dwarf::Attribute> Attrs) const {
if (auto Value = Die.find(Attrs))
return Value;
- for (dwarf::Attribute Attr :
- {DW_AT_abstract_origin, DW_AT_specification, DW_AT_signature}) {
- if (auto D = Die.getAttributeValueAsReferencedDie(Attr))
- if (Seen.insert(D).second)
- Worklist.push_back(D);
- }
+ if (auto D = Die.getAttributeValueAsReferencedDie(DW_AT_abstract_origin))
+ if (Seen.insert(D).second)
+ Worklist.push_back(D);
+
+ if (auto D = Die.getAttributeValueAsReferencedDie(DW_AT_specification))
+ if (Seen.insert(D).second)
+ Worklist.push_back(D);
}
return std::nullopt;
@@ -314,14 +319,21 @@ DWARFDie::getAttributeValueAsReferencedDie(const DWARFFormValue &V) const {
} else if (Offset = V.getAsDebugInfoReference(); Offset) {
if (DWARFUnit *SpecUnit = U->getUnitVector().getUnitForOffset(*Offset))
Result = SpecUnit->getDIEForOffset(*Offset);
- } else if (std::optional<uint64_t> Sig = V.getAsSignatureReference()) {
- if (DWARFTypeUnit *TU = U->getContext().getTypeUnitForHash(
- U->getVersion(), *Sig, U->isDWOUnit()))
- Result = TU->getDIEForOffset(TU->getTypeOffset() + TU->getOffset());
}
return Result;
}
+DWARFDie DWARFDie::resolveTypeUnitReference() const {
+ if (auto Attr = find(DW_AT_signature)) {
+ if (std::optional<uint64_t> Sig = Attr->getAsReferenceUVal()) {
+ if (DWARFTypeUnit *TU = U->getContext().getTypeUnitForHash(
+ U->getVersion(), *Sig, U->isDWOUnit()))
+ return TU->getDIEForOffset(TU->getTypeOffset() + TU->getOffset());
+ }
+ }
+ return *this;
+}
+
std::optional<uint64_t> DWARFDie::getRangesBaseAttribute() const {
return toSectionOffset(find({DW_AT_rnglists_base, DW_AT_GNU_ranges_base}));
}
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp b/llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp
index fc1aae77a9293..a26431e8313f6 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp
@@ -62,10 +62,17 @@ void DWARFTypePrinter::appendArrayType(const DWARFDie &D) {
EndedWithTemplate = false;
}
+static DWARFDie resolveReferencedType(DWARFDie D,
+ dwarf::Attribute Attr = DW_AT_type) {
+ return D.getAttributeValueAsReferencedDie(Attr).resolveTypeUnitReference();
+}
+static DWARFDie resolveReferencedType(DWARFDie D, DWARFFormValue F) {
+ return D.getAttributeValueAsReferencedDie(F).resolveTypeUnitReference();
+}
DWARFDie DWARFTypePrinter::skipQualifiers(DWARFDie D) {
while (D && (D.getTag() == DW_TAG_const_type ||
D.getTag() == DW_TAG_volatile_type))
- D = D.getAttributeValueAsReferencedDie(DW_AT_type);
+ D = resolveReferencedType(D);
return D;
}
@@ -96,9 +103,7 @@ DWARFTypePrinter::appendUnqualifiedNameBefore(DWARFDie D,
return DWARFDie();
}
DWARFDie InnerDIE;
- auto Inner = [&] {
- return InnerDIE = D.getAttributeValueAsReferencedDie(DW_AT_type);
- };
+ auto Inner = [&] { return InnerDIE = resolveReferencedType(D); };
const dwarf::Tag T = D.getTag();
switch (T) {
case DW_TAG_pointer_type: {
@@ -129,8 +134,7 @@ DWARFTypePrinter::appendUnqualifiedNameBefore(DWARFDie D,
OS << '(';
else if (Word)
OS << ' ';
- if (DWARFDie Cont =
- D.getAttributeValueAsReferencedDie(DW_AT_containing_type)) {
+ if (DWARFDie Cont = resolveReferencedType(D, DW_AT_containing_type)) {
appendQualifiedName(Cont);
EndedWithTemplate = false;
OS << "::";
@@ -169,8 +173,7 @@ DWARFTypePrinter::appendUnqualifiedNameBefore(DWARFDie D,
case DW_TAG_base_type:
*/
default: {
- const char *NamePtr =
- dwarf::toString(D.findRecursively(DW_AT_name), nullptr);
+ const char *NamePtr = dwarf::toString(D.find(DW_AT_name), nullptr);
if (!NamePtr) {
appendTypeTagName(D.getTag());
return DWARFDie();
@@ -232,9 +235,9 @@ void DWARFTypePrinter::appendUnqualifiedNameAfter(
case DW_TAG_pointer_type: {
if (needsParens(Inner))
OS << ')';
- appendUnqualifiedNameAfter(
- Inner, Inner.getAttributeValueAsReferencedDie(DW_AT_type),
- /*SkipFirstParamIfArtificial=*/D.getTag() == DW_TAG_ptr_to_member_type);
+ appendUnqualifiedNameAfter(Inner, resolveReferencedType(Inner),
+ /*SkipFirstParamIfArtificial=*/D.getTag() ==
+ DW_TAG_ptr_to_member_type);
break;
}
case DW_TAG_LLVM_ptrauth_type: {
@@ -338,7 +341,7 @@ bool DWARFTypePrinter::appendTemplateParameters(DWARFDie D,
appendTemplateParameters(C, FirstParameter);
}
if (C.getTag() == dwarf::DW_TAG_template_value_parameter) {
- DWARFDie T = C.getAttributeValueAsReferencedDie(DW_AT_type);
+ DWARFDie T = resolveReferencedType(C);
Sep();
if (T.getTag() == DW_TAG_enumeration_type) {
OS << '(';
@@ -458,7 +461,7 @@ bool DWARFTypePrinter::appendTemplateParameters(DWARFDie D,
continue;
auto TypeAttr = C.find(DW_AT_type);
Sep();
- appendQualifiedName(TypeAttr ? C.getAttributeValueAsReferencedDie(*TypeAttr)
+ appendQualifiedName(TypeAttr ? resolveReferencedType(C, *TypeAttr)
: DWARFDie());
}
if (IsTemplate && *FirstParameter && FirstParameter == &FirstParameterValue) {
@@ -470,15 +473,15 @@ bool DWARFTypePrinter::appendTemplateParameters(DWARFDie D,
void DWARFTypePrinter::decomposeConstVolatile(DWARFDie &N, DWARFDie &T,
DWARFDie &C, DWARFDie &V) {
(N.getTag() == DW_TAG_const_type ? C : V) = N;
- T = N.getAttributeValueAsReferencedDie(DW_AT_type);
+ T = resolveReferencedType(N);
if (T) {
auto Tag = T.getTag();
if (Tag == DW_TAG_const_type) {
C = T;
- T = T.getAttributeValueAsReferencedDie(DW_AT_type);
+ T = resolveReferencedType(T);
} else if (Tag == DW_TAG_volatile_type) {
V = T;
- T = T.getAttributeValueAsReferencedDie(DW_AT_type);
+ T = resolveReferencedType(T);
}
}
}
@@ -488,11 +491,10 @@ void DWARFTypePrinter::appendConstVolatileQualifierAfter(DWARFDie N) {
DWARFDie T;
decomposeConstVolatile(N, T, C, V);
if (T && T.getTag() == DW_TAG_subroutine_type)
- appendSubroutineNameAfter(T, T.getAttributeValueAsReferencedDie(DW_AT_type),
- false, C.isValid(), V.isValid());
+ appendSubroutineNameAfter(T, resolveReferencedType(T), false, C.isValid(),
+ V.isValid());
else
- appendUnqualifiedNameAfter(T,
- T.getAttributeValueAsReferencedDie(DW_AT_type));
+ appendUnqualifiedNameAfter(T, resolveReferencedType(T));
}
void DWARFTypePrinter::appendConstVolatileQualifierBefore(DWARFDie N) {
DWARFDie C;
@@ -502,7 +504,7 @@ void DWARFTypePrinter::appendConstVolatileQualifierBefore(DWARFDie N) {
bool Subroutine = T && T.getTag() == DW_TAG_subroutine_type;
DWARFDie A = T;
while (A && A.getTag() == DW_TAG_array_type)
- A = A.getAttributeValueAsReferencedDie(DW_AT_type);
+ A = resolveReferencedType(A);
bool Leading =
(!A || (A.getTag() != DW_TAG_pointer_type &&
A.getTag() != llvm::dwarf::DW_TAG_ptr_to_member_type)) &&
@@ -544,7 +546,7 @@ void DWARFTypePrinter::appendSubroutineNameAfter(
if (P.getTag() != DW_TAG_formal_parameter &&
P.getTag() != DW_TAG_unspecified_parameters)
return;
- DWARFDie T = P.getAttributeValueAsReferencedDie(DW_AT_type);
+ DWARFDie T = resolveReferencedType(P);
if (SkipFirstParamIfArtificial && RealFirst && P.find(DW_AT_artificial)) {
FirstParamIfArtificial = T;
RealFirst = false;
@@ -565,7 +567,7 @@ void DWARFTypePrinter::appendSubroutineNameAfter(
if (DWARFDie P = FirstParamIfArtificial) {
if (P.getTag() == DW_TAG_pointer_type) {
auto CVStep = [&](DWARFDie CV) {
- if (DWARFDie U = CV.getAttributeValueAsReferencedDie(DW_AT_type)) {
+ if (DWARFDie U = resolveReferencedType(CV)) {
Const |= U.getTag() == DW_TAG_const_type;
Volatile |= U.getTag() == DW_TAG_volatile_type;
return U;
@@ -651,8 +653,7 @@ void DWARFTypePrinter::appendSubroutineNameAfter(
if (D.find(DW_AT_rvalue_reference))
OS << " &&";
- appendUnqualifiedNameAfter(
- Inner, Inner.getAttributeValueAsReferencedDie(DW_AT_type));
+ appendUnqualifiedNameAfter(Inner, resolveReferencedType(Inner));
}
void DWARFTypePrinter::appendScopes(DWARFDie D) {
if (D.getTag() == DW_TAG_compile_unit)
@@ -665,6 +666,7 @@ void DWARFTypePrinter::appendScopes(DWARFDie D) {
return;
if (D.getTag() == DW_TAG_lexical_block)
return;
+ D = D.resolveTypeUnitReference();
if (DWARFDie P = D.getParent())
appendScopes(P);
appendUnqualifiedName(D);
diff --git a/llvm/test/tools/llvm-dwarfdump/X86/prettyprint_type_units.s b/llvm/test/tools/llvm-dwarfdump/X86/prettyprint_type_units.s
index 5611963a585f6..aad748a301e6b 100644
--- a/llvm/test/tools/llvm-dwarfdump/X86/prettyprint_type_units.s
+++ b/llvm/test/tools/llvm-dwarfdump/X86/prettyprint_type_units.s
@@ -18,15 +18,12 @@
# doesn't really need templates - two local variables would've sufficed
# (anything that references the type units) but I was working on something else
# and this seemed minimal enough.
-# A gcc-style type signature reference was also inserted.
# CHECK: DW_TAG_template_type_parameter
# CHECK: DW_AT_type ({{.*}} "t1")
# CHECK: DW_TAG_template_type_parameter
# CHECK: DW_AT_type ({{.*}} "t2")
-# CHECK: DW_TAG_template_type_parameter
-# CHECK: DW_AT_type (0xc6694e51369161f2 "t1")
.text
.file "test.cpp"
@@ -273,13 +270,6 @@ _Z2f1IJ2t12t2EEvv: # @_Z2f1IJ2t12t2EEvv
.byte 11 # DW_FORM_data1
.byte 0 # EOM(1)
.byte 0 # EOM(2)
- .byte 12 # Abbreviation Code
- .byte 47 # DW_TAG_template_type_parameter
- .byte 0 # DW_CHILDREN_no
- .byte 73 # DW_AT_type
- .byte 32 # DW_FORM_ref_sig8
- .byte 0 # EOM(1)
- .byte 0 # EOM(2)
.byte 0 # EOM(3)
.section .debug_info,"",@progbits
.Lcu_begin0:
@@ -323,23 +313,18 @@ _Z2f1IJ2t12t2EEvv: # @_Z2f1IJ2t12t2EEvv
.byte 6 # Abbrev [6] 0x46:0xd DW_TAG_GNU_template_parameter_pack
.byte 5 # DW_AT_name
.byte 7 # Abbrev [7] 0x48:0x5 DW_TAG_template_type_parameter
- .long .Lt1_decl-.Lcu_begin0 # DW_AT_type
+ .long 88 # DW_AT_type
.byte 7 # Abbrev [7] 0x4d:0x5 DW_TAG_template_type_parameter
- # Simulate DWARF emitted by GCC where the signature is directly in the type attribute.
- .long .Lt2_decl-.Lcu_begin0 # DW_AT_type
- .byte 12 # Abbrev [12] DW_TAG_template_type_parameter
- .quad -4149699470930386446 # DW_AT_type
+ .long 97 # DW_AT_type
.byte 0 # End Of Children Mark
.byte 0 # End Of Children Mark
.byte 8 # Abbrev [8] 0x54:0x4 DW_TAG_base_type
.byte 4 # DW_AT_name
.byte 5 # DW_AT_encoding
.byte 4 # DW_AT_byte_size
- .Lt1_decl:
.byte 9 # Abbrev [9] 0x58:0x9 DW_TAG_structure_type
# DW_AT_declaration
.quad -4149699470930386446 # DW_AT_signature
- .Lt2_decl:
.byte 9 # Abbrev [9] 0x61:0x9 DW_TAG_structure_type
# DW_AT_declaration
.quad 5649318945901130368 # DW_AT_signature
|
labath
added a commit
to labath/llvm-project
that referenced
this pull request
Jul 18, 2024
…llvm#99444) The previous version introduced a bug (caught by cross-project tests). Explicit signature resolution is still necessary when one wants to access the children (not attributes) of a given DIE. In the new version of the patch, I keep the `resolveTypeUnitReference` function, and call it in the function doing child iteration. I've also extended the prettyprint_type_units test case to cover this scenario (and also reduced it to remove irrelevant details).
Harini0924
pushed a commit
to Harini0924/llvm-project
that referenced
this pull request
Jul 22, 2024
…lvm#99444) Reverts llvm#97423 due to a failure in the cross-project-tests.
sgundapa
pushed a commit
to sgundapa/upstream_effort
that referenced
this pull request
Jul 23, 2024
…lvm#99444) Reverts llvm#97423 due to a failure in the cross-project-tests.
yuxuanchen1997
pushed a commit
that referenced
this pull request
Jul 25, 2024
…99444) Summary: Reverts #97423 due to a failure in the cross-project-tests. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60250990
labath
added a commit
to labath/llvm-project
that referenced
this pull request
Sep 2, 2024
…llvm#99444) The previous version introduced a bug (caught by cross-project tests). Explicit signature resolution is still necessary when one wants to access the children (not attributes) of a given DIE. The new version keeps just the findRecursively extension, and reverts all the DWARFTypePrinter modifications.
labath
added a commit
that referenced
this pull request
Sep 4, 2024
#99495) … (#99444) The previous version introduced a bug (caught by cross-project tests). Explicit signature resolution is still necessary when one wants to access the children (not attributes) of a given DIE. The new version keeps just the findRecursively extension, and reverts all the DWARFTypePrinter modifications.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reverts #97423 due to a failure in the cross-project-tests.