fix: enable linux shared-library-safe v8 tls mode by default#1911
fix: enable linux shared-library-safe v8 tls mode by default#1911mplemay wants to merge 4 commits intodenoland:mainfrom
Conversation
|
@fraidev or @bartlomieju - when you get a chance, could you take a look at this? |
kajukitli
left a comment
There was a problem hiding this comment.
looks like the right default to me
linux cdylib consumers hitting TLS relocation failures is a real footgun, and setting V8_TLS_USED_IN_LIBRARY by default for linux source builds is the least ugly fix.
one thing i'd still call out: the GN_ARGS parsing here is pretty flimsy.
for arg in args.split_whitespace() {
if arg.contains("V8_TLS_USED_IN_LIBRARY") {
has_tls_library_mode_define = true;
}
gn_args.push(arg.to_string());
}GN_ARGS is not actually whitespace-safe in the general case, so this can misparse quoted args and arrays. rusty_v8 already has this problem elsewhere in build.rs, so it's not a regression unique to this PR, but it's worth keeping in mind.
for this specific change though, i think the behavior is good and the override logic is reasonable.
|
I'm gonna defer to @devsnek for final approval |
Hey @kajukitli - thanks for the quick review. I went ahead and bolstered the logics so it does a better job with the edge cases. Let me know if there is anything else I should do to improve it. @devsnek - let me know what you think. Happy to make any additional edits to get this shipped. |
Summary
Fixes Linux shared-library (
cdylib) linking failures caused by V8 TLS relocations whenrusty_v8static archives are linked into downstream shared objects.Closes #1706.
Root cause
On Linux, V8 uses fast TLS access unless
V8_TLS_USED_IN_LIBRARYis defined.Without that define, V8 code can emit relocations such as
R_X86_64_TPOFF32, which are invalid when linking into-sharedand fail downstreamcdylibbuilds (for example PyO3 extension modules).What changed
build.rs:extra_cflags=["-DV8_TLS_USED_IN_LIBRARY"]GN_ARGSalready containsV8_TLS_USED_IN_LIBRARY.README.md:Why this approach
This fixes the issue without requiring changes to vendored V8 GN logic and avoids enabling broader build-mode switches (for example
v8_monolithic=true) just to get TLS library mode behavior.Compatibility and risk
Override behavior
If needed, users can still fully control TLS-related flags via
GN_ARGS; build.rs only injects the define when it is not already present.