* [PATCH] kbuild: change __retain macro for gcc-11
@ 2025-06-20 11:13 Arnd Bergmann
2025-06-20 13:00 ` Miguel Ojeda
0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2025-06-20 11:13 UTC (permalink / raw)
To: Nathan Chancellor, Tony Ambardar, Daniel Borkmann
Cc: Arnd Bergmann, Nick Desaulniers, Bill Wendling, Justin Stitt,
Kees Cook, Miguel Ojeda, Andrew Morton, linux-kernel, llvm
From: Arnd Bergmann <arnd@arndb.de>
Building kernels with CONFIG_LD_DEAD_CODE_DATA_ELIMINATION using gcc-11
causes compiler warnings:
kernel/cgroup/rstat.c:65:1: error: 'retain' attribute ignored [-Werror=attributes]
It appears that this version reports __has_attribute(__retain__) as true
but doesn't actually support the feature.
Fixes: 0a5d3258d7c9 ("compiler_types.h: Define __retain for __attribute__((__retain__))")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
include/linux/compiler_types.h | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
index 4684277bdd3b..c295b376a305 100644
--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -153,12 +153,15 @@ static inline void __chk_io_ptr(const volatile void __iomem *ptr) { }
* being optimized out, but operates at the compiler/IR-level and may still
* allow unintended removal of objects during linking.
*
- * Optional: only supported since gcc >= 11, clang >= 13
+ * Optional: only supported since gcc >= 12, clang >= 13
+ *
+ * On gcc-11 the feature is reported to be present but causes build warnings.
*
* gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-retain-function-attribute
* clang: https://clang.llvm.org/docs/AttributeReference.html#retain
*/
#if __has_attribute(__retain__) && \
+ (__GNUC__ != 11) && \
(defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || \
defined(CONFIG_LTO_CLANG))
# define __retain __attribute__((__retain__))
--
2.39.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] kbuild: change __retain macro for gcc-11
2025-06-20 11:13 [PATCH] kbuild: change __retain macro for gcc-11 Arnd Bergmann
@ 2025-06-20 13:00 ` Miguel Ojeda
2025-06-20 13:02 ` Miguel Ojeda
0 siblings, 1 reply; 3+ messages in thread
From: Miguel Ojeda @ 2025-06-20 13:00 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Nathan Chancellor, Tony Ambardar, Daniel Borkmann, Arnd Bergmann,
Nick Desaulniers, Bill Wendling, Justin Stitt, Kees Cook,
Miguel Ojeda, Andrew Morton, linux-kernel, llvm
On Fri, Jun 20, 2025 at 1:14 PM Arnd Bergmann <arnd@kernel.org> wrote:
>
> Building kernels with CONFIG_LD_DEAD_CODE_DATA_ELIMINATION using gcc-11
> causes compiler warnings:
>
> kernel/cgroup/rstat.c:65:1: error: 'retain' attribute ignored [-Werror=attributes]
>
> It appears that this version reports __has_attribute(__retain__) as true
> but doesn't actually support the feature.
Hmm... I can't reproduce the error in Compiler Explorer:
https://godbolt.org/z/roMrfjxGM
And locally with a GCC 11.4 I can see the attribute keeping a function
in the final binary when marked as `retain` against `retain` against
`-ffunction-sections -Wl,--gc-sections`.
Is something else going on?
Cheers,
Miguel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] kbuild: change __retain macro for gcc-11
2025-06-20 13:00 ` Miguel Ojeda
@ 2025-06-20 13:02 ` Miguel Ojeda
0 siblings, 0 replies; 3+ messages in thread
From: Miguel Ojeda @ 2025-06-20 13:02 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Nathan Chancellor, Tony Ambardar, Daniel Borkmann, Arnd Bergmann,
Nick Desaulniers, Bill Wendling, Justin Stitt, Kees Cook,
Miguel Ojeda, Andrew Morton, linux-kernel, llvm
On Fri, Jun 20, 2025 at 3:00 PM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> Is something else going on?
Ah, I see -- it does error on arm and arm64, but not x86:
https://godbolt.org/z/G4Pbd9Gar
So it is architecture dependent.
Cheers,
Miguel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-06-20 13:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-20 11:13 [PATCH] kbuild: change __retain macro for gcc-11 Arnd Bergmann
2025-06-20 13:00 ` Miguel Ojeda
2025-06-20 13:02 ` Miguel Ojeda
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).