Re: [PATCH] compiler-gcc.h: Disable __retain on gcc-11

From: Miguel Ojeda
Date: Tue Sep 24 2024 - 13:21:31 EST


On Tue, Sep 24, 2024 at 3:55 PM Geert Uytterhoeven
<geert+renesas@xxxxxxxxx> wrote:
>
> All my gcc-11 compilers (Ubuntu 11.4.0-1ubuntu1~22.04) claim to support
> the __retain__ attribute, but only riscv64-linux-gnu-gcc-11 and
> x86_64-linux-gnu-gcc-11 (not x86_64-linux-gnux32-gcc-11!) actually do.
> The arm-linux-gnueabi-gcc-11.5.0 compiler from kernel.org crosstool
> fails in the same way:
>
> error: ‘retain’ attribute ignored [-Werror=attributes]

That appears to be the case indeed:

https://godbolt.org/z/78Gj94vMW

The `.section` does not get emitted, so the warning appears to be
right, but we cannot trust `__has_attribute` for this :(

> Fixes: 0a5d3258d7c97295 ("compiler_types.h: Define __retain for __attribute__((__retain__))")

Nit: 12 char hash.

> +/*
> + * Most 11.x compilers claim to support it, but only riscv64-linux-gnu-gcc and
> + * x86_64-linux-gnu-gcc actually do.
> + */

Just to confirm: did you try all? If not, perhaps we should say "at
least X does not work" instead.

> +#if GCC_VERSION < 120000
> +#undef __retain
> +#define __retain
> +#endif

Should this go into the conditional in `compiler_types.h` instead? And
perhaps the `__has__attribute` test removed for GCC?

Even if we keep it here, I think at least a comment there should be
added, since it says GCC >= 11 supports it, which can be confusing if
one is not aware of this other thing in this file.

Thanks!

Cheers,
Miguel