From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7824) id 46D35385802B; Fri, 7 Oct 2022 18:34:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 46D35385802B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665167676; bh=ICZH5w4TFMs+2o425oXY7bbQUmwcycrdM/RuE1a1U0E=; h=From:To:Subject:Date:From; b=PRV9edtU2uF+b6n//H3fcK2J0MmBUekJLscqa+JuTEo3ESsNerNSk0ofMr8wzNJmV fbPYdCGlDYwKYSFdClkrofXpXgWT5qiPaREeGyA/OjtdfoOCd/GTH+Z2CA1dT2RnMI RaPKVkyD+GDkAa7enRv8oNo5Hje/1qh97UEKRe0E= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: David Faust To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/dfaust/heads/btf-type-tag-new-rebase)] dwarf: create BTF decl and type tag DIEs X-Act-Checkin: gcc X-Git-Author: David Faust X-Git-Refname: refs/users/dfaust/heads/btf-type-tag-new-rebase X-Git-Oldrev: 4587fe84d9fed5eb7f0ea58784ec04f878ea5312 X-Git-Newrev: c71525e7f0d10fcc20892e8986d9a43c1c8f4d64 Message-Id: <20221007183436.46D35385802B@sourceware.org> Date: Fri, 7 Oct 2022 18:34:36 +0000 (GMT) List-Id: https://gcc.gnu.org/g:c71525e7f0d10fcc20892e8986d9a43c1c8f4d64 commit c71525e7f0d10fcc20892e8986d9a43c1c8f4d64 Author: David Faust Date: Wed Mar 2 15:03:34 2022 -0800 dwarf: create BTF decl and type tag DIEs The "btf_decl_tag" and "btf_type_tag" attributes are handled by constructing DW_TAG_LLVM_annotation DIEs. The DIEs are children of the declarations or types which they annotate, and convey the annotation via a string constant. Currently, all generation of these DIEs is gated behind btf_debuginfo_p (). That is, they will not be generated nor output unless BTF debug information is generated. The DIEs will be output in DWARF if both -gbtf and -gdwarf are supplied by the user. gcc/ * dwarf2out.cc (gen_btf_decl_tag_dies): New function. (gen_btf_type_tag_dies): Likewise. (modified_type_die): Call them here, if appropriate. (gen_formal_parameter_die): Likewise. (gen_typedef_die): Likewise. (gen_type_die): Likewise. (gen_decl_die): Likewise. Diff: --- gcc/dwarf2out.cc | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc index 9429e04cb06..daf9312f0a3 100644 --- a/gcc/dwarf2out.cc +++ b/gcc/dwarf2out.cc @@ -13612,6 +13612,78 @@ long_double_as_float128 (tree type) return NULL_TREE; } +/* BTF support. Given a tree T, which may be a decl or a type, process any + "btf_decl_tag" attributes on T, provided in ATTR. Construct + DW_TAG_GNU_annotation DIEs appropriately as children of TARGET, usually + the DIE for T. */ + +static void +gen_btf_decl_tag_dies (tree t, dw_die_ref target) +{ + dw_die_ref die; + tree attr; + + if (t == NULL_TREE || !target) + return; + + if (TYPE_P (t)) + attr = lookup_attribute ("btf_decl_tag", TYPE_ATTRIBUTES (t)); + else if (DECL_P (t)) + attr = lookup_attribute ("btf_decl_tag", DECL_ATTRIBUTES (t)); + else + /* This is an error. */ + gcc_unreachable (); + + while (attr != NULL_TREE) + { + die = new_die (DW_TAG_GNU_annotation, target, t); + add_name_attribute (die, IDENTIFIER_POINTER (get_attribute_name (attr))); + add_AT_string (die, DW_AT_const_value, + TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)))); + attr = TREE_CHAIN (attr); + } + + /* Strip the decl tag attribute to avoid creating multiple copies if we hit + this tree node again in some recursive call. */ + if (TYPE_P (t)) + TYPE_ATTRIBUTES (t) = + remove_attribute ("btf_decl_tag", TYPE_ATTRIBUTES (t)); + else if (DECL_P (t)) + DECL_ATTRIBUTES (t) = + remove_attribute ("btf_decl_tag", DECL_ATTRIBUTES (t)); +} + +/* BTF support. Given a tree TYPE, process any "btf_type_tag" attributes on + TYPE. Construct DW_TAG_GNU_annotation DIEs appropriately as children of + TARGET, usually the DIE for TYPE. */ + +static void +gen_btf_type_tag_dies (tree type, dw_die_ref target) +{ + dw_die_ref die; + tree attr; + + if (type == NULL_TREE || !target) + return; + + gcc_assert (TYPE_P (type)); + + attr = lookup_attribute ("btf_type_tag", TYPE_ATTRIBUTES (type)); + while (attr != NULL_TREE) + { + die = new_die (DW_TAG_GNU_annotation, target, type); + add_name_attribute (die, IDENTIFIER_POINTER (get_attribute_name (attr))); + add_AT_string (die, DW_AT_const_value, + TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)))); + attr = TREE_CHAIN (attr); + } + + /* Strip the type tag attribute to avoid creating multiple copies if we hit + this type again in some recursive call. */ + TYPE_ATTRIBUTES (type) = + remove_attribute ("btf_type_tag", TYPE_ATTRIBUTES (type)); +} + /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging entry that chains the modifiers specified by CV_QUALS in front of the given type. REVERSE is true if the type is to be interpreted in the @@ -14010,6 +14082,10 @@ modified_type_die (tree type, int cv_quals, bool reverse, if (TYPE_ARTIFICIAL (type)) add_AT_flag (mod_type_die, DW_AT_artificial, 1); + /* BTF support. Handle any "btf_type_tag" attributes on the type. */ + if (btf_debuginfo_p ()) + gen_btf_type_tag_dies (type, mod_type_die); + return mod_type_die; } @@ -23006,6 +23082,10 @@ gen_formal_parameter_die (tree node, tree origin, bool emit_name_p, gcc_unreachable (); } + /* BTF Support */ + if (btf_debuginfo_p ()) + gen_btf_decl_tag_dies (node, parm_die); + return parm_die; } @@ -26084,6 +26164,10 @@ gen_typedef_die (tree decl, dw_die_ref context_die) if (get_AT (type_die, DW_AT_name)) add_pubtype (decl, type_die); + + /* BTF: handle attribute btf_decl_tag which may appear on the typedef. */ + if (btf_debuginfo_p ()) + gen_btf_decl_tag_dies (decl, type_die); } /* Generate a DIE for a struct, class, enum or union type. */ @@ -26397,6 +26481,20 @@ gen_type_die (tree type, dw_die_ref context_die) if (die) check_die (die); } + + /* BTF support. Handle any "btf_type_tag" or "btf_decl_tag" attributes + on the type, constructing annotation DIEs as appropriate. */ + if (btf_debuginfo_p ()) + { + dw_die_ref die = lookup_type_die (type); + if (die) + { + gen_btf_type_tag_dies (type, die); + + /* decl tags may also be attached to a type. */ + gen_btf_decl_tag_dies (type, die); + } + } } } @@ -27153,6 +27251,10 @@ gen_decl_die (tree decl, tree origin, struct vlr_context *ctx, break; } + /* BTF: handle attribute btf_decl_tag. */ + if (btf_debuginfo_p ()) + gen_btf_decl_tag_dies (decl, lookup_decl_die (decl)); + return NULL; }