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

Avoid linking contract into contract #30

Closed
webmaster128 opened this issue Aug 11, 2020 · 9 comments · Fixed by #32
Closed

Avoid linking contract into contract #30

webmaster128 opened this issue Aug 11, 2020 · 9 comments · Fixed by #32
Assignees

Comments

@webmaster128
Copy link
Member

On current master I tried:

docker run --rm -v "$(pwd)":/code \
  --mount type=volume,source="cosmwasm_plus_cache",target=/code/target \
  --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
  cosmwasm/rust-optimizer:0.9.0 ./contracts/cw1-subkeys

which fails at link time with

   Building contract in /code/contracts/cw1-subkeys
    Updating crates.io index
  Downloading crates ...
  Downloaded ryu v1.0.5
  Downloaded serde_derive v1.0.114
  Downloaded serde_json v1.0.57
   [...]
   Compiling serde-json-wasm v0.2.1
   Compiling cosmwasm-std v0.10.0
   Compiling cosmwasm-storage v0.10.0
   Compiling cw20 v0.1.0 (/code/packages/cw20)
   Compiling cw1-whitelist v0.1.0 (/code/contracts/cw1-whitelist)
   Compiling cw1-subkeys v0.1.0 (/code/contracts/cw1-subkeys)
error: linking with `rust-lld` failed: exit code: 1
  |
  = note: "rust-lld" "-flavor" "wasm" "--no-threads" "-z" "stack-size=1048576" "--stack-first" "--allow-undefined" "--fatal-warnings" "--no-demangle" "--export-dynamic" "--no-entry" "-L" "/usr/local/rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib" "/code/target/wasm32-unknown-unknown/release/deps/cw1_subkeys.cw1_subkeys.edpvpi68-cgu.0.rcgu.o" "/code/target/wasm32-unknown-unknown/release/deps/cw1_subkeys.cw1_subkeys.edpvpi68-cgu.1.rcgu.o" "/code/target/wasm32-unknown-unknown/release/deps/cw1_subkeys.cw1_subkeys.edpvpi68-cgu.10.rcgu.o" "/code/target/wasm32-unknown-unknown/release/deps/cw1_subkeys.cw1_subkeys.edpvpi68-cgu.11.rcgu.o" "/code/target/wasm32-unknown-unknown/release/deps/cw1_subkeys.cw1_subkeys.edpvpi68-cgu.12.rcgu.o" "/code/target/wasm32-unknown-unknown/release/deps/cw1_subkeys.cw1_subkeys.edpvpi68-cgu.13.rcgu.o" "/code/target/wasm32-unknown-unknown/release/deps/cw1_subkeys.cw1_subkeys.edpvpi68-cgu.14.rcgu.o" "/code/target/wasm32-unknown-unknown/release/deps/cw1_subkeys.cw1_subkeys.edpvpi68-cgu.15.rcgu.o" "/code/target/wasm32-unknown-unknown/release/deps/cw1_subkeys.cw1_subkeys.edpvpi68-cgu.2.rcgu.o" "/code/target/wasm32-unknown-unknown/release/deps/cw1_subkeys.cw1_subkeys.edpvpi68-cgu.3.rcgu.o" "/code/target/wasm32-unknown-unknown/release/deps/cw1_subkeys.cw1_subkeys.edpvpi68-cgu.4.rcgu.o" "/code/target/wasm32-unknown-unknown/release/deps/cw1_subkeys.cw1_subkeys.edpvpi68-cgu.5.rcgu.o" "/code/target/wasm32-unknown-unknown/release/deps/cw1_subkeys.cw1_subkeys.edpvpi68-cgu.6.rcgu.o" "/code/target/wasm32-unknown-unknown/release/deps/cw1_subkeys.cw1_subkeys.edpvpi68-cgu.7.rcgu.o" "/code/target/wasm32-unknown-unknown/release/deps/cw1_subkeys.cw1_subkeys.edpvpi68-cgu.8.rcgu.o" "/code/target/wasm32-unknown-unknown/release/deps/cw1_subkeys.cw1_subkeys.edpvpi68-cgu.9.rcgu.o" "-o" "/code/target/wasm32-unknown-unknown/release/deps/cw1_subkeys.wasm" "--export" "handle" "--export" "init" "--export" "query" "--export" "allocate" "--export" "cosmwasm_vm_version_3" "--export" "deallocate" "--export" "handle" "--export" "init" "--export" "query" "--export=__heap_base" "--export=__data_end" "/code/target/wasm32-unknown-unknown/release/deps/cw1_subkeys.3ud1cdnswvb0gv8q.rcgu.o" "--gc-sections" "--no-entry" "-O3" "-L" "/code/target/wasm32-unknown-unknown/release/deps" "-L" "/code/target/release/deps" "-L" "/usr/local/rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib" "/code/target/wasm32-unknown-unknown/release/deps/libcw20-b055068809359fb5.rlib" "/code/target/wasm32-unknown-unknown/release/deps/libcw1_whitelist.rlib" "/code/target/wasm32-unknown-unknown/release/deps/libcosmwasm_storage-2f977327130675bf.rlib" "/code/target/wasm32-unknown-unknown/release/deps/libcosmwasm_std-46f86e334b1f2699.rlib" "/code/target/wasm32-unknown-unknown/release/deps/libserde_json_wasm-fd625dbf49c6983b.rlib" "/code/target/wasm32-unknown-unknown/release/deps/libbase64-4599cac9ef208a35.rlib" "/code/target/wasm32-unknown-unknown/release/deps/libsnafu-2851ee6f4901727d.rlib" "/code/target/wasm32-unknown-unknown/release/deps/libdoc_comment-bac7a973323b8efe.rlib" "/code/target/wasm32-unknown-unknown/release/deps/libschemars-fa286a1f9b77bc1c.rlib" "/code/target/wasm32-unknown-unknown/release/deps/libserde_json-64a983c58636b2c0.rlib" "/code/target/wasm32-unknown-unknown/release/deps/libryu-4c2166b6a7371059.rlib" "/code/target/wasm32-unknown-unknown/release/deps/libitoa-3b5317f8135b4fc6.rlib" "/code/target/wasm32-unknown-unknown/release/deps/libserde-0655f9d4f93fcc00.rlib" "/usr/local/rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libstd-0e15d81285ef9c5e.rlib" "/usr/local/rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libpanic_abort-34947b3cc643563f.rlib" "/usr/local/rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libdlmalloc-6b294adc19156ae8.rlib" "/usr/local/rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libhashbrown-58d23605d0d5de33.rlib" "/usr/local/rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/librustc_std_workspace_alloc-0fe91d8ec108e6e2.rlib" "/usr/local/rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libbacktrace-372a268696b9cc5b.rlib" "/usr/local/rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/librustc_demangle-a22152a68a4c1806.rlib" "/usr/local/rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libunwind-a7a6ecf939ca4bfa.rlib" "/usr/local/rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libcfg_if-97056b9676d330ba.rlib" "/usr/local/rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/liblibc-db3306f467412913.rlib" "/usr/local/rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/liballoc-29d36a52659bbac5.rlib" "/usr/local/rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/librustc_std_workspace_core-b50ae3e1cc06c201.rlib" "/usr/local/rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libcore-56084c30744b3d96.rlib" "/usr/local/rustup/toolchains/1.45.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libcompiler_builtins-618bea36272ab7ec.rlib" "-s"
  = note: rust-lld: error: duplicate symbol: init
          >>> defined in /code/target/wasm32-unknown-unknown/release/deps/cw1_subkeys.cw1_subkeys.edpvpi68-cgu.14.rcgu.o
          >>> defined in /code/target/wasm32-unknown-unknown/release/deps/libcw1_whitelist.rlib(cw1_whitelist.cw1_whitelist.crnxeiab-cgu.12.rcgu.o)
          
          rust-lld: error: duplicate symbol: handle
          >>> defined in /code/target/wasm32-unknown-unknown/release/deps/cw1_subkeys.cw1_subkeys.edpvpi68-cgu.14.rcgu.o
          >>> defined in /code/target/wasm32-unknown-unknown/release/deps/libcw1_whitelist.rlib(cw1_whitelist.cw1_whitelist.crnxeiab-cgu.12.rcgu.o)
          
          rust-lld: error: duplicate symbol: query
          >>> defined in /code/target/wasm32-unknown-unknown/release/deps/cw1_subkeys.cw1_subkeys.edpvpi68-cgu.14.rcgu.o
          >>> defined in /code/target/wasm32-unknown-unknown/release/deps/libcw1_whitelist.rlib(cw1_whitelist.cw1_whitelist.crnxeiab-cgu.12.rcgu.o)

This makes sense, because as soon as you use cw1_whitelist::, you export it's C exports. I don't think it is possible to link a contract as a dependency of a contract.

@maurolacy
Copy link
Contributor

maurolacy commented Aug 11, 2020 via email

@webmaster128
Copy link
Member Author

One way to get this working quickly would be to use a feature flag in cw1_whitelist like "disable_contract", to use the crate as a library. Then you conditionally compile cosmwasm_std::create_entry_points!(contract); only when disable_contract is not set.

@maurolacy
Copy link
Contributor

maurolacy commented Aug 11, 2020 via email

@webmaster128
Copy link
Member Author

Go ahead!

I just ran into this when trying to create production builds in the CI (#29). In order to do that, calls like

docker run --rm -v "$(pwd)":/code \
  --mount type=volume,source="cosmwasm_plus_cache",target=/code/target \
  --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
  cosmwasm/rust-optimizer:0.9.0 ./contracts/cw1-subkeys

must work first

@maurolacy
Copy link
Contributor

maurolacy commented Aug 11, 2020 via email

@webmaster128
Copy link
Member Author

No worries and no rush :)

@ethanfrey ethanfrey self-assigned this Aug 11, 2020
@ethanfrey
Copy link
Member

I thought the CI should catch this. Interestingly it runs cargo wasm-debug which does not trigger this issue.
If I use cargo wasm, the build fails.

I will update the CI to do the longer one, then dig into the fix.

@maurolacy
Copy link
Contributor

Interesting. Maybe there's a flag to suppress the issue in the release build too. With some consequences, probably...

@ethanfrey
Copy link
Member

I would rather trigger it in debug build...

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