Skip to contentSkip to conversation

compiler.h: Make __always_inline match glibc definition, preventing redefine error

PATCH Applied Nicholas Piggin 2 participants 2 messages Mar 27, 2023 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 compiler.h: Make __always_inline match glibc definition, preventing redefine error

This makes __always_inline match glibc's cdefs.h file, which prevents redefinition errors which can happen e.g., if glibc limits.h is included before kvm-unit-tests compiler.h.

---
I ran into this with some powerpc patches. I since changed include ordering in that series so it no longer depends on this change, but it might be good to have this to be less fragile.

Thanks,
Nick

 lib/linux/compiler.h | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
lib/linux/compiler.h +8 -1
index 6f565e4..bf3313b 100644
@@ -45,7 +45,14 @@
 
 #define barrier()	asm volatile("" : : : "memory")
 
-#define __always_inline	inline __attribute__((always_inline))
+/*
+ * As glibc's sys/cdefs.h does, this undefines __always_inline because
+ * Linux's stddef.h kernel header also defines it in an incompatible
+ * way.
+ */
+#undef __always_inline
+#define __always_inline __inline __attribute__ ((__always_inline__))
+
 #define noinline __attribute__((noinline))
 #define __unused __attribute__((__unused__))
 
Signature · 1 line
2.37.2
Applied
#1 lore raw
Quoted 26 lines · Nicholas Piggin

This makes __always_inline match glibc's cdefs.h file, which prevents redefinition errors which can happen e.g., if glibc limits.h is included before kvm-unit-tests compiler.h.

---
I ran into this with some powerpc patches. I since changed include ordering in that series so it no longer depends on this change, but it might be good to have this to be less fragile.

Thanks,
Nick

  lib/linux/compiler.h | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)
lib/linux/compiler.h +1 -1
index 6f565e4..bf3313b 100644
@@ -45,7 +45,14 @@
 
  #define barrier()	asm volatile("" : : : "memory")
 
-#define __always_inline	inline __attribute__((always_inline))
+/*

lib/linux/compiler.h line 58

Quoted 10 lines
lib/linux/compiler.h +7 -0
+ * As glibc's sys/cdefs.h does, this undefines __always_inline because
+ * Linux's stddef.h kernel header also defines it in an incompatible
+ * way.
+ */
+#undef __always_inline
+#define __always_inline __inline __attribute__ ((__always_inline__))
+
  #define noinline __attribute__((noinline))
  #define __unused __attribute__((__unused__))
 

Thanks, applied.

Thomas