From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SUBJ_OBFU_PUNCT_FEW autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 22074 invoked from network); 28 Oct 2020 01:51:13 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 28 Oct 2020 01:51:13 -0000 Received: (qmail 30586 invoked by uid 550); 28 Oct 2020 01:51:11 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 30565 invoked from network); 28 Oct 2020 01:51:10 -0000 Date: Tue, 27 Oct 2020 21:50:57 -0400 From: Rich Felker To: Patrick Oppenlander Cc: musl@lists.openwall.com, unicorn_wang Message-ID: <20201028015057.GY534@brightrain.aerifal.cx> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] [Question] about arch/riscv64/crt_arch.h On Wed, Oct 28, 2020 at 12:48:02PM +1100, Patrick Oppenlander wrote: > On Wed, Oct 28, 2020 at 12:40 PM Chen Wang 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