[PATCH 37/46] Compiler attributes, lto: disable __flatten with LTO

From: Jiri Slaby (SUSE)
Date: Mon Nov 14 2022 - 06:48:21 EST


From: Andi Kleen <andi@xxxxxxxxxxxxxx>

Using __flatten causes a simple gcc 12 LTO build not fit into 16GB
anymore. Disable flatten with LTO. With gcc 12, the build still does not
finish linking in 10 minutes, eating 40GB of RAM at that point.

There is an upstream bug about this:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107014

Until this is resolved, simply disable __flatten with LTO.

In the future, instead of this patch, we should likely drop __flatten
and its only user (pcpu_build_alloc_info()) and use always_inline to all
functions which shall be inlined there.

Cc: Miguel Ojeda <ojeda@xxxxxxxxxx>
Cc: Nick Desaulniers <ndesaulniers@xxxxxxxxxx>
Signed-off-by: Andi Kleen <andi@xxxxxxxxxxxxxx>
Signed-off-by: Martin Liska <mliska@xxxxxxx>
Signed-off-by: Jiri Slaby <jslaby@xxxxxxx>
---
include/linux/compiler_attributes.h | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/include/linux/compiler_attributes.h b/include/linux/compiler_attributes.h
index be6c71fd5ebb..09cf8eebcb0d 100644
--- a/include/linux/compiler_attributes.h
+++ b/include/linux/compiler_attributes.h
@@ -229,7 +229,12 @@
* gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes
* clang: https://clang.llvm.org/docs/AttributeReference.html#flatten
*/
+#ifndef CONFIG_LTO_GCC
# define __flatten __attribute__((flatten))
+#else
+/* Causes very large memory use with gcc in LTO mode */
+# define __flatten
+#endif

/*
* Note the missing underscores.
--
2.38.1