]> git.ipfire.org Git - thirdparty/gcc.git/commit
btf: emit symbol refs in DATASEC entries only for BPF [PR114608]
authorDavid Faust <david.faust@oracle.com>
Mon, 8 Apr 2024 18:10:41 +0000 (11:10 -0700)
committerDavid Faust <david.faust@oracle.com>
Tue, 9 Apr 2024 15:40:08 +0000 (08:40 -0700)
commit8075477f81ae8d0abf64b80dfbd179151f91b417
tree94d6cd151c5eb012934a3fc84f08dd3b2f1e8fd1
parent685d822e524cc8b2726ad6c44c2ccaabe55a198c
btf: emit symbol refs in DATASEC entries only for BPF [PR114608]

The behavior introduced in
  fa60ac54964 btf: Emit labels in DATASEC bts_offset entries.

is only fully correct when compiling for the BPF target with BPF CO-RE
enabled.  In other cases, depending on optimizations, it can result in
an incorrect symbol reference in the entry bts_offset field for a symbol
which may not be emitted at all, causing link-time undefined symbol
reference errors like in PR114608.

The offending bts_offset field of BTF_KIND_DATASEC entries is in reality
only currently useful to consumers of BTF information for BPF programs
anyway.  Correct the regression by only emitting symbol references in
these entries when compiling for the BPF target.  For other targets, the
behavior returns to that prior to fa60ac54964.

The underlying cause is related to PR 113566 "btf: incorrect
BTF_KIND_DATASEC entries for variables which are optimized out." A
complete fix for 113566 is more involved and unsuitable for stage 4,
but will be addressed in the near future.

gcc/
PR debug/114608
* btfout.cc (btf_asm_datasec_entry): Only emit a symbol reference when
generating BTF for BPF CO-RE target.

gcc/testsuite/
PR debug/114608
* gcc.dg/debug/btf/btf-datasec-1.c: Check bts_offset symbol references
only for BPF target.
* gcc.dg/debug/btf/btf-datasec-2.c: Likewise.
* gcc.dg/debug/btf/btf-pr106773.c: Likewise.
gcc/btfout.cc
gcc/testsuite/gcc.dg/debug/btf/btf-datasec-1.c
gcc/testsuite/gcc.dg/debug/btf/btf-datasec-2.c
gcc/testsuite/gcc.dg/debug/btf/btf-pr106773.c