Skip to content

core: fix C++ TLS linkage when invoking sandbox functions - #23

Closed
squk wants to merge 1 commit into
lfi-project:masterfrom
squk:fix/cpp_tls_invoke_info
Closed

squk wants to merge 1 commit into
lfi-project:masterfrom
squk:fix/cpp_tls_invoke_info

Conversation

@squk

@squk squk commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

lfi_invoke_info is a thread-local variable defined in C (trampoline.c).
When a C++ caller invokes a sandbox function via LFI_INVOKE, accessing
lfi_invoke_info directly as a C++ thread_local causes the compiler to
emit a call to a C++ thread-local initialization wrapper that the C runtime
never defines, resulting in a link error.

Setting the invocation state through lfi_set_invoke_info (introduced in
55025e8) avoids referencing the thread_local variable at the call site.

`lfi_invoke_info` is a thread-local variable defined in C (`trampoline.c`).
When a C++ caller invokes a sandbox function via `LFI_INVOKE`, accessing
`lfi_invoke_info` directly as a C++ `thread_local` causes the compiler to
emit a call to a C++ thread-local initialization wrapper that the C runtime
never defines, resulting in a link error.

Setting the invocation state through `lfi_set_invoke_info` (introduced in
55025e8) avoids referencing the `thread_local` variable at the call site.
zyedidia added a commit that referenced this pull request Oct 6, 2026
@zyedidia

zyedidia commented Oct 6, 2026

Copy link
Copy Markdown
Member

I've replaced thread_local with __thread for the C++ TLS. I think that should address this problem, please let me know if not.

@squk

squk commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor Author

That addresses it. Thanks!

EDIT: For reference, 7f487c1

@squk squk closed this Oct 6, 2026
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.

2 participants