mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Patrick Oppenlander <patrick.oppenlander@gmail.com>
Cc: musl@lists.openwall.com, unicorn_wang <unicorn_wang@outlook.com>
Subject: Re: [musl] [Question] about arch/riscv64/crt_arch.h
Date: Tue, 27 Oct 2020 21:50:57 -0400	[thread overview]
Message-ID: <20201028015057.GY534@brightrain.aerifal.cx> (raw)
In-Reply-To: <CAEg67G=yLdAa8Q66N6K-7z7UKL54ninhsL35T66rRm7G=B3ySg@mail.gmail.com>

On Wed, Oct 28, 2020 at 12:48:02PM +1100, Patrick Oppenlander wrote:
> On Wed, Oct 28, 2020 at 12:40 PM Chen Wang <unicorn_wang@outlook.com> wrote:
> >
> > hi,
> > I'm reading musl (1.2.1) code for riscv. In arch/riscv64/crt_arch.h,
> >
> > __asm__(
> > ......
> > "andi sp, sp, -16\n\t" // <--- why do we need this?
> > "tail " START "_c"
> > );
> >
> 
> I'm not familiar with RISC-V, but it's there to guarantee that the
> stack is 16-byte aligned which must be either an architectural or ABI
> requirement.
> 
> Perhaps the kernel can start the process with a more relaxed stack
> alignment. Otherwise it's there for safety (paranoia).

Regardless of whether the kernel can, the dynamic linker can, because
it peels off a possibly odd number of 8-byte arguments when executed
as a command:

	/lib/ld-musl-riscv64.so.1 [options] your_program [args]

The ELF entry point contract is just that SP point to the argument
vector, not that it be a valid stack pointer for entering a C
function. So the entry point has to align the stack before
transferring control to C.

Rich

      reply	other threads:[~2020-10-28  1:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-28  1:40 Chen Wang
2020-10-28  1:48 ` Patrick Oppenlander
2020-10-28  1:50   ` 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=20201028015057.GY534@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    --cc=patrick.oppenlander@gmail.com \
    --cc=unicorn_wang@outlook.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).