From 239a057c048baa31bf94f2c765d19f3f01109000 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Thu, 30 Jul 2026 16:25:38 -0600 Subject: [PATCH] reorder `wasm-tools component link` arguments 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. --- tests/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index dc081b9..515a499 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -173,9 +173,8 @@ function(add_testcase test) POST_BUILD COMMAND ${wasm_tools} component link - $ ${so_files} - ${arg_SHARED_LIBS} + $ -o $ ) add_dependencies(${target_name} wasm-tools)