Skip to content

Commit

Permalink
fix: issue while creating statically linked binary that depends on `m…
Browse files Browse the repository at this point in the history
…usl` instead of `glibc`.

Closes #181
  • Loading branch information
plusvic committed Aug 29, 2024
1 parent 9ba46f8 commit 6953528
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Special configuration for linking with musl instead of glibc.
# See: https://github.com/VirusTotal/yara-x/issues/181
#
[target.x86_64-unknown-linux-musl]
# Relocation model is "pic" by default (i.e: position independent code),
# Here we force the "static" (i.e: non-relocatable code) model. Without this
# the produced binaries crash with SIGSEGV as described in:
# https://github.com/rust-lang/rust/issues/74757
# https://github.com/rust-lang/rust/issues/81987
rustflags = ["-C", "relocation-model=static"]
# This is not necessary when building from a host where gcc already links
# against musl by default, and it can be commented out (e.g: when building
# from a Alpine Linux host). But in most cases what we want is cross-compiling
# a host with a standard gcc that links against glibc. In such cases from we
# must link using musl-gcc.
#
# In Debian/Ubuntu you need to install the musl-tools package in order to
# build YARA-X with musl. This package contains musl-gcc, which is a gcc
# wrapper that creates binaries that depends on musl instead of glibc.
linker = "musl-gcc"
12 changes: 12 additions & 0 deletions lib/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,20 @@ pub(crate) struct WasmSymbols {
lazy_static! {
pub(crate) static ref CONFIG: Config = {
let mut config = Config::default();
// Wasmtime produces a nasty warning when linked against musl. The
// warning can be fixed by disabling native unwind information.
//
// More details:
//
// https://github.com/bytecodealliance/wasmtime/issues/8897
// https://github.com/VirusTotal/yara-x/issues/181
//
#[cfg(target_env = "musl")]
config.native_unwind_info(false);

config.cranelift_opt_level(wasmtime::OptLevel::SpeedAndSize);
config.epoch_interruption(true);

config
};
pub(crate) static ref ENGINE: Engine = Engine::new(&CONFIG).unwrap();
Expand Down

0 comments on commit 6953528

Please sign in to comment.