From: Willy Tarreau <w@1wt.eu>
To: Zhangjin Wu <falcon@tinylab.org>
Cc: arnd@arndb.de, david.laight@aculab.com,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
thomas@t-8ch.de
Subject: Re: [PATCH] tools/nolibc: fix up size inflate regression
Date: Sun, 6 Aug 2023 15:43:48 +0200 [thread overview]
Message-ID: <20230806134348.GA19145@1wt.eu> (raw)
In-Reply-To: <20230806131921.52453-1-falcon@tinylab.org>
On Sun, Aug 06, 2023 at 09:19:21PM +0800, Zhangjin Wu wrote:
> As reported and suggested by Willy, the inline __sysret() helper
> introduces three types of conversions and increases the size:
Thanks Zhangjin. A few things:
> --- a/tools/include/nolibc/compiler.h
> +++ b/tools/include/nolibc/compiler.h
> @@ -22,4 +22,13 @@
> # define __no_stack_protector __attribute__((__optimize__("-fno-stack-protector")))
> #endif /* defined(__has_attribute) */
>
> +/*
> + * from include/linux/compiler.h
> + *
> + * Whether 'type' is a signed type or an unsigned type. Supports scalar types,
> + * bool and also pointer types.
> + */
> +#define is_signed_type(type) (((type)(-1)) < (type)1)
> +#define is_unsigned_type(type) (!is_signed_type(type))
These names may conflict with application's local definitions. And since
there's a single call place we should probably just inline it instead.
> +#define __sysret(arg) \
> +({ \
> + __typeof__(arg) __sysret_arg = (arg); \
> + if (is_signed_type(__typeof__(arg))) { \
> + if (__sysret_arg < 0) { \
> + SET_ERRNO(-(int)__sysret_arg); \
> + __sysret_arg = -1L; \
> + } \
> + } else { \
> + if ((unsigned long)__sysret_arg >= (unsigned long)-MAX_ERRNO) { \
> + SET_ERRNO(-(int)__sysret_arg); \
> + __sysret_arg = -1L; \
> + } \
> + } \
> + __sysret_arg; \
> +})
I also found during my tests that this one can return a build error if
the arg has "const" in its type, due to the error assignment. We need
to think about reworking it as a ternary evaluation, it will be more
reliable even if less readable. But let's not change this now, I'm on
the changelog already.
> /* Functions in this file only describe syscalls. They're declared static so
> * that the compiler usually decides to inline them while still being allowed
> @@ -94,7 +101,7 @@ void *sbrk(intptr_t inc)
> if (ret && sys_brk(ret + inc) == ret + inc)
> return ret + inc;
>
> - return (void *)__sysret(-ENOMEM);
> + return (void *)__sysret((unsigned long)-ENOMEM);
I noticed that one as well during my tests, but if we're purist, we're
supposed to use (void*) for the cast and not (unsigned long), and it
should allow to get rid of the outer cast.
Regards,
Willy
next prev parent reply other threads:[~2023-08-06 13:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-06 13:19 [PATCH] tools/nolibc: fix up size inflate regression Zhangjin Wu
2023-08-06 13:43 ` Willy Tarreau [this message]
2023-08-06 16:36 ` Zhangjin Wu
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=20230806134348.GA19145@1wt.eu \
--to=w@1wt.eu \
--cc=arnd@arndb.de \
--cc=david.laight@aculab.com \
--cc=falcon@tinylab.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=thomas@t-8ch.de \
/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