Skip to content

Commit 97b9a27

Browse files
committed
platform: Update picolibc.c for linker script compatibility
Always use picolibc_startup to initialize all .data and .bss segments. Set the picolibc initialization values for these segments to all zeros so that the crt0.o code doesn't do anything. Provide a stub for _set_tls as tf-m doesn't use thread local variables. Signed-off-by: Keith Packard <[email protected]>
1 parent b4765f0 commit 97b9a27

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

platform/ext/common/picolibc.c

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
#include <string.h>
1010
#include "config_impl.h"
1111

12+
#ifdef __PICOLIBC__
13+
1214
/*
1315
* Picolibc's startup code only initializes a single data and bss
1416
* segment. Augment that by initializing the remaining segments using
1517
* the lists provided by the linker script in a constructor which will
1618
* be called from _start
1719
*/
1820

19-
#if defined(__PICOLIBC__) && TFM_ISOLATION_LEVEL > 0
20-
2121
static void __attribute__((constructor))
2222
picolibc_startup(void)
2323
{
@@ -45,4 +45,44 @@ picolibc_startup(void)
4545
memset(pTable->dest, 0, pTable->wlen << 2);
4646
}
4747
}
48+
49+
/*
50+
* Create symbols for picolibc. These are used by the
51+
* startup code to initialize memory, but that work
52+
* is done by the function above
53+
*/
54+
55+
__asm__(".globl __data_source\n"
56+
".globl __data_start\n"
57+
".globl __data_size\n"
58+
".globl __bss_size\n"
59+
".globl __bss_start\n"
60+
".equ __data_source, 0\n"
61+
".equ __data_start, 0\n"
62+
".equ __data_size, 0\n"
63+
".equ __bss_size, 0\n"
64+
".equ __bss_start, 0");
65+
66+
#ifdef __THREAD_LOCAL_STORAGE
67+
68+
__asm__(".globl __tls_base\n"
69+
".equ __tls_base, 0");
70+
71+
#include <picotls.h>
72+
73+
/*
74+
* Picolibc's startup code wants to initialize the thread local
75+
* storage base address, but tf-m doesn't use any TLS variables.
76+
*
77+
* Stub out this function until TLS is required.
78+
*/
79+
80+
void
81+
_set_tls(void *tls_base)
82+
{
83+
(void) tls_base;
84+
}
85+
4886
#endif
87+
88+
#endif /* __PICOLIBC__ */

0 commit comments

Comments
 (0)