You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[DebugInfo][BPF] Add 'btf:type_tag' annotation in DWARF
This commit is a follow-up for BPF mailing list discussion at [1].
It changes the way `__attribute__((btf_type_tag("...")))`s are
represented in DWARF.
Prior to this commit type tags could only be attached to pointers.
Such attachments associated the tags with a pointee type.
E.g. for the following C code:
int __attribute__((btf_type_tag("tag1"))) *g;
Generated DWARF looked as follows:
0x0000001e: DW_TAG_variable
DW_AT_name ("g")
DW_AT_type (0x00000029 "int *")
0x00000029: DW_TAG_pointer_type
DW_AT_type (0x00000032 "int")
0x0000002e: DW_TAG_LLVM_annotation
DW_AT_name ("btf_type_tag")
DW_AT_const_value ("tag1")
0x00000032: DW_TAG_base_type
DW_AT_name ("int")
The goal of this commit is to allow attachment of type tags to the
tagged types instead. E.g. for the same example DWARF should look as
follows:
0x0000001e: DW_TAG_variable
DW_AT_name ("g")
DW_AT_type (0x00000029 "int *")
0x00000029: DW_TAG_pointer_type
DW_AT_type (0x00000032 "int")
0x00000032: DW_TAG_base_type
DW_AT_name ("int")
0x00000036: DW_TAG_LLVM_annotation
DW_AT_name ("btf:type_tag")
DW_AT_const_value ("tag1")
A new tag name, `btf:type_tag`, is used so that DWARF consumers
could distinguish between old and new attachment semantics.
This feature is mostly used by Linux Kernel in combination with tool
named pahole [2]. Reasonably recent versions of pahole generate
errors (1.23, 1.24) or warnings (1.25) when `DW_TAG_LLVM_annotation`
is attached to `DW_TAG_base_type` or `DW_TAG_unspecified_type`.
Hence the `btf:type_tag` generation is controlled by a hidden option
`-mllvm -btf-type-tag-v2`. The goal is to provide a way for tooling to
work on adding support `btf:type_tag` and eventually replace
`btf_type_tag` by `btf:type_tag`, removing the above option.
The commit includes the following changes:
- Changes in debug info generation:
- New method `DIBuilder::createAnnotationsPlaceholder()` is added,
it creates a temporary `DIDerivedType` that plays as annotations
placeholder while debug info metadata is being constructed;
- New overload for `CGDebugInfo::CreateType` method is added:
llvm::DIType *CGDebugInfo::CreateType(const BTFTagAttributedType *Ty,
llvm::DIFile *Unit);
This overload collects BTF type tags in `Ty`, creates annotations
placeholder pointing to the base type of `Ty`, registers the
placeholder in the `CGDebugInfo::AnnotationsPlaceholder` vector.
- `CGDebugInfo::finalize()` is updated to do the following for each
annotation placeholder:
- clone underlying base type;
- attach annotations the clone using `replaceAnnotations()` call;
- replace all placeholder usages by a clone.
Such scheme allows to deal with type cycles.
- Changes in AST construction:
- `ASTContext::getBTFTagAttributedType()` is updated to ensure that
`BTFTagAttributedType` always wraps `QualType` w/o local
constant/volatile/restricted qualifiers. This simplifies debug info
generation.
[1] https://lore.kernel.org/bpf/87r0w9jjoq.fsf@oracle.com/
[2] https://git.kernel.org/pub/scm/devel/pahole/pahole.git/
This was previously tracked as differential revision:
https://reviews.llvm.org/D143967
0 commit comments