You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2026/01/09 13:48:37 UTC
(nuttx) 02/02: arch/arm: Fix TLS initialization to account for padding between sections
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit fac76746eae2afe91a5cb9948e3843596c9f941f
Author: guoshengyuan1 <gu...@xiaomi.com>
AuthorDate: Fri Jan 9 18:33:35 2026 +0800
arch/arm: Fix TLS initialization to account for padding between sections
The TLS initialization logic needs to be updated to match the modified
linker script section definitions. The previous implementation assumed
that _END_TDATA and _START_TBSS were contiguous, but there may be
padding between these sections for alignment purposes.
This commit updates up_tls_initialize() to explicitly account for the
padding gap between _END_TDATA and _START_TBSS when zeroing the .tbss
section. The size calculation in up_tls_size() is also updated to use
_END_TBSS instead of the previous _END_TXXX definition to match the
current linker script layout.
Changes:
- Calculate padding gap: (_START_TBSS - _END_TDATA)
- Zero .tbss at correct offset accounting for padding
- Update size calculation to use proper section boundaries
Signed-off-by: guoshengyuan1 <gu...@xiaomi.com>
---
arch/arm/src/common/arm_tls.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/arch/arm/src/common/arm_tls.c b/arch/arm/src/common/arm_tls.c
index f887a08066b..23812e7f881 100644
--- a/arch/arm/src/common/arm_tls.c
+++ b/arch/arm/src/common/arm_tls.c
@@ -69,7 +69,7 @@ int up_tls_size(void)
return sizeof(struct tls_info_s) +
sizeof(void *) * 2 +
- sizeof(uint32_t) * (_END_TBSS - _START_TDATA);
+ (_END_TBSS - _START_TDATA);
}
/****************************************************************************
@@ -85,15 +85,12 @@ int up_tls_size(void)
void up_tls_initialize(struct tls_info_s *info)
{
- uint8_t *tls_data = (uint8_t *)(info + 1);
-
- uint32_t tdata_len = sizeof(uint32_t) * (_END_TDATA - _START_TDATA);
- uint32_t tbss_len = sizeof(uint32_t) * (_END_TBSS - _START_TBSS);
-
- tls_data += sizeof(void *) * 2;
+ uint8_t *tls_data = (uint8_t *)(info + 1) + sizeof(void *) * 2;
+ uint32_t tdata_len = _END_TDATA - _START_TDATA;
+ uint32_t tbss_len = _END_TBSS - _START_TBSS;
memcpy(tls_data, _START_TDATA, tdata_len);
- memset(tls_data + tdata_len, 0, tbss_len);
+ memset(tls_data + tdata_len + (_START_TBSS - _END_TDATA), 0, tbss_len);
}
/****************************************************************************