[PATCH v4 next 01/23] tools/nolibc: Add _NOLIBC_OPTIMIZER_HIDE_VAR() to compiler.h

david.laight.linux@gmail.com posted 23 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH v4 next 01/23] tools/nolibc: Add _NOLIBC_OPTIMIZER_HIDE_VAR() to compiler.h
Posted by david.laight.linux@gmail.com 1 month, 1 week ago
From: David Laight <david.laight.linux@gmail.com>

Needed to stop compiler 'optimisations' bloating code.
Equivalent to the definition in include/linux/compiler.h

Signed-off-by: David Laight <david.laight.linux@gmail.com>
---
Changes for v4:
- Remove #if guard

 tools/include/nolibc/compiler.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/include/nolibc/compiler.h b/tools/include/nolibc/compiler.h
index a8c7619dcdde..f03f84cfadce 100644
--- a/tools/include/nolibc/compiler.h
+++ b/tools/include/nolibc/compiler.h
@@ -71,4 +71,7 @@
 #  define __nolibc_static_assert(_t)
 #endif
 
+/* Make the optimizer believe the variable can be manipulated arbitrarily. */
+#define _NOLIBC_OPTIMIZER_HIDE_VAR(var)	__asm__ ("" : "+r" (var))
+
 #endif /* _NOLIBC_COMPILER_H */
-- 
2.39.5
Re: [PATCH v4 next 01/23] tools/nolibc: Add _NOLIBC_OPTIMIZER_HIDE_VAR() to compiler.h
Posted by Willy Tarreau 1 month ago
On Mon, Mar 02, 2026 at 10:17:53AM +0000, david.laight.linux@gmail.com wrote:
> From: David Laight <david.laight.linux@gmail.com>
> 
> Needed to stop compiler 'optimisations' bloating code.
> Equivalent to the definition in include/linux/compiler.h

Can definitely be useful from time to time, I'm doing similar things
in my programs all the time and after I regret not having centralized
it. Here it will help contributors who could get discouraged by code
size variations caused by their tiny changes.

> Signed-off-by: David Laight <david.laight.linux@gmail.com>

Acked-by: Willy Tarreau <w@1wt.eu>

Willy

> ---
> Changes for v4:
> - Remove #if guard
> 
>  tools/include/nolibc/compiler.h | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/tools/include/nolibc/compiler.h b/tools/include/nolibc/compiler.h
> index a8c7619dcdde..f03f84cfadce 100644
> --- a/tools/include/nolibc/compiler.h
> +++ b/tools/include/nolibc/compiler.h
> @@ -71,4 +71,7 @@
>  #  define __nolibc_static_assert(_t)
>  #endif
>  
> +/* Make the optimizer believe the variable can be manipulated arbitrarily. */
> +#define _NOLIBC_OPTIMIZER_HIDE_VAR(var)	__asm__ ("" : "+r" (var))
> +
>  #endif /* _NOLIBC_COMPILER_H */
> -- 
> 2.39.5