apache / incubator-teaclave-sgx-sdk

Apache Teaclave (incubating) SGX SDK helps developers to write Intel SGX applications in the Rust programming language, and also known as Rust SGX SDK.
https://teaclave.apache.org
Apache License 2.0
1.17k stars 262 forks source link

duplicate lang item in crate `sgx_tstd` (which `num_bigint` depends on): `f32_runtime`. #207

Closed samsondav closed 4 years ago

samsondav commented 4 years ago

Hey all

Upgrading from 1.09 to 1.10 gives this error:

error: duplicate lang item in crate `sgx_tstd` (which `num_bigint` depends on): `f32_runtime`.
  |
  = note: first defined in crate `sgx_tstd` (which `bigdecimal` depends on).

error: duplicate lang item in crate `sgx_tstd` (which `num_bigint` depends on): `f64_runtime`.
  |
  = note: first defined in crate `sgx_tstd` (which `bigdecimal` depends on).

error: duplicate lang item in crate `sgx_tstd` (which `num_bigint` depends on): `panic_impl`.
  |
  = note: first defined in crate `sgx_tstd` (which `bigdecimal` depends on).

error: duplicate lang item in crate `sgx_tstd` (which `num_bigint` depends on): `begin_panic`.
  |
  = note: first defined in crate `sgx_tstd` (which `bigdecimal` depends on).

error: duplicate lang item in crate `sgx_tstd` (which `num_bigint` depends on): `oom`.
  |
  = note: first defined in crate `sgx_tstd` (which `bigdecimal` depends on).

Any ideas?

dingelish commented 4 years ago

hey there, could i have your Cargo.toml and the output of cargo tree for your enclave? Thanks!

samsondav commented 4 years ago

Hi @dingelish thanks for the fast response.

Cargo.toml:

[package]
name = "bigdecimal"
version = "0.1.0"
authors = ["Andrew Kubera"]
description = "Arbitrary percision decimal numbers"
documentation = "https://docs.rs/bigdecimal"
homepage = "https://github.com/akubera/bigdecimal-rs"
repository = "https://github.com/akubera/bigdecimal-rs"
keywords = ["mathematics", "numerics", "decimal", "arbitrary-precision", "floating-point"]
license = "MIT/Apache-2.0"

[dependencies]
num-bigint = { path = "/opt/sgx-world/num-bigint-sgx" }
num-integer = { path = "/opt/sgx-world/num-integer-sgx" }
num-traits = { path = "/opt/sgx-world/num-traits-sgx" }
serde = { path = "/opt/sgx-world/serde-sgx/serde" }

[target.'cfg(not(target_env = "sgx"))'.dependencies]
sgx_tstd = { path = "/opt/rust-sgx-sdk/sgx_tstd" }
sgx_types = { path = "/opt/rust-sgx-sdk/sgx_types" }

cargo tree

bigdecimal v0.1.0 (/Users/sam/code/smartcontractkit/chainlink/core/sgx/bigdecimal-rs)
├── num-bigint v0.2.5 (/opt/sgx-world/num-bigint-sgx)
│   ├── num-integer v0.1.41 (git+https://github.com/mesalock-linux/num-integer-sgx#83a8eb4ef29fd64d8a1c319b0fe0f295372205e3)
│   │   ├── num-traits v0.2.10 (git+https://github.com/mesalock-linux/num-traits-sgx#34a83e2bf71c99910b4bff3028efbb37a9922a48)
│   │   │   └── sgx_tstd v1.1.0 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.0#71a88b647bb76a16cbc5c3e29403e2afb67f82fd)
│   │   │       ├── sgx_alloc v1.1.0 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.0#71a88b647bb76a16cbc5c3e29403e2afb67f82fd)
│   │   │       ├── sgx_backtrace_sys v1.1.0 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.0#71a88b647bb76a16cbc5c3e29403e2afb67f82fd)
│   │   │       │   └── sgx_libc v1.1.0 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.0#71a88b647bb76a16cbc5c3e29403e2afb67f82fd)
│   │   │       │   [build-dependencies]
│   │   │       │   ├── cc v1.0.50
│   │   │       │   └── sgx_build_helper v0.1.0 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.0#71a88b647bb76a16cbc5c3e29403e2afb67f82fd)
│   │   │       ├── sgx_demangle v1.1.0 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.0#71a88b647bb76a16cbc5c3e29403e2afb67f82fd)
│   │   │       ├── sgx_libc v1.1.0 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.0#71a88b647bb76a16cbc5c3e29403e2afb67f82fd) (*)
│   │   │       ├── sgx_tprotected_fs v1.1.0 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.0#71a88b647bb76a16cbc5c3e29403e2afb67f82fd)
│   │   │       │   ├── sgx_trts v1.1.0 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.0#71a88b647bb76a16cbc5c3e29403e2afb67f82fd)
│   │   │       │   │   ├── sgx_libc v1.1.0 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.0#71a88b647bb76a16cbc5c3e29403e2afb67f82fd) (*)
│   │   │       │   │   └── sgx_types v1.1.0 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.0#71a88b647bb76a16cbc5c3e29403e2afb67f82fd)
│   │   │       │   └── sgx_types v1.1.0 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.0#71a88b647bb76a16cbc5c3e29403e2afb67f82fd) (*)
│   │   │       ├── sgx_trts v1.1.0 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.0#71a88b647bb76a16cbc5c3e29403e2afb67f82fd) (*)
│   │   │       ├── sgx_tseal v1.1.0 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.0#71a88b647bb76a16cbc5c3e29403e2afb67f82fd)
│   │   │       │   ├── sgx_tcrypto v1.1.0 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.0#71a88b647bb76a16cbc5c3e29403e2afb67f82fd)
│   │   │       │   │   └── sgx_types v1.1.0 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.0#71a88b647bb76a16cbc5c3e29403e2afb67f82fd) (*)
│   │   │       │   ├── sgx_trts v1.1.0 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.0#71a88b647bb76a16cbc5c3e29403e2afb67f82fd) (*)
│   │   │       │   ├── sgx_tse v1.1.0 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.0#71a88b647bb76a16cbc5c3e29403e2afb67f82fd)
│   │   │       │   │   └── sgx_types v1.1.0 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.0#71a88b647bb76a16cbc5c3e29403e2afb67f82fd) (*)
│   │   │       │   └── sgx_types v1.1.0 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.0#71a88b647bb76a16cbc5c3e29403e2afb67f82fd) (*)
│   │   │       ├── sgx_types v1.1.0 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.0#71a88b647bb76a16cbc5c3e29403e2afb67f82fd) (*)
│   │   │       └── sgx_unwind v0.1.0 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.0#71a88b647bb76a16cbc5c3e29403e2afb67f82fd)
│   │   │           [build-dependencies]
│   │   │           └── sgx_build_helper v0.1.0 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.0#71a88b647bb76a16cbc5c3e29403e2afb67f82fd) (*)
│   │   │   [build-dependencies]
│   │   │   └── autocfg v0.1.7
│   │   └── sgx_tstd v1.1.0 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.0#71a88b647bb76a16cbc5c3e29403e2afb67f82fd) (*)
│   │   [build-dependencies]
│   │   └── autocfg v0.1.7 (*)
│   ├── num-traits v0.2.10 (git+https://github.com/mesalock-linux/num-traits-sgx#34a83e2bf71c99910b4bff3028efbb37a9922a48) (*)
│   └── sgx_tstd v1.1.0 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.0#71a88b647bb76a16cbc5c3e29403e2afb67f82fd) (*)
│   [build-dependencies]
│   └── autocfg v1.0.0
├── num-integer v0.1.41 (/opt/sgx-world/num-integer-sgx)
│   ├── num-traits v0.2.10 (git+https://github.com/mesalock-linux/num-traits-sgx#34a83e2bf71c99910b4bff3028efbb37a9922a48) (*)
│   └── sgx_tstd v1.1.0 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.0#71a88b647bb76a16cbc5c3e29403e2afb67f82fd) (*)
│   [build-dependencies]
│   └── autocfg v0.1.7 (*)
├── num-traits v0.2.10 (/opt/sgx-world/num-traits-sgx)
│   └── sgx_tstd v1.1.0 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.0#71a88b647bb76a16cbc5c3e29403e2afb67f82fd) (*)
│   [build-dependencies]
│   └── autocfg v0.1.7 (*)
├── serde v1.0.104 (/opt/sgx-world/serde-sgx/serde)
│   └── sgx_tstd v1.1.0 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.0#71a88b647bb76a16cbc5c3e29403e2afb67f82fd) (*)
├── sgx_tstd v1.1.0 (/opt/rust-sgx-sdk/sgx_tstd)
│   ├── sgx_alloc v1.1.0 (/opt/rust-sgx-sdk/sgx_alloc)
│   ├── sgx_backtrace_sys v1.1.0 (/opt/rust-sgx-sdk/sgx_backtrace_sys)
│   │   └── sgx_libc v1.1.0 (/opt/rust-sgx-sdk/sgx_libc)
│   │   [build-dependencies]
│   │   ├── cc v1.0.50 (*)
│   │   └── sgx_build_helper v0.1.0 (/opt/rust-sgx-sdk/sgx_build_helper)
│   ├── sgx_demangle v1.1.0 (/opt/rust-sgx-sdk/sgx_demangle)
│   ├── sgx_libc v1.1.0 (/opt/rust-sgx-sdk/sgx_libc) (*)
│   ├── sgx_tprotected_fs v1.1.0 (/opt/rust-sgx-sdk/sgx_tprotected_fs)
│   │   ├── sgx_trts v1.1.0 (/opt/rust-sgx-sdk/sgx_trts)
│   │   │   ├── sgx_libc v1.1.0 (/opt/rust-sgx-sdk/sgx_libc) (*)
│   │   │   └── sgx_types v1.1.0 (/opt/rust-sgx-sdk/sgx_types)
│   │   └── sgx_types v1.1.0 (/opt/rust-sgx-sdk/sgx_types) (*)
│   ├── sgx_trts v1.1.0 (/opt/rust-sgx-sdk/sgx_trts) (*)
│   ├── sgx_tseal v1.1.0 (/opt/rust-sgx-sdk/sgx_tseal)
│   │   ├── sgx_tcrypto v1.1.0 (/opt/rust-sgx-sdk/sgx_tcrypto)
│   │   │   └── sgx_types v1.1.0 (/opt/rust-sgx-sdk/sgx_types) (*)
│   │   ├── sgx_trts v1.1.0 (/opt/rust-sgx-sdk/sgx_trts) (*)
│   │   ├── sgx_tse v1.1.0 (/opt/rust-sgx-sdk/sgx_tse)
│   │   │   └── sgx_types v1.1.0 (/opt/rust-sgx-sdk/sgx_types) (*)
│   │   └── sgx_types v1.1.0 (/opt/rust-sgx-sdk/sgx_types) (*)
│   ├── sgx_types v1.1.0 (/opt/rust-sgx-sdk/sgx_types) (*)
│   └── sgx_unwind v0.1.0 (/opt/rust-sgx-sdk/sgx_unwind)
│       [build-dependencies]
│       └── sgx_build_helper v0.1.0 (/opt/rust-sgx-sdk/sgx_build_helper) (*)
└── sgx_types v1.1.0 (/opt/rust-sgx-sdk/sgx_types) (*)
dingelish commented 4 years ago

Hi @samsondav, I noticed that the crates under /opt/sgx-world are using sgx_tstd from github, while your enclave directly depends on /opt/rust-sgx-sdk. Could you please try adding a patch to the Cargo.toml shown as below, to let everything depends on your local rust-sgx-sdk?

[patch.'https://github.com/apache/teaclave-sgx-sdk.git']
sgx_alloc = { path = "/opt/rust-sgx-sdk/sgx_alloc" }
sgx_build_helper = { path = "/opt/rust-sgx-sdk/sgx_build_helper" }
sgx_cov = { path = "/opt/rust-sgx-sdk/sgx_cov" }
sgx_crypto_helper = { path = "/opt/rust-sgx-sdk/sgx_crypto_helper" }
sgx_libc = { path = "/opt/rust-sgx-sdk/sgx_libc" }
sgx_rand = { path = "/opt/rust-sgx-sdk/sgx_rand" }
sgx_rand_derive = { path = "/opt/rust-sgx-sdk/sgx_rand_derive" }
sgx_serialize = { path = "/opt/rust-sgx-sdk/sgx_serialize" }
sgx_serialize_derive = { path = "/opt/rust-sgx-sdk/sgx_serialize_derive" }
sgx_serialize_derive_internals = { path = "/opt/rust-sgx-sdk/sgx_serialize_derive_internals" }
sgx_tcrypto = { path = "/opt/rust-sgx-sdk/sgx_tcrypto" }
sgx_tcrypto_helper = { path = "/opt/rust-sgx-sdk/sgx_tcrypto_helper" }
sgx_tdh = { path = "/opt/rust-sgx-sdk/sgx_tdh" }
sgx_tkey_exchange = { path = "/opt/rust-sgx-sdk/sgx_tkey_exchange" }
sgx_tprotected_fs = { path = "/opt/rust-sgx-sdk/sgx_tprotected_fs" }
sgx_trts = { path = "/opt/rust-sgx-sdk/sgx_trts" }
sgx_tse = { path = "/opt/rust-sgx-sdk/sgx_tse" }
sgx_tseal = { path = "/opt/rust-sgx-sdk/sgx_tseal" }
sgx_tservice = { path = "/opt/rust-sgx-sdk/sgx_tservice" }
sgx_tstd = { path = "/opt/rust-sgx-sdk/sgx_tstd" }
sgx_tunittest = { path = "/opt/rust-sgx-sdk/sgx_tunittest" }
sgx_types = { path = "/opt/rust-sgx-sdk/sgx_types" }
sgx_ucrypto = { path = "/opt/rust-sgx-sdk/sgx_ucrypto" }
sgx_unwind = { path = "/opt/rust-sgx-sdk/sgx_unwind" }
sgx_urts = { path = "/opt/rust-sgx-sdk/sgx_urts" }
samsondav commented 4 years ago

Hmm, I tried this but it didn't work.

Would it be better if instead of cloning sgx-world locally I just pointed to each github release individually?

dingelish commented 4 years ago

It's really weird. Currently our examples are using the above patch, like this

If your code is open sourced, I can help you fix the build dependencies :-)

samsondav commented 4 years ago

@dingelish I tried adding the dependencies using github directly and it worked. This will be fine for us :)

dingelish commented 4 years ago

@dingelish I tried adding the dependencies using github directly and it worked. This will be fine for us :)

Cool!