Skip to content

pthread: zero-fill .tbss when initializing thread TLS#78

Open
quic-k wants to merge 1 commit into
masterfrom
tls-fix
Open

pthread: zero-fill .tbss when initializing thread TLS#78
quic-k wants to merge 1 commit into
masterfrom
tls-fix

Conversation

@quic-k

@quic-k quic-k commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

pthread_create_common() copied the whole TLS image with memcpy, but the .tbss portion is NOBITS and has no valid source bytes -- it must be zeroed, not copied. As a result a new thread's .tbss inherited garbage.

Initialize TLS per the ELF spec: memcpy .tdata, then memset .tbss to zero, using the weak linker symbols __tdata_source/__tdata_size/ __tbss_size (they resolve to 0 on legacy non-picolibc links, making the change a no-op there).

pthread_create_common() copied the whole TLS image with memcpy, but the
.tbss portion is NOBITS and has no valid source bytes -- it must be
zeroed, not copied. As a result a new thread's .tbss inherited garbage.

Initialize TLS per the ELF spec: memcpy .tdata, then memset .tbss to
zero, using the weak linker symbols __tdata_source/__tdata_size/
__tbss_size (they resolve to 0 on legacy non-picolibc links, making the
change a no-op there).

Signed-off-by: Kushal Pal <kushpal@qti.qualcomm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

untested Mark untested PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant