• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1load("@com_github_johnynek_bazel_jar_jar//:jar_jar.bzl", "jar_jar")
2load("@fmeum_rules_jni//jni:defs.bzl", "java_jni_library")
3load("//bazel:compat.bzl", "SKIP_ON_WINDOWS")
4load("//bazel:jar.bzl", "strip_jar")
5
6# The transitive dependencies of this target will be appended to the search path
7# of the bootstrap class loader. They will be visible to all classes - care must
8# be taken to shade everything and generally keep this target as small as
9# possible.
10java_binary(
11    name = "jazzer_bootstrap_unshaded",
12    create_executable = False,
13    runtime_deps = [":jazzer_bootstrap_lib"],
14)
15
16java_library(
17    name = "jazzer_bootstrap_lib",
18    visibility = ["//src/main/java/com/code_intelligence/jazzer:__pkg__"],
19    runtime_deps = [
20        ":runtime",
21        "//sanitizers",
22    ],
23)
24
25# These classes with public Bazel visibility are contained in jazzer_bootstrap.jar
26# and will thus be available on the bootstrap class path. This target can be
27# passed to the `deploy_env` attribute of the Jazzer `java_binary` to ensure that
28# it doesn't bundle in these classes.
29java_binary(
30    name = "jazzer_bootstrap_env",
31    create_executable = False,
32    visibility = ["//src/main/java/com/code_intelligence/jazzer:__pkg__"],
33    runtime_deps = [
34        "//src/main/java/com/code_intelligence/jazzer/api:hooks",
35        "//src/main/java/com/code_intelligence/jazzer/utils:unsafe_provider",
36    ],
37)
38
39jar_jar(
40    name = "jazzer_bootstrap_unstripped",
41    input_jar = ":jazzer_bootstrap_unshaded_deploy.jar",
42    rules = "bootstrap_shade_rules",
43)
44
45strip_jar(
46    name = "jazzer_bootstrap",
47    out = "jazzer_bootstrap.jar",
48    jar = ":jazzer_bootstrap_unstripped",
49    paths_to_keep = [
50        "com/code_intelligence/jazzer/**",
51        "jaz/**",
52        "META-INF/MANIFEST.MF",
53    ],
54    visibility = [
55        "//src/main/java/com/code_intelligence/jazzer/agent:__pkg__",
56        "//src/main/java/com/code_intelligence/jazzer/android:__pkg__",
57    ],
58)
59
60sh_test(
61    name = "jazzer_bootstrap_shading_test",
62    srcs = ["verify_shading.sh"],
63    args = [
64        "$(rootpath jazzer_bootstrap.jar)",
65    ],
66    data = [
67        "jazzer_bootstrap.jar",
68        "@local_jdk//:bin/jar",
69    ],
70    tags = [
71        # Coverage instrumentation necessarily adds files to the jar that we
72        # wouldn't want to release and thus causes this test to fail.
73        "no-coverage",
74    ],
75    target_compatible_with = SKIP_ON_WINDOWS,
76)
77
78# At runtime, the AgentInstaller appends jazzer_bootstrap.jar to the bootstrap
79# class loader's search path - these classes must not be available on the
80# regular classpath. Since dependents should not have to resort to reflection to
81# access these classes they know will be there at runtime, this compile-time
82# only dependency can be used as a replacement.
83java_library(
84    name = "jazzer_bootstrap_compile_only",
85    neverlink = True,
86    visibility = [
87        "//src/main/java/com/code_intelligence/jazzer/autofuzz:__pkg__",
88        "//src/main/java/com/code_intelligence/jazzer/driver:__pkg__",
89        "//src/main/java/com/code_intelligence/jazzer/instrumentor:__pkg__",
90    ],
91    exports = [
92        ":fuzz_target_runner_natives",
93        ":runtime",
94    ],
95)
96
97# The following targets must only be referenced directly by tests or native implementations.
98
99java_jni_library(
100    name = "coverage_map",
101    srcs = ["CoverageMap.java"],
102    native_libs = select({
103        "@platforms//os:android": ["//src/main/native/com/code_intelligence/jazzer/driver:jazzer_driver"],
104        "//conditions:default": [],
105    }),
106    visibility = [
107        "//src/jmh/java/com/code_intelligence/jazzer/instrumentor:__pkg__",
108        "//src/main/native/com/code_intelligence/jazzer/driver:__pkg__",
109        "//src/test:__subpackages__",
110    ],
111    deps = [
112        "//src/main/java/com/code_intelligence/jazzer/runtime:constants",
113        "//src/main/java/com/code_intelligence/jazzer/utils:unsafe_provider",
114    ],
115)
116
117java_jni_library(
118    name = "trace_data_flow_native_callbacks",
119    srcs = ["TraceDataFlowNativeCallbacks.java"],
120    visibility = [
121        "//src/main/native/com/code_intelligence/jazzer/driver:__pkg__",
122    ],
123    deps = ["@org_ow2_asm_asm//jar"],
124)
125
126java_jni_library(
127    name = "fuzz_target_runner_natives",
128    srcs = ["FuzzTargetRunnerNatives.java"],
129    visibility = ["//src/main/native/com/code_intelligence/jazzer/driver:__pkg__"],
130    deps = [
131        ":constants",
132    ],
133)
134
135java_jni_library(
136    name = "mutator",
137    srcs = ["Mutator.java"],
138    visibility = [
139        "//src/main/java/com/code_intelligence/jazzer/mutation/mutator/libfuzzer:__pkg__",
140        "//src/main/native/com/code_intelligence/jazzer/driver:__pkg__",
141    ],
142)
143
144java_library(
145    name = "runtime",
146    srcs = [
147        "HardToCatchError.java",
148        "JazzerInternal.java",
149        "NativeLibHooks.java",
150        "TraceCmpHooks.java",
151        "TraceDivHooks.java",
152        "TraceIndirHooks.java",
153    ],
154    visibility = [
155        "//src/main/java/com/code_intelligence/jazzer/android:__pkg__",
156        "//src/main/native/com/code_intelligence/jazzer/driver:__pkg__",
157        "//src/test:__subpackages__",
158    ],
159    runtime_deps = [
160        ":fuzz_target_runner_natives",
161        ":mutator",
162        # Access to Unsafe is possible without any tricks if the class that does it is loaded by the
163        # bootstrap loader. We thus want Jazzer to use this class from jazzer_bootstrap.
164        "//src/main/java/com/code_intelligence/jazzer/utils:unsafe_provider",
165    ],
166    deps = [
167        ":constants",
168        ":coverage_map",
169        ":trace_data_flow_native_callbacks",
170        "//src/main/java/com/code_intelligence/jazzer/api:hooks",
171    ],
172)
173
174# This target exposes a class that can safely be loaded in both the system and the bootstrap class
175# loader as it provides true constants that do not change over the lifetime of the JVM.
176java_library(
177    name = "constants",
178    srcs = ["Constants.java"],
179    visibility = ["//visibility:public"],
180)
181