https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128441

            Bug ID: 128441
           Summary: duplicate DW_TAG_typedef when btf_type_tag is applied
                    to a use of a named typedef
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: vineetg at gcc dot gnu.org
          Reporter: vineetg at gcc dot gnu.org
                CC: dfaust at gcc dot gnu.org, jemarch at gcc dot gnu.org
  Target Milestone: ---

Applying btf_type_tag to a *use* of an existing typedef makes GCC clone a
second DW_TAG_typedef carrying a name that is already in use.

```c
    typedef unsigned int uint_t;
    uint_t __attribute__((btf_type_tag("tag1"))) uint_A;
    uint_t __attribute__((btf_type_tag("tag2"))) uint_B;
    uint_t plain;
```

Compiled with -gbtf, three BTF records are emitted for one typedef:

```
    [1] TYPEDEF 'uint_t' type_id=2
    [3] TYPEDEF 'uint_t' type_id=2
    [4] TYPEDEF 'uint_t' type_id=2
```
Expected: one TYPEDEF record named uint_t.

The same happens in DWARF: three DW_TAG_typedef DIEs named uint_t.

This breaks BTF consumers which can't tell the duplicates apart by name.
"bpftool gen skeleton" renames the collisions and then does not define the
renamed
types, so the generated header does not compile:

    uint_t  plain;
    uint_t___2 uint_B;      /* uint_t___2 never defined */
    uint_t___3 uint_A;      /* uint_t___3 never defined */

This shows up when building the BPF selftests in the Linux kernel tree,
which tag uses of typedefs in arena code, e.g.

    tools/testing/selftests/bpf/progs/arena_spin_lock.c:
        arena_spinlock_t __arena lock;

where __arena expands to __attribute__((btf_type_tag("arena"))).  

This is unrelated to issues with enabling gcc style btf tags in kernel
(CONFIG_PAHOLE_HASBTF_TAG).

Reply via email to