[RFC PATCH 0/2] percpu, local_lock: drop btf_type_tag where no compiler records it
From: Vineet Gupta
Date: Mon Nov 09 2026 - 20:31:21 EST
Hi,
Currently PAHOLE_HAS_BTF_TAG is gated on CC_IS_CLANG and the goal is
to allow CC_IS_GCC. There are GCC fixes (PR128479, PR125991) in the
making [1] but despite all of them an x86 defconfig still emits ~40k
instances of spew like:
arch/x86/include/asm/processor.h:232:36: warning: ignoring attributes
applied to 'struct cpuinfo_x86' after definition [-Wattributes]
where one is enough to break a -Werror build.
Making GCC stop warning here was proposed as PR128480 and rejected:
the suggested answer was -Wno-attributes, which the kernel would not
accept just to suppress this noise.
And even if warnings were to be ignored, the build would still fail
with 33 hard errors from a separate GCC bug, PR128477,
include/linux/percpu-defs.h:216:45: error: initialization from
pointer to non-enclosed address space
These come from the same tag on the same declarations, so this series
removes them too.
The root cause is where the tag is applied. BTF_TYPE_TAG(percpu)
records that a pointer points to per-cpu memory, but two places apply
it where the thing qualified is an aggregate, which no compiler can
tag (GCC or clang): every variant of an aggregate shares one DIE,
so there is nowhere to put it.
- __PCPU_ATTRS(), so DECLARE_PER_CPU() and DEFINE_PER_CPU() put the tag
on the per-cpu variable's own type;
- the type argument of DEFINE_LOCK_GUARD_1() in local_lock.h, which
cleanup.h turns into "typedef _type lock_<name>_t".
Nothing reads a tag in either position. The verifier matches "percpu" in
btf_ctx_access() and in the member walk in btf_struct_walk(), and both
check btf_type_is_ptr() first, so it only ever sees the tag on a pointer.
The aggregate case is the only one that warns. Where the per-cpu variable
is a pointer there is no diagnostic, but the record is wrong: GCC puts
the tag on the pointee, so
static DEFINE_PER_CPU(struct bpf_hrtimer *, hrtimer_running);
comes out saying hrtimer_running is an ordinary pointer to per-cpu
memory, when in truth it lives in per-cpu memory and points at ordinary
memory. clang records no tag there at all.
The following two patches address this:
- 1/2 provides a new variant of __percpu, __percpu_var which elides
the btf tag. Switches __PCPU_ATTRS to use it.
- 2/2: Applies __percpu_var in local_lock code.
Binary impact, x86 defconfig built with clang: patch 1 drops 280 BTF types
(140 TYPE_TAG and the 140 pointers carrying them, none referenced) and 3360
bytes of .BTF, with .text unchanged. Patch 2 changes nothing at all.
[1] https://inbox.sourceware.org/gcc-patches/20261109213600.772524-1-vineet.gupta@xxxxxxxxx/
Vineet Gupta (2):
percpu: do not put btf_type_tag on per-cpu variable declarations
local_lock: do not put btf_type_tag on the lock guard type
include/linux/compiler_types.h | 8 ++++++++
include/linux/local_lock.h | 8 ++++----
include/linux/percpu-defs.h | 2 +-
3 files changed, 13 insertions(+), 5 deletions(-)
--
2.53.0-Meta