Some code includes the __used macro to prevent functions and data from being optimized out. This macro implements __attribute__((__used__)), which operates at the compiler and IR-level, and so still allows a linker to remove objects intended to be kept.
Compilers supporting __attribute__((__retain__)) can address this gap by setting the flag SHF_GNU_RETAIN on the section of a function/variable, indicating to the linker the object should be retained. This attribute is available since gcc 11, clang 13, and binutils 2.36.
Provide a __retain macro implementing __attribute__((__retain__)), whose first user will be the '__bpf_kfunc' tag.
Link: https://lore.kernel.org/bpf/ZlmGoT9KiYLZd91S@krava/T/ Cc: stable@vger.kernel.org # v6.6+ Signed-off-by: Tony Ambardar Tony.Ambardar@gmail.com --- include/linux/compiler_attributes.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
diff --git a/include/linux/compiler_attributes.h b/include/linux/compiler_attributes.h index 32284cd26d52..1c22e1a734dc 100644 --- a/include/linux/compiler_attributes.h +++ b/include/linux/compiler_attributes.h @@ -326,6 +326,20 @@ */ #define __pure __attribute__((__pure__))
+/* + * Optional: only supported since gcc >= 11, clang >= 13 + * + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-ret... + * clang: https://clang.llvm.org/docs/AttributeReference.html#retain + */ +#if __has_attribute(__retain__) && \ + (defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || \ + defined(CONFIG_LTO_CLANG)) +# define __retain __attribute__((__retain__)) +#else +# define __retain +#endif + /* * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-sec... * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-sec...
On Mon, Jun 3, 2024 at 2:16 PM Tony Ambardar tony.ambardar@gmail.com wrote:
+#if __has_attribute(__retain__) && \
(defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || \
defined(CONFIG_LTO_CLANG))
Since this attribute depends on the configuration, please move it to `compiler_types.h` instead.
Cheers, Miguel
On Mon, Jun 03, 2024 at 03:57:38PM +0200, Miguel Ojeda wrote:
On Mon, Jun 3, 2024 at 2:16 PM Tony Ambardar tony.ambardar@gmail.com wrote:
+#if __has_attribute(__retain__) && \
(defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || \
defined(CONFIG_LTO_CLANG))
Since this attribute depends on the configuration, please move it to `compiler_types.h` instead.
Noted and thanks for clarifying; I'll change in v2.
Cheers, Tony
Cheers, Miguel
linux-stable-mirror@lists.linaro.org