public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug debug/112849] New: btf: wrong BTF_KIND_DATSEC entries for extern variables without known section
@ 2023-12-04 21:12 david.faust at oracle dot com
  2023-12-04 21:14 ` [Bug debug/112849] " david.faust at oracle dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: david.faust at oracle dot com @ 2023-12-04 21:12 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-12-05 22:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-04 21:12 [Bug debug/112849] New: btf: wrong BTF_KIND_DATSEC entries for extern variables without known section david.faust at oracle dot com
2023-12-04 21:14 ` [Bug debug/112849] " david.faust at oracle dot com
2023-12-05 22:07 ` ibhagat at gcc dot gnu.org
2023-12-05 22:08 ` cvs-commit at gcc dot gnu.org

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).