Commit 23e2bcb7 authored by Jonathan Metzman's avatar Jonathan Metzman Committed by Commit Bot

Reland "[LPM] Improve process for using the plugin for LITE_RUNTIME."

Add fuzzable_proto_library to wrap proto_libraries used in production
and by LPM.

This is a reland of 2f46bdba

Original change's description:
> [LPM] Improve process for using the plugin for LITE_RUNTIME.
>
>
>
> Bug: 860750,861746
> Change-Id: I43d4c51f686895fc8aafb8bdae368815aee4ace2
> Reviewed-on: https://chromium-review.googlesource.com/1128249
> Reviewed-by: Martin Barbella <mbarbella@chromium.org>
> Commit-Queue: Jonathan Metzman <metzman@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#577035}

Bug: 860750, 861746
Change-Id: I03bae3970b7fd333268a35aa738029ff7549705a
Reviewed-on: https://chromium-review.googlesource.com/1145205Reviewed-by: default avatarMartin Barbella <mbarbella@chromium.org>
Commit-Queue: Jonathan Metzman <metzman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577043}
parent 18c48e96
...@@ -95,28 +95,18 @@ the full protobuf library, all `.proto` files in Chromium that are used in ...@@ -95,28 +95,18 @@ the full protobuf library, all `.proto` files in Chromium that are used in
production contain this line: `option optimize_for = LITE_RUNTIME` But this production contain this line: `option optimize_for = LITE_RUNTIME` But this
line is incompatible with libprotobuf-mutator. Thus, we need to modify the line is incompatible with libprotobuf-mutator. Thus, we need to modify the
`proto_library` build target so that builds when fuzzing are compatible with `proto_library` build target so that builds when fuzzing are compatible with
libprotobuf-mutator. We do this by using a protobuf compiler plugin, libprotobuf-mutator. To do this, change your `proto_library` to
`override_lite_runtime_plugin`. Here's what a `proto_library` build target that `fuzzable_proto_library` (don't worry, this works just like `proto_library` when
is configured properly looks like: `use_libfuzzer` is `false`) like so:
```python ```python
proto_library("my_proto") { import("//third_party/libprotobuf-mutator/fuzzable_proto_library.gni")
... // These lines (probably) dont need to be changed.
fuzzable_proto_library("my_proto") {
if (use_libfuzzer && current_toolchain == host_toolchain) { ...
generator_plugin_label =
"//third_party/libprotobuf-mutator:override_lite_runtime_plugin"
generator_plugin_suffix = ".pb"
# The plugin will generate cc, so don't ask for it to be done by protoc.
generate_cc = false
// If deps is already defined, change "=" to "+=".
deps = ["//third_party/libprotobuf-mutator:override_lite_runtime_plugin"]
}
} }
``` ```
Note that this will not have any affects on the proto_library in production,
since the plugin is only used when `use_libfuzzer == true`.
And with that we have completed writing a libprotobuf-mutator fuzz target for And with that we have completed writing a libprotobuf-mutator fuzz target for
Chromium code that accepts protobufs. Chromium code that accepts protobufs.
......
# Copyright 2017 The Chromium Authors. All rights reserved. # Copyright 2017 The Chromium Authors. All rights reserved.
import("//build/config/sanitizers/sanitizers.gni") import("//build/config/sanitizers/sanitizers.gni")
import("//testing/libfuzzer/fuzzer_test.gni") import("//testing/libfuzzer/fuzzer_test.gni")
import("//third_party/protobuf/proto_library.gni") import("//third_party/libprotobuf-mutator/fuzzable_proto_library.gni")
config("include_config") { config("include_config") {
include_dirs = [ "src/" ] include_dirs = [ "src/" ]
...@@ -63,18 +63,9 @@ if (current_toolchain == host_toolchain) { ...@@ -63,18 +63,9 @@ if (current_toolchain == host_toolchain) {
] ]
public_configs = [ "//third_party/protobuf:protobuf_config" ] public_configs = [ "//third_party/protobuf:protobuf_config" ]
} }
# To use the plugin in a proto_library you want to fuzz, add these lines to # To use the plugin in a proto_library you want to fuzz, change the build
# the proto_library definition (note the "=" in second to last line in the # target to fuzzable_proto_library (defined in
# comment will need to be changed to "+=" if you have already defined # //third_party/libprotobuf-mutator/fuzzable_proto_library.gni)
# deps):
# if (use_libfuzzer && current_toolchain == host_toolchain) {
# generator_plugin_label =
# "//third_party/libprotobuf-mutator:override_lite_runtime_plugin"
# generator_plugin_suffix = ".pb"
# # The plugin will generate cc, so don't ask for it to be done by protoc.
# generate_cc = false
# deps = ["//third_party/libprotobuf-mutator:override_lite_runtime_plugin"]
# }
} }
# The CQ will try building this target without "use_libfuzzer" if it is defined. # The CQ will try building this target without "use_libfuzzer" if it is defined.
...@@ -99,24 +90,21 @@ if (use_libfuzzer) { ...@@ -99,24 +90,21 @@ if (use_libfuzzer) {
} }
# Proto library for override_lite_runtime_plugin_test_fuzzer # Proto library for override_lite_runtime_plugin_test_fuzzer
proto_library("override_lite_runtime_plugin_test_fuzzer_proto") { fuzzable_proto_library("override_lite_runtime_plugin_test_fuzzer_proto") {
sources = [ sources = [
"protoc_plugin/imported.proto", "protoc_plugin/imported.proto",
"protoc_plugin/imported_publicly.proto", "protoc_plugin/imported_publicly.proto",
"protoc_plugin/test_fuzzer_input.proto", "protoc_plugin/test_fuzzer_input.proto",
] ]
}
# TODO(metzman): Figure out how we can avoid using this toolchain check # Component that can provide protobuf_full to non-testonly targets
# (maybe remove compilation from the plugin). component("protobuf_full") {
if (use_libfuzzer && current_toolchain == host_toolchain) { # Stop people from using me by accident.
generator_plugin_label = if (!use_libfuzzer) {
"//third_party/libprotobuf-mutator:override_lite_runtime_plugin" testonly = true
generator_plugin_suffix = ".pb"
# The plugin will generate cc, so don't ask for it to be done by protoc.
generate_cc = false
deps = [
"//third_party/libprotobuf-mutator:override_lite_runtime_plugin",
]
} }
public_deps = [
"//third_party/protobuf:protobuf_full",
]
} }
import("//third_party/protobuf/proto_library.gni")
template("fuzzable_proto_library") {
forward_variables_from(invoker, "*")
if (use_libfuzzer) {
proto_library("proto_library_" + target_name) {
assert(current_toolchain == host_toolchain)
if (!defined(deps)) {
deps = []
}
deps +=
[ "//third_party/libprotobuf-mutator:override_lite_runtime_plugin" ]
generator_plugin_label =
"//third_party/libprotobuf-mutator:override_lite_runtime_plugin"
generator_plugin_suffix = ".pb"
# The plugin will generate cc, so don't ask for it to be done by protoc.
generate_cc = false
generate_python = false
}
# Use a component for the build target with target_name. That way we can
# also force dependencies to build using protobuf_full.
component(target_name) {
public_deps = [
":proto_library_" + target_name,
"//third_party/libprotobuf-mutator:protobuf_full",
]
}
} else {
# fuzzable_proto_library should behave like a proto_library when
# !use_libfuzzer.
proto_library(target_name) {
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment