Fixes for serdeany_autoreg (#1479)

* fixes for serdeany_autoreg

* fmt

* yet more docs

---------

Co-authored-by: Dominik Maier <dmnk@google.com>
This commit is contained in:
Addison Crump 2023-08-30 00:13:50 +02:00 committed by GitHub
parent 5710c8b28a
commit 9149d69699
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 14 deletions

View File

@ -643,12 +643,12 @@ pub use serdeany_registry::*;
/// ///
/// Do nothing for without the `serdeany_autoreg` feature, you'll have to register it manually /// Do nothing for without the `serdeany_autoreg` feature, you'll have to register it manually
/// in `main()` with [`RegistryBuilder::register`] or using `<T>::register()`. /// in `main()` with [`RegistryBuilder::register`] or using `<T>::register()`.
#[cfg(all(feature = "serdeany_autoreg", not(miri)))]
#[macro_export] #[macro_export]
macro_rules! create_register { macro_rules! create_register {
($struct_type:ty) => { ($struct_type:ty) => {
const _: () = { const _: () = {
/// Automatically register this type /// Automatically register this type
#[cfg(all(feature = "serdeany_autoreg", not(miri)))]
#[$crate::ctor] #[$crate::ctor]
fn register() { fn register() {
// # Safety // # Safety
@ -661,6 +661,16 @@ macro_rules! create_register {
}; };
} }
/// Register a `SerdeAny` type in the [`RegistryBuilder`]
///
/// Do nothing for without the `serdeany_autoreg` feature, you'll have to register it manually
/// in `main()` with [`RegistryBuilder::register`] or using `<T>::register()`.
#[cfg(not(all(feature = "serdeany_autoreg", not(miri))))]
#[macro_export]
macro_rules! create_register {
($struct_type:ty) => {};
}
/// Implement a [`SerdeAny`], registering it in the [`RegistryBuilder`] when on std /// Implement a [`SerdeAny`], registering it in the [`RegistryBuilder`] when on std
#[macro_export] #[macro_export]
macro_rules! impl_serdeany { macro_rules! impl_serdeany {

View File

@ -25,7 +25,6 @@ rustversion = "1.0"
[features] [features]
#! ## Feature Flags #! ## Feature Flags
document-features = ["dep:document-features"]
## Enables the derive macros for the arbitrary dependency, transparently forwarded from libfuzzer-sys ## Enables the derive macros for the arbitrary dependency, transparently forwarded from libfuzzer-sys
arbitrary-derive = ["libfuzzer-sys/arbitrary-derive"] arbitrary-derive = ["libfuzzer-sys/arbitrary-derive"]
@ -34,7 +33,7 @@ introspection = []
[dependencies] [dependencies]
libfuzzer-sys = { version = "0.4.7", default-features = false } libfuzzer-sys = { version = "0.4.7", default-features = false }
document-features = { version = "0.2", optional = true } document-features = { version = "0.2" }
[package.metadata.docs.rs] [package.metadata.docs.rs]
features = ["document-features"] features = ["document-features"]

View File

@ -41,7 +41,7 @@ fn main() {
command.arg("build"); command.arg("build");
let mut features = vec!["serdeany_autoreg"]; let mut features = vec![];
if cfg!(any(feature = "fork")) { if cfg!(any(feature = "fork")) {
features.push("fork"); features.push("fork");
@ -50,13 +50,15 @@ fn main() {
features.push("libafl/introspection"); features.push("libafl/introspection");
} }
if features.is_empty() {
command.arg("--features").arg(features.join(","));
}
command command
.arg("--release") .arg("--release")
.arg("--no-default-features") .arg("--no-default-features")
.arg("--target-dir") .arg("--target-dir")
.arg(&custom_lib_dir) .arg(&custom_lib_dir)
.arg("--features")
.arg(features.join(","))
.arg("--target") .arg("--target")
.arg(std::env::var_os("TARGET").unwrap()); .arg(std::env::var_os("TARGET").unwrap());

View File

@ -7,12 +7,10 @@ publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features] [features]
default = ["fork", "serdeany_autoreg"] default = ["fork"]
## Enables forking mode for the LibAFL launcher (instead of starting new processes) ## Enables forking mode for the LibAFL launcher (instead of starting new processes)
fork = ["libafl/fork"] fork = ["libafl/fork"]
serdeany_autoreg = [] # TODO: drop this when fixed in libafl proper
[profile.release] [profile.release]
lto = true lto = true
codegen-units = 1 codegen-units = 1

View File

@ -81,9 +81,6 @@ use libafl_bolts::AsSlice;
use crate::options::{LibfuzzerMode, LibfuzzerOptions}; use crate::options::{LibfuzzerMode, LibfuzzerOptions};
#[cfg(not(feature = "serdeany_autoreg"))]
compile_error!("serdeany_autoreg feature must be enabled.");
mod feedbacks; mod feedbacks;
mod fuzz; mod fuzz;
mod merge; mod merge;

View File

@ -2,7 +2,7 @@
//! //!
//! ## Usage //! ## Usage
//! //!
//! To use LibAFL in place of libfuzzer, change the following line in your fuzz/Cargo.toml: //! To use `LibAFL` in place of `LibFuzzer`, change the following line in your `fuzz/Cargo.toml`:
//! //!
//! ```toml //! ```toml
//! libfuzzer-sys = { version = "*", features = [...] } //! libfuzzer-sys = { version = "*", features = [...] }
@ -14,12 +14,15 @@
//! libfuzzer-sys = { version = "*", features = [...], package = "libafl_libfuzzer" } //! libfuzzer-sys = { version = "*", features = [...], package = "libafl_libfuzzer" }
//! ``` //! ```
//! //!
//! To use bleeding changes from upstream, use the following: //! To use bleeding-edge changes from upstream, use the following:
//! //!
//! ```toml //! ```toml
//! libfuzzer-sys = { version = "*", features = [...], package = "libafl_libfuzzer", git = "https://github.com/AFLplusplus/LibAFL" } //! libfuzzer-sys = { version = "*", features = [...], package = "libafl_libfuzzer", git = "https://github.com/AFLplusplus/LibAFL" }
//! ``` //! ```
//! //!
//! You could also specify a specific git revision using `rev = "..."` in this case.
//!
//!
//! ## Flags //! ## Flags
//! //!
//! You can pass additional flags to the libfuzzer runtime in `cargo-fuzz` like so: //! You can pass additional flags to the libfuzzer runtime in `cargo-fuzz` like so: