Re: [PATCH] kbuild: change __retain macro for gcc-11

From: Miguel Ojeda
Date: Fri Jun 20 2025 - 09:00:23 EST


On Fri, Jun 20, 2025 at 1:14 PM Arnd Bergmann <arnd@xxxxxxxxxx> 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