aboutsummaryrefslogtreecommitdiff
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
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.
-rw-r--r--BUILD.bazel41
-rw-r--r--bazel/BUILD.bazel11
-rw-r--r--bazel/FuzzTargetTestWrapper.java78
-rw-r--r--bazel/cc.bzl23
-rw-r--r--bazel/fuzz_target.bzl19
-rwxr-xr-xbazel/fuzz_target_test_wrapper.sh42
-rwxr-xr-xbazel/jazzer11
-rwxr-xr-xbazel/jazzer_wrapper.sh29
-rw-r--r--bazel/local_jdk_libjvm.bzl59
-rw-r--r--driver/BUILD.bazel3
-rw-r--r--driver/libfuzzer_driver.cpp3
-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
-rw-r--r--init.bzl2
-rw-r--r--repositories.bzl13
-rw-r--r--third_party/libjpeg_turbo.BUILD3
19 files changed, 151 insertions, 286 deletions
diff --git a/BUILD.bazel b/BUILD.bazel
index cf7f5d3e..e59b1a21 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -26,48 +26,31 @@ pkg_tar(
srcs = [
"//agent:jazzer_agent_deploy.jar",
"//agent:jazzer_api_deploy.jar",
- "//bazel:jazzer",
"//driver:jazzer_driver",
],
extension = "tar.gz",
mode = "0777",
- remap_paths = {"bazel/": ""},
+ remap_paths = {
+ "agent/jazzer_agent_deploy.jar": "jazzer_agent_deploy.jar",
+ "agent/jazzer_api_deploy.jar": "jazzer_api_deploy.jar",
+ "driver/jazzer_driver": "jazzer",
+ },
+ strip_prefix = "./",
)
-sh_binary(
+alias(
name = "jazzer",
- srcs = ["//bazel:jazzer_wrapper.sh"],
- args = [
- "$(rootpath //driver:jazzer_driver)",
- ],
- data = [
- "//driver:jazzer_driver",
- ],
- deps = [
- "@bazel_tools//tools/bash/runfiles",
- ],
+ actual = "//driver:jazzer_driver",
)
-sh_binary(
+alias(
name = "jazzer_asan",
- srcs = ["//bazel:jazzer_wrapper.sh"],
- args = [
- "$(rootpath //driver:jazzer_driver_asan)",
- ],
- data = [
- "//driver:jazzer_driver_asan",
- ],
+ actual = "//driver:jazzer_driver_asan",
)
-sh_binary(
+alias(
name = "jazzer_ubsan",
- srcs = ["//bazel:jazzer_wrapper.sh"],
- args = [
- "$(rootpath //driver:jazzer_driver_ubsan)",
- ],
- data = [
- "//driver:jazzer_driver_ubsan",
- ],
+ actual = "//driver:jazzer_driver_ubsan",
)
exports_files([
diff --git a/bazel/BUILD.bazel b/bazel/BUILD.bazel
index 9df500d6..1e2348c1 100644
--- a/bazel/BUILD.bazel
+++ b/bazel/BUILD.bazel
@@ -1,5 +1,6 @@
-exports_files([
- "fuzz_target_test_wrapper.sh",
- "jazzer",
- "jazzer_wrapper.sh",
-])
+java_library(
+ name = "fuzz_target_test_wrapper",
+ srcs = ["FuzzTargetTestWrapper.java"],
+ visibility = ["//:__subpackages__"],
+ deps = ["@bazel_tools//tools/java/runfiles"],
+)
diff --git a/bazel/FuzzTargetTestWrapper.java b/bazel/FuzzTargetTestWrapper.java
new file mode 100644
index 00000000..ef22ea0e
--- /dev/null
+++ b/bazel/FuzzTargetTestWrapper.java
@@ -0,0 +1,78 @@
+// 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.
+
+import com.google.devtools.build.runfiles.Runfiles;
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class FuzzTargetTestWrapper {
+ public static void main(String[] args) {
+ String driverActualPath;
+ String jarActualPath;
+ Runfiles runfiles;
+ try {
+ runfiles = Runfiles.create();
+ driverActualPath = runfiles.rlocation(args[0]);
+ jarActualPath = runfiles.rlocation(args[1]);
+ } catch (IOException | ArrayIndexOutOfBoundsException e) {
+ e.printStackTrace();
+ System.exit(1);
+ return;
+ }
+
+ ProcessBuilder processBuilder = new ProcessBuilder();
+ Map<String, String> environment = processBuilder.environment();
+ // Ensure that Jazzer can find its runfiles.
+ environment.putAll(runfiles.getEnvVars());
+
+ // Crashes will be available as test outputs. These are cleared on the next run,
+ // so this is only useful for examples.
+ String outputDir = System.getenv("TEST_UNDECLARED_OUTPUTS_DIR");
+ List<String> command =
+ Stream
+ .concat(Stream.of(driverActualPath, String.format("-artifact_prefix=%s/", outputDir),
+ String.format("--reproducer_path=%s", outputDir), "-seed=2735196724",
+ String.format("--cp=%s", jarActualPath)),
+ Arrays.stream(args).skip(2))
+ .collect(Collectors.toList());
+ processBuilder.inheritIO();
+ processBuilder.command(command);
+
+ try {
+ int exitCode = processBuilder.start().waitFor();
+ // Assert that we either found a crash in Java (exit code 77) or a sanitizer crash (exit code
+ // 76).
+ if (exitCode != 76 && exitCode != 77) {
+ System.exit(3);
+ }
+ String[] outputFiles = new File(outputDir).list();
+ if (outputFiles == null) {
+ System.exit(4);
+ }
+ // Verify that libFuzzer dumped a crashing input.
+ if (Arrays.stream(outputFiles).noneMatch(name -> name.startsWith("crash-"))) {
+ System.exit(5);
+ }
+ } catch (IOException | InterruptedException e) {
+ e.printStackTrace();
+ System.exit(2);
+ }
+ System.exit(0);
+ }
+}
diff --git a/bazel/cc.bzl b/bazel/cc.bzl
index 465127cf..5785513d 100644
--- a/bazel/cc.bzl
+++ b/bazel/cc.bzl
@@ -72,26 +72,3 @@ def cc_17_library(name, visibility = None, **kwargs):
library = library_name,
visibility = visibility,
)
-
-# Workaround for https://github.com/bazelbuild/bazel/issues/11082
-# By explicitly setting the name of a cc_binary and selecting based on the
-# platform, the resulting shared object will have the correct extension on both
-# Linux and macOS.
-def cc_shared_library(name, visibility = None, **kwargs):
- # Linux
- linux_name = "lib%s.so" % name
- native.cc_binary(
- name = linux_name,
- linkshared = True,
- visibility = visibility,
- **kwargs
- )
-
- # macOS
- osx_name = "lib%s.dylib" % name
- native.cc_binary(
- name = osx_name,
- linkshared = True,
- visibility = visibility,
- **kwargs
- )
diff --git a/bazel/fuzz_target.bzl b/bazel/fuzz_target.bzl
index 801fa292..0b31afc2 100644
--- a/bazel/fuzz_target.bzl
+++ b/bazel/fuzz_target.bzl
@@ -46,33 +46,34 @@ def java_fuzz_target_test(
additional_args = []
- native_libs_paths = ":".join(["$$(dirname $(rootpaths %s) | paste -sd ':' -)" % native_lib for native_lib in native_libs])
- if native_libs_paths != "":
- additional_args.append("--jvm_args=-Djava.library.path=" + native_libs_paths)
-
if sanitizer == None:
driver = "//driver:jazzer_driver"
+ driver_rlocation = "jazzer/driver/jazzer_driver"
elif sanitizer == "address":
driver = "//driver:jazzer_driver_asan"
+ driver_rlocation = "jazzer/driver/jazzer_driver_asan"
elif sanitizer == "undefined":
driver = "//driver:jazzer_driver_ubsan"
+ driver_rlocation = "jazzer/driver/jazzer_driver_ubsan"
else:
fail("Invalid sanitizer: " + sanitizer)
- native.sh_test(
+ native.java_test(
name = name,
- srcs = ["//bazel:fuzz_target_test_wrapper.sh"],
- size = "large",
+ runtime_deps = ["//bazel:fuzz_target_test_wrapper"],
+ size = "enormous",
timeout = "moderate",
args = [
- "$(rootpath %s)" % driver,
- "--cp=$(rootpath :%s_deploy.jar)" % target_name,
+ driver_rlocation,
+ "jazzer/$(rootpath :%s_deploy.jar)" % target_name,
] + additional_args + fuzzer_args,
data = [
":%s_deploy.jar" % target_name,
"//agent:jazzer_agent_deploy.jar",
driver,
] + native_libs,
+ main_class = "FuzzTargetTestWrapper",
+ use_testrunner = False,
tags = tags,
visibility = visibility,
)
diff --git a/bazel/fuzz_target_test_wrapper.sh b/bazel/fuzz_target_test_wrapper.sh
deleted file mode 100755
index 53a46e35..00000000
--- a/bazel/fuzz_target_test_wrapper.sh
+++ /dev/null
@@ -1,42 +0,0 @@
-#!/usr/bin/env bash
-# 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.
-
-# Crashes will be available as test outputs. These are cleared on the next run,
-# so this is only useful for examples.
-DEFAULT_CRASH_PREFIX="$TEST_UNDECLARED_OUTPUTS_DIR"
-
-# Determine the path to load libjvm.so from, either relative to the location of
-# the java binary or to $JAVA_HOME, if set.
-JAVA_BIN=$(readlink -f "$(which java)")
-JAVA_HOME=${JAVA_HOME:-${JAVA_BIN%/bin/java}}
-# The location of libjvm.so relative to the JDK differs between JDK <= 8 and 9+.
-JVM_LD_LIBRARY_PATH="$JAVA_HOME/lib/server:$JAVA_HOME/lib/amd64/server"
-
-LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$JVM_LD_LIBRARY_PATH \
-eval "$1" -artifact_prefix="$DEFAULT_CRASH_PREFIX/" --reproducer_path="$DEFAULT_CRASH_PREFIX" -seed=2735196724 "${@:2}"
-# Assert that we either found a crash in java (exit code 77) or an ASan crash
-# (exit code 76).
-declare -i exit_code=$?
-if [ $exit_code -eq 77 ] || [ $exit_code -eq 76 ]
-then
- if [ "$(ls "$DEFAULT_CRASH_PREFIX/")" ]; then
- exit 0
- else
- exit 1
- fi
-else
- echo "Unexpected exit code: $exit_code"
- exit 1
-fi
diff --git a/bazel/jazzer b/bazel/jazzer
deleted file mode 100755
index 97a0ada1..00000000
--- a/bazel/jazzer
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/env bash
-# Determine the path to load libjvm.so from, either relative to the location of
-# the java binary or to $JAVA_HOME, if set.
-JAVA_BIN=$(readlink -f "$(which java)")
-JAVA_HOME=${JAVA_HOME:-${JAVA_BIN%/bin/java}}
-# The location of libjvm.so relative to the JDK differs between JDK <= 8 and 9+.
-JVM_LD_LIBRARY_PATH="$JAVA_HOME/lib/server:$JAVA_HOME/lib/amd64/server"
-
-LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$JVM_LD_LIBRARY_PATH \
-"$(dirname "$0")/jazzer_driver" "$@"
-
diff --git a/bazel/jazzer_wrapper.sh b/bazel/jazzer_wrapper.sh
deleted file mode 100755
index d12e1571..00000000
--- a/bazel/jazzer_wrapper.sh
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/usr/bin/env bash
-# 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.
-
-# --- begin runfiles.bash initialization v2 ---
-# Copy-pasted from the Bazel Bash runfiles library v2.
-set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
-source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
-source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
-source "$0.runfiles/$f" 2>/dev/null || \
-source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
-source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
-{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
-# --- end runfiles.bash initialization v2 --
-
-DEFAULT_CRASH_PREFIX="/tmp/jazzer"
-mkdir -p $DEFAULT_CRASH_PREFIX
-eval "$1" -artifact_prefix="$DEFAULT_CRASH_PREFIX/" --reproducer_path="$DEFAULT_CRASH_PREFIX" "${@:2}"
diff --git a/bazel/local_jdk_libjvm.bzl b/bazel/local_jdk_libjvm.bzl
deleted file mode 100644
index f1481601..00000000
--- a/bazel/local_jdk_libjvm.bzl
+++ /dev/null
@@ -1,59 +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.
-
-def _find_recursively_under_path(repository_ctx, path, basename):
- result = repository_ctx.execute([
- repository_ctx.which("sh"),
- "-c",
- """find -L "{path}" -name "{basename}" | head -1""".format(
- path = path,
- basename = basename,
- ),
- ])
- if result.return_code != 0:
- return None
- file_path = result.stdout.strip()
- if not file_path:
- return None
- return repository_ctx.path(file_path)
-
-LIBJVM_NAMES = [
- "libjvm.dylib",
- "libjvm.so",
-]
-
-def _local_jdk_libjvm(repository_ctx):
- java_binary = str(repository_ctx.path(Label("@local_jdk//:bin/java")))
- java_home = str(repository_ctx.path(java_binary + "/../../"))
-
- libjvm_path = None
- for libjvm_name in LIBJVM_NAMES:
- libjvm_path = _find_recursively_under_path(repository_ctx, java_home, libjvm_name)
- if libjvm_path != None:
- break
-
- if libjvm_path != None:
- repository_ctx.symlink(libjvm_path, libjvm_path.basename)
- build_content = """
-cc_import(
- name = "libjvm",
- shared_library = "{libjvm}",
- visibility = ["//visibility:public"],
-)
-""".format(libjvm = libjvm_path.basename)
- repository_ctx.file("BUILD.bazel", build_content, executable = False)
-
-local_jdk_libjvm = repository_rule(
- implementation = _local_jdk_libjvm,
-)
diff --git a/driver/BUILD.bazel b/driver/BUILD.bazel
index d699697f..2dfcc84d 100644
--- a/driver/BUILD.bazel
+++ b/driver/BUILD.bazel
@@ -60,12 +60,11 @@ cc_library(
deps = [
":sanitizer_hooks_with_pc",
"@bazel_tools//tools/cpp/runfiles",
- "@bazel_tools//tools/jdk:jni",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@com_google_glog//:glog",
+ "@fmeum_rules_jni//jni:libjvm",
"@jazzer_com_github_gflags_gflags//:gflags",
- "@jazzer_libjvm//:libjvm",
],
)
diff --git a/driver/libfuzzer_driver.cpp b/driver/libfuzzer_driver.cpp
index 02d567bb..80358922 100644
--- a/driver/libfuzzer_driver.cpp
+++ b/driver/libfuzzer_driver.cpp
@@ -14,6 +14,8 @@
#include "libfuzzer_driver.h"
+#include <rules_jni.h>
+
#include <algorithm>
#include <filesystem>
#include <fstream>
@@ -86,6 +88,7 @@ AbstractLibfuzzerDriver::AbstractLibfuzzerDriver(
// Disable glog log prefixes to mimic libFuzzer output.
FLAGS_log_prefix = false;
google::InitGoogleLogging((*argv)[0]);
+ rules_jni_init((*argv)[0]);
auto argv_start = *argv;
auto argv_end = *argv + *argc;
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
diff --git a/init.bzl b/init.bzl
index f1ae17f5..4e2a25c6 100644
--- a/init.bzl
+++ b/init.bzl
@@ -18,6 +18,7 @@ load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
load("@com_github_johnynek_bazel_jar_jar//:jar_jar.bzl", "jar_jar_repositories")
load("@io_bazel_rules_kotlin//kotlin:dependencies.bzl", "kt_download_local_dev_dependencies")
load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories")
+load("@fmeum_rules_jni//jni:repositories.bzl", "rules_jni_dependencies")
def jazzer_init():
bazel_skylib_workspace()
@@ -25,3 +26,4 @@ def jazzer_init():
kotlin_repositories()
native.register_toolchains("@jazzer//:kotlin_toolchain")
jar_jar_repositories()
+ rules_jni_dependencies()
diff --git a/repositories.bzl b/repositories.bzl
index 7294b673..58ef4dd5 100644
--- a/repositories.bzl
+++ b/repositories.bzl
@@ -16,7 +16,6 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
-load("//bazel:local_jdk_libjvm.bzl", "local_jdk_libjvm")
def jazzer_dependencies():
maybe(
@@ -99,6 +98,13 @@ def jazzer_dependencies():
maybe(
http_archive,
+ name = "fmeum_rules_jni",
+ sha256 = "9d17a403ccb8b005fdb490a0e94942f163d55fdbb4a3e51fb135bd44e174d170",
+ url = "https://github.com/fmeum/rules_jni/releases/download/v0.1.1/rules_jni-v0.1.1.tar.gz",
+ )
+
+ maybe(
+ http_archive,
build_file = "@jazzer//third_party:asm.BUILD",
name = "jazzer_ow2_asm",
sha256 = "7b596cc584b241619911e99c5c96366fccd533b1a50b8720c151c2f74b5915e3",
@@ -138,8 +144,3 @@ def jazzer_dependencies():
strip_prefix = "llvm-project-jazzer-b9c07e9c1e75857901808c13101c909104c413a8/compiler-rt/lib/fuzzer",
url = "https://github.com/CodeIntelligenceTesting/llvm-project-jazzer/archive/b9c07e9c1e75857901808c13101c909104c413a8.tar.gz",
)
-
- maybe(
- local_jdk_libjvm,
- name = "jazzer_libjvm",
- )
diff --git a/third_party/libjpeg_turbo.BUILD b/third_party/libjpeg_turbo.BUILD
index 8d447d87..4621f862 100644
--- a/third_party/libjpeg_turbo.BUILD
+++ b/third_party/libjpeg_turbo.BUILD
@@ -36,8 +36,7 @@ cmake(
],
deps = [
":libawt",
- "@bazel_tools//tools/jdk:jni",
- "@jazzer//third_party/jni:jni_libs",
+ "@fmeum_rules_jni//jni",
],
)