From 3180fc0ecc3cd442be436d630ec1511e060f3b91 Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Fri, 25 Sep 2020 13:10:00 -0700 Subject: [PATCH] linker: add linker sections for thread local storage This adds the tdata and tbss sections required for thread local storage. They are in ROM area as these sections are not to be directly accessed, but copied to thread local storage area at thread creation. Signed-off-by: Daniel Leung --- include/linker/linker-defs.h | 12 +++++++++++ include/linker/thread-local-storage.ld | 29 ++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 include/linker/thread-local-storage.ld diff --git a/include/linker/linker-defs.h b/include/linker/linker-defs.h index e0332204309..7d4b98c536a 100644 --- a/include/linker/linker-defs.h +++ b/include/linker/linker-defs.h @@ -291,6 +291,18 @@ extern char z_user_stacks_start[]; extern char z_user_stacks_end[]; #endif /* CONFIG_USERSPACE */ +#ifdef CONFIG_THREAD_LOCAL_STORAGE +extern char __tdata_start[]; +extern char __tdata_end[]; +extern char __tdata_size[]; +extern char __tbss_start[]; +extern char __tbss_end[]; +extern char __tbss_size[]; +extern char __tls_start[]; +extern char __tls_end[]; +extern char __tls_size[]; +#endif /* CONFIG_THREAD_LOCAL_STORAGE */ + #endif /* ! _ASMLANGUAGE */ #endif /* ZEPHYR_INCLUDE_LINKER_LINKER_DEFS_H_ */ diff --git a/include/linker/thread-local-storage.ld b/include/linker/thread-local-storage.ld new file mode 100644 index 00000000000..4682773384c --- /dev/null +++ b/include/linker/thread-local-storage.ld @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + + SECTION_DATA_PROLOGUE(tdata,,) + { + *(.tdata .tdata.* .gnu.linkonce.td.*); + } GROUP_LINK_IN(ROMABLE_REGION) + + SECTION_DATA_PROLOGUE(tbss,,) + { + *(.tbss .tbss.* .gnu.linkonce.tb.* .tcommon); + } GROUP_LINK_IN(ROMABLE_REGION) + + /* + * These needs to be outside of the tdata/tbss + * sections or else they would be considered + * thread-local variables, and the code would use + * the wrong values. + */ + PROVIDE(__tdata_start = LOADADDR(tdata)); + PROVIDE(__tdata_size = SIZEOF(tdata)); + PROVIDE(__tdata_end = __tdata_start + __tdata_size); + + PROVIDE(__tbss_start = LOADADDR(tbss)); + PROVIDE(__tbss_size = SIZEOF(tbss)); + PROVIDE(__tbss_end = __tbss_start + __tbss_size); + + PROVIDE(__tls_start = __tdata_start); + PROVIDE(__tls_end = __tbss_end); + PROVIDE(__tls_size = __tbss_end - __tdata_start);