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

            Bug ID: 112849
           Summary: btf: wrong BTF_KIND_DATSEC entries for extern
                    variables without known section
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: btf-debug, wrong-debug
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: david.faust at oracle dot com
                CC: cupertino.miranda at oracle dot com, ibhagat at gcc dot 
gnu.org,
                    jemarch at gcc dot gnu.org
  Target Milestone: ---

When building bpf-next selftests with gcc trunk, we get the following
error from libbpf:

libbpf: linker: adding object file 'linked_vars1.bpf.o'...
libbpf: linker: adding object file 'linked_vars2.bpf.o'...
libbpf: global 'input_data1': section mismatch 4 vs 5
Error: failed to link 'linked_vars2.bpf.o': Invalid argument (22)

Here libbpf is doing some form of linking of the two objects.
'input_data1' is declared and initialized in linked_vars1, and
placed in .data. In linked_vars2 it is declared extern, however
an entry for it is added in the .bss BTF_KIND_DATASEC record in
linked_vars2.bpf.o.

clang does not emit entries in BTF_KIND_DATASEC for extern variable
decls without an explicit section e.g. via __attribute__((section(...))).

gcc
[7237] DATASEC '.bss' size=0 vlen=8
        type_id=7059 offset=0 size=4 (VAR 'input_data1')      <-----
        type_id=7167 offset=0 size=4 (VAR 'input_bss1')       <-----
        type_id=7100 offset=0 size=4 (VAR 'output_sink2')
        type_id=7111 offset=0 size=4 (VAR 'output_rodata2')
        type_id=7065 offset=0 size=4 (VAR 'output_data2')
        type_id=7090 offset=0 size=4 (VAR 'output_bss2')
        type_id=7079 offset=0 size=4 (VAR 'input_bss_weak')
        type_id=7192 offset=0 size=4 (VAR 'input_bss2')

clang
[34] DATASEC '.bss' size=0 vlen=6
        type_id=18 offset=0 size=4 (VAR 'input_bss2')
        type_id=19 offset=0 size=4 (VAR 'input_bss_weak')
        type_id=20 offset=0 size=4 (VAR 'output_bss2')
        type_id=21 offset=0 size=4 (VAR 'output_data2')
        type_id=22 offset=0 size=4 (VAR 'output_rodata2')
        type_id=23 offset=0 size=4 (VAR 'output_sink2')


The problem is that when creating the BTF_KIND_DATASEC entires,
gcc is incorrectly falling back to a default section name (like .bss)
for variables, even if they are 'extern' decls. 

gcc should be changed to not emit entries in any BTF_KIND_DATASEC
for extern variable decls without a known section.

Reply via email to