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

Link error with v0.11.0 rust-lld: error: undefined symbol: mbedtls_pk_ec__extern mbedtls_cipher_get_cipher_mode__extern #304

Closed
xiaoyuxlu opened this issue Aug 10, 2023 · 2 comments · Fixed by #305

Comments

@xiaoyuxlu
Copy link
Contributor

xiaoyuxlu commented Aug 10, 2023

Hi,

I'm trying rust-mbedtls in no_std environment. This problem also exists in std environment with the following code.

    use mbedtls::pk::Pk;
    use mbedtls::pk::{EcGroup, EcGroupId};
    use mbedtls::rng::OsEntropy;
    use mbedtls::rng::CtrDrbg;
    let mut rng = CtrDrbg::new(Arc::new(OsEntropy::new()), None).unwrap();
    let secp256r1 = EcGroup::new(EcGroupId::SecP256R1).unwrap();
    let pk = Pk::generate_ec(&mut rng, secp256r1.clone()).unwrap();
    let peer_key = pk.ec_public().ok().unwrap().to_binary(&secp256r1, false).unwrap();

version 0.9.1 works fine. But the new version 0.11.0 has the following problem.

note: rust-lld: error: undefined symbol: mbedtls_pk_ec__extern
           ...
          >>> referenced 2 more times
          
          rust-lld: error: undefined symbol: mbedtls_cipher_get_cipher_mode__extern
          ...
         >>> referenced 1 more times

Investigate:

objdump -D -S target/release/build/mbedtls-sys-auto-694c12a76746dc19/out/libstatic-wrappers.a | grep mbedtls_pk_ec
Disassembly of section .gnu.lto_mbedtls_pk_ec__extern.c11f27ebb7176389:
0000000000000000 <.gnu.lto_mbedtls_pk_ec__extern.c11f27ebb7176389>:

Is it the reason of .gnu.lto?

Comment out this line. This problem is gone.

.flag_if_supported("-flto=thin")

Can disable this optimization option?

@Taowyoo any comments?

@Taowyoo
Copy link
Collaborator

Taowyoo commented Aug 10, 2023

It seems LTO does not works good with all compiler and linkers.
Could you create a PR for removing this?

xiaoyuxlu added a commit to xiaoyuxlu/rust-mbedtls that referenced this issue Aug 11, 2023
LTO doesn't works good with rust-lld.
Removed it to fix the link issue fortanix#304.
xiaoyuxlu added a commit to xiaoyuxlu/rust-mbedtls that referenced this issue Aug 11, 2023
LTO doesn't works good with rust-lld.
Remove LTO to fix the link issue fortanix#304.
@xiaoyuxlu
Copy link
Contributor Author

It seems LTO does not works good with all compiler and linkers. Could you create a PR for removing this?

Done. Please take a look #305. Thank you.

github-merge-queue bot pushed a commit that referenced this issue Aug 11, 2023
LTO doesn't works good with rust-lld.
Remove LTO to fix the link issue #304.
@Taowyoo Taowyoo linked a pull request Aug 11, 2023 that will close this issue
@Taowyoo Taowyoo closed this as completed Aug 11, 2023
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.

2 participants