From ce642b5f51d35c51ddbf41c2e0a9c7b426890dd6 Mon Sep 17 00:00:00 2001 From: Avril Date: Wed, 23 Jun 2021 23:58:11 +0100 Subject: [PATCH] static linking works when cc lto is disabled --- build.rs | 5 +++-- test.sh | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build.rs b/build.rs index 86c8dfc..e2cea4e 100644 --- a/build.rs +++ b/build.rs @@ -8,6 +8,7 @@ use rustc_version::{version, version_meta, Channel}; 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) { let mut builder = cc::Build::new(); @@ -21,14 +22,14 @@ fn build_cookie_wrapper(floc: impl AsRef) .flag("-fno-strict-aliasing") .include("include/") .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. //.pic(false) //.use_plt(false) .file(Path::new(FFI_SRC_DIR).join(floc)) - .compile("cwrapper"); + .compile("wrapper"); } fn main() { diff --git a/test.sh b/test.sh index 1cc1806..130e3b4 100755 --- a/test.sh +++ b/test.sh @@ -1,7 +1,6 @@ #!/bin/bash -gcc test.c -Iinclude -Wall --std=gnu11 -pedantic -Wextra -O3 -o test-ffi -l:target/release/libchacha20stream.so || exit -#-lssl -lcrypto -lpthread -ldl || exit +gcc test.c -Iinclude -Wall --std=gnu11 -pedantic -Wextra -O3 -o test-ffi -l:target/release/libchacha20stream.a -lssl -lcrypto -lpthread -ldl || exit valgrind ./test-ffi test-ffi-output hexview test-ffi-output rm -f test-ffi{,-output}