Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent registering static FASTTLS with multiple libjulias #50083

Merged
merged 2 commits into from
Jun 13, 2023

Conversation

topolarity
Copy link
Member

When there are multiple copies of libjulia present in the application, they can both end up trying to use the same static fast tls storage.

The alternative change here would be to add jl_options.use_static_fasttls and modify PackageCompiler.jl to set the flag to false.

However, that requires injecting a #define in PackageCompiler depending on the presence of the new flag, or starting to assign version numbers to jl_options_t

@gbaraldi
Copy link
Member

gbaraldi commented Jun 6, 2023

I wonder how can we test this? Maybe a small dylib that just tries to access the TLS?

@vchuravy
Copy link
Sponsor Member

vchuravy commented Jun 6, 2023

There is also a bit of a design challenge here.

If we have two libjulia's loaded who owns the TLS? It presumably is the outer one. But if the linjulia is of an older (or newer) version it may make assumptions about the data layout behind the TLS. Those assumptions are baked into the generated code.

If we load two libjulia's are we running two GCs?

I suspect we need to limit it to the same version of Julia (if we expect to run any code within it) or indeed setup a separate TLS (but then our fast TLS for generated code is gonna bit a bit iffy)

@topolarity
Copy link
Member Author

If we have two libjulia's loaded who owns the TLS? It presumably is the outer one. But if the linjulia is of an older (or newer) version it may make assumptions about the data layout behind the TLS. Those assumptions are baked into the generated code.

This PR makes it so that the first one loaded will get the fast local-exec TLS, and the other will use its embedding fallback TLS (tied to a static local in each copy of libjulia)

If we load two libjulia's are we running two GCs?

We are - they are intended to be as isolated as possible for now, with only C-style objects passing between them

When there are multiple copies of libjulia present in the application,
they can both end up trying to use the same static fast tls storage.

The alternative options I considered for this were:
  - Add `jl_options.use_static_fasttls` and update PackageCompiler.jl to
    set the flag to FALSE
  - Use `dlvsym` in the CLI loader and attach to the exported
    jl_pgcstack_static symbols `__attribute__((symver(...)))`

The second approach is not available on musl, but the first one seems
like the ideal way to handle this long-term.
cli/loader_lib.c Outdated Show resolved Hide resolved
From Jameson:
> apparently on Windows, the _Atomic x syntax means something slightly different and is not correctly implemented

Co-authored-by: Jameson Nash <[email protected]>
@topolarity topolarity added the status:merge me PR is reviewed. Merge when all tests are passing label Jun 13, 2023
@topolarity topolarity merged commit 84fc130 into JuliaLang:master Jun 13, 2023
2 checks passed
@topolarity topolarity deleted the fasttls-semaphore branch June 13, 2023 19:06
@topolarity topolarity removed the status:merge me PR is reviewed. Merge when all tests are passing label Jun 13, 2023
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.

4 participants