enable exception support for shared libraries - #648
Conversation
This backports llvm/llvm-project#209282 to resolve the remaining LLVM issues with Wasm exceptions and shared libraries. I've updated `tests/CMakeLists.txt` to run all p2 and p3 tests as shared libraries as well as normal executables. As usual my CMake skills are underwhelming; very open to feedback. Currently a few of the p3 tests are failing in shared library mode, apparently due to TLS-related issues. I'll work on debugging those.
185ad7f to
6683f1b
Compare
This helps ensure that `libc.so` is instantiated first, which matters because other libraries like `libunwind.so` have start functions which call functions like `__wasm_set_tls_base` imported from `libc.so`. Specifically, there's a dependency cycle between `libc.so` and the application `.so` because `libc.so` imports `__main_argc_argv` and the application `.so` imports a bunch of stuff from `libc.so`. `wit-component` will try to break that cycle by having the synthesized `env` module re-export functions using `call_indirect`, but that only works if the start functions of each library participating in the cycle don't call imports from each other, since the table used by the `call_indirect` calls is only initialized as part of the last `__init` module's instantiation. `wit-component` isn't smart enough inspect the code and figure all that out, but it will attempt to preserve the order libraries were specified (programatically or via the CLI), so if we specify `libc.so` first, it will be instantiated first in its "cyclical dependency" group.
alexcrichton
left a comment
There was a problem hiding this comment.
lgtm, but it looks like bytecodealliance/wasm-tools#2584 I forgot to handle shared libraries and with WebAssembly/wasi-libc#856 coupled that means that I broke shared libraries again
In theory a pretty easy fix within wasm-tools I think though? Should be easy enough to publish a new version + a new wasm-component-ld
|
@dicej I've applied this locally: and I'm still seeing failures: for example: IIRC you fixed this by passing |
|
Yeah, the order in which libraries are passed to |
|
@alexcrichton I took a closer look, and the latest issues are unrelated to the instantiation order issue we saw earlier. Instead, |
|
Oh, right, we need to patch the driver to export the TLS size symbols in clang |
Known to not work for now
|
Ok I've added a commit to export TLS information and I've also spun off the final test failures into WebAssembly/tool-conventions#270 and ignored those tests for now. Gonna see if this is green to land... |
|
Ok this is getting messy enough I'm going to avoid landing this for now. Exceptions + shared libraries are known to be broken on coop threads with no known fix, and it's also known now that one of the patches included here won't be included in LLVM. Testing here is also getting pretty messy trying to deal with system-toolchains-vs-not, so I think it may be best to revisit this once shared libraries are supported for exceptions. |
|
Closing this for now; we can either reopen this or create a new one later once we've sorted out how shared libraries, TLS, and exceptions should interact in LLVM. |
Pull request was closed
This backports llvm/llvm-project#209282 to resolve the remaining LLVM issues with Wasm exceptions and shared libraries.
I've updated
tests/CMakeLists.txtto run all p2 and p3 tests as shared libraries as well as normal executables. As usual my CMake skills are underwhelming; very open to feedback.Currently a few of the p3 tests are failing in shared library mode, apparently due to TLS-related issues. I'll work on debugging those.