From 9e1528cea64e7ce99d7d97e4a1986410e654208a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20H=C3=B6ner?= Date: Sun, 9 Jun 2024 17:33:59 +0200 Subject: [PATCH] Add `no-stack-protector` feature flag --- Cargo.toml | 3 ++- build.rs | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6084447..de051b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,8 @@ full-decoder = [] formatter = ["alloc", "full-decoder"] encoder = ["alloc", "full-decoder"] serialization = ["serde", "bitflags/serde"] -nolibc = [] +nolibc = ["no-stack-protector"] +no-stack-protector = [] [[example]] name = "pattern" diff --git a/build.rs b/build.rs index 707439c..95b4470 100644 --- a/build.rs +++ b/build.rs @@ -35,11 +35,18 @@ fn build_library() { bool2cmake(env::var("CARGO_FEATURE_NOLIBC").is_ok()), ); - let dst = config.build(); - let target = env::var("TARGET").unwrap_or("(unknown)".to_string()); let is_msvc = target.ends_with("windows-msvc"); + if env::var("CARGO_FEATURE_NO_STACK_PROTECTOR").is_ok() { + if is_msvc { + config.cflag("/GS-"); + } else { + config.cflag("-fno-stack-protector"); + } + } + + let dst = config.build(); let relative_build_dir = if is_msvc { config.get_profile() } else { "" }; println!(