Skip to content

Commit 8b5d751

Browse files
committed
doc: document btf_type_tag and btf_decl_tag attributes
gcc/ * doc/extend.texi (Common Function Attributes) (Common Variable Attributes): Document btf_decl_tag attribute. (Common Type Attributes): Document btf_type_tag attribute.
1 parent 43dcea4 commit 8b5d751

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

gcc/doc/extend.texi

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,6 +1976,13 @@ declares that @code{my_alloc1} returns 16-byte aligned pointers and
19761976
that @code{my_alloc2} returns a pointer whose value modulo 32 is equal
19771977
to 8.
19781978

1979+
@cindex @code{btf_decl_tag} function attribute
1980+
@item btf_decl_tag
1981+
The @code{btf_decl_tag} attribute may be used to associate function
1982+
declarations with arbitrary strings by recording those strings in DWARF
1983+
and/or BTF information in the same way that it is used for variables.
1984+
See @ref{Common Variable Attributes}.
1985+
19791986
@cindex @code{cold} function attribute
19801987
@item cold
19811988
The @code{cold} attribute on functions is used to inform the compiler that
@@ -7172,6 +7179,41 @@ is given by the product of arguments 1 and 2, and similarly, that
71727179
@code{malloc_ptr}, like the standard C function @code{malloc},
71737180
returns an object whose size is given by argument 1 to the function.
71747181

7182+
@cindex @code{btf_decl_tag} variable attribute
7183+
@item btf_decl_tag (@var{argument})
7184+
The @code{btf_decl_tag} attribute may be used to associate variable
7185+
declarations, struct or union member declarations, function
7186+
declarations, and function parameter declarations with arbitrary strings.
7187+
These strings are not interpreted by the compiler in any way, and have
7188+
no effect on code generation. Instead, these user-provided strings
7189+
are recorded in DWARF (via @code{DW_AT_GNU_annotation} and
7190+
@code{DW_TAG_GNU_annotation} extensions) and BTF information (via
7191+
@code{BTF_KIND_DECL_TAG} records), and associated to the attributed
7192+
declaration. If neither DWARF nor BTF information is generated, the
7193+
attribute has no effect.
7194+
7195+
The argument is treated as a null-terminated sequence of zero or more
7196+
non-null bytes. Wide character strings are not supported.
7197+
7198+
The attribute may be supplied multiple times for a single declaration,
7199+
in which case each distinct argument string will be recorded in a
7200+
separate DIE or BTF record, each associated to the declaration. For
7201+
a single declaration with multiple @code{btf_decl_tag} attributes,
7202+
the order of the @code{DW_TAG_GNU_annotation} DIEs produced is not
7203+
guaranteed to maintain the order of attributes in the source code.
7204+
7205+
For example:
7206+
7207+
@smallexample
7208+
int *foo __attribute__ ((btf_decl_tag ("__percpu")));
7209+
@end smallexample
7210+
7211+
@noindent
7212+
when compiled with @option{-gbtf} results in an additional
7213+
@code{BTF_KIND_DECL_TAG} BTF record to be emitted in the BTF info,
7214+
associating the string @samp{__percpu} with the @code{BTF_KIND_VAR}
7215+
record for the variable @code{foo}.
7216+
71757217
@cindex @code{cleanup} variable attribute
71767218
@item cleanup (@var{cleanup_function})
71777219
The @code{cleanup} attribute runs a function when the variable goes
@@ -8361,6 +8403,43 @@ is given by the product of arguments 1 and 2, and that
83618403
@code{malloc_type}, like the standard C function @code{malloc},
83628404
returns an object whose size is given by argument 1 to the function.
83638405

8406+
@cindex @code{btf_type_tag} type attribute
8407+
@item btf_type_tag (@var{argument})
8408+
The @code{btf_type_tag} attribute may be used to associate (to ``tag'')
8409+
particular types with arbitrary string annotations. These annotations
8410+
are recorded in debugging info by supported debug formats, currently
8411+
DWARF (via @code{DW_AT_GNU_annotation} and @code{DW_TAG_GNU_annotation}
8412+
extensions) and BTF (via @code{BTF_KIND_TYPE_TAG} records). These
8413+
annotation strings are not interpreted by the compiler in any way, and
8414+
have no effect on code generation. If neither DWARF nor BTF
8415+
information is generated, the attribute has no effect.
8416+
8417+
The argument is treated as a null-terminated sequence of zero or more
8418+
non-null bytes. Wide character strings are not supported.
8419+
8420+
The attribute may be supplied multiple times for a single type, in
8421+
which case each distinct argument string will be recorded in a
8422+
separate DIE or BTF record, each associated to the type. For a single
8423+
type with multiple @code{btf_type_tag} attributes, the order of the
8424+
@code{DW_TAG_GNU_annotation} DIEs produced is not guaranteed to
8425+
maintain the order of attributes in the source code.
8426+
8427+
For example the following code:
8428+
8429+
@smallexample
8430+
int * __attribute__ ((btf_type_tag ("__user"))) foo;
8431+
@end smallexample
8432+
8433+
@noindent
8434+
when compiled with @option{-gbtf} results in an additional
8435+
@code{BTF_KIND_TYPE_TAG} BTF record to be emitted in the BTF info,
8436+
associating the string @samp{__user} with the normal @code{BTF_KIND_PTR}
8437+
record for the pointer-to-integer type used in the declaration.
8438+
8439+
Note that the BTF format currently only has a representation for type
8440+
tags associated with pointer types. Type tags on non-pointer types
8441+
may be silently skipped when generating BTF.
8442+
83648443
@cindex @code{copy} type attribute
83658444
@item copy
83668445
@itemx copy (@var{expression})

0 commit comments

Comments
 (0)