Skip to content

Add support for Mach-O thread local variables#68

Open
Popax21 wants to merge 1 commit into
netwide-assembler:masterfrom
Popax21:patch-1
Open

Add support for Mach-O thread local variables#68
Popax21 wants to merge 1 commit into
netwide-assembler:masterfrom
Popax21:patch-1

Conversation

@Popax21

@Popax21 Popax21 commented Feb 28, 2023

Copy link
Copy Markdown

This patch adds support for thread local sections, which were previously unimplemented. Specifically, it allows the user to emit sections with the types S_THREAD_LOCAL_REGULAR (for .tdata and the new thread_data section attribute) and S_THREAD_LOCAL_ZEROFILL (for .tbss and the new thread_bss/zerofill attribute). Additionally, it also maps specific section names to the section types S_THREAD_LOCAL_VARIABLES (__thread_vars), S_THREAD_LOCAL_VARIABLE_POINTERS (__thread_ptrs) and S_THREAD_LOCAL_INIT_FUNCTION_POINTERS (__thread_init - note that I couldn't determine how this section type is usually named, so I chose my own name). These special section names don't have an associated Unix section name, yet are sometimes still required when interacting with thread local variables.

I hereby sign off the Developer’s Certificate of Origin 1.1.

This patch adds support for thread local sections, which were previously unimplemented. Specifically, it allows the user to emit sections with the types `S_THREAD_LOCAL_REGULAR` (for `.tdata` and the new `thread_data` section attribute) and `S_THREAD_LOCAL_ZEROFILL` (for `.tbss` and the new `thread_bss/zerofill` attribute). Additionally, it also maps specific section names to the section types `S_THREAD_LOCAL_VARIABLES` (`__thread_vars`), `S_THREAD_LOCAL_VARIABLE_POINTERS` (`__thread_ptrs`) and `S_THREAD_LOCAL_INIT_FUNCTION_POINTERS` (`__thread_init` - note that I couldn't determine how this section type is usually named, so I chose my own name). These special section names don't have an associated Unix section name, yet are sometimes still required when interacting with thread local variables.

I hereby sign off the Developer’s Certificate of Origin 1.1.
@sezero

sezero commented Oct 11, 2023

Copy link
Copy Markdown
Contributor

Has this been reviewed?

@hpax

hpax commented Oct 6, 2025

Copy link
Copy Markdown
Member

This is great, but it needs documentation. It might possibly be nicer to use "wrt ..tls" for compatibility with ELF, though.

@hpax

hpax commented Oct 17, 2025

Copy link
Copy Markdown
Member

Question: right now we don't have anyone on the NASM team who is familiar with the intricacies of MachO. Would you be able to help with information and/or validation if we need to make changes that affect the MachO backend?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants