Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--whole-archive causes trouble when linking rust #17109

Closed
hoodmane opened this issue May 31, 2022 · 2 comments
Closed

--whole-archive causes trouble when linking rust #17109

hoodmane opened this issue May 31, 2022 · 2 comments

Comments

@hoodmane
Copy link
Collaborator

hoodmane commented May 31, 2022

Continuing the discussion from llvm/llvm-project#55786 xref rust-lang/rust#80775, xref pyodide/pyodide#2378.

Rust libraries contain a lib.rmeta file and must be linked with --no-whole-archive. When I try to build rust libraries targeting wasm32-unknown-emscripten I run into linker errors because the rust libraries are being loaded with --whole-archive set.

I think that emscripten is indeed the culprit here:

if settings.LINKABLE:

  # Emscripten currently expects linkable output (SIDE_MODULE/MAIN_MODULE) to
  # include all archive contents.
  if settings.LINKABLE:
    args.insert(0, '--whole-archive')
    args.append('--no-whole-archive')

We probably need a separate setting to disable this.

Response file with problematic linker args
root:WARNING: Creating response file /tmp/emscripten_w2dsyqtv.rsp with following contents: -o
/src/packages/cryptography/build/cryptography-36.0.2/src/rust/target/wasm32-unknown-emscripten/release/deps/cryptography_rust.wasm
--whole-archive
<... tons of files, some of which require --no-whole-archive>
-lc
-L/src/.docker_home/.rustup/toolchains/nightly-2022-05-28-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib
-L/src/.docker_home/.rustup/toolchains/nightly-2022-05-28-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/self-contained
--fatal-warnings
-L/src/emsdk/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/pic
--no-whole-archive
-mllvm
-combiner-global-alias-analysis=false
-mllvm
-enable-emscripten-cxx-exceptions
-mllvm
-enable-emscripten-sjlj
-mllvm
-disable-lsr
--import-undefined
--import-memory
--strip-debug
--export-all
--no-gc-sections
--experimental-pic
-shared
@sbc100
Copy link
Collaborator

sbc100 commented May 31, 2022

I wonder if we can/should just remove this block... folks could always add it back themselves if they really wanted to force all symbols from libraries

@adamnovak
Copy link

So since #17221 was closed without being merged, is the resolution here "just use -sMAIN_MODULE=2 and not -sMAIN_MODULE=1 when building Rust code"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants