tools compiler.h: Add OPTIMIZER_HIDE_VAR()
authorMark Brown <broonie@kernel.org>
Thu, 27 Jul 2023 23:26:13 +0000 (00:26 +0100)
committerWill Deacon <will@kernel.org>
Fri, 4 Aug 2023 16:36:52 +0000 (17:36 +0100)
Port over the definition of OPTIMIZER_HIDE_VAR() so we can use it in
kselftests.

Signed-off-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20230728-arm64-signal-memcpy-fix-v4-2-0c1290db5d46@kernel.org
Signed-off-by: Will Deacon <will@kernel.org>
tools/include/linux/compiler.h

index 9d36c8c..f75cced 100644 (file)
@@ -190,4 +190,10 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
 #define ___PASTE(a, b) a##b
 #define __PASTE(a, b) ___PASTE(a, b)
 
+#ifndef OPTIMIZER_HIDE_VAR
+/* Make the optimizer believe the variable can be manipulated arbitrarily. */
+#define OPTIMIZER_HIDE_VAR(var)                                                \
+       __asm__ ("" : "=r" (var) : "0" (var))
+#endif
+
 #endif /* _TOOLS_LINUX_COMPILER_H */