]> begriffs open source - freertos/commit
Fix TLS and stack alignment when using picolibc (#637)
authorKeith Packard <keithp@keithp.com>
Mon, 6 Mar 2023 06:29:39 +0000 (22:29 -0800)
committerGitHub <noreply@github.com>
Mon, 6 Mar 2023 06:29:39 +0000 (11:59 +0530)
commit563c57e7dab713aa1e289795c44549239f732a43
tree85d77658547250afc3cb2d33fd5433e286113e1e
parentddd50d9a80fd80e2bca7e93d49baf5c71986cbbb
Fix TLS and stack alignment when using picolibc (#637)

Both the TLS block and stack must be correctly aligned when using
picolibc. The architecture stack alignment is represented by the
portBYTE_ALIGNMENT_MASK and the TLS block alignment is provided by the
Picolibc _tls_align() inline function for Picolibc version 1.8 and
above. For older versions of Picolibc, we'll assume that the TLS block
requires the same alignment as the stack.

For downward growing stacks, this requires aligning the start of the
TLS block to the maximum of the stack alignment and the TLS
alignment. With this, both the TLS block and stack will now be
correctly aligned.

For upward growing stacks, the two areas must be aligned
independently; the TLS block is aligned from the start of the stack,
then the tls space is allocated, and then the stack is aligned above
that.

It's probably useful to know here that the linker ensures that
variables within the TLS block are assigned offsets that match their
alignment requirements. If the TLS block itself is correctly aligned,
then everything within will also be.

I have only tested the downward growing stack branch of this patch.

Signed-off-by: Keith Packard <keithpac@amazon.com>
Co-authored-by: Keith Packard <keithpac@amazon.com>
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
include/picolibc-freertos.h