tools/compiler: match glibc 2.42 definition of __attribute_const__
PATCH 1/1 tools/compiler: match glibc 2.42 definition of __attribute_const__
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.
--- tools/include/linux/compiler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/include/linux/compiler.h +1 -1
@@ -119,7 +119,7 @@#define __read_mostly#ifndef __attribute_const__ -# define __attribute_const__ +# define __attribute_const__ __attribute__ ((__const__))#endif #ifndef __maybe_unused
Signature · 1 line
2.53.0
Quoted 23 lines · On Tue, 30 Jun 2026 23:58:40 +0900 "Joy H.J. Lee" <[email protected]> wrote:
glibc 2.42 added
__attribute_const__tosys/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 <[email protected]>--- tools/include/linux/compiler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/include/linux/compiler.h +0
-0
tools/include/linux/compiler.h line 122
Quoted 5 lines
tools/include/linux/compiler.h +1
-1@@ -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
Quoted 3 lines
tools/include/linux/compiler.h +0
-0#endif #ifndef __maybe_unused
Nathan Chancellor
maintainerQuoted 28 lines · David Laight
Quoted 25 lines · On Tue, 30 Jun 2026 23:58:40 +0900 "Joy H.J. Lee" <[email protected]> wrote:
glibc 2.42 added
__attribute_const__tosys/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 <[email protected]>--- tools/include/linux/compiler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/include/linux/compiler.h +0
-0@@ -119,7 +119,7 @@#define __read_mostly
Quoted 6 lines
tools/include/linux/compiler.h line 122
Quoted 3 lines
tools/include/linux/compiler.h +1
-1#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?
Quoted 4 lines
Quoted 3 lines
tools/include/linux/compiler.h +0
-0#endif #ifndef __maybe_unused
Signature · 2 lines
Cheers, Nathan