1load("//bazel:cc.bzl", "cc_17_library") 2 3cc_library( 4 name = "sanitizer_hooks_with_pc", 5 srcs = ["sanitizer_hooks_with_pc.cpp"], 6 hdrs = ["sanitizer_hooks_with_pc.h"], 7 linkstatic = True, 8) 9 10cc_test( 11 name = "sanitizer_hooks_with_pc_test", 12 size = "small", 13 srcs = ["sanitizer_hooks_with_pc_test.cpp"], 14 deps = [ 15 ":sanitizer_hooks_with_pc", 16 "@googletest//:gtest", 17 "@googletest//:gtest_main", 18 ], 19) 20 21cc_library( 22 name = "fuzzed_data_provider", 23 srcs = [ 24 "fuzzed_data_provider.cpp", 25 ], 26 hdrs = [ 27 "fuzzed_data_provider.h", 28 ], 29 visibility = [ 30 "//agent/src/main/native/com/code_intelligence/jazzer/replay:__pkg__", 31 ], 32 deps = [ 33 "@com_google_absl//absl/strings:str_format", 34 "@fmeum_rules_jni//jni", 35 ], 36) 37 38cc_library( 39 name = "jvm_tooling_lib", 40 srcs = [ 41 "coverage_tracker.cpp", 42 "fuzz_target_runner.cpp", 43 "java_reproducer.cpp", 44 "java_reproducer.h", 45 "java_reproducer_templates.h", 46 "jvm_tooling.cpp", 47 "libfuzzer_callbacks.cpp", 48 "libfuzzer_callbacks.h", 49 "libfuzzer_driver.cpp", 50 "signal_handler.cpp", 51 "signal_handler.h", 52 "utils.cpp", 53 "utils.h", 54 ], 55 hdrs = [ 56 "coverage_tracker.h", 57 "fuzz_target_runner.h", 58 "fuzzed_data_provider.h", 59 "jvm_tooling.h", 60 "libfuzzer_driver.h", 61 ], 62 linkopts = select({ 63 "@platforms//os:windows": [], 64 "//conditions:default": ["-ldl"], 65 }), 66 # Needs to be linked statically for JNI_OnLoad_jazzer_initialize to be found 67 # by the JVM. 68 linkstatic = True, 69 local_defines = select({ 70 # Windows does not have SIGUSR1, which triggers a graceful exit of 71 # libFuzzer. Instead, trigger a hard exit. 72 "@platforms//os:windows": ["SIGUSR1=SIGTERM"], 73 "//conditions:default": [], 74 }), 75 tags = [ 76 # Should be built through the cc_17_library driver_lib. 77 "manual", 78 ], 79 visibility = ["//visibility:public"], 80 deps = [ 81 ":fuzzed_data_provider", 82 ":sanitizer_hooks_with_pc", 83 "@bazel_tools//tools/cpp/runfiles", 84 "@com_google_absl//absl/strings", 85 "@com_google_absl//absl/strings:str_format", 86 "@com_google_glog//:glog", 87 "@fmeum_rules_jni//jni:libjvm", 88 "@jazzer_com_github_gflags_gflags//:gflags", 89 ], 90) 91 92cc_17_library( 93 name = "driver_lib", 94 srcs = [ 95 "libfuzzer_fuzz_target.cpp", 96 ], 97 linkstatic = True, 98 deps = [ 99 ":jvm_tooling_lib", 100 "@jazzer_libfuzzer//:libFuzzer", 101 ], 102 alwayslink = True, 103) 104 105cc_binary( 106 name = "jazzer_driver", 107 srcs = [ 108 # Defines symbols otherwise defined by sanitizers to prevent linker 109 # errors and print JVM stack traces. 110 # Windows-compatible replacement for __attribute__((weak)). 111 "sanitizer_symbols.cpp", 112 ], 113 data = [ 114 "//agent:jazzer_agent_deploy.jar", 115 ], 116 linkopts = select({ 117 "@platforms//os:windows": [], 118 "//conditions:default": [ 119 "-rdynamic", 120 ], 121 }) + select({ 122 "//:clang_on_linux": ["-fuse-ld=lld"], 123 "//conditions:default": [], 124 }), 125 linkstatic = True, 126 visibility = ["//visibility:public"], 127 deps = [":driver_lib"], 128) 129 130alias( 131 name = "using_toolchain_on_osx", 132 actual = select({ 133 "//third_party:uses_toolchain": "@platforms//os:osx", 134 # In order to achieve AND semantics, reference a setting that is known 135 # not to apply. 136 "//conditions:default": "//third_party:uses_toolchain", 137 }), 138) 139 140cc_binary( 141 name = "jazzer_driver_asan", 142 data = [ 143 "//agent:jazzer_agent_deploy.jar", 144 ], 145 linkopts = [ 146 ] + select({ 147 "@platforms//os:windows": [ 148 # Sanitizer runtimes have to be linked manually on Windows: 149 # https://devblogs.microsoft.com/cppblog/addresssanitizer-asan-for-windows-with-msvc/ 150 "/wholearchive:clang_rt.asan-x86_64.lib", 151 "/wholearchive:clang_rt.asan_cxx-x86_64.lib", 152 ], 153 "//conditions:default": [ 154 "-fsanitize=address", 155 "-static-libsan", 156 "-rdynamic", 157 ], 158 }) + select({ 159 "//:clang_on_linux": ["-fuse-ld=lld"], 160 "//conditions:default": [], 161 }), 162 linkstatic = True, 163 visibility = ["//visibility:public"], 164 deps = [":driver_lib"] + select({ 165 # There is no static ASan runtime on macOS, so link to the dynamic 166 # runtime library if on macOS and using the toolchain. 167 ":using_toolchain_on_osx": ["@llvm_toolchain_llvm//:macos_asan_dynamic"], 168 "//conditions:default": [], 169 }), 170) 171 172cc_binary( 173 name = "jazzer_driver_ubsan", 174 data = [ 175 "//agent:jazzer_agent_deploy.jar", 176 ], 177 linkopts = [ 178 ] + select({ 179 "@platforms//os:windows": [ 180 # Sanitizer runtimes have to be linked manually on Windows: 181 # https://devblogs.microsoft.com/cppblog/addresssanitizer-asan-for-windows-with-msvc/ 182 "/wholearchive:clang_rt.ubsan_standalone-x86_64.lib", 183 "/wholearchive:clang_rt.ubsan_standalone_cxx-x86_64.lib", 184 ], 185 "//conditions:default": [ 186 "-fsanitize=undefined", 187 # Link UBSan statically, even on macOS. 188 "-static-libsan", 189 "-fsanitize-link-c++-runtime", 190 "-rdynamic", 191 ], 192 }) + select({ 193 "//:clang_on_linux": ["-fuse-ld=lld"], 194 "//conditions:default": [], 195 }), 196 linkstatic = True, 197 visibility = ["//visibility:public"], 198 deps = [":driver_lib"], 199) 200 201cc_test( 202 name = "jvm_tooling_test", 203 size = "small", 204 srcs = [ 205 "jvm_tooling_test.cpp", 206 "sanitizer_symbols_for_tests.cpp", 207 ], 208 args = [ 209 "--cp=jazzer/$(rootpath //driver/testdata:fuzz_target_mocks_deploy.jar)", 210 ], 211 data = [ 212 "//agent:jazzer_agent_deploy.jar", 213 "//driver/testdata:fuzz_target_mocks_deploy.jar", 214 ], 215 includes = ["."], 216 linkopts = select({ 217 "@platforms//os:windows": [], 218 "//conditions:default": [ 219 # Needs to export symbols dynamically for JNI_OnLoad_jazzer_initialize 220 # to be found by the JVM. 221 "-rdynamic", 222 ], 223 }), 224 deps = [ 225 ":jvm_tooling_lib", 226 ":test_main", 227 "@bazel_tools//tools/cpp/runfiles", 228 "@googletest//:gtest", 229 "@jazzer_com_github_gflags_gflags//:gflags", 230 ], 231) 232 233cc_test( 234 name = "fuzzed_data_provider_test", 235 size = "medium", 236 srcs = [ 237 "fuzzed_data_provider_test.cpp", 238 "sanitizer_symbols_for_tests.cpp", 239 ], 240 args = [ 241 "--cp=jazzer/$(rootpath //driver/testdata:fuzz_target_mocks_deploy.jar)", 242 ], 243 data = [ 244 "//agent:jazzer_agent_deploy.jar", 245 "//driver/testdata:fuzz_target_mocks_deploy.jar", 246 ], 247 includes = ["."], 248 deps = [ 249 ":jvm_tooling_lib", 250 ":test_main", 251 "@bazel_tools//tools/cpp/runfiles", 252 "@googletest//:gtest", 253 "@jazzer_com_github_gflags_gflags//:gflags", 254 ], 255) 256 257cc_library( 258 name = "test_main", 259 srcs = ["test_main.cpp"], 260 linkstatic = True, 261 deps = [ 262 "@googletest//:gtest", 263 "@jazzer_com_github_gflags_gflags//:gflags", 264 ], 265) 266