run on win32 using the clang wrapper
This commit is contained in:
parent
6ddc3ef85a
commit
40fe286cf9
@ -1,4 +1,4 @@
|
||||
use libafl_cc::{ClangWrapper, CompilerWrapper};
|
||||
use libafl_cc::{ClangWrapper, CompilerWrapper, LIB_EXT, LIB_PREFIX};
|
||||
use std::env;
|
||||
|
||||
fn main() {
|
||||
@ -11,7 +11,11 @@ fn main() {
|
||||
.unwrap()
|
||||
.add_arg("-fsanitize-coverage=trace-pc-guard".into())
|
||||
.unwrap()
|
||||
.add_link_arg(dir.join("liblibfuzzer_libpng.a").display().to_string())
|
||||
.add_link_arg(
|
||||
dir.join(format!("{}libfuzzer_libpng.{}", LIB_PREFIX, LIB_EXT))
|
||||
.display()
|
||||
.to_string(),
|
||||
)
|
||||
.unwrap()
|
||||
.run()
|
||||
.unwrap();
|
||||
|
@ -1,4 +1,4 @@
|
||||
use libafl_cc::{ClangWrapper, CompilerWrapper};
|
||||
use libafl_cc::{ClangWrapper, CompilerWrapper, LIB_EXT, LIB_PREFIX};
|
||||
use std::env;
|
||||
|
||||
fn main() {
|
||||
@ -12,7 +12,11 @@ fn main() {
|
||||
.unwrap()
|
||||
.add_arg("-fsanitize-coverage=trace-pc-guard".into())
|
||||
.unwrap()
|
||||
.add_link_arg(dir.join("liblibfuzzer_libpng.a").display().to_string())
|
||||
.add_link_arg(
|
||||
dir.join(format!("{}libfuzzer_libpng.{}", LIB_PREFIX, LIB_EXT))
|
||||
.display()
|
||||
.to_string(),
|
||||
)
|
||||
.unwrap()
|
||||
.run()
|
||||
.unwrap();
|
||||
|
@ -131,7 +131,7 @@ fn fuzz(corpus_dirs: Vec<PathBuf>, objective_dir: PathBuf, broker_port: u16) ->
|
||||
|
||||
// The actual target run starts here.
|
||||
// Call LLVMFUzzerInitialize() if present.
|
||||
let args: Vec<String> = env::args().collect();
|
||||
let args: Vec<String> = env::args().collect();
|
||||
if libfuzzer_initialize(&args) == -1 {
|
||||
println!("Warning: LLVMFuzzerInitialize failed with -1")
|
||||
}
|
||||
|
@ -7,6 +7,17 @@ pub enum Error {
|
||||
Unknown(String),
|
||||
}
|
||||
|
||||
// TODO macOS
|
||||
#[cfg(windows)]
|
||||
pub const LIB_EXT: &'static str = "lib";
|
||||
#[cfg(not(windows))]
|
||||
pub const LIB_EXT: &'static str = "a";
|
||||
|
||||
#[cfg(windows)]
|
||||
pub const LIB_PREFIX: &'static str = "";
|
||||
#[cfg(not(windows))]
|
||||
pub const LIB_PREFIX: &'static str = "lib";
|
||||
|
||||
/// Wrap a compiler hijacking its arguments
|
||||
pub trait CompilerWrapper {
|
||||
/// Set the wrapper arguments parsing a command line set of arguments
|
||||
|
@ -31,6 +31,8 @@
|
||||
#define EXTERNAL_FUNC(Name, Default) \
|
||||
__pragma(comment(linker, "/alternatename:" WIN_SYM_PREFIX STRINGIFY( \
|
||||
Name) "=" WIN_SYM_PREFIX STRINGIFY(Default)))
|
||||
|
||||
#define CHECK_WEAK_FN(Name) (Name != &Name##Def)
|
||||
#else
|
||||
// Declare external functions as weak to allow them to default to a specified
|
||||
// function if not defined explicitly. We must use weak symbols because clang's
|
||||
@ -38,21 +40,20 @@
|
||||
// https://bugs.llvm.org/show_bug.cgi?id=40218 for more details.
|
||||
#define EXTERNAL_FUNC(Name, Default) \
|
||||
__attribute__((weak, alias(STRINGIFY(Default))))
|
||||
|
||||
#define CHECK_WEAK_FN(Name) (Name != NULL)
|
||||
#endif // LIBFUZZER_MSVC
|
||||
|
||||
#define EXT_FUNC(NAME, RETURN_TYPE, FUNC_SIG, WARN) \
|
||||
RETURN_TYPE NAME##Def FUNC_SIG { \
|
||||
printf("ERROR: Function \"%s\" not defined.\n", #NAME); \
|
||||
exit(1); \
|
||||
} \
|
||||
RETURN_TYPE (*NAME##Def) FUNC_SIG = NULL; \
|
||||
EXTERNAL_FUNC(NAME, NAME##Def) RETURN_TYPE NAME FUNC_SIG
|
||||
|
||||
#else
|
||||
|
||||
// Declare these symbols as weak to allow them to be optionally defined.
|
||||
#define EXT_FUNC(NAME, RETURN_TYPE, FUNC_SIG, WARN) \
|
||||
__attribute__((weak, visibility("default"))) RETURN_TYPE NAME FUNC_SIG
|
||||
|
||||
#define CHECK_WEAK_FN(Name) (Name != NULL)
|
||||
#endif
|
||||
|
||||
EXT_FUNC(LLVMFuzzerInitialize, int, (int *argc, char ***argv), false);
|
||||
@ -68,13 +69,13 @@ EXT_FUNC(LLVMFuzzerCustomCrossOver, size_t,
|
||||
#undef EXT_FUNC
|
||||
|
||||
int libafl_targets_has_libfuzzer_init() {
|
||||
return LLVMFuzzerInitialize != NULL;
|
||||
return CHECK_WEAK_FN(LLVMFuzzerInitialize);
|
||||
}
|
||||
|
||||
int libafl_targets_libfuzzer_init(int *argc, char ***argv) {
|
||||
if (LLVMFuzzerInitialize) {
|
||||
if (libafl_targets_has_libfuzzer_init()) {
|
||||
return LLVMFuzzerInitialize(argc, argv);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user