Skip to contentSkip to conversation

Build error in next-20260223 gcc-plugins/latent_entropy_plugin.so

DISCUSSION Valdis Klētnieks 3 participants 7 messages Feb 25 – Mar 21 Gcc plugins

lore
Share & tools
lore
#0 lore raw

Building next-20260223 dies an early death:

HOSTLD arch/x86/tools/relocs
HOSTCC arch/x86/tools/vdso2c
HOSTCXX scripts/gcc-plugins/latent_entropy_plugin.so
In file included from scripts/gcc-plugins/latent_entropy_plugin.c:78:
scripts/gcc-plugins/gcc-common.h: In function 'void debug_tree(const_tree)':
scripts/gcc-plugins/gcc-common.h:417:20: error: 'CONST_CAST_TREE' was not declared in this scope; did you mean 'CONST_CAST_EXPR'?

  417 |         debug_tree(CONST_CAST_TREE(t));
      |                    ^~~~~~~~~~~~~~~
      |                    CONST_CAST_EXPR

scripts/gcc-plugins/gcc-common.h: In function 'void debug_gimple_stmt(const_gimple_ptr)':
scripts/gcc-plugins/gcc-common.h:312:47: error: expected primary-expression before ',' token
312 | #define CONST_CAST_GIMPLE(X) CONST_CAST(gimple, (X))
| ^
scripts/gcc-plugins/gcc-common.h:422:27: note: in expansion of macro 'CONST_CAST_GIMPLE'

  422 |         debug_gimple_stmt(CONST_CAST_GIMPLE(s));
      |                           ^~~~~~~~~~~~~~~~~
scripts/gcc-plugins/gcc-common.h:312:30: error: 'CONST_CAST' was not declared in this scope; did you mean 'CONST_INT'?
  312 | #define CONST_CAST_GIMPLE(X) CONST_CAST(gimple, (X))
      |                              ^~~~~~~~~~
scripts/gcc-plugins/gcc-common.h:422:27: note: in expansion of macro 'CONST_CAST_GIMPLE'
  422 |         debug_gimple_stmt(CONST_CAST_GIMPLE(s));
      |                           ^~~~~~~~~~~~~~~~~

make[3]: *** [scripts/gcc-plugins/Makefile:54: scripts/gcc-plugins/latent_entropy_plugin.so] Error 1 make[2]: *** [scripts/Makefile.build:546: scripts/gcc-plugins] Error 2
make[1]: *** [/usr/src/linux-next/Makefile:1316: scripts] Error 2
make: *** [Makefile:248: __sub-make] Error 2

'git blame' isn't showing any recent changes..

next-20260109 built OK. Any ideas before I start bisecting in more detail?

maintainer
#1 lore raw
Quoted 29 lines · Valdis Klētnieks

Building next-20260223 dies an early death:

HOSTLD arch/x86/tools/relocs
HOSTCC arch/x86/tools/vdso2c
HOSTCXX scripts/gcc-plugins/latent_entropy_plugin.so
In file included from scripts/gcc-plugins/latent_entropy_plugin.c:78:
scripts/gcc-plugins/gcc-common.h: In function 'void debug_tree(const_tree)':
scripts/gcc-plugins/gcc-common.h:417:20: error: 'CONST_CAST_TREE' was not declared in this scope; did you mean 'CONST_CAST_EXPR'?

  417 |         debug_tree(CONST_CAST_TREE(t));
      |                    ^~~~~~~~~~~~~~~
      |                    CONST_CAST_EXPR

scripts/gcc-plugins/gcc-common.h: In function 'void debug_gimple_stmt(const_gimple_ptr)':
scripts/gcc-plugins/gcc-common.h:312:47: error: expected primary-expression before ',' token
312 | #define CONST_CAST_GIMPLE(X) CONST_CAST(gimple, (X))
| ^
scripts/gcc-plugins/gcc-common.h:422:27: note: in expansion of macro 'CONST_CAST_GIMPLE'

  422 |         debug_gimple_stmt(CONST_CAST_GIMPLE(s));
      |                           ^~~~~~~~~~~~~~~~~
scripts/gcc-plugins/gcc-common.h:312:30: error: 'CONST_CAST' was not declared in this scope; did you mean 'CONST_INT'?
  312 | #define CONST_CAST_GIMPLE(X) CONST_CAST(gimple, (X))
      |                              ^~~~~~~~~~
scripts/gcc-plugins/gcc-common.h:422:27: note: in expansion of macro 'CONST_CAST_GIMPLE'
  422 |         debug_gimple_stmt(CONST_CAST_GIMPLE(s));
      |                           ^~~~~~~~~~~~~~~~~

make[3]: *** [scripts/gcc-plugins/Makefile:54: scripts/gcc-plugins/latent_entropy_plugin.so] Error 1 make[2]: *** [scripts/Makefile.build:546: scripts/gcc-plugins] Error 2
make[1]: *** [/usr/src/linux-next/Makefile:1316: scripts] Error 2
make: *** [Makefile:248: __sub-make] Error 2

Quoted 5 lines

'git blame' isn't showing any recent changes..

next-20260109 built OK. Any ideas before I start bisecting in more detail?

????????

Which GCC version?

Signature · 1 line
Kees Cook
#2 lore raw
Quoted 2 lines · Kees Cook

Which GCC version?

Oh nuts. I thought I included that.. Dug into it more, looks like a GCC bug rather than a kernel bug.

From the gcc RPM changelog:

This one works.

* Tue Jan 27 2026 Jakub Jelinek <[email protected]> 16.0.1-0.5
- update from trunk

This doesn't:

* Mon Feb 09 2026 Jakub Jelinek <[email protected]> 16.0.1-0.7
- update from trunk

#3 lore raw

I get the same error with

    gcc (Debian 16-20260308-1) 16.0.1 20260308 (experimental) [trunk r16-7949-g6c5de6335f5]

It seems gcc removed the CONST_CAST macros in gcc-16. CONST_CAST_TREE got removed in commit c3d96ff, CONST_CAST in commit 458c792.

    https://github.com/gcc-mirror/gcc/commit/c3d96ff9e916c02584aa081f03ab999292efbb50
    https://github.com/gcc-mirror/gcc/commit/458c7926d48959abcb2c1adaa22458e27459a551

So this does not seem to be a gcc bug, but the CONST_CAST macros being gone for good.

I attached a quick patch to get the kernel build with the current gcc-16 development version, but it still needs to be guarded against different gcc versions.

Ingo

Signature · 1 line
const_cast<long double>(Λ)
#4 lore raw
Quoted 1 line · Ingo Saitz

I attached [...]

Grml, here you go

Ingo

Signature · 1 line
const_cast<long double>(Λ)

From 552485b879d19780afd3614d69508c3ea7cb242f Mon Sep 17 00:00:00 2001
From: Ingo Saitz <[email protected]>
Date: Sat, 14 Mar 2026 14:24:56 +0100
Subject: [PATCH] Replace CONST_CAST with const_cast<>.

For gcc-16, this was removed in gcc trunk

see commits
c3d96ff9e916c02584aa081f03ab999292efbb50
458c7926d48959abcb2c1adaa22458e27459a551

---
 scripts/gcc-plugins/gcc-common.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
scripts/gcc-plugins/gcc-common.h +3 -3
index 8f1b3500f8e2..7b3517b31e0a 100644
@@ -309,7 +309,7 @@ typedef const gimple *const_gimple_ptr;
 #define gimple gimple_ptr
 #define const_gimple const_gimple_ptr
 #undef CONST_CAST_GIMPLE
-#define CONST_CAST_GIMPLE(X) CONST_CAST(gimple, (X))
+#define CONST_CAST_GIMPLE(X) const_cast<gimple>((X))
 
 /* gimple related */
 static inline gimple gimple_build_assign_with_ops(enum tree_code subcode, tree lhs, tree op1, tree op2 MEM_STAT_DECL)
@@ -414,7 +414,7 @@ static inline void ipa_remove_stmt_references(symtab_node *referring_node, gimpl
 #ifdef __cplusplus
 static inline void debug_tree(const_tree t)
 {
-	debug_tree(CONST_CAST_TREE(t));
+	debug_tree(const_cast<tree>(t));
 }
 
 static inline void debug_gimple_stmt(const_gimple s)
@@ -422,7 +422,7 @@ static inline void debug_gimple_stmt(const_gimple s)
 	debug_gimple_stmt(CONST_CAST_GIMPLE(s));
 }
 #else
-#define debug_tree(t) debug_tree(CONST_CAST_TREE(t))
+#define debug_tree(t) debug_tree(const_cast<tree>(t))
 #define debug_gimple_stmt(s) debug_gimple_stmt(CONST_CAST_GIMPLE(s))
 #endif
 
Signature · 1 line
2.53.0
maintainer
#5 lore raw
Quoted 46 lines · Ingo Saitz
Quoted 1 line · Ingo Saitz

I attached [...]

Grml, here you go

Ingo

Signature · 15 lines
const_cast<long double>(Λ)

From 552485b879d19780afd3614d69508c3ea7cb242f Mon Sep 17 00:00:00 2001
From: Ingo Saitz <[email protected]>
Date: Sat, 14 Mar 2026 14:24:56 +0100
Subject: [PATCH] Replace CONST_CAST with const_cast<>.

For gcc-16, this was removed in gcc trunk

see commits
  c3d96ff9e916c02584aa081f03ab999292efbb50
  458c7926d48959abcb2c1adaa22458e27459a551
---
 scripts/gcc-plugins/gcc-common.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
scripts/gcc-plugins/gcc-common.h +2 -2
index 8f1b3500f8e2..7b3517b31e0a 100644
@@ -309,7 +309,7 @@ typedef const gimple *const_gimple_ptr;
 #define gimple gimple_ptr
 #define const_gimple const_gimple_ptr
 #undef CONST_CAST_GIMPLE
-#define CONST_CAST_GIMPLE(X) CONST_CAST(gimple, (X))
+#define CONST_CAST_GIMPLE(X) const_cast<gimple>((X))
 
 /* gimple related */
 static inline gimple gimple_build_assign_with_ops(enum tree_code subcode, tree lhs, tree op1, tree op2 MEM_STAT_DECL)
@@ -414,7 +414,7 @@ static inline void ipa_remove_stmt_references(symtab_node *referring_node, gimpl
 #ifdef __cplusplus
 static inline void debug_tree(const_tree t)
 {
-	debug_tree(CONST_CAST_TREE(t));
+	debug_tree(const_cast<tree>(t));
 }
 
 static inline void debug_gimple_stmt(const_gimple s)

scripts/gcc-plugins/gcc-common.h static inline void debug_gimple_stmt(const_gimple s) · line 427

Quoted 7 lines
scripts/gcc-plugins/gcc-common.h +1 -1
@@ -422,7 +422,7 @@ static inline void debug_gimple_stmt(const_gimple s)
 	debug_gimple_stmt(CONST_CAST_GIMPLE(s));
 }
 #else
-#define debug_tree(t) debug_tree(CONST_CAST_TREE(t))
+#define debug_tree(t) debug_tree(const_cast<tree>(t))
 #define debug_gimple_stmt(s) debug_gimple_stmt(CONST_CAST_GIMPLE(s))
 #endif

Thanks for this!

Should CONST_CAST_TREE be explicitly defined instead, to match CONST_CAST_GIMPLE in the this header file? It seems weird to have one of two done this way: we should either do both or neither (CONST_CAST_GIMPLE is only used in the header file too).

Is const_cast<gimple> and const_cast<tree> valid back through GCC 8 (earliest Linux-supported GCC)?

-Kees

Signature · 1 line
Kees Cook
#6 lore raw
Quoted 6 lines · Kees Cook

Thanks for this!

Should CONST_CAST_TREE be explicitly defined instead, to match CONST_CAST_GIMPLE in the this header file? It seems weird to have one of two done this way: we should either do both or neither (CONST_CAST_GIMPLE is only used in the header file too).

My first idea was to simplay guard this depending on the gcc version, since the CONST_CAST_TREE type changed from (union tree_node *) to tree. But the typedef union tree_node *tree (in gcc source: gcc/coretypes.h) is already there in gcc-8, and const_cast is an old c++ feature.

Quoted 2 lines

Is const_cast<gimple> and const_cast<tree> valid back through GCC 8 (earliest Linux-supported GCC)?

I successfully compiled and booted linux 6.19.8 with my patch applied with gcc-8 (Debian 8.3.0-7) 8.3.0, so it think this patch does work with all supported gcc versions and a guard is not needed indeed.

I tried to minimize the changes, since I don't really know how gcc plugins actually work. But changing CONST_CAST_GIMPLE to const_cast<gimple>, too, should not fail since that's now a simple text replacement.

Ingo

Signature · 1 line
const_cast<long double>(Λ)