Re: [PATCH 2/3] selftests/nolibc: cast execve() argv string to character pointer

From: Thomas Weißschuh

Date: Fri May 22 2026 - 17:40:31 EST


On 2026-05-22 19:48:07+0100, David Laight wrote:
> On Fri, 22 May 2026 16:39:58 +0200
> Thomas Weißschuh <linux@xxxxxxxxxxxxxx> wrote:
> > On 2026-05-21 19:15:58+0100, David Laight wrote:
> > > On Thu, 21 May 2026 18:29:30 +0200
> > > Thomas Weißschuh <linux@xxxxxxxxxxxxxx> wrote:
> > >
> > > > The existing code would trigger a warning under -Wwrite-strings which is
> > > > about to be enabled. execve() is specified as not modifying the argv
> > > > array, but the exact semantics are not representable in the type system.
> > >
> > > I suspect you'll have to fix it again to avoid 'casting away const'.
> >
> > Where would this warning be coming from? Which compiler flags are needed?
> > Afaik it is legal to cast away const.
>
> IIRC -Wcast-qual

Yes that's it, thanks.

> Lots of things are legal :-)
> The problem with enabling -Wcast-qual (NetBSD's kernel does/did) it is makes
> life annoying when you really do have to do it.
> (From what I remember there weren't really that many.)
> You sort of want an (unconst foo *) cast that won't generate a warning when
> a simple (foo *) cast would.

There seem to be a fair amount of standard C APIs which require such
casts, for example strstr(). Also the UAPI headers currently emit such
warnings. So I am not sure if it makes sense to try to get nolibc
compile with this warning.

> > > Can you use something like (char[]){"/"} ?
> >
> > That looks good. However if this issue is real we will also have it in
> > nolibc's errno.h. There I don't want to use this pattern, as it requires
> > more memory.
>
> You can move a string from .rodata to .data easily enough.
> Doesn't change the memory footprint.

When using the proposed pattern in errno.h I get plus 4 bytes of .bss
usage for each variable. While it doesn't make a difference in the
binary, at runtime these bytes are quite wasted.
I didn't look closely at it yet, but the compiler could be reusing a
single empty string in .rodata for all different users, while the .data
one needs to be duplicated for each one.

So I think the current version, casting to (char *), is still the
best aproach for now.

> Not relevant for nolibc, but initialising a short string on stack
> may well be faster than accessing the same string in .rodata because
> of the missed caches miss (if you get what I mean).

Ack.


Thomas