1c5a3c4d3823 updated the variables inserted by Emscripten SjLj lowering to be
thread-local, depending on the CoalesceFeaturesAndStripAtomics pass to downgrade
them to normal globals if the target features did not support TLS. However, this
had the unintended side effect of preventing all non-TLS-supporting objects from
being linked into modules with shared memory, because stripping TLS marks an
object as thread-unsafe. This patch fixes the problem by only making the SjLj
lowering variables thread-local if the target machine supports TLS so that it
never introduces new usage of TLS that will be stripped. Since SjLj lowering
works on Modules instead of Functions, this required that the
WebAssemblyTargetMachine have its feature string updated to reflect the
coalesced features collected from all the functions so that a
WebAssemblySubtarget can be created without using any particular function.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/include/llvm/Target/TargetMachine.h | ||
---|---|---|
114 | where does the feature string usually get initialized? just during TM construction? Is there any particular risk in allowing it to be changed after init? |
llvm/include/llvm/Target/TargetMachine.h | ||
---|---|---|
114 | Yes, usually just during initialization. It comes from whatever -mattr=... options are provided on the command line, but doesn't actually represent the full set of enabled features because functions can introduce additional features. I don't think there's much risk in changing the string after creation, especially since we were already changing the feature strings on each individual function and those feature strings seem to be more widely used. |
- Restore proper pass order. It is important to run CoalesceFeaturesAndStripAtomics before SjLj lowering so that SjLj lowering reads the correctly updated feature string.
I don't understand the LLVM side enough to review, but running this locally it fixes all the issues we had earlier!
llvm/include/llvm/Target/TargetMachine.h | ||
---|---|---|
114 | This did remind me to put the passes back in the proper order so that CoalesceLocalsAndStripAtomics runs first again. |
llvm/include/llvm/Target/TargetMachine.h | ||
---|---|---|
114 | Sounds good. Especially given that the string already doesn't match the used features, it sounds like nobody is really using it after init. |
where does the feature string usually get initialized? just during TM construction? Is there any particular risk in allowing it to be changed after init?