diff --git a/libafl_cc/src/clang.rs b/libafl_cc/src/clang.rs index 7a8c27494c..0b609685ea 100644 --- a/libafl_cc/src/clang.rs +++ b/libafl_cc/src/clang.rs @@ -89,6 +89,7 @@ pub struct ClangWrapper { link_args: Vec, passes: Vec, passes_args: Vec, + passes_linking_args: Vec, } #[allow(clippy::match_same_arms)] // for the linking = false wip for "shared" @@ -302,6 +303,8 @@ impl CompilerWrapper for ClangWrapper { fn command(&mut self) -> Result, Error> { let mut args = vec![]; + let mut use_pass = false; + if self.is_cpp { args.push(self.wrapped_cxx.clone()); } else { @@ -324,6 +327,7 @@ impl CompilerWrapper for ClangWrapper { } } for pass in &self.passes { + use_pass = true; if self.use_new_pm { // https://github.com/llvm/llvm-project/issues/56137 // Need this -Xclang -load -Xclang -.so thing even with the new PM @@ -358,6 +362,10 @@ impl CompilerWrapper for ClangWrapper { args.extend_from_slice(self.link_args.as_slice()); + if use_pass { + args.extend_from_slice(self.passes_linking_args.as_slice()); + } + if cfg!(unix) { args.push("-pthread".into()); args.push("-ldl".into()); @@ -423,6 +431,7 @@ impl ClangWrapper { link_args: vec![], passes: vec![], passes_args: vec![], + passes_linking_args: vec![], is_silent: false, } } @@ -466,6 +475,15 @@ impl ClangWrapper { self } + /// Add arguments for LLVM passes during linking. For example, ngram needs -lm + pub fn add_passes_linking_arg(&mut self, arg: S) -> &'_ mut Self + where + S: AsRef, + { + self.passes_linking_args.push(arg.as_ref().to_string()); + self + } + /// Set if linking pub fn linking(&mut self, value: bool) -> &'_ mut Self { self.linking = value;