static linking works when cc lto is disabled

ffi
Avril 3 years ago
parent e76499c166
commit ce642b5f51
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -8,6 +8,7 @@ use rustc_version::{version, version_meta, Channel};
const FFI_SRC_DIR: &str = "src/ffi"; const FFI_SRC_DIR: &str = "src/ffi";
//TODO: Replace the wrapper C file with a pure Rust impl in `ffi::cookie::`
fn build_cookie_wrapper(floc: impl AsRef<Path>) fn build_cookie_wrapper(floc: impl AsRef<Path>)
{ {
let mut builder = cc::Build::new(); let mut builder = cc::Build::new();
@ -21,14 +22,14 @@ fn build_cookie_wrapper(floc: impl AsRef<Path>)
.flag("-fno-strict-aliasing") .flag("-fno-strict-aliasing")
.include("include/") .include("include/")
.opt_level(3) .opt_level(3)
.flag_if_supported("-flto") // .flag_if_supported("-flto") //XXX: For some reason, this makes static linking the library fail.
// Not sure if we want these two. We can check the codegen later. // Not sure if we want these two. We can check the codegen later.
//.pic(false) //.pic(false)
//.use_plt(false) //.use_plt(false)
.file(Path::new(FFI_SRC_DIR).join(floc)) .file(Path::new(FFI_SRC_DIR).join(floc))
.compile("cwrapper"); .compile("wrapper");
} }
fn main() { fn main() {

@ -1,7 +1,6 @@
#!/bin/bash #!/bin/bash
gcc test.c -Iinclude -Wall --std=gnu11 -pedantic -Wextra -O3 -o test-ffi -l:target/release/libchacha20stream.so || exit gcc test.c -Iinclude -Wall --std=gnu11 -pedantic -Wextra -O3 -o test-ffi -l:target/release/libchacha20stream.a -lssl -lcrypto -lpthread -ldl || exit
#-lssl -lcrypto -lpthread -ldl || exit
valgrind ./test-ffi test-ffi-output valgrind ./test-ffi test-ffi-output
hexview test-ffi-output hexview test-ffi-output
rm -f test-ffi{,-output} rm -f test-ffi{,-output}

Loading…
Cancel
Save