extra DW_TAG_typedef layer in DWARF
Open
@philberty is already working on this.
Since Sep 15, 2026.
bug
- Dominant language
- C++
- Stars
- 2.9k
- Forks
- 231
- Avg merge
- 19h 55m
- Merged PRs (30d)
- 67
Description
I tried this code:
pub struct Example {
value: i32
}
fn main() {
let x = Example {value: 97};
}
Then I examined the DWARF using readelf -wi.
I see this:
<1><5e>: Abbrev Number: 4 (DW_TAG_typedef)
<5f> DW_AT_name : (indirect string, offset: 0x85): str::Example
<63> DW_AT_decl_file : 1
<64> DW_AT_decl_line : 1
<65> DW_AT_decl_column : 5
<66> DW_AT_type : <0x6f>
However, I don't think having an extra DW_TAG_typedef here is very useful -- it just bloats the debuginfo without providing any extra useful information. Instead, I think the type itself ought to have a name.
Applying a hack to rust-gcc.cc:
diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc
index f674fc8efb27..aa7e813167c3 100644
--- a/gcc/rust/rust-gcc.cc
+++ b/gcc/rust/rust-gcc.cc
@@ -933,12 +933,12 @@ Gcc_backend::named_type (const std::string &name, tree type, Location location)
return type;
}
- tree copy = build_variant_type_copy (type);
+ // tree copy = build_variant_type_copy (type);
tree decl = build_decl (location.gcc_location (), TYPE_DECL,
- get_identifier_from_string (name), copy);
- DECL_ORIGINAL_TYPE (decl) = type;
- TYPE_NAME (copy) = decl;
- return copy;
+ get_identifier_from_string (name), type);
+ // DECL_ORIGINAL_TYPE (decl) = type;
+ TYPE_NAME (type) = decl;
+ return type;
}
// Return the size of a type.
... makes it better:
<1><5e>: Abbrev Number: 4 (DW_TAG_structure_type)
<5f> DW_AT_name : (indirect string, offset: 0x85): str::Example
<63> DW_AT_byte_size : 4
<64> DW_AT_sibling : <0x73>
...
Note that gdb's rust support currently only works with the latter. While this could be fixed in gdb, I think there's not really a strong reason to.
I'm using git gccrs, commit 2f9f77f9dd6330fe60554400133d7217f78afa43.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.