mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: "Érico Nogueira" <ericonr@disroot.org>
Cc: musl@lists.openwall.com
Subject: Re: [musl] Some pending changes/patches
Date: Sat, 30 Jan 2021 16:40:20 -0500	[thread overview]
Message-ID: <20210130214020.GQ23432@brightrain.aerifal.cx> (raw)
In-Reply-To: <C8LOU9XLKVEU.3L90RP56PTHYV@mussels>

On Sun, Jan 17, 2021 at 04:42:31PM -0300, Érico Nogueira wrote:
> - fix type for __libc_start_main. In crt1.c and rcrt1.c, it is:
> 
> int __libc_start_main(int (*)(), int, char **,
> 	void (*)(), void(*)(), void(*)());
> 
> but in __libc_start_main.c, it is
> 
> int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv)
> 
> as far as I can tell the fix is simple and the signature mismatch isn't
> an issue. Since I don't know the context for the mismatch and therefore
> wouldn't be able to write an appropriate commit message, I refrained
> from sending a patch for it.

I've wanted to fix this, but actually I don't know if we can; it needs
analysis. Defining the function with the unused junk args imposes an
ABI constraint that the caller (__libc_start_main) is entered with
argument space for 6 arguments. On some pass-by-register archs this is
not a constraint at all, but on pass-by-stack archs or archs where the
ABI requires the caller to reserve stack slots for the callee to spill
argument registers into, it does. If there's not sufficient space
reserved here, __libc_start_main could clobber space that overlaps
with argv[].

Now, crt1.c makes the call correctly with space reserved for 6
arguments. But prior to the switch to crt1.c and crt_arch.h, there was
separate per-arch asm making the call to __libc_start_main, and some
archs might have omitted the stack space for these slots. So this old
asm needs to be read to determine if there may be binaries calling the
function as if it were a 3-arg one.

I *think* we're okay here. The asm was removed in commit
6fef8cafbd0f6f185897bc87feb1ff66e2e204e1, and at that time (2015), all
the remaining asm versions seemed to still be passing the extra 3
args, despite __libc_start_main having dropped use of them much
earlier (2013, commit 7586360badcae6e73f04eb1b8189ce630281c4b2). But I
would like to review it further before making a change here.

Rich

      parent reply	other threads:[~2021-01-30 21:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-17 19:42 Érico Nogueira
2021-01-18  4:11 ` Érico Nogueira
2021-01-30 21:40 ` Rich Felker [this message]

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=20210130214020.GQ23432@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=ericonr@disroot.org \
    --cc=musl@lists.openwall.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).