public inbox for llvm@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH] genksyms: Fix parsing a declarator with a preceding attribute
@ 2026-02-25 22:07 Nathan Chancellor
  2026-02-26  4:36 ` sun jian
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Nathan Chancellor @ 2026-02-25 22:07 UTC (permalink / raw)
  To: Nathan Chancellor, Nicolas Schier
  Cc: Nick Desaulniers, Bill Wendling, Justin Stitt, Sun Jian,
	Florian Westphal, linux-kernel, linux-kbuild, llvm

After commit 07919126ecfc ("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: 07919126ecfc ("netfilter: annotate NAT helper hook pointers with __rcu")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
I plan to take this via the Kbuild tree for 7.0.
---
 scripts/genksyms/parse.y | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/genksyms/parse.y b/scripts/genksyms/parse.y
index efdcf07c4eb6..cabcd146f3aa 100644
--- a/scripts/genksyms/parse.y
+++ b/scripts/genksyms/parse.y
@@ -325,8 +325,8 @@ direct_declarator:
 		{ $$ = $4; }
 	| direct_declarator BRACKET_PHRASE
 		{ $$ = $2; }
-	| '(' declarator ')'
-		{ $$ = $3; }
+	| '(' attribute_opt declarator ')'
+		{ $$ = $4; }
 	;
 
 /* Nested declarators differ from regular declarators in that they do

---
base-commit: 6de23f81a5e08be8fbf5e8d7e9febc72a5b5f27f
change-id: 20260224-genksyms-fix-attribute-declarator-9b3d63ba5caa

Best regards,
--  
Nathan Chancellor <nathan@kernel.org>


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] genksyms: Fix parsing a declarator with a preceding attribute
  2026-02-25 22:07 [PATCH] genksyms: Fix parsing a declarator with a preceding attribute Nathan Chancellor
@ 2026-02-26  4:36 ` sun jian
  2026-02-26 20:26   ` Nathan Chancellor
  2026-02-27  7:54 ` Nicolas Schier
  2026-03-05  0:36 ` Nathan Chancellor
  2 siblings, 1 reply; 5+ messages in thread
From: sun jian @ 2026-02-26  4:36 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Nicolas Schier, Nick Desaulniers, Bill Wendling, Justin Stitt,
	Florian Westphal, linux-kernel, linux-kbuild, llvm

On Thu, Feb 26, 2026 at 6:07 AM Nathan Chancellor <nathan@kernel.org> wrote:
>
> After commit 07919126ecfc ("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.

Hi Nathan,

Thanks for tracking this down and for the minimal reproducer.

I've noticed the same thing while building on my laptop during MODPOST
Module.symvers:

WARNING: modpost: EXPORT symbol "nf_nat_ftp_hook" [vmlinux] version
generation failed, symbol will not be versioned.
Is "nf_nat_ftp_hook" prototyped in <asm/asm-prototypes.h>?
WARNING: modpost: EXPORT symbol "nf_nat_irc_hook" [vmlinux] version
generation failed, symbol will not be versioned.
Is "nf_nat_irc_hook" prototyped in <asm/asm-prototypes.h>?

>
> diff --git a/scripts/genksyms/parse.y b/scripts/genksyms/parse.y
> index efdcf07c4eb6..cabcd146f3aa 100644
> --- a/scripts/genksyms/parse.y
> +++ b/scripts/genksyms/parse.y
> @@ -325,8 +325,8 @@ direct_declarator:
>                 { $$ = $4; }
>         | direct_declarator BRACKET_PHRASE
>                 { $$ = $2; }
> -       | '(' declarator ')'
> -               { $$ = $3; }
> +       | '(' attribute_opt declarator ')'
> +               { $$ = $4; }
>         ;
>

Your grammar tweak to allow an optional attribute before the nested
declarator looks correct to me.

Best regards,
Sun Jian

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] genksyms: Fix parsing a declarator with a preceding attribute
  2026-02-26  4:36 ` sun jian
@ 2026-02-26 20:26   ` Nathan Chancellor
  0 siblings, 0 replies; 5+ messages in thread
From: Nathan Chancellor @ 2026-02-26 20:26 UTC (permalink / raw)
  To: sun jian
  Cc: Nicolas Schier, Nick Desaulniers, Bill Wendling, Justin Stitt,
	Florian Westphal, linux-kernel, linux-kbuild, llvm

On Thu, Feb 26, 2026 at 12:36:00PM +0800, sun jian wrote:
> On Thu, Feb 26, 2026 at 6:07 AM Nathan Chancellor <nathan@kernel.org> wrote:
> >
> > After commit 07919126ecfc ("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.
> 
> Hi Nathan,
> 
> Thanks for tracking this down and for the minimal reproducer.
> 
> I've noticed the same thing while building on my laptop during MODPOST
> Module.symvers:
> 
> WARNING: modpost: EXPORT symbol "nf_nat_ftp_hook" [vmlinux] version
> generation failed, symbol will not be versioned.
> Is "nf_nat_ftp_hook" prototyped in <asm/asm-prototypes.h>?
> WARNING: modpost: EXPORT symbol "nf_nat_irc_hook" [vmlinux] version
> generation failed, symbol will not be versioned.
> Is "nf_nat_irc_hook" prototyped in <asm/asm-prototypes.h>?
> 
> >
> > diff --git a/scripts/genksyms/parse.y b/scripts/genksyms/parse.y
> > index efdcf07c4eb6..cabcd146f3aa 100644
> > --- a/scripts/genksyms/parse.y
> > +++ b/scripts/genksyms/parse.y
> > @@ -325,8 +325,8 @@ direct_declarator:
> >                 { $$ = $4; }
> >         | direct_declarator BRACKET_PHRASE
> >                 { $$ = $2; }
> > -       | '(' declarator ')'
> > -               { $$ = $3; }
> > +       | '(' attribute_opt declarator ')'
> > +               { $$ = $4; }
> >         ;
> >
> 
> Your grammar tweak to allow an optional attribute before the nested
> declarator looks correct to me.

Thanks a lot for taking a look!

Cheers,
Nathan

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] genksyms: Fix parsing a declarator with a preceding attribute
  2026-02-25 22:07 [PATCH] genksyms: Fix parsing a declarator with a preceding attribute Nathan Chancellor
  2026-02-26  4:36 ` sun jian
@ 2026-02-27  7:54 ` Nicolas Schier
  2026-03-05  0:36 ` Nathan Chancellor
  2 siblings, 0 replies; 5+ messages in thread
From: Nicolas Schier @ 2026-02-27  7:54 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Nick Desaulniers, Bill Wendling, Justin Stitt, Sun Jian,
	Florian Westphal, linux-kernel, linux-kbuild, llvm

On Wed, Feb 25, 2026 at 03:07:17PM -0700, Nathan Chancellor wrote:
> After commit 07919126ecfc ("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: 07919126ecfc ("netfilter: annotate NAT helper hook pointers with __rcu")
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> ---
> I plan to take this via the Kbuild tree for 7.0.
> ---
>  scripts/genksyms/parse.y | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 

Thanks for the detailed explanation and reproducer!

Tested-by: Nicolas Schier <nsc@kernel.org>
Reviewed-by: Nicolas Schier <nsc@kernel.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] genksyms: Fix parsing a declarator with a preceding attribute
  2026-02-25 22:07 [PATCH] genksyms: Fix parsing a declarator with a preceding attribute Nathan Chancellor
  2026-02-26  4:36 ` sun jian
  2026-02-27  7:54 ` Nicolas Schier
@ 2026-03-05  0:36 ` Nathan Chancellor
  2 siblings, 0 replies; 5+ messages in thread
From: Nathan Chancellor @ 2026-03-05  0:36 UTC (permalink / raw)
  To: Nicolas Schier, Nathan Chancellor
  Cc: Nick Desaulniers, Bill Wendling, Justin Stitt, Sun Jian,
	Florian Westphal, linux-kernel, linux-kbuild, llvm

On Wed, 25 Feb 2026 15:07:17 -0700, Nathan Chancellor wrote:
> After commit 07919126ecfc ("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)
> 
> [...]

Applied to

  https://git.kernel.org/pub/scm/linux/kernel/git/kbuild/linux.git kbuild-fixes

Thanks!

[1/1] genksyms: Fix parsing a declarator with a preceding attribute
      https://git.kernel.org/kbuild/c/d2395bb194ef2

Please look out for regression or issue reports or other follow up
comments, as they may result in the patch/series getting dropped or
reverted. Patches applied to an "unstable" branch are accepted pending
wider testing in -next and any post-commit review; they will generally
be moved to the main branch in a week if no issues are found.

Best regards,
-- 
Nathan Chancellor <nathan@kernel.org>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-03-05  0:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-25 22:07 [PATCH] genksyms: Fix parsing a declarator with a preceding attribute Nathan Chancellor
2026-02-26  4:36 ` sun jian
2026-02-26 20:26   ` Nathan Chancellor
2026-02-27  7:54 ` Nicolas Schier
2026-03-05  0:36 ` Nathan Chancellor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox