Skip to content
This repository has been archived by the owner on Feb 14, 2021. It is now read-only.

duplicate symbol error: memset, memcpy, memove and memcmp #82

Open
dforsten opened this issue Feb 5, 2019 · 7 comments
Open

duplicate symbol error: memset, memcpy, memove and memcmp #82

dforsten opened this issue Feb 5, 2019 · 7 comments

Comments

@dforsten
Copy link
Contributor

dforsten commented Feb 5, 2019

To finish the pwasm ERC777 implementation at https://github.com/lab10-coop/pwasm-erc777 I need to check for granularity, involving multiplications of U256 values.

Attempting to multiply U256 values in pwasm contracts currently causes link conflicts between rlibc and compiler_builtins.

It is easy to reproduce the errors with the pwasm-tutorials "step-5" example by just adding a multiplication with 3 to the "total_supply" function:

    // Reads balance by address
    fn read_balance_of(owner: &Address) -> U256 {
        U256::from_big_endian(&pwasm_ethereum::read(&balance_key(owner))) * U256::from(3u64)
    }

The reported errors:

  = note: rust-lld: error: duplicate symbol: memset
          >>> defined in /home/davidf/branches/pwasm-tutorial/step-5/target/wasm32-unknown-unknown/release/deps/librlibc-4a3676c92aca5d34.rlib(rlibc-4a3676c92aca5d34.rlibc.3b5qwd65-cgu.0.rcgu.o)
          >>> defined in /home/davidf/.rustup/toolchains/nightly-2018-11-12-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libcompiler_builtins-a950277054e8795f.rlib(compiler_builtins-a950277054e8795f.compiler_builtins.9cyfw09r-cgu.0.rcgu.o)
          
          rust-lld: error: duplicate symbol: memcpy
          >>> defined in /home/davidf/branches/pwasm-tutorial/step-5/target/wasm32-unknown-unknown/release/deps/librlibc-4a3676c92aca5d34.rlib(rlibc-4a3676c92aca5d34.rlibc.3b5qwd65-cgu.0.rcgu.o)
          >>> defined in /home/davidf/.rustup/toolchains/nightly-2018-11-12-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libcompiler_builtins-a950277054e8795f.rlib(compiler_builtins-a950277054e8795f.compiler_builtins.9cyfw09r-cgu.0.rcgu.o)
          
          rust-lld: error: duplicate symbol: memmove
          >>> defined in /home/davidf/branches/pwasm-tutorial/step-5/target/wasm32-unknown-unknown/release/deps/librlibc-4a3676c92aca5d34.rlib(rlibc-4a3676c92aca5d34.rlibc.3b5qwd65-cgu.0.rcgu.o)
          >>> defined in /home/davidf/.rustup/toolchains/nightly-2018-11-12-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libcompiler_builtins-a950277054e8795f.rlib(compiler_builtins-a950277054e8795f.compiler_builtins.9cyfw09r-cgu.0.rcgu.o)
          
          rust-lld: error: duplicate symbol: memcmp
          >>> defined in /home/davidf/branches/pwasm-tutorial/step-5/target/wasm32-unknown-unknown/release/deps/librlibc-4a3676c92aca5d34.rlib(rlibc-4a3676c92aca5d34.rlibc.3b5qwd65-cgu.0.rcgu.o)
          >>> defined in /home/davidf/.rustup/toolchains/nightly-2018-11-12-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libcompiler_builtins-a950277054e8795f.rlib(compiler_builtins-a950277054e8795f.compiler_builtins.9cyfw09r-cgu.0.rcgu.o)

Multiplying with 1, 2 and 4 do not reproduce the link error interestingly, neither does multiplication in the "step-0" project, unless a contract is added with at least one function with at least one return type (can be as simple as a bool) - so it may be triggered by using the pwasm-abi library.

Optimizations in the release builds make the issue appear and disappear depending on the setup, but removing the "--release" option reproduces the link error immediately, even in a build of the unmodified "step-0" pwasm-tutorial example.

I would like to help with tracing this issue down, it currently keeps me from finishing the erc777 implementation, but also from implementing a number of internal, math-heavy contracts in the pwasm environment.

@pepyakin
Copy link
Contributor

pepyakin commented Feb 5, 2019

Hm I think we don't need to either use rlibc nor define our own.

I removing this declaration and corresponding extern crate should solve the issue.

@dforsten
Copy link
Contributor Author

dforsten commented Feb 5, 2019

Indeed!
Removing pwasm-libc from the pwasm-std project immediately fixed the link errors.

Could that fix be applied to the main branch, or are there some dependencies which would break upon removal?

@pepyakin
Copy link
Contributor

pepyakin commented Feb 5, 2019

I would glad to merge that PR : )

@dforsten
Copy link
Contributor Author

dforsten commented Feb 5, 2019

I would glad to merge that PR : )

I would be glad too if it were merged :-)
Should I create the PR or are you already on it?

@pepyakin
Copy link
Contributor

pepyakin commented Feb 5, 2019

Nope, feel free!

@dforsten
Copy link
Contributor Author

dforsten commented Feb 5, 2019

Nope, feel free!

On it!

@dforsten
Copy link
Contributor Author

dforsten commented Feb 5, 2019

Pull Request submitted!

pepyakin added a commit that referenced this issue Feb 6, 2019
Fix for issue #82 - duplicate symbol error: memset, memcpy, memove an…
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants