From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5055E385829B; Mon, 4 Dec 2023 21:12:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5055E385829B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701724333; bh=4JG11fnwOujju94J0EBRlTIWzRAF2if7TVYmWm+02vw=; h=From:To:Subject:Date:From; b=er+Klj9jXjNIJt2cKuWDyVV6fH7S+T142DJ94FJoeSFCW6nOoJKLd20slu0VxwYHK tDa6zIBqTWfK4KzmMYPPVHosJlxTx0o2sUnYhC+gMQFPeBiVQVfUY+7M/ntXZzs2kA r3ZRpS1+4dJs9oEeZDKa7CdFOPhLlo+cKo1sGnVU= From: "david.faust at oracle dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug debug/112849] New: btf: wrong BTF_KIND_DATSEC entries for extern variables without known section Date: Mon, 04 Dec 2023 21:12:12 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: debug X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: btf-debug, wrong-debug X-Bugzilla-Severity: normal X-Bugzilla-Who: david.faust at oracle dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status keywords bug_severity priority component assigned_to reporter cc target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D112849 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=3D0 vlen=3D8 type_id=3D7059 offset=3D0 size=3D4 (VAR 'input_data1') <----- type_id=3D7167 offset=3D0 size=3D4 (VAR 'input_bss1') <----- type_id=3D7100 offset=3D0 size=3D4 (VAR 'output_sink2') type_id=3D7111 offset=3D0 size=3D4 (VAR 'output_rodata2') type_id=3D7065 offset=3D0 size=3D4 (VAR 'output_data2') type_id=3D7090 offset=3D0 size=3D4 (VAR 'output_bss2') type_id=3D7079 offset=3D0 size=3D4 (VAR 'input_bss_weak') type_id=3D7192 offset=3D0 size=3D4 (VAR 'input_bss2') clang [34] DATASEC '.bss' size=3D0 vlen=3D6 type_id=3D18 offset=3D0 size=3D4 (VAR 'input_bss2') type_id=3D19 offset=3D0 size=3D4 (VAR 'input_bss_weak') type_id=3D20 offset=3D0 size=3D4 (VAR 'output_bss2') type_id=3D21 offset=3D0 size=3D4 (VAR 'output_data2') type_id=3D22 offset=3D0 size=3D4 (VAR 'output_rodata2') type_id=3D23 offset=3D0 size=3D4 (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.=20 gcc should be changed to not emit entries in any BTF_KIND_DATASEC for extern variable decls without a known section.=