Skip to content

Commit

Permalink
Add new configs for OSS-Fuzz build (#26010)
Browse files Browse the repository at this point in the history
  • Loading branch information
abcSup authored and pull[bot] committed Oct 12, 2023
1 parent a09ba9d commit 2050352
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
16 changes: 10 additions & 6 deletions build/chip/fuzz_test.gni
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,21 @@ template("chip_fuzz_target") {
executable(target_name) {
forward_variables_from(invoker, "*")

if (defined(public_configs)) {
public_configs += [
"//build/config/compiler:libfuzzer_fuzzing",
"//build/config/compiler:sanitize_address",
]
fuzz_configs = []
if (oss_fuzz) {
fuzz_configs += [ "//build/config/compiler:oss_fuzz" ]
} else {
public_configs = [
fuzz_configs += [
"//build/config/compiler:libfuzzer_fuzzing",
"//build/config/compiler:sanitize_address",
]
}

if (defined(public_configs)) {
public_configs += fuzz_configs
} else {
public_configs = fuzz_configs
}
if (!defined(oubput_dir)) {
output_dir = "${root_out_dir}/tests"
}
Expand Down
9 changes: 9 additions & 0 deletions build/config/compiler/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -453,11 +453,20 @@ config("libfuzzer_fuzzing") {
ldflags = cflags
}

config("oss_fuzz") {
cflags = string_split(getenv("CFLAGS"))
ldflags = string_split(getenv("CXXFLAGS"))
ldflags += [ getenv("LIB_FUZZING_ENGINE") ]
}

config("fuzzing_default") {
configs = []
if (is_libfuzzer) {
configs += [ ":libfuzzer_fuzzing" ]
}
if (oss_fuzz) {
configs += [ ":oss_fuzz" ]
}
}

config("coverage") {
Expand Down
3 changes: 3 additions & 0 deletions build/config/compiler/compiler.gni
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,7 @@ declare_args() {

# Debug prefix mapping (values for -fdebug-prefix-map=).
prefix_mappings = []

# Enable fuzzer build for OSS-Fuzz
oss_fuzz = false
}
11 changes: 11 additions & 0 deletions build/config/linux/pkg_config.gni
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ template("pkg_config") {
lib_dirs = pkgresult[3]
}

# Link libraries statically for OSS-Fuzz fuzzer build
if (oss_fuzz) {
libs = []
ldflags = [ "-Wl,-Bstatic" ]
foreach(lib, pkgresult[2]) {
ldflags += [ "-l$lib" ]
}
ldflags += [ "-Wl,-Bdynamic" ]
lib_dirs = pkgresult[3]
}

forward_variables_from(invoker,
[
"defines",
Expand Down

0 comments on commit 2050352

Please sign in to comment.