Skip to content

Commit fac7674

Browse files
suoyuan666xiaoxiang781216
authored andcommitted
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 <guoshengyuan1@xiaomi.com>
1 parent dd9f666 commit fac7674

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

arch/arm/src/common/arm_tls.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ int up_tls_size(void)
6969

7070
return sizeof(struct tls_info_s) +
7171
sizeof(void *) * 2 +
72-
sizeof(uint32_t) * (_END_TBSS - _START_TDATA);
72+
(_END_TBSS - _START_TDATA);
7373
}
7474

7575
/****************************************************************************
@@ -85,15 +85,12 @@ int up_tls_size(void)
8585

8686
void up_tls_initialize(struct tls_info_s *info)
8787
{
88-
uint8_t *tls_data = (uint8_t *)(info + 1);
89-
90-
uint32_t tdata_len = sizeof(uint32_t) * (_END_TDATA - _START_TDATA);
91-
uint32_t tbss_len = sizeof(uint32_t) * (_END_TBSS - _START_TBSS);
92-
93-
tls_data += sizeof(void *) * 2;
88+
uint8_t *tls_data = (uint8_t *)(info + 1) + sizeof(void *) * 2;
89+
uint32_t tdata_len = _END_TDATA - _START_TDATA;
90+
uint32_t tbss_len = _END_TBSS - _START_TBSS;
9491

9592
memcpy(tls_data, _START_TDATA, tdata_len);
96-
memset(tls_data + tdata_len, 0, tbss_len);
93+
memset(tls_data + tdata_len + (_START_TBSS - _END_TDATA), 0, tbss_len);
9794
}
9895

9996
/****************************************************************************

0 commit comments

Comments
 (0)