aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorFabian Meumertzheim <fabian@meumertzhe.im>2021-10-08 15:41:08 +0200
committerFabian Meumertzheim <fabian@meumertzhe.im>2021-10-17 10:37:34 +0200
commit27b15be5fd30af5f3b64ab6451fb26c417681221 (patch)
tree285c944b7669e73952fb276c694ac2560acd83ac /examples
parentc470f962424801a4020cf7215dc27422949f34fd (diff)
downloadjazzer-api-27b15be5fd30af5f3b64ab6451fb26c417681221.tar.gz
Use rules_jni
This simplifies the libjvm location logic as well as native library packaging. Incidentally, this fixes the libjpeg_turbo build. In anticipation of Windows support and because it simplifies further improvements to the fuzz target test setup, the wrapper is rewritten in Java.
Diffstat (limited to 'examples')
-rw-r--r--examples/BUILD.bazel39
-rw-r--r--examples/src/main/java/com/example/ExampleFuzzerWithNative.java8
-rw-r--r--examples/src/main/native/com/example/BUILD.bazel (renamed from examples/src/main/native/BUILD.bazel)16
-rw-r--r--examples/src/main/native/com/example/com_example_ExampleFuzzerWithNative.cpp (renamed from examples/src/main/native/com_example_ExampleFuzzerWithNative.cpp)0
-rw-r--r--examples/src/main/native/com_example_ExampleFuzzerWithNative.h37
5 files changed, 31 insertions, 69 deletions
diff --git a/examples/BUILD.bazel b/examples/BUILD.bazel
index 0d900c74..ca17ba3f 100644
--- a/examples/BUILD.bazel
+++ b/examples/BUILD.bazel
@@ -1,4 +1,5 @@
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library")
+load("@fmeum_rules_jni//jni:defs.bzl", "java_library_with_native")
load("//bazel:fuzz_target.bzl", "java_fuzz_target_test")
java_fuzz_target_test(
@@ -12,30 +13,39 @@ java_fuzz_target_test(
target_class = "com.example.ExampleFuzzer",
)
-java_fuzz_target_test(
- name = "ExampleFuzzerWithASan",
+java_library_with_native(
+ name = "example_fuzzer_with_native_lib",
srcs = [
"src/main/java/com/example/ExampleFuzzerWithNative.java",
],
native_libs = [
- "//examples/src/main/native:libnative_asan.dylib",
- "//examples/src/main/native:libnative_asan.so",
+ "//examples/src/main/native/com/example:native_asan",
+ "//examples/src/main/native/com/example:native_ubsan",
+ ],
+ visibility = ["//examples/src/main/native/com/example:__pkg__"],
+ deps = [
+ "//agent:jazzer_api_compile_only",
],
+)
+
+java_fuzz_target_test(
+ name = "ExampleFuzzerWithASan",
+ fuzzer_args = ["--jvm_args=-Djazzer.native_lib=native_asan"],
sanitizer = "address",
target_class = "com.example.ExampleFuzzerWithNative",
+ runtime_deps = [
+ ":example_fuzzer_with_native_lib",
+ ],
)
java_fuzz_target_test(
name = "ExampleFuzzerWithUBSan",
- srcs = [
- "src/main/java/com/example/ExampleFuzzerWithNative.java",
- ],
- native_libs = [
- "//examples/src/main/native:libnative_ubsan.dylib",
- "//examples/src/main/native:libnative_ubsan.so",
- ],
+ fuzzer_args = ["--jvm_args=-Djazzer.native_lib=native_ubsan"],
sanitizer = "undefined",
target_class = "com.example.ExampleFuzzerWithNative",
+ runtime_deps = [
+ ":example_fuzzer_with_native_lib",
+ ],
)
java_fuzz_target_test(
@@ -84,11 +94,8 @@ java_fuzz_target_test(
],
fuzzer_args = [
"-fork=5",
- # Only used to verify that arguments are correctly passed down to child
- # processes. Quoting with both " and ' is necessary in this test since
- # one level of quoting is lost when passing through jazzer_wrapper.sh
- "--jvm_args=\"'-Dfoo=foo;-Dbar=bar'\"",
- "--additional_jvm_args=\"'-Dbaz=baz'\"",
+ "--jvm_args=-Dfoo=foo;-Dbar=bar",
+ "--additional_jvm_args=-Dbaz=baz",
],
# The exit codes of the forked libFuzzer processes are not picked up correctly.
tags = ["broken-on-darwin"],
diff --git a/examples/src/main/java/com/example/ExampleFuzzerWithNative.java b/examples/src/main/java/com/example/ExampleFuzzerWithNative.java
index 071446aa..b9a13e24 100644
--- a/examples/src/main/java/com/example/ExampleFuzzerWithNative.java
+++ b/examples/src/main/java/com/example/ExampleFuzzerWithNative.java
@@ -15,14 +15,12 @@
package com.example;
import com.code_intelligence.jazzer.api.FuzzedDataProvider;
+import com.github.fmeum.rules_jni.RulesJni;
public class ExampleFuzzerWithNative {
static {
- try {
- System.loadLibrary("native_asan");
- } catch (UnsatisfiedLinkError e) {
- System.loadLibrary("native_ubsan");
- }
+ String native_lib = System.getProperty("jazzer.native_lib");
+ RulesJni.loadLibrary(native_lib, ExampleFuzzerWithNative.class);
}
public static void fuzzerTestOneInput(FuzzedDataProvider data) {
diff --git a/examples/src/main/native/BUILD.bazel b/examples/src/main/native/com/example/BUILD.bazel
index 91d6f8cd..309e2d0a 100644
--- a/examples/src/main/native/BUILD.bazel
+++ b/examples/src/main/native/com/example/BUILD.bazel
@@ -1,40 +1,34 @@
-load("//bazel:cc.bzl", "cc_shared_library")
+load("@fmeum_rules_jni//jni:defs.bzl", "java_native_library")
-cc_shared_library(
+java_native_library(
name = "native_asan",
srcs = [
"com_example_ExampleFuzzerWithNative.cpp",
- "com_example_ExampleFuzzerWithNative.h",
],
copts = [
"-fsanitize=fuzzer-no-link,address",
],
+ java_lib = "//examples:example_fuzzer_with_native_lib",
linkopts = select({
"//:clang_on_linux": ["-fuse-ld=lld"],
"//conditions:default": [],
}),
visibility = ["//examples:__pkg__"],
- deps = [
- "@bazel_tools//tools/jdk:jni",
- ],
)
-cc_shared_library(
+java_native_library(
name = "native_ubsan",
srcs = [
"com_example_ExampleFuzzerWithNative.cpp",
- "com_example_ExampleFuzzerWithNative.h",
],
copts = [
"-fsanitize=fuzzer-no-link,undefined",
"-fno-sanitize-recover=all",
],
+ java_lib = "//examples:example_fuzzer_with_native_lib",
linkopts = select({
"//:clang_on_linux": ["-fuse-ld=lld"],
"//conditions:default": [],
}),
visibility = ["//examples:__pkg__"],
- deps = [
- "@bazel_tools//tools/jdk:jni",
- ],
)
diff --git a/examples/src/main/native/com_example_ExampleFuzzerWithNative.cpp b/examples/src/main/native/com/example/com_example_ExampleFuzzerWithNative.cpp
index 774e5998..774e5998 100644
--- a/examples/src/main/native/com_example_ExampleFuzzerWithNative.cpp
+++ b/examples/src/main/native/com/example/com_example_ExampleFuzzerWithNative.cpp
diff --git a/examples/src/main/native/com_example_ExampleFuzzerWithNative.h b/examples/src/main/native/com_example_ExampleFuzzerWithNative.h
deleted file mode 100644
index 0349cfc4..00000000
--- a/examples/src/main/native/com_example_ExampleFuzzerWithNative.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright 2021 Code Intelligence GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* DO NOT EDIT THIS FILE - it is machine generated */
-#include <jni.h>
-/* Header for class com_example_ExampleFuzzerWithNative */
-
-#ifndef _Included_com_example_ExampleFuzzerWithNative
-#define _Included_com_example_ExampleFuzzerWithNative
-#ifdef __cplusplus
-extern "C" {
-#endif
-/*
- * Class: com_example_ExampleFuzzerWithNative
- * Method: parse
- * Signature: (Ljava/lang/String;)Z
- */
-JNIEXPORT jboolean JNICALL
-Java_com_example_ExampleFuzzerWithNative_parse(JNIEnv *, jobject, jstring);
-
-#ifdef __cplusplus
-}
-#endif
-#endif