tag1consulting / goose

Load testing framework, inspired by Locust
https://tag1.com/goose
Apache License 2.0
791 stars 70 forks source link

Error when statically compiling w `rustls-tls` feature: "error: linking with `cc` failed:" #493

Closed ElijahLynn closed 2 years ago

ElijahLynn commented 2 years ago

I followed https://book.goose.rs/config/rustls.html?highlight=rust-tls#rustls and am trying to statically compile a Linux target and getting this error. And here is my Cargo.toml too:

[dependencies]
goose = { version = "^0.16", default-features = false, features = ["rustls-tls"] }
tokio = "^1.12"
goose-eggs = "0.4"
rand = "0.8.5"
rustls = "0.20.6"
#openssl = { version = "0.10", features = ["vendored"] }
❯ RUSTFLAGS='-C target-feature=+crt-static' cargo build --release --target x86_64-unknown-linux-gnu                                                                                                                                                            
   Compiling untrusted v0.7.1                                                                                                                                                                                                                                  
   Compiling spin v0.5.2                                                                                                                                                                                                                                       
   Compiling rustls-pemfile v0.3.0                                                                                                                                                                                                                             
   Compiling ring v0.16.20                                                                                                                                                                                                                                     
   Compiling openssl-sys v0.9.73                                                                                                                                                                                                                               
   Compiling goose v0.16.2                                                                                                                                                                                                                                     
   Compiling openssl v0.10.40                                                                                                                                                                                                                                  
   Compiling native-tls v0.2.10                                                                                                                                                                                                                                
   Compiling rustls v0.20.6                                                                                                                                                                                                                                    
   Compiling tokio-native-tls v0.3.0                                                                                                                                                                                                                           
   Compiling hyper-tls v0.5.0                                                                                                                                                                                                                                  
   Compiling webpki v0.21.4                                                                                                                                                                                                                                    
   Compiling webpki v0.22.0                                                                                                                                                                                                                                    
   Compiling sct v0.6.1                                                                                                                                                                                                                                        
   Compiling sct v0.7.0                                                                                                                                                                                                                                        
   Compiling rustls v0.19.1                                                                                                                                                                                                                                    
   Compiling webpki-roots v0.21.1                                                                                                                                                                                                                              
   Compiling webpki-roots v0.22.3                                                                                                                                                                                                                              
   Compiling rustls-native-certs v0.5.0                                                                                                                                                                                                                        
   Compiling tokio-rustls v0.22.0                                                                                                                                                                                                                              
   Compiling tungstenite v0.14.0                                                                                                                                                                                                                               
   Compiling tokio-rustls v0.23.4                                                                                                                                                                                                                              
   Compiling hyper-rustls v0.23.0                                                                                                                                                                                                                              
   Compiling reqwest v0.11.10                                                                                                                                                                                                                                  
   Compiling tokio-tungstenite v0.15.0                                                                                                                                                                                                                         
   Compiling goose-eggs v0.4.0                                                                                                                                                                                                                                 
   Compiling loadtest v0.1.0 (/home/elijah/Projects/va.gov/va.gov-cms/tests/loadtest)                                                                                                                                                                          
error: linking with `cc` failed: exit status: 1                                                                                                                                                                                                                
  |
  = note: "cc" "-m64" "/home/elijah/Projects/va.gov/va.gov-cms/tests/loadtest/target/x86_64-unknown-linux-gnu/release/deps/loadtest-476a38899997ad95.loadtest.6ffc12e8-cgu.0.rcgu.o" "/home/elijah/Projects/va.gov/va.gov-cms/tests/loadtest/target/x86_64-unkn
...
...
...
...
...
-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/elijah/Projects/va.gov/va.gov-cms/tests/loadtest/target/x86_64-unknown-linux-gnu/release/deps/loadtest-476a38899997ad95" "-Wl,--gc-sections" "-static-pie" "-Wl,-zrelro,-znow" 
"-Wl,-O1" "-nodefaultlibs"
  = note: /usr/bin/ld: /home/elijah/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-05b39ac0cb4c5688.rlib(std-05b39ac0cb4c5688.std.c9093c22-cgu.0.rcgu.o): in function `std::sys::unix::os::home_dir::fallba
ck':
          /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e//library/std/src/sys/unix/os.rs:605: warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
          /usr/bin/ld: /home/elijah/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-05b39ac0cb4c5688.rlib(std-05b39ac0cb4c5688.std.c9093c22-cgu.0.rcgu.o): in function `<std::sys_common::net::LookupHost as
 core::convert::TryFrom<(&str,u16)>>::try_from':
          /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e//library/std/src/sys_common/net.rs:206: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
          /usr/bin/ld: /home/elijah/Projects/va.gov/va.gov-cms/tests/loadtest/target/x86_64-unknown-linux-gnu/release/deps/libgoose_eggs-eb65ecb27fbc0e74.rlib(goose_eggs-eb65ecb27fbc0e74.goose_eggs.a694af44-cgu.1.rcgu.o): undefined reference to symbol '__
tls_get_addr@@GLIBC_2.3'
          /usr/bin/ld: /usr/lib/ld-linux-x86-64.so.2: error adding symbols: DSO missing from command line
          collect2: error: ld returned 1 exit status

  = help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

error: could not compile `loadtest` due to previous error
ElijahLynn commented 2 years ago

I had also tried with #openssl = { version = "0.10", features = ["vendored"] } (which is why it is commented out, but am getting a segmentation fault (see https://github.com/naftulikay/rust-openssl-static-example/issues/5#issuecomment-1145998505) after a minute or two of 20-30 users running with the static binary.

jeremyandrews commented 2 years ago

It seems you're running into this general problem: https://stackoverflow.com/questions/2725255/create-statically-linked-binary-that-uses-getaddrinfo

jeremyandrews commented 2 years ago

@ElijahLynn I don't see any way to solve this. There does not seem to be any useful way to statically link the Goose binary. Sorry -- please re-open if you have ideas for how it can be fixed.