[Bug debug/111735] incorrect BTF representation of forward-declared enums

2023-12-19 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111735

--- Comment #2 from GCC Commits  ---
The master branch has been updated by David Faust :

https://gcc.gnu.org/g:1502d724df85163b14b04e8f67072ca88eac411d

commit r14-6716-g1502d724df85163b14b04e8f67072ca88eac411d
Author: David Faust 
Date:   Tue Dec 12 13:55:59 2023 -0800

btf: change encoding of forward-declared enums [PR111735]

The BTF specification does not formally define a representation for
forward-declared enum types such as:

  enum Foo;

Forward-declarations for struct and union types are represented by
BTF_KIND_FWD, which has a 1-bit flag distinguishing the two.

The de-facto standard format used by other tools like clang and pahole
is to represent forward-declared enums as BTF_KIND_ENUM with vlen=0,
i.e. as a regular enum type with no enumerators.  This patch changes
GCC to adopt that format, and makes a couple of minor cleanups in
btf_asm_type ().

gcc/

PR debug/111735
* btfout.cc (btf_fwd_to_enum_p): New.
(btf_asm_type_ref): Special case references to enum forwards.
(btf_asm_type): Special case enum forwards. Rename btf_size_type to
btf_size, and change chained ifs switching on btf_kind into else
ifs.

gcc/testsuite/

PR debug/111735
* gcc.dg/debug/btf/btf-forward-2.c: New test.

[Bug debug/111735] incorrect BTF representation of forward-declared enums

2023-12-05 Thread david.faust at oracle dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111735

David Faust  changed:

   What|Removed |Added

 CC||david.faust at oracle dot com

--- Comment #1 from David Faust  ---
Sorry for the delay, somehow I missed this until now.

Confirmed... though this really ought to be further discussed and
formalized with the kernel BPF folks. As of now, btf.rst does not
specify any representation at all for forward-declared enums. And,
it lists in 'encoding requirements' for BTF_KIND_ENUM that 'size'
must be one of 1/2/4/8, so in a sense this de-facto representation
is not really valid.

IMO it would be better to adjust the BTF_KIND_FWD definition to
support forward-declared enums. CTF for example encodes the kind
of the forward in the 'type' field of its KIND_FWD, which in BTF
is simply unused. Anyway, that can be raised for discussion on
the bpf list.

In the meanwhile, it should not be problematic to adapt GCC to
follow clang and pahole in emitting KIND_ENUM with vlen=0.