From: "Guillermo E. Martinez" <guillermo.e.martinez@oracle.com>
To: Indu Bhagat <indu.bhagat@oracle.com>, gcc-patches@gcc.gnu.org
Cc: david.faust@oracle.com
Subject: Re: [PATCH v3] btf: Add support to BTF_KIND_ENUM64 type
Date: Tue, 18 Oct 2022 16:48:51 -0500 [thread overview]
Message-ID: <4e8dc5be-5516-e4f6-7893-a594948e16d5@oracle.com> (raw)
In-Reply-To: <89f6eab1-aaf7-2f54-f3e5-c3618603cfc2@oracle.com>
On 10/18/22 16:40, Indu Bhagat wrote:
> Hi Guillermo,
>
Hi Indu,
> On 10/14/22 8:55 PM, Guillermo E. Martinez wrote:
>> Hello,
>>
>> The following is patch v3 to update BTF/CTF backend supporting
>> BTF_KIND_ENUM64 type. Changes from v2:
>>
>> + Add a new `dtd_enum_unsigned' field in `ctf_dtdef' to indicate
>> signedness of the enum type.
>> + Fix endianness for representing BTF enum 64-bits enumerators.
>> + Add {little,big}-endian testcases.
>>
>> Comments will be welcomed and appreciated!,
>>
>> Kind regards,
>> guillermo
>>
>> --
>>
>> BTF supports 64-bits enumerators with following encoding:
>>
>> struct btf_type:
>> name_off: 0 or offset to a valid C identifier
>> info.kind_flag: 0 for unsigned, 1 for signed
>> info.kind: BTF_KIND_ENUM64
>> info.vlen: number of enum values
>> size: 1/2/4/8
>>
>> The btf_type is followed by info.vlen number of:
>>
>> struct btf_enum64
>> {
>> uint32_t name_off; /* Offset in string section of enumerator name. */
>> uint32_t val_lo32; /* lower 32-bit value for a 64-bit value Enumerator */
>> uint32_t val_hi32; /* high 32-bit value for a 64-bit value Enumerator */
>> };
>>
>> So, a new btf_enum64 structure was added to represent BTF_KIND_ENUM64
>> and a new field dtd_enum_unsigned in ctf_dtdef structure to distinguish
>> when CTF enum is a signed or unsigned type, later that information is
>> used to encode the BTF enum type.
>>
>> gcc/ChangeLog:
>>
>> * btfout.cc (btf_calc_num_vbytes): Compute enumeration size depending of
>> enumerator type btf_enum{,64}.
>> (btf_asm_type): Update btf_kflag according to enumeration type sign
>> using dtd_enum_unsigned field for both: BTF_KIND_ENUM{,64}.
>> (btf_asm_enum_const): New argument to represent the size of
>> the BTF enum type, writing the enumerator constant value for
>> 32 bits, if it's 64 bits then explicitly writes lower 32-bits
>> value and higher 32-bits value.
>> (output_asm_btf_enum_list): Add enumeration size argument.
>> * ctfc.cc (ctf_add_enum): New argument to represent CTF enum
>> basic information.
>> (ctf_add_generic): Use of ei_{name. size, unsigned} to build the
>> dtd structure containing enumeration information.
>> (ctf_add_enumerator): Update comment mention support for BTF
>> enumeration in 64-bits.
>> * ctfc.h (ctf_dmdef): Update dmd_value to HOST_WIDE_INT to allow
>> use 32/64 bits enumerators.
>> (ctf_enum_binfo): New type to represent CTF basic enum type
>> information.
>> (ctf_dtdef): New field to describe enum signedness.
>> * dwarf2ctf.cc (gen_ctf_enumeration_type): Use of ctf_enum_binfo
>> type to pass information to ctf_add_enum to build the enum type.
>>
>> include/
>> * btf.h (btf_enum64): Add new definition and new symbolic
>> constant to BTF_KIND_ENUM64 and BTF_KF_ENUM_{UN,}SIGNED.
>>
>> gcc/testsuite/ChangeLog:
>>
>> * gcc.dg/debug/btf/btf-enum-1.c: Update testcase, with correct
>> info.kflags encoding.
>> * gcc.dg/debug/btf/btf-enum64-be-1.c: New testcase.
>> * gcc.dg/debug/btf/btf-enum64-le-1.c: New testcase.
>> ---
>> gcc/btfout.cc | 30 ++++++++++---
>> gcc/ctfc.cc | 22 +++++-----
>> gcc/ctfc.h | 15 +++++--
>> gcc/dwarf2ctf.cc | 8 +++-
>> gcc/testsuite/gcc.dg/debug/btf/btf-enum-1.c | 2 +-
>> .../gcc.dg/debug/btf/btf-enum64-be-1.c | 44 +++++++++++++++++++
>> .../gcc.dg/debug/btf/btf-enum64-le-1.c | 44 +++++++++++++++++++
>> include/btf.h | 19 ++++++--
>> 8 files changed, 160 insertions(+), 24 deletions(-)
>> create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-enum64-be-1.c
>> create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-enum64-le-1.c
>>
>> diff --git a/gcc/btfout.cc b/gcc/btfout.cc
>> index 997a33fa089..aef9fd70a28 100644
>> --- a/gcc/btfout.cc
>> +++ b/gcc/btfout.cc
>> @@ -223,7 +223,9 @@ btf_calc_num_vbytes (ctf_dtdef_ref dtd)
>> break;
>> case BTF_KIND_ENUM:
>> - vlen_bytes += vlen * sizeof (struct btf_enum);
>> + vlen_bytes += (dtd->dtd_data.ctti_size == 0x8)
>> + ? vlen * sizeof (struct btf_enum64)
>> + : vlen * sizeof (struct btf_enum);
>> break;
>> case BTF_KIND_FUNC_PROTO:
>> @@ -622,6 +624,15 @@ btf_asm_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd)
>> btf_size_type = 0;
>> }
>> + if (btf_kind == BTF_KIND_ENUM)
>> + {
>> + btf_kflag = dtd->dtd_enum_unsigned
>> + ? BTF_KF_ENUM_UNSIGNED
>> + : BTF_KF_ENUM_SIGNED;
>> + if (dtd->dtd_data.ctti_size == 0x8)
>> + btf_kind = BTF_KIND_ENUM64;
>> + }
>> +
>> dw2_asm_output_data (4, dtd->dtd_data.ctti_name, "btt_name");
>> dw2_asm_output_data (4, BTF_TYPE_INFO (btf_kind, btf_kflag, btf_vlen),
>> "btt_info: kind=%u, kflag=%u, vlen=%u",
>> @@ -634,6 +645,7 @@ btf_asm_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd)
>> case BTF_KIND_UNION:
>> case BTF_KIND_ENUM:
>> case BTF_KIND_DATASEC:
>> + case BTF_KIND_ENUM64:
>> dw2_asm_output_data (4, dtd->dtd_data.ctti_size, "btt_size: %uB",
>> dtd->dtd_data.ctti_size);
>> return;
>> @@ -707,13 +719,19 @@ btf_asm_sou_member (ctf_container_ref ctfc, ctf_dmdef_t * dmd)
>> }
>> }
>> -/* Asm'out an enum constant following a BTF_KIND_ENUM. */
>> +/* Asm'out an enum constant following a BTF_KIND_ENUM{,64}. */
>> static void
>> -btf_asm_enum_const (ctf_dmdef_t * dmd)
>> +btf_asm_enum_const (unsigned int size, ctf_dmdef_t * dmd)
>> {
>> dw2_asm_output_data (4, dmd->dmd_name_offset, "bte_name");
>> - dw2_asm_output_data (4, dmd->dmd_value, "bte_value");
>> + if (size == 4)
>> + dw2_asm_output_data (size, dmd->dmd_value, "bte_value");
>> + else
>> + {
>> + dw2_asm_output_data (4, dmd->dmd_value & 0xffffffff, "bte_value_lo32");
>> + dw2_asm_output_data (4, (dmd->dmd_value >> 32) & 0xffffffff, "bte_value_hi32");
>> + }
>> }
>> /* Asm'out a function parameter description following a BTF_KIND_FUNC_PROTO. */
>> @@ -871,7 +889,7 @@ output_asm_btf_sou_fields (ctf_container_ref ctfc, ctf_dtdef_ref dtd)
>> btf_asm_sou_member (ctfc, dmd);
>> }
>> -/* Output all enumerator constants following a BTF_KIND_ENUM. */
>> +/* Output all enumerator constants following a BTF_KIND_ENUM{,64}. */
>> static void
>> output_asm_btf_enum_list (ctf_container_ref ARG_UNUSED (ctfc),
>> @@ -881,7 +899,7 @@ output_asm_btf_enum_list (ctf_container_ref ARG_UNUSED (ctfc),
>> for (dmd = dtd->dtd_u.dtu_members;
>> dmd != NULL; dmd = (ctf_dmdef_t *) ctf_dmd_list_next (dmd))
>> - btf_asm_enum_const (dmd);
>> + btf_asm_enum_const (dtd->dtd_data.ctti_size, dmd);
>> }
>> /* Output all function arguments following a BTF_KIND_FUNC_PROTO. */
>> diff --git a/gcc/ctfc.cc b/gcc/ctfc.cc
>> index 9773358a475..80322eea91a 100644
>> --- a/gcc/ctfc.cc
>> +++ b/gcc/ctfc.cc
>> @@ -576,8 +576,8 @@ ctf_add_array (ctf_container_ref ctfc, uint32_t flag, const ctf_arinfo_t * arp,
>> }
>> ctf_id_t
>> -ctf_add_enum (ctf_container_ref ctfc, uint32_t flag, const char * name,
>> - HOST_WIDE_INT size, dw_die_ref die)
>> +ctf_add_enum (ctf_container_ref ctfc, uint32_t flag,
>> + const ctf_enum_binfo_t *ei, dw_die_ref die)
>
> The name and size information is typically being passed via explicit arguments in the other similar APIs in this functionality. I have a slight preference towards keeping it that way when possible. So in this API ctf_add_enum, how about just adding another function argument for signedness and getting rid of the data structure ctf_enum_binfo_t altogether. What do you think ?
>
Sure!, I'll send the patch v4 with this change.
> Patch looks good to me otherwise.
>
Thanks for your comments,
> Thanks
> Indu
>
>> [...]
Kind regards,
guillermo
next prev parent reply other threads:[~2022-10-18 21:49 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-29 21:11 [PATCH] " Guillermo E. Martinez
2022-09-20 19:32 ` Guillermo E. Martinez
2022-09-28 18:45 ` David Faust
2022-09-28 21:07 ` Guillermo E. Martinez
2022-09-28 21:15 ` [PATCH v2] " Guillermo E. Martinez
2022-09-29 22:35 ` Indu Bhagat
2022-10-03 14:39 ` Guillermo E. Martinez
2022-10-11 18:55 ` Indu Bhagat
2022-10-15 3:45 ` Guillermo E. Martinez
2022-10-15 3:55 ` [PATCH v3] " Guillermo E. Martinez
2022-10-18 21:40 ` Indu Bhagat
2022-10-18 21:48 ` Guillermo E. Martinez [this message]
2022-10-20 2:05 ` [PATCH v4] " Guillermo E. Martinez
2022-10-21 9:28 ` Indu Bhagat
2022-10-31 18:26 ` Indu Bhagat
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4e8dc5be-5516-e4f6-7893-a594948e16d5@oracle.com \
--to=guillermo.e.martinez@oracle.com \
--cc=david.faust@oracle.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=indu.bhagat@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).