The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] tools/compiler: match glibc 2.42 definition of __attribute_const__
@ 2026-06-30 14:58 Joy H.J. Lee
  2026-06-30 17:41 ` David Laight
  0 siblings, 1 reply; 3+ messages in thread
From: Joy H.J. Lee @ 2026-06-30 14:58 UTC (permalink / raw)
  To: linux-kbuild; +Cc: linux-kernel, masahiroy, nathan, Joy H.J. Lee

glibc 2.42 added __attribute_const__ to sys/cdefs.h:

    # define __attribute_const__ __attribute__ ((__const__))

GCC 15 warns when a macro is redefined to a different replacement list
(-Wbuiltin-macro-redefined). Since host tool Makefiles (resolve_btfids,
objtool) pass -Werror, this conflict becomes fatal when building with
glibc 2.42 and GCC 15.

Per C11 §6.10.3, identical replacement lists are accepted silently.
Match the glibc definition exactly, including the space before "((", so
the redefinition is accepted without warning.

Signed-off-by: Joy H.J. Lee <rkr0k0r@gmail.com>
---
 tools/include/linux/compiler.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
index f40bd2b04..f2f54b038 100644
--- a/tools/include/linux/compiler.h
+++ b/tools/include/linux/compiler.h
@@ -119,7 +119,7 @@
 #define __read_mostly
 
 #ifndef __attribute_const__
-# define __attribute_const__
+# define __attribute_const__ __attribute__ ((__const__))
 #endif
 
 #ifndef __maybe_unused
-- 
2.53.0


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

* Re: [PATCH] tools/compiler: match glibc 2.42 definition of __attribute_const__
  2026-06-30 14:58 [PATCH] tools/compiler: match glibc 2.42 definition of __attribute_const__ Joy H.J. Lee
@ 2026-06-30 17:41 ` David Laight
  2026-06-30 18:42   ` Nathan Chancellor
  0 siblings, 1 reply; 3+ messages in thread
From: David Laight @ 2026-06-30 17:41 UTC (permalink / raw)
  To: Joy H.J. Lee; +Cc: linux-kbuild, linux-kernel, masahiroy, nathan

On Tue, 30 Jun 2026 23:58:40 +0900
"Joy H.J. Lee" <rkr0k0r@gmail.com> wrote:

> glibc 2.42 added __attribute_const__ to sys/cdefs.h:
> 
>     # define __attribute_const__ __attribute__ ((__const__))
> 
> GCC 15 warns when a macro is redefined to a different replacement list
> (-Wbuiltin-macro-redefined). Since host tool Makefiles (resolve_btfids,
> objtool) pass -Werror, this conflict becomes fatal when building with
> glibc 2.42 and GCC 15.
> 
> Per C11 §6.10.3, identical replacement lists are accepted silently.
> Match the glibc definition exactly, including the space before "((", so
> the redefinition is accepted without warning.
> 
> Signed-off-by: Joy H.J. Lee <rkr0k0r@gmail.com>
> ---
>  tools/include/linux/compiler.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
> index f40bd2b04..f2f54b038 100644
> --- a/tools/include/linux/compiler.h
> +++ b/tools/include/linux/compiler.h
> @@ -119,7 +119,7 @@
>  #define __read_mostly
>  
>  #ifndef __attribute_const__
> -# define __attribute_const__
> +# define __attribute_const__ __attribute__ ((__const__))

That doesn't look right, you are completely changing the value
when it isn't already defined.

	David

>  #endif
>  
>  #ifndef __maybe_unused


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

* Re: [PATCH] tools/compiler: match glibc 2.42 definition of __attribute_const__
  2026-06-30 17:41 ` David Laight
@ 2026-06-30 18:42   ` Nathan Chancellor
  0 siblings, 0 replies; 3+ messages in thread
From: Nathan Chancellor @ 2026-06-30 18:42 UTC (permalink / raw)
  To: David Laight; +Cc: Joy H.J. Lee, linux-kbuild, linux-kernel, masahiroy

On Tue, Jun 30, 2026 at 06:41:06PM +0100, David Laight wrote:
> On Tue, 30 Jun 2026 23:58:40 +0900
> "Joy H.J. Lee" <rkr0k0r@gmail.com> wrote:
> 
> > glibc 2.42 added __attribute_const__ to sys/cdefs.h:
> > 
> >     # define __attribute_const__ __attribute__ ((__const__))
> > 
> > GCC 15 warns when a macro is redefined to a different replacement list
> > (-Wbuiltin-macro-redefined). Since host tool Makefiles (resolve_btfids,
> > objtool) pass -Werror, this conflict becomes fatal when building with
> > glibc 2.42 and GCC 15.
> > 
> > Per C11 §6.10.3, identical replacement lists are accepted silently.
> > Match the glibc definition exactly, including the space before "((", so
> > the redefinition is accepted without warning.
> > 
> > Signed-off-by: Joy H.J. Lee <rkr0k0r@gmail.com>
> > ---
> >  tools/include/linux/compiler.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
> > index f40bd2b04..f2f54b038 100644
> > --- a/tools/include/linux/compiler.h
> > +++ b/tools/include/linux/compiler.h
> > @@ -119,7 +119,7 @@
> >  #define __read_mostly
> >  
> >  #ifndef __attribute_const__
> > -# define __attribute_const__
> > +# define __attribute_const__ __attribute__ ((__const__))
> 
> That doesn't look right, you are completely changing the value
> when it isn't already defined.

That's the point, no? If compiler.h is included before sys/cdefs.h, you
would get an instance of -Wbuiltin-macro-redefined like described in the
commit message. I am sure this is fine, we unconditionally define it in
compiler_attributes.h.

For the record, I have not seen an error like the commit message
describes in any of my build tests or environment. It would be good to
know under what circumstances this actually happens (or is this just
some contrivied issue or AI hallucination?).

Lastly, I don't think this should go through Kbuild, we don't touch
tools/. Perhaps this should go through Andrew Morton?

> >  #endif
> >  
> >  #ifndef __maybe_unused
> 

-- 
Cheers,
Nathan

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

end of thread, other threads:[~2026-06-30 18:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-30 14:58 [PATCH] tools/compiler: match glibc 2.42 definition of __attribute_const__ Joy H.J. Lee
2026-06-30 17:41 ` David Laight
2026-06-30 18:42   ` Nathan Chancellor

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