The CHERI port of Linux, similar to CheriBSD, now uses __has_feature() to check whether the compiler supports CHERI and provides the proper flags to enable it. However, __has_feature() only exists in Clang and recent versions of GCC. Building with older GCC versions that do not define this macro will cause the Linux build to fail.
This commit adds backward compatibility for such cases by defining __has_feature() to 0. In the corner case of building with an older CHERI-GCC that uses CHERI ABIs, it defines __has_feature(capabilities) to 1.
Signed-off-by: Hesham Almatary Hesham.Almatary@cl.cam.ac.uk --- include/linux/compiler_types.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h index f67fc7b9d..4677d9b17 100644 --- a/include/linux/compiler_types.h +++ b/include/linux/compiler_types.h @@ -11,6 +11,25 @@ #define __has_builtin(x) (0) #endif
+/* + * __has_feature is supported in Clang and GCC >= 14. + * For older GCC versions, define __has_feature manually. + */ +#ifndef __has_feature +#define __has_feature(x) 0 +#endif + +/* + * Provide backward compatibility for older CHERI GCC toolchains that + * may not define __has_feature, but still support CHERI-enabled code. + */ +#if !__has_feature(capabilities) && \ + (defined(__CHERI__) || defined(__CHERI_HYBRID__) || \ + defined(__CHERI_PURE_CAPABILITY__)) +#undef __has_feature +#define __has_feature(x) (__builtin_strcmp(#x, "capabilities") == 0) +#endif + #ifndef __ASSEMBLY__
/*
linux-morello@op-lists.linaro.org