https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112849
--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by David Faust <dfa...@gcc.gnu.org>: https://gcc.gnu.org/g:b8cf266f4ca4ff89704b190c827abf9ea7e7b5bf commit r14-6195-gb8cf266f4ca4ff89704b190c827abf9ea7e7b5bf Author: David Faust <david.fa...@oracle.com> Date: Mon Dec 4 14:08:03 2023 -0800 btf: avoid wrong DATASEC entries for extern vars [PR112849] The process of creating BTF_KIND_DATASEC records involves iterating through variable declarations, determining which section they will be placed in, and creating an entry in the appropriate DATASEC record accordingly. For variables without e.g. an explicit __attribute__((section)), we use categorize_decl_for_section () to identify the appropriate named section and corresponding BTF_KIND_DATASEC record. This was incorrectly being done for 'extern' variable declarations as well as non-extern ones, which meant that extern variable declarations could result in BTF_KIND_DATASEC entries claiming the variable is allocated in some section such as '.bss' without any knowledge whether that is actually true. That resulted in errors building the Linux kernel BPF selftests. This patch corrects btf_collect_datasec () to avoid assuming a section for extern variables, and only emit BTF_KIND_DATASEC entries for them if they have a known section. gcc/ PR debug/112849 * btfout.cc (btf_collect_datasec): Avoid incorrectly creating an entry in a BTF_KIND_DATASEC record for extern variable decls without a known section. gcc/testsuite/ PR debug/112849 * gcc.dg/debug/btf/btf-datasec-3.c: New test.