Date: Thu, 11 Jul 2019 08:29:35 -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: <1CB61FE0-5665-424F-8B94-ABFC06906112@yahoo.com> In-Reply-To: <AFF6488F-B2F5-486E-8F14-FAF852DB2C3C@yahoo.com> 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> <AFF6488F-B2F5-486E-8F14-FAF852DB2C3C@yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2019-Jul-10, at 15:18, Mark Millard <marklmi at yahoo.com> wrote: >=20 > On 2019-Jul-10, at 13:47, adr <adr at SDF.ORG> wrote: >=20 >> On Wed, 10 Jul 2019, Ian Lepore wrote: >>=20 >>> 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? >>=20 >> 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! >=20 > Curious, I looked around in NetBSD code and found the likes of: >=20 > /* ARM-specific macro to align a stack pointer (downwards). */ > #define STACK_ALIGNBYTES (8 - 1) >=20 > in netbsd's src/sys/arch/arm/include/param.h . >=20 > In src/sys/arch/aarch64/include/param.h there is: >=20 > /* AARCH64-specific macro to align a stack pointer (downwards). */ > #define STACK_ALIGNBYTES (16 - 1) >=20 >=20 > So it appears that the kernel does have stack alignment: > src/sys/sys/param.h has . . . >=20 > #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)) >=20 > There is code for signal delivery: >=20 > void > sendsig_siginfo(const ksiginfo_t *ksi, const sigset_t *mask) > { > . . .=09 > fp =3D getframe(l, sig, &onstack); > =09 > /* make room on the stack */ > fp--; > =09 > /* make the stack aligned */ > fp =3D (struct sigframe_siginfo *)STACK_ALIGN(fp, = STACK_ALIGNBYTES); > . . . >=20 > AARCH64 even has for runing 32-bit code: >=20 > static void > netbsd32_sendsig_siginfo(const ksiginfo_t *ksi, const sigset_t *mask) > { > . . . > fp =3D (struct netbsd32_sigframe_siginfo *)sp; > fp =3D (struct netbsd32_sigframe_siginfo *)STACK_ALIGN(fp - 1, = 8); > . . . >=20 > (But that last looks wrong: 8 should likely be 8-1, as in > STACK_ALIGNBYTES for 32-bit ARM.) >=20 > There is: >=20 > 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); > } >=20 > I saw other comments mentioning ' stack "safely" aligned' when > looking around. >=20 > So it basically matches up with Ian's comments at the kernel vs. user > space interface, despite the probable netbsd32_sendsig_siginfo error. I had an exchange via Jared McNeill (who is active on NetBSD) that involved NetBSD's criteria. Overallit went like this for that aspect of the exchange: QUOTE From: Nick Hudson <nick.hudson at gmx.co.uk> Subject: Re: netbsd32_sendsig_siginfo STACK_ALIGN use problem? Date: July 11, 2019 at 03:59:52 PDT To: Jared McNeill <jared.mcneill at live.ca>, Mark Millard <marklmi at = yahoo.com> On 11/07/2019 11:21, Jared McNeill wrote: > Hi Mark =E2=80=94 >=20 > This isn=E2=80=99t really an area I am familiar with. Nick Hudson (in = copy), our resident arm expert, can likely help. >=20 > Cheers, > Jared >=20 >=20 >> On Jul 10, 2019, at 7:17 PM, Mark Millard <marklmi at yahoo.com> = wrote: >>=20 >> Curious about 32-bit arm stack alignment requirements in netbsd >> (based on a FreeBSD thread making claims that user space allows >> 4-byte stack alignment), I went looking around some in NetBSD >> code. . . . >>=20 8 byte stack alignment is a requirement of = http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042f/IHI0042F_aapcs.p= df 5.2.1.2 Stack constraints at a public interface The stack must also conform to the following constraint at a public = interface: SP mod 8 =3D 0. The stack must be double-word aligned I hope this helps. END QUOTE (I was really reporting a coding error in netbsd32_sendsig_siginfo relative to meeting this criteria.) =3D=3D=3D 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?1CB61FE0-5665-424F-8B94-ABFC06906112>