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

Linker Error when using rust-http in a dylib (plugin) #17763

Closed
reem opened this issue Oct 4, 2014 · 12 comments
Closed

Linker Error when using rust-http in a dylib (plugin) #17763

reem opened this issue Oct 4, 2014 · 12 comments

Comments

@reem
Copy link
Contributor

reem commented Oct 4, 2014

Reproduce: https://github.com/reem/rust-http-content-type

The linker error goes away if you remove the implementation of this method: https://github.com/reem/rust-http-content-type/blob/master/generator/src/download.rs#L7-L24, which is the only usage of rust-http.

The actual error, I believe, has to do with rust-https usage of rust-openssl, but I don't really know how to debug any further.

Opening this issue because @huonw suggested it after we tried to debug.

Actual Error Log:

   Compiling generator v0.1.0 (https://github.com/reem/rust-http-content-type.git#6f656bbe)
error: linking with `cc` failed: exit code: 1
note: cc '-m64' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-o' '/Users/Jonathan/hackreactor/iron-middleware/cookie/target/deps/libgenerator-e170cac01c08bdc6.dylib' '/Users/Jonathan/hackreactor/iron-middleware/cookie/target/deps/generator-e170cac01c08bdc6.o' '-Wl,-force_load,/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libmorestack.a' '/Users/Jonathan/hackreactor/iron-middleware/cookie/target/deps/generator-e170cac01c08bdc6.metadata.o' '-nodefaultlibs' '-fno-lto' '-Wl,-dead_strip' '-L' '/Users/Jonathan/hackreactor/iron-middleware/cookie/target/deps' '-lphf_mac-78b8694be35c3487' '/Users/Jonathan/hackreactor/iron-middleware/cookie/target/deps/libhttp-b27c1e7938f5a5d0.rlib' '/Users/Jonathan/hackreactor/iron-middleware/cookie/target/deps/libopenssl-fbe75530f7eda428.rlib' '/Users/Jonathan/hackreactor/iron-middleware/cookie/target/deps/liburl-921578b148f50e06.rlib' '/Users/Jonathan/hackreactor/iron-middleware/cookie/target/deps/libencoding-4805bc5305f7cd87.rlib' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-lrustc-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-lrbml-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-lrustc_llvm-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-lflate-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-lgraphviz-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-lgetopts-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-lrustc_back-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-lsyntax-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-larena-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-ldebug-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-lfmt_macros-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-lterm-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-ltime-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-lserialize-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-llog-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-lregex-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-lstd-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-lsync-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-lrustrt-4e7c5e5c' '-L' '/Users/Jonathan/hackreactor/iron-middleware/cookie/target/deps' '-L' '/Users/Jonathan/hackreactor/iron-middleware/cookie/target/deps' '-L' '/Users/Jonathan/hackreactor/iron-middleware/cookie/target/native/http-b27c1e7938f5a5d0' '-L' '/Users/Jonathan/.cargo/git/checkouts/rust-http-content-type-e95bbac12cca2eca/master/generator/.rust' '-L' '/Users/Jonathan/.cargo/git/checkouts/rust-http-content-type-e95bbac12cca2eca/master/generator' '-lssl' '-lcrypto' '-lpthread' '-ledit' '-lm' '-lc++' '-lSystem' '-lpthread' '-lc' '-lm' '-dynamiclib' '-Wl,-dylib' '-lcompiler-rt'
note: ld: warning: directory not found for option '-L/Users/Jonathan/.cargo/git/checkouts/rust-http-content-type-e95bbac12cca2eca/master/generator/.rust'
Undefined symbols for architecture x86_64:
  "_BN_is_zero", referenced from:
      bn::BigNum.Zero::is_zero::h0dfd42cc0d9b593ebTa in libopenssl-fbe75530f7eda428.rlib(openssl-fbe75530f7eda428.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
@alexcrichton
Copy link
Member

This may be a dupe of #14344, but I'd want to investigate more thoroughly.

@alexcrichton
Copy link
Member

Actually, this is a bug in rust-openssl

$ grep -R BN_is_zero /usr/include  
/usr/include/openssl/bn.h:#define BN_is_zero(a)       ((a)->top == 0)

Looks like the symbol is a macro, not an actual function on some platforms.

@alexcrichton
Copy link
Member

cc @sfackler

@reem
Copy link
Contributor Author

reem commented Oct 5, 2014

@alexcrichton Thanks a ton for figuring this out. I've was struggling to figure this out all day yesterday.

@reem
Copy link
Contributor Author

reem commented Oct 5, 2014

Hmmm.. I tried to fix this with sfackler/rust-openssl#64 but the error hasn't changed. Any ideas?

@sfackler
Copy link
Member

sfackler commented Oct 5, 2014

Are you sure you're pulling the new version?

@reem
Copy link
Contributor Author

reem commented Oct 5, 2014

Yes.

@reem
Copy link
Contributor Author

reem commented Oct 5, 2014

This is super strange because it only happens when you try to use it in a dylib (specifically a plugin) - using rust-openssl in something static works fine.

@emk
Copy link
Contributor

emk commented Oct 6, 2014

Yup. This is still failing on my builds, too, which run cargo update.

@reem
Copy link
Contributor Author

reem commented Oct 7, 2014

@alexcrichton Since there aren't any problems using rust-openssl as a static library or in a static library, I think this is potentially a rust issue instead of an openssl issue, especially with the latest fix for BN_is_zero being a macro.

@reem
Copy link
Contributor Author

reem commented Oct 7, 2014

I'm especially convinced that this is an error because you can find bn_is_zero.o in target/native/open-ssl-hash/ in generator in rust-http-content-type and that definitely defines a bn_is_zero. Creating a .a instead of a .o does nothing to relieve the error.

@alexcrichton
Copy link
Member

@reem, your comment here: sfackler/rust-openssl#64 (comment) is not quite true, you need to assemble the object file into an archive and then provide a #[link] directive for the compiler to pick up the library. This is likely why you're still seeing the symbol error.

lnicola pushed a commit to lnicola/rust that referenced this issue Aug 13, 2024
fix: Insert a tail `Ok(())` for expr block instead of wrapping with `Ok`

Fixes rust-lang#17728

When type mismatch is `Result<(), E>, ()` or `Option<()>, ()` and target expr is a block expression, it is more reasonable to insert a wrapped unit - `Ok(())` or `Some(())` - as the tail expression of that block than wrapping the entire block with `Ok` or `Some`
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

No branches or pull requests

4 participants