Add --libafl arg in libafl_cc and enable it for fuzzbench (#466)

This commit is contained in:
Andrea Fioraldi 2022-01-13 15:40:39 +01:00 committed by GitHub
parent bca1f392a7
commit 9b3a435778
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 1 deletions

View File

@ -12,7 +12,7 @@ target/release/libafl_cxx: src/* src/bin/*
target/release/libafl_cc: target/release/libafl_cxx target/release/libafl_cc: target/release/libafl_cxx
fuzz.o: fuzz.c target/release/libafl_cc fuzz.o: fuzz.c target/release/libafl_cc
target/release/libafl_cc -O3 -c $^ -o $@ target/release/libafl_cc --libafl-no-link -O3 -c $^ -o $@
fuzzer: target/release/libafl_cxx fuzz.o fuzzer: target/release/libafl_cxx fuzz.o
# Build the fuzzer compiler # Build the fuzzer compiler
@ -20,6 +20,7 @@ fuzzer: target/release/libafl_cxx fuzz.o
# Build the harness # Build the harness
target/release/libafl_cxx \ target/release/libafl_cxx \
--libafl \
fuzz.o \ fuzz.o \
-o $(FUZZER_NAME) \ -o $(FUZZER_NAME) \
-lm -lz -lm -lz

View File

@ -20,6 +20,8 @@ pub fn main() {
.cpp(is_cpp) .cpp(is_cpp)
// silence the compiler wrapper output, needed for some configure scripts. // silence the compiler wrapper output, needed for some configure scripts.
.silence(true) .silence(true)
// add arguments only if --libafl or --libafl-no-link are present
.need_libafl_arg(true)
.from_args(&args) .from_args(&args)
.expect("Failed to parse the command line") .expect("Failed to parse the command line")
.link_staticlib(&dir, "fuzzbench") .link_staticlib(&dir, "fuzzbench")

View File

@ -60,6 +60,8 @@ pub struct ClangWrapper {
linking: bool, linking: bool,
x_set: bool, x_set: bool,
bit_mode: u32, bit_mode: u32,
need_libafl_arg: bool,
has_libafl_arg: bool,
from_args_called: bool, from_args_called: bool,
base_args: Vec<String>, base_args: Vec<String>,
@ -112,6 +114,11 @@ impl CompilerWrapper for ClangWrapper {
match arg.as_ref() { match arg.as_ref() {
"--libafl-no-link" => { "--libafl-no-link" => {
linking = false; linking = false;
self.has_libafl_arg = true;
continue;
}
"--libafl" => {
self.has_libafl_arg = true;
continue; continue;
} }
"-x" => self.x_set = true, "-x" => self.x_set = true,
@ -207,6 +214,10 @@ impl CompilerWrapper for ClangWrapper {
args.push(self.wrapped_cc.clone()); args.push(self.wrapped_cc.clone());
} }
args.extend_from_slice(self.base_args.as_slice()); args.extend_from_slice(self.base_args.as_slice());
if self.need_libafl_arg && !self.has_libafl_arg {
return Ok(args);
}
if !self.passes.is_empty() { if !self.passes.is_empty() {
args.push("-fno-experimental-new-pass-manager".into()); args.push("-fno-experimental-new-pass-manager".into());
} }
@ -270,6 +281,8 @@ impl ClangWrapper {
linking: false, linking: false,
x_set: false, x_set: false,
bit_mode: 0, bit_mode: 0,
need_libafl_arg: false,
has_libafl_arg: false,
from_args_called: false, from_args_called: false,
base_args: vec![], base_args: vec![],
cc_args: vec![], cc_args: vec![],
@ -308,6 +321,18 @@ impl ClangWrapper {
self.passes.push(pass); self.passes.push(pass);
self self
} }
/// Set if linking
pub fn linking(&mut self, value: bool) -> &'_ mut Self {
self.linking = value;
self
}
/// Set if it needs the --libafl arg to add the custom arguments to clang
pub fn need_libafl_arg(&mut self, value: bool) -> &'_ mut Self {
self.need_libafl_arg = value;
self
}
} }
#[cfg(test)] #[cfg(test)]