public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Szabolcs Nagy <szabolcs.nagy@arm.com>
Cc: "H.J. Lu" <hjl.tools@gmail.com>,  libc-alpha@sourceware.org
Subject: Re: [PATCH] Linux: Support non-variadic calls to prctl (bug 29770)
Date: Mon, 04 Sep 2023 16:46:32 +0200	[thread overview]
Message-ID: <8734zuuhbr.fsf@oldenburg3.str.redhat.com> (raw)
In-Reply-To: <Y25Nqxi+lSpI4ok3@arm.com> (Szabolcs Nagy's message of "Fri, 11 Nov 2022 13:27:07 +0000")

* Szabolcs Nagy:

>> I don't think that's true for our current ABIs.  They support
>> unprototyped calls, and by extension this also means that calls through
>> a variadic prototype to a prototyped non-variadic function must work as
>> well.  There are other ABIs which do not work this way, but glibc hasn't
>> been ported to them (and it's unclear how useful they would be for
>> GNU/Linux).
>
> this is not true in general.
>
> unprototyped call to variadic functions is not valid in c.

It is valid C before C99.

GCC still accepts unprotyped calls with a warning in all C language
modes, which is why I think we need to keep supporting it.

> so unprototyped call abi does not have to match both the
> variadic and non-variadic call abi. (only non-variadic calls
> with arg types that promote to themselves need to work.)

It's true that the ABI does not have to match exactly.  We already have
several ABIs where non-variadic calls to functions implemented as
variadic functions fail.  to my knowledge, we do not have something in
the other direction (and we really can't, for pre-C99 support).

The patch I posted avoids an ABI break on powerpc64le.

> e.g. on arm variadic functions always take float args following the
> soft float abi, but an unprototyped call with double args uses the
> hard float abi on armhf (int vs float regs).

How do you maintain C89 compatibility with such an ABI?  I assume the
difference is only in the non-variadic part.  For the variadic part,
float needs to be promoted to double.

> i guess the prctl case works on existing abis now, but i think
> future abis might want different variadic call abi (morello is an
> example, though that's an experimental target).

The ABIs are already different today on powerpc64le today, even for
prctl.  Variadic functions on powerpc64le assume additional setup by the
caller, which does not happen with a non-variadic call.

The man-pages project used to document prctl as a non-variadic function.

> prctl is nasty because the arguments are often passed with the
> wrong type (e.g. int arguments instead of unsigned long) and
> with variadic prototype this can pass wrong value (e.g. non-zero
> top bits on 64bit targets) down to the kernel. unfortunately
> whatever glibc does internally won't solve this issue: the public
> API would need to change.

The C wrapper I'm fixing tries to solve this for the ILP32 with 64-bit
syscall registers case.  It's just that the original fix exposes another
bug.

Thanks,
Florian


  reply	other threads:[~2023-09-04 14:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-10 16:07 Florian Weimer
2022-11-10 18:43 ` H.J. Lu
2022-11-10 19:18   ` Florian Weimer
2022-11-10 19:55     ` H.J. Lu
2022-11-10 20:08       ` Florian Weimer
2022-11-11 13:27         ` Szabolcs Nagy
2023-09-04 14:46           ` Florian Weimer [this message]
2023-09-04 16:37             ` Szabolcs Nagy
2022-11-10 20:34 ` H.J. Lu
2022-11-10 20:41   ` Florian Weimer

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=8734zuuhbr.fsf@oldenburg3.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=hjl.tools@gmail.com \
    --cc=libc-alpha@sourceware.org \
    --cc=szabolcs.nagy@arm.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).