public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Willy Tarreau <w@1wt.eu>
To: "Thomas Weißschuh" <linux@weissschuh.net>
Cc: Shuah Khan <shuah@kernel.org>,
	linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
	Yuan Tan <tanyuan@tinylab.org>, Zhangjin Wu <falcon@tinylab.org>
Subject: Re: [PATCH v3 05/14] tools/nolibc: stdint: use int for size_t on 32bit
Date: Sat, 5 Aug 2023 18:35:24 +0200	[thread overview]
Message-ID: <20230805163524.GD15284@1wt.eu> (raw)
In-Reply-To: <44f1bab4-9d0a-4e7d-a73b-2c00c6029070@t-8ch.de>

On Sat, Aug 05, 2023 at 06:25:52PM +0200, Thomas Weißschuh wrote:
> On 2023-08-05 18:19:29+0200, Willy Tarreau wrote:
> > Hi Thomas,
> > 
> > On Thu, Aug 03, 2023 at 09:28:49AM +0200, Thomas Weißschuh wrote:
> > > Otherwise both gcc and clang may generate warnings about type
> > > mismatches:
> > > 
> > > sysroot/mips/include/string.h:12:14: warning: mismatch in argument 1 type of built-in function 'malloc'; expected 'unsigned int' [-Wbuiltin-declaration-mismatch]
> > >    12 | static void *malloc(size_t len);
> > >       |              ^~~~~~
> > > 
> > > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> > > ---
> > >  tools/include/nolibc/stdint.h | 4 ++++
> > >  1 file changed, 4 insertions(+)
> > > 
> > > diff --git a/tools/include/nolibc/stdint.h b/tools/include/nolibc/stdint.h
> > > index 4b282435a59a..0f390c3028d8 100644
> > > --- a/tools/include/nolibc/stdint.h
> > > +++ b/tools/include/nolibc/stdint.h
> > > @@ -15,7 +15,11 @@ typedef unsigned int       uint32_t;
> > >  typedef   signed int        int32_t;
> > >  typedef unsigned long long uint64_t;
> > >  typedef   signed long long  int64_t;
> > > +#if __SIZE_WIDTH__ == 64
> > >  typedef unsigned long        size_t;
> > > +#else
> > > +typedef unsigned int         size_t;
> > > +#endif
> > 
> > This one breaks gcc < 7 for me because __SIZE_WIDTH__ is not defined
> > there. However I could trace __SIZE_TYPE__ to be defined since at least
> > gcc-3.4 so instead we can do this, which will always match the type set
> > by the compiler (either "unsigned int" or "unsigned long int") :
> > 
> >   #ifdef __SIZE_TYPE__
> >   typedef __SIZE_TYPE__ size_t;
> >   #else
> >   typedef unsigned long size_t;
> >   #endif
> 
> Sounds good. But do we need the fallback?

I don't know. It's always the same when using a compiler-defined macro
that you discover when you need it, you never know how spread it is.
At least I've also found it in clang as old as 3.8, so maybe it can be
considered safe enough.

> Further below we are also unconditionally using preprocessor-defines
> like __INT_MAX__ and __LONG_MAX__.
> 
> So I guess we can drop the proposed #ifdef.

I'll try with this, the risk is quite low anyway (famous last words).

> > Please just let me know if you want me to modify your patch accordingly.
> > I'm still continuing the tests.
> 
> Feel free to modify the patch.

Will do, thanks!

Willy

  reply	other threads:[~2023-08-05 16:35 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-03  7:28 [PATCH v3 00/14] tools/nolibc: enable compiler warnings Thomas Weißschuh
2023-08-03  7:28 ` [PATCH v3 01/14] tools/nolibc: drop unused variables Thomas Weißschuh
2023-08-03  7:28 ` [PATCH v3 02/14] tools/nolibc: fix return type of getpagesize() Thomas Weißschuh
2023-08-03  7:28 ` [PATCH v3 03/14] tools/nolibc: setvbuf: avoid unused parameter warnings Thomas Weißschuh
2023-08-03  7:28 ` [PATCH v3 04/14] tools/nolibc: sys: avoid implicit sign cast Thomas Weißschuh
2023-08-03  7:28 ` [PATCH v3 05/14] tools/nolibc: stdint: use int for size_t on 32bit Thomas Weißschuh
2023-08-05 16:19   ` Willy Tarreau
2023-08-05 16:25     ` Thomas Weißschuh
2023-08-05 16:35       ` Willy Tarreau [this message]
2023-08-03  7:28 ` [PATCH v3 06/14] selftests/nolibc: drop unused variables Thomas Weißschuh
2023-08-03  7:28 ` [PATCH v3 07/14] selftests/nolibc: mark test helpers as potentially unused Thomas Weißschuh
2023-08-03  7:28 ` [PATCH v3 08/14] selftests/nolibc: make functions static if possible Thomas Weißschuh
2023-08-03  7:28 ` [PATCH v3 09/14] selftests/nolibc: avoid unused parameter warnings Thomas Weißschuh
2023-08-03  7:28 ` [PATCH v3 10/14] selftests/nolibc: avoid sign-compare warnings Thomas Weißschuh
2023-08-03  7:28 ` [PATCH v3 11/14] selftests/nolibc: use correct return type for read() and write() Thomas Weißschuh
2023-08-03  7:28 ` [PATCH v3 12/14] selftests/nolibc: prevent out of bounds access in expect_vfprintf Thomas Weißschuh
2023-08-03  7:28 ` [PATCH v3 13/14] selftests/nolibc: don't strip nolibc-test Thomas Weißschuh
2023-08-03  7:28 ` [PATCH v3 14/14] selftests/nolibc: enable compiler warnings Thomas Weißschuh
2023-08-05 16:23   ` Willy Tarreau
2023-08-05 16:54 ` [PATCH v3 00/14] tools/nolibc: " Willy Tarreau

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=20230805163524.GD15284@1wt.eu \
    --to=w@1wt.eu \
    --cc=falcon@tinylab.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux@weissschuh.net \
    --cc=shuah@kernel.org \
    --cc=tanyuan@tinylab.org \
    /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