[PATCH 04/17] init: Add __noreorder and mark initcalls __noreorder

From: Andi Kleen
Date: Thu Mar 21 2019 - 18:01:09 EST


From: Andi Kleen <ak@xxxxxxxxxxxxxxx>

gcc 5 has a new no_reorder attribute that prevents top level
reordering only for that symbol.

Kernels don't like any reordering of initcalls between files, as several
initcalls depend on each other.

Add a __noreorder wrapper for the no_reorder attribute and use
it for initcalls.

LTO previously needed to use -fno-toplevel-reordering to prevent boot
failures, but with noreorder this is not needed.

I believe the patch is useful even without LTO because it clearly
documents this dependency in the source.

Signed-off-by: Andi Kleen <ak@xxxxxxxxxxxxxxx>
---
include/linux/compiler_attributes.h | 11 +++++++++++
include/linux/init.h | 2 +-
2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/include/linux/compiler_attributes.h b/include/linux/compiler_attributes.h
index 6b318efd8a74..1c44ef9034bb 100644
--- a/include/linux/compiler_attributes.h
+++ b/include/linux/compiler_attributes.h
@@ -39,6 +39,7 @@
# define __GCC4_has_attribute___externally_visible__ 1
# define __GCC4_has_attribute___noclone__ 1
# define __GCC4_has_attribute___nonstring__ 0
+# define __GCC4_has_attribute___no_reorder__ 0
# define __GCC4_has_attribute___no_sanitize_address__ (__GNUC_MINOR__ >= 8)
#endif

@@ -253,4 +254,14 @@
*/
#define __weak __attribute__((__weak__))

+/*
+ * https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes
+ */
+
+#if __has_attribute(__no_reorder__)
+#define __noreorder __attribute__((no_reorder))
+#else
+#define __noreorder
+#endif
+
#endif /* __LINUX_COMPILER_ATTRIBUTES_H */
diff --git a/include/linux/init.h b/include/linux/init.h
index 5255069f5a9f..49d032916604 100644
--- a/include/linux/init.h
+++ b/include/linux/init.h
@@ -190,7 +190,7 @@ extern bool initcall_debug;
".previous \n");
#else
#define ___define_initcall(fn, id, __sec) \
- static initcall_t __initcall_##fn##id __used \
+ static initcall_t __initcall_##fn##id __used __noreorder \
__attribute__((__section__(#__sec ".init"))) = fn;
#endif

--
2.20.1