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.
pull/648/head
Joel Dice 5 days ago
parent 6683f1bc11
commit 239a057c04
No known key found for this signature in database
GPG Key ID: 8ACE463C2489997B

@ -173,9 +173,8 @@ function(add_testcase test)
POST_BUILD
COMMAND
${wasm_tools} component link
$<TARGET_FILE:${target_name}>
${so_files}
${arg_SHARED_LIBS}
$<TARGET_FILE:${target_name}>
-o $<TARGET_FILE:${target_name}>
)
add_dependencies(${target_name} wasm-tools)

Loading…
Cancel
Save