Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions fuzztest/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@rules_cc//cc:cc_static_library.bzl", "cc_static_library")
load("@rules_cc//cc:cc_test.bzl", "cc_test")

package(default_visibility = ["//visibility:public"])
Expand Down Expand Up @@ -176,6 +177,21 @@ cc_library(
alwayslink = True,
)

# A full self-contained library archive that external llvm fuzzers should link
# to their fuzz targets to make them compatible with FuzzTest.
#
# Note that the library should be linked with
# `--undefined=fuzztest_llvm_fuzzer_wrapper_link_hook` or `--whole-archive`
# linker flag, as otherwise the test registration would not work.
cc_static_library(
name = "fuzztest_llvm_fuzzer_static",
testonly = True,
deps = [
":llvm_fuzzer_main",
":llvm_fuzzer_wrapper",
],
)

cc_library(
name = "domain",
hdrs = ["domain.h"],
Expand Down
5 changes: 5 additions & 0 deletions fuzztest/llvm_fuzzer_wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ extern "C" size_t LLVMFuzzerCustomCrossOver(const uint8_t* data1, size_t size1,
exit(-1);
}

// A dummy symbol to be referenced by the linker flag
// `--undefined=fuzztest_llvm_fuzzer_wrapper_link_hook` to force this file to be
// included, otherwise the test registration would not be triggered.
extern "C" [[maybe_unused]] int fuzztest_llvm_fuzzer_wrapper_link_hook = 42;

std::vector<std::vector<uint8_t>> ReadByteArraysFromDirectory() {
const std::string flag = absl::GetFlag(FLAGS_llvm_fuzzer_wrapper_corpus_dir);
if (flag.empty()) return {};
Expand Down
Loading