aboutsummaryrefslogtreecommitdiff
path: root/examples/src/main
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/src/main
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/src/main')
-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
4 files changed, 8 insertions, 53 deletions
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