Skip to content

Commit 239a057

Browse files
committed
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.
1 parent 6683f1b commit 239a057

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

tests/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,8 @@ function(add_testcase test)
173173
POST_BUILD
174174
COMMAND
175175
${wasm_tools} component link
176-
$<TARGET_FILE:${target_name}>
177176
${so_files}
178-
${arg_SHARED_LIBS}
177+
$<TARGET_FILE:${target_name}>
179178
-o $<TARGET_FILE:${target_name}>
180179
)
181180
add_dependencies(${target_name} wasm-tools)

0 commit comments

Comments
 (0)