From: Ammar Faizi <ammarfaizi2@openresty.com>
To: "Thomas Weißschuh" <linux@weissschuh.net>
Cc: Willy Tarreau <w@1wt.eu>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Linux Kselftest Mailing List <linux-kselftest@vger.kernel.org>,
LLVM Mailing List <llvm@lists.linux.dev>,
Yichun Zhang <yichun@openresty.com>,
Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>,
Shuah Khan <shuah@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <nick.desaulniers+lkml@gmail.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
gwml@gnuweeb.org
Subject: Re: [PATCH 3/4] selftests/nolibc: add abs() range test
Date: Mon, 27 Jul 2026 08:32:58 +0700 [thread overview]
Message-ID: <6a5f7481-124f-48ad-ab44-577b12d33592@openresty.com> (raw)
In-Reply-To: <8bdacaf3-7f93-4095-8875-4c13a273fe3d@t-8ch.de>
On 7/27/26 3:00 AM, Thomas Weißschuh wrote:
>> +/* abs(), labs() and llabs() over the whole range of their argument type */
>> +int test_abs_range(void)
>> +{
>> + int i, ri;
>> + long l, rl;
>> + long long ll, rll;
>
> Reverse xmas?
Fixed for the next revision.
>> +
>> + /*
>> + * Both the inputs and the results have to stay opaque: the compiler
>> + * knows abs() and friends never return a negative value and would
>> + * otherwise fold the comparisons below at build time, which would also
>> + * hide the undefined behavior that is being tested for.
>> + */
>> + i = INT_MIN; l = LONG_MIN; ll = LLONG_MIN;
>> + __asm__ ("" : "+r" (i), "+r" (l), "+r" (ll));
>
> We have _NOLIBC_OPTIMIZER_HIDE_VAR() for this.
Oh, I missed it.
> Maybe it can be made variadic.
Sounds good to me.
Does the following patch look good?
From: Ammar Faizi <ammarfaizi2@openresty.com>
Date: Sun, 26 Jul 2026 13:17:14 -0700
Subject: [PATCH] tools/nolibc: make _NOLIBC_OPTIMIZER_HIDE_VAR() variadic
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The macro only takes a single variable, so code that needs to hide
several at once has to either repeat it or open-code an asm statement
with a list of operands. Accept up to four variables and build the
operand list from them.
Existing single-argument users are unaffected; the code generated for
the callers in stdio.h is unchanged on i386 and x86-64.
Suggested-by: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Ammar Faizi <ammarfaizi2@openresty.com>
---
tools/include/nolibc/compiler.h | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/tools/include/nolibc/compiler.h b/tools/include/nolibc/compiler.h
index f2d7a81d0d7c..ed69f6d26f56 100644
--- a/tools/include/nolibc/compiler.h
+++ b/tools/include/nolibc/compiler.h
@@ -77,8 +77,19 @@
# 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))
+#define __nolibc_hide1(_1) "+r" (_1)
+#define __nolibc_hide2(_1, ...) "+r" (_1), __nolibc_hide1(__VA_ARGS__)
+#define __nolibc_hide3(_1, ...) "+r" (_1), __nolibc_hide2(__VA_ARGS__)
+#define __nolibc_hide4(_1, ...) "+r" (_1), __nolibc_hide3(__VA_ARGS__)
+#define ___nolibc_hide_narg(_1, _2, _3, _4, N, ...) N
+#define __nolibc_hide_narg(...) ___nolibc_hide_narg(__VA_ARGS__, 4, 3, 2, 1)
+#define __nolibc_hide(N, ...) __nolibc_hide##N(__VA_ARGS__)
+#define __nolibc_hide_n(N, ...) __nolibc_hide(N, __VA_ARGS__)
+
+/* Make the optimizer believe the variables can be manipulated arbitrarily. */
+#define _NOLIBC_OPTIMIZER_HIDE_VAR(...) \
+ __asm__ ("" : __nolibc_hide_n(__nolibc_hide_narg(__VA_ARGS__), \
+ __VA_ARGS__))
#if __nolibc_has_feature(undefined_behavior_sanitizer)
# if defined(__clang__)
--
Ammar Faizi
next prev parent reply other threads:[~2026-07-27 1:33 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-26 10:13 [PATCH 0/4] nolibc: syscall() and abs() fixes, plus a cleanup Ammar Faizi
2026-07-26 10:13 ` [PATCH 1/4] tools/nolibc: evaluate syscall() arguments before the arch macros Ammar Faizi
2026-07-26 20:16 ` Thomas Weißschuh
2026-07-27 1:21 ` Ammar Faizi
2026-07-27 3:42 ` Willy Tarreau
2026-07-28 6:53 ` Ammar Faizi
2026-07-27 3:30 ` Willy Tarreau
2026-07-27 16:18 ` Thomas Weißschuh
2026-07-28 6:51 ` Ammar Faizi
2026-07-26 10:13 ` [PATCH 2/4] tools/nolibc: stdlib: avoid signed overflow in abs() and friends Ammar Faizi
2026-07-26 14:13 ` David Laight
2026-07-26 16:01 ` Willy Tarreau
2026-07-27 7:32 ` David Laight
2026-07-27 16:15 ` Thomas Weißschuh
2026-07-28 8:46 ` David Laight
2026-07-28 16:31 ` Thomas Weißschuh
2026-07-28 16:37 ` Ammar Faizi
2026-07-26 10:13 ` [PATCH 3/4] selftests/nolibc: add abs() range test Ammar Faizi
2026-07-26 20:00 ` Thomas Weißschuh
2026-07-27 1:32 ` Ammar Faizi [this message]
2026-07-27 2:01 ` Ammar Faizi
2026-07-27 16:13 ` Thomas Weißschuh
2026-07-28 6:14 ` Ammar Faizi
2026-07-26 10:13 ` [PATCH 4/4] tools/nolibc: remove dead __ARCH_WANT_SYS_OLD_SELECT Ammar Faizi
2026-07-26 20:01 ` Thomas Weißschuh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6a5f7481-124f-48ad-ab44-577b12d33592@openresty.com \
--to=ammarfaizi2@openresty.com \
--cc=alviro.iskandar@gnuweeb.org \
--cc=gwml@gnuweeb.org \
--cc=justinstitt@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=llvm@lists.linux.dev \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=nick.desaulniers+lkml@gmail.com \
--cc=shuah@kernel.org \
--cc=w@1wt.eu \
--cc=yichun@openresty.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®