diff mbox series

[kvm-unit-tests] compiler.h: Make __always_inline match glibc definition, preventing redefine error

Message ID 20230327122248.2693856-1-npiggin@gmail.com (mailing list archive)
State New, archived
Headers show
Series [kvm-unit-tests] compiler.h: Make __always_inline match glibc definition, preventing redefine error | expand

Commit Message

Nicholas Piggin March 27, 2023, 12:22 p.m. UTC
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.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
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(-)

Comments

Thomas Huth March 27, 2023, 6:25 p.m. UTC | #1
On 27/03/2023 14.22, Nicholas Piggin wrote:
> 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.
> 
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
> 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(-)
> 
> diff --git a/lib/linux/compiler.h b/lib/linux/compiler.h
> index 6f565e4..bf3313b 100644
> --- a/lib/linux/compiler.h
> +++ b/lib/linux/compiler.h
> @@ -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__))
>   

Thanks, applied.

  Thomas
diff mbox series

Patch

diff --git a/lib/linux/compiler.h b/lib/linux/compiler.h
index 6f565e4..bf3313b 100644
--- a/lib/linux/compiler.h
+++ b/lib/linux/compiler.h
@@ -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__))