[llvm] [BPF] Support wrapping BPF map structs into nested, single field structs (PR #144097)
Michal Rostecki via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 14 00:16:10 PDT 2025
================
@@ -976,11 +976,21 @@ void BTFDebug::visitMapDefType(const DIType *Ty, uint32_t &TypeId) {
if (Tag != dwarf::DW_TAG_structure_type || CTy->isForwardDecl())
return;
- // Visit all struct members to ensure pointee type is visited
+ // Visit all struct members to ensure their types are visited.
const DINodeArray Elements = CTy->getElements();
+ // In Aya/Rust, BPF maps are wrapped into nested types. Such wrapper types
+ // always have only one element. When encountering them, we need to visit its
+ // (only) element with an assumption that it might contain either an another
+ // wrapper, or an actual map struct.
+ const bool IsAWrapperType = Elements.size() == 1;
for (const auto *Element : Elements) {
const auto *MemberType = cast<DIDerivedType>(Element);
- visitTypeEntry(MemberType->getBaseType());
+ if (IsAWrapperType) {
----------------
vadorovsky wrote:
> but also I wonder if there's a more sensible way to do this.
Good point. Assuming that BPF map definitions should have only pointers and arrays, maybe we could assume that any `DICompositeType` element is a wrapper?
> What if we decide to have more than one element in the wrapper struct in the future?
Hard to imagine that happening, but the idea of recursively looking into `DICompositeType` elements should solve it.
https://github.com/llvm/llvm-project/pull/144097
More information about the llvm-commits
mailing list