Skip to content

Commit

Permalink
ctf: add support to pass through BTF tags
Browse files Browse the repository at this point in the history
BTF generation currently relies on the internal CTF representation to
convert debug info from DWARF dies. This patch adds a new internal
header, "ctf-int.h", which defines CTF kinds to be used internally to
represent BTF tags which must pass through the CTF container. It also
adds a new type for representing information specific to those tags, and
a member for that type in struct ctf_dtdef.

This patch also updates ctf_add_reftype to accept a const char * name,
and add it for the newly added type.

gcc/

	* ctf-int.h: New file.
	* ctfc.h: Include ctf-int.h.
	(struct ctf_btf_annotation): New.
	(struct ctf_dtdef): Add dtu_btfnote member to dtd_u union.
	(enum ctf_dtu_d_union_enum): Add CTF_DTU_D_BTFNOTE.
	(ctf_add_reftype): Add name argument.
	* ctfc.cc (ctf_dtu_d_union_selector): Handle CTFC_INT_K_DECL_TAG.
	(ctf_add_reftype): Add name argument. Pass it to ctf_add_generic.
	(ctf_add_pointer): Update ctf_add_reftype call.
	* btfout.cc (btf_init_postprocess): Update ctf_add_reftype call.
	* dwarf2ctf.cc (gen_ctf_modifier_type): Update ctf_add_reftype call.
  • Loading branch information
dafaust authored and ouuleilei-bot committed Jul 11, 2023
1 parent a4cf736 commit 05f815d
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 9 deletions.
2 changes: 1 addition & 1 deletion gcc/btfout.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ btf_init_postprocess (void)

/* Create the 'const' modifier type for void. */
if (constvoid_id == CTF_NULL_TYPEID)
constvoid_id = ctf_add_reftype (tu_ctfc, CTF_ADD_ROOT,
constvoid_id = ctf_add_reftype (tu_ctfc, CTF_ADD_ROOT, NULL,
dvd->dvd_type, CTF_K_CONST, NULL);
dvd->dvd_type = constvoid_id;
}
Expand Down
28 changes: 28 additions & 0 deletions gcc/ctf-int.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* ctf-int.h - GCC internal definitions used for CTF debug info.
Copyright (C) 2023 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */

#ifndef GCC_CTF_INT_H
#define GCC_CTF_INT_H 1

/* This CTF kind exists only as a bridge to generating BTF types for
BTF_KIND_DECL_TAG. It does not correspond to any representable type
kind in CTF. */
#define CTFC_INT_K_DECL_TAG 63

#endif /* GCC_CTF_INT_H */
10 changes: 6 additions & 4 deletions gcc/ctfc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ ctf_dtu_d_union_selector (ctf_dtdef_ref ctftype)
return CTF_DTU_D_ARGUMENTS;
case CTF_K_SLICE:
return CTF_DTU_D_SLICE;
case CTFC_INT_K_DECL_TAG:
return CTF_DTU_D_BTFNOTE;
default:
/* The largest member as default. */
return CTF_DTU_D_ARRAY;
Expand Down Expand Up @@ -428,15 +430,15 @@ ctf_add_encoded (ctf_container_ref ctfc, uint32_t flag, const char * name,
}

ctf_id_t
ctf_add_reftype (ctf_container_ref ctfc, uint32_t flag, ctf_id_t ref,
uint32_t kind, dw_die_ref die)
ctf_add_reftype (ctf_container_ref ctfc, uint32_t flag, const char * name,
ctf_id_t ref, uint32_t kind, dw_die_ref die)
{
ctf_dtdef_ref dtd;
ctf_id_t type;

gcc_assert (ref <= CTF_MAX_TYPE);

type = ctf_add_generic (ctfc, flag, NULL, &dtd, die);
type = ctf_add_generic (ctfc, flag, name, &dtd, die);
dtd->dtd_data.ctti_info = CTF_TYPE_INFO (kind, flag, 0);
/* Caller of this API must guarantee that a CTF type with id = ref already
exists. This will also be validated for us at link-time. */
Expand Down Expand Up @@ -548,7 +550,7 @@ ctf_id_t
ctf_add_pointer (ctf_container_ref ctfc, uint32_t flag, ctf_id_t ref,
dw_die_ref die)
{
return (ctf_add_reftype (ctfc, flag, ref, CTF_K_POINTER, die));
return (ctf_add_reftype (ctfc, flag, NULL, ref, CTF_K_POINTER, die));
}

ctf_id_t
Expand Down
17 changes: 14 additions & 3 deletions gcc/ctfc.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ along with GCC; see the file COPYING3. If not see
#include "dwarf2ctf.h"
#include "ctf.h"
#include "btf.h"
#include "ctf-int.h"

/* Invalid CTF type ID definition. */

Expand Down Expand Up @@ -151,6 +152,13 @@ typedef struct GTY (()) ctf_func_arg

#define ctf_farg_list_next(elem) ((ctf_func_arg_t *)((elem)->farg_next))

/* BTF support: a BTF type tag or decl tag. */

typedef struct GTY (()) ctf_btf_annotation
{
uint32_t component_idx;
} ctf_btf_annotation_t;

/* Type definition for CTF generation. */

struct GTY ((for_user)) ctf_dtdef
Expand All @@ -175,6 +183,8 @@ struct GTY ((for_user)) ctf_dtdef
ctf_func_arg_t * GTY ((tag ("CTF_DTU_D_ARGUMENTS"))) dtu_argv;
/* slice. */
ctf_sliceinfo_t GTY ((tag ("CTF_DTU_D_SLICE"))) dtu_slice;
/* btf annotation. */
ctf_btf_annotation_t GTY ((tag ("CTF_DTU_D_BTFNOTE"))) dtu_btfnote;
} dtd_u;
};

Expand Down Expand Up @@ -214,7 +224,8 @@ enum ctf_dtu_d_union_enum {
CTF_DTU_D_ARRAY,
CTF_DTU_D_ENCODING,
CTF_DTU_D_ARGUMENTS,
CTF_DTU_D_SLICE
CTF_DTU_D_SLICE,
CTF_DTU_D_BTFNOTE
};

enum ctf_dtu_d_union_enum
Expand Down Expand Up @@ -404,8 +415,8 @@ extern bool ctf_dvd_ignore_lookup (const ctf_container_ref ctfc,
extern const char * ctf_add_string (ctf_container_ref, const char *,
uint32_t *, int);

extern ctf_id_t ctf_add_reftype (ctf_container_ref, uint32_t, ctf_id_t,
uint32_t, dw_die_ref);
extern ctf_id_t ctf_add_reftype (ctf_container_ref, uint32_t, const char *,
ctf_id_t, uint32_t, dw_die_ref);
extern ctf_id_t ctf_add_enum (ctf_container_ref, uint32_t, const char *,
HOST_WIDE_INT, bool, dw_die_ref);
extern ctf_id_t ctf_add_slice (ctf_container_ref, uint32_t, ctf_id_t,
Expand Down
2 changes: 1 addition & 1 deletion gcc/dwarf2ctf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ gen_ctf_modifier_type (ctf_container_ref ctfc, dw_die_ref modifier)
gcc_assert (kind != CTF_K_MAX);
/* Now register the modifier itself. */
if (!ctf_type_exists (ctfc, modifier, &modifier_type_id))
modifier_type_id = ctf_add_reftype (ctfc, CTF_ADD_ROOT,
modifier_type_id = ctf_add_reftype (ctfc, CTF_ADD_ROOT, NULL,
qual_type_id, kind,
modifier);

Expand Down

0 comments on commit 05f815d

Please sign in to comment.