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

unable to use third-party crates rust-crypto and ring #138

Closed puzzlewolf closed 5 years ago

puzzlewolf commented 5 years ago

I would like to use either rust-crypto or ring inside the enclave, both exist in the sgx/third_party folder. For rust-crypto, I use Cargo.toml

[dependencies]
rust-crypto = { path = "../../../third_party/rust-crypto" }

and lib.rs:

extern crate crypto;

For ring:

[dependencies]
ring = { path = "../../../third_party/ring" }

and

extern crate ring;

Both give the same error:

make -C ./enclave/
make[1]: Entering directory '/root/sgx/bft/tc/enclave'
cargo build --release
    Updating crates.io index
   Compiling ring v0.13.2 (/root/sgx/third_party/ring)
   Compiling tc v0.1.0 (/root/sgx/bft/tc/enclave)
error: the #[global_allocator] in sgx_tstd conflicts with this global allocator in: sgx_tstd

error: duplicate lang item in crate `sgx_tstd`: `f32_runtime`.
  |
  = note: first defined in crate `sgx_tstd`.

error: duplicate lang item in crate `sgx_tstd`: `f64_runtime`.
  |
  = note: first defined in crate `sgx_tstd`.

error: duplicate lang item in crate `sgx_tstd`: `panic_impl`.
  |
  = note: first defined in crate `sgx_tstd`.

error: duplicate lang item in crate `sgx_trts`: `oom`.
  |
  = note: first defined in crate `sgx_trts`.

error: aborting due to 5 previous errors

error: Could not compile `tc`.

To learn more, run the command again with --verbose.
Makefile:42: recipe for target 'libenclave.a' failed
make[1]: *** [libenclave.a] Error 101
make[1]: Leaving directory '/root/sgx/bft/tc/enclave'
Makefile:165: recipe for target 'enclave' failed
make: *** [enclave] Error 2

I saw #31 and tried default-features = false with both crates, but the error remains. What is going on here, and can you please suggest a fix or workaround?

What does it mean when a crate is in the sgx/third_party folder?

puzzlewolf commented 5 years ago

I just realized the error in #31 refers to std, which is not the same as my error.

Maybe it's relevant: My project is based on the hello-rust samplecode. Adding the lines above to its enclave/Cargo.toml and enclave/src/lib.rs also gives the error.

dingelish commented 5 years ago

@sonea-pm8

This means a collision of "sgx_tstd" and "sgxtstd". If you look into the hello-rust sample code, you'll find that it depends on sgx* crates fetched from github directly as:

sgx_types = { rev = "v1.0.8", git = "https://github.com/baidu/rust-sgx-sdk.git" }
sgx_tstd = { rev = "v1.0.8", git = "https://github.com/baidu/rust-sgx-sdk.git" }

So if you put something like ring = { path = "../../../third_party/ring" } there, ring in that directory would depends on local sgx_* crates, instead of fetch them from github. So there are two sgx_tstd, one from local, and one from github -- they cannot live together.

I'm maintaining forks for third_party crates, and finally I'll remove the third_party dir and replace it with an index of those forks. The proper way to use ring in hello-rust sample is to use the fork like

[dependencies]
ring = { git = "https://github.com/mesalock-linux/ring-sgx" }

One sample usage is at the ported webpki at https://github.com/mesalock-linux/webpki/blob/1f0412bb199158191bd96b5d1d28939e1d7a245d/Cargo.toml#L70

puzzlewolf commented 5 years ago

That was it, thank you