linux/scripts/genksyms
Nathan Chancellor d2395bb194 genksyms: Fix parsing a declarator with a preceding attribute
After commit 07919126ec ("netfilter: annotate NAT helper hook pointers
with __rcu"), genksyms fails to parse the __rcu annotation when building
with CONFIG_DEBUG_INFO_BTF=y, CONFIG_PAHOLE_HAS_BTF_TAG=y, and a version
of clang that supports btf_type_tag.

  $ clang --version | head -1
  ClangBuiltLinux clang version 22.1.0 (https://github.com/llvm/llvm-project.git 4434dabb69916856b824f68a64b029c67175e532)

  $ cat kernel/configs/repro.config
  CONFIG_BPF_SYSCALL=y
  CONFIG_MODVERSIONS=y
  # CONFIG_DEBUG_INFO_NONE is not set
  CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y
  CONFIG_DEBUG_INFO_BTF=y

  $ make -skj"$(nproc)" ARCH=x86_64 LLVM=1 mrproper defconfig repro.config all
  WARNING: modpost: EXPORT symbol "nf_nat_ftp_hook" [vmlinux] version generation failed, symbol will not be versioned.
  ...
  WARNING: modpost: EXPORT symbol "nf_nat_irc_hook" [vmlinux] version generation failed, symbol will not be versioned.
  ...

genksyms falls over parsing the __rcu attribute in the declarator:

  # Kernel reproducer
  $ make -skj"$(nproc)" ARCH=x86_64 KCFLAGS=-D__GENKSYMS__ LLVM=1 net/netfilter/nf_conntrack_ftp.i

  $ scripts/genksyms/genksyms -w <net/netfilter/nf_conntrack_ftp.i &| rg 'syntax error'
  include/linux/netfilter/nf_conntrack_ftp.h:29: syntax error
  net/netfilter/nf_conntrack_ftp.c:46: syntax error

  # Trivial reproducer
  $ cat test.c
  int (*func)(void *foo, int bar);
  int (__attribute__((btf_type_tag("rcu"))) *func_with_attr)(void *foo, int bar);

  $ scripts/genksyms/genksyms -w <test.c
  <stdin>:2: syntax error

Optionally allow an attribute to precede a declarator to resolve this
error and properly generate symbol versions.

Fixes: 07919126ec ("netfilter: annotate NAT helper hook pointers with __rcu")
Link: https://patch.msgid.link/20260225-genksyms-fix-attribute-declarator-v1-1-1b21478663fb@kernel.org
Tested-by: Nicolas Schier <nsc@kernel.org>
Reviewed-by: Nicolas Schier <nsc@kernel.org>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
2026-02-26 11:53:05 -07:00
..
.gitignore .gitignore: prefix local generated files with a slash 2021-05-02 00:43:35 +09:00
genksyms.c genksyms: Fix enum consts from a reference affecting new values 2025-06-07 14:38:07 +09:00
genksyms.h genksyms: fix 6 shift/reduce conflicts and 5 reduce/reduce conflicts 2025-01-18 09:11:38 +09:00
keywords.c genksyms: Handle typeof_unqual keyword and __seg_{fs,gs} qualifiers 2025-04-14 09:19:04 +02:00
lex.l genksyms: factor out APP for the ST_NORMAL state 2025-03-15 21:16:21 +09:00
Makefile genksyms: remove Makefile hack 2025-01-18 09:11:46 +09:00
parse.y genksyms: Fix parsing a declarator with a preceding attribute 2026-02-26 11:53:05 -07:00