Date: Wed, 10 Jul 2019 15:18:52 -0700 From: Mark Millard <marklmi@yahoo.com> To: adr <adr@SDF.ORG> Cc: Robert Crowston via freebsd-arm <freebsd-arm@freebsd.org> Subject: Re: FreeBSD arm EABI5 documentation? Message-ID: <AFF6488F-B2F5-486E-8F14-FAF852DB2C3C@yahoo.com> In-Reply-To: <alpine.NEB.2.21.1907102043040.9461@sdf.lonestar.org> References: <alpine.NEB.2.21.1907101508370.22895@sdf.lonestar.org> <f2967859f68f1d40f260661791126956f48f4d12.camel@freebsd.org> <alpine.NEB.2.21.1907101735020.3201@sdf.lonestar.org> <da6a8f7e596da9bf9015f76798a5575908ad1be4.camel@freebsd.org> <alpine.NEB.2.21.1907101904570.15468@sdf.lonestar.org> <1788e13e706b9fdaf610e4ddd671a5ed715f9dfe.camel@freebsd.org> <alpine.NEB.2.21.1907102043040.9461@sdf.lonestar.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2019-Jul-10, at 13:47, adr <adr at SDF.ORG> wrote: > On Wed, 10 Jul 2019, Ian Lepore wrote: > >> That's... odd. The arm spec requires the stack to be 8-byte aligned at >> any public interface. It's hard to imagine how anything could work >> properly if it were not, given that the toolchains will assume that 64- >> bit values are aligned at 64-bit boundaries and will thus generate >> instructions that require that alignment (require it even if strict >> alignment checking for most instructions is disabled in the control >> register). If you could enter a function with the stack only 4-byte >> aligned, how would the compiler know it's safe to use something like an >> LDREXD instruction on a local variable allocated on the stack? > > I have no idea. The only thing I can assure you is that in the code I'm > talking about (a forth implementation using SDL2) I've never aligned the > C stack when passing arguments to external functions. Until now! Curious, I looked around in NetBSD code and found the likes of: /* ARM-specific macro to align a stack pointer (downwards). */ #define STACK_ALIGNBYTES (8 - 1) in netbsd's src/sys/arch/arm/include/param.h . In src/sys/arch/aarch64/include/param.h there is: /* AARCH64-specific macro to align a stack pointer (downwards). */ #define STACK_ALIGNBYTES (16 - 1) So it appears that the kernel does have stack alignment: src/sys/sys/param.h has . . . #if defined(_KERNEL) || defined(__EXPOSE_STACK) . . . #ifndef STACK_ALIGNBYTES #define STACK_ALIGNBYTES __ALIGNBYTES #endif . . . #define STACK_ALIGN(sp, bytes) \ ((char *)(((unsigned long)(sp)) & ~(bytes))) . . . #define STACK_LEN_ALIGN(len, bytes) (((len) + (bytes)) & ~(bytes)) There is code for signal delivery: void sendsig_siginfo(const ksiginfo_t *ksi, const sigset_t *mask) { . . . fp = getframe(l, sig, &onstack); /* make room on the stack */ fp--; /* make the stack aligned */ fp = (struct sigframe_siginfo *)STACK_ALIGN(fp, STACK_ALIGNBYTES); . . . AARCH64 even has for runing 32-bit code: static void netbsd32_sendsig_siginfo(const ksiginfo_t *ksi, const sigset_t *mask) { . . . fp = (struct netbsd32_sigframe_siginfo *)sp; fp = (struct netbsd32_sigframe_siginfo *)STACK_ALIGN(fp - 1, 8); . . . (But that last looks wrong: 8 should likely be 8-1, as in STACK_ALIGNBYTES for 32-bit ARM.) There is: static size_t calcstack(struct execve_data * restrict data, const size_t gaplen) { . . . /* make the stack "safely" aligned */ return STACK_LEN_ALIGN(stacklen, STACK_ALIGNBYTES); } I saw other comments mentioning ' stack "safely" aligned' when looking around. So it basically matches up with Ian's comments at the kernel vs. user space interface, despite the probable netbsd32_sendsig_siginfo error. === Mark Millard marklmi at yahoo.com ( dsl-only.net went away in early 2018-Mar)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AFF6488F-B2F5-486E-8F14-FAF852DB2C3C>