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