xref: /aosp_15_r20/external/jazzer-api/examples/src/main/native/com/example/BUILD.bazel (revision 33edd6723662ea34453766bfdca85dbfdd5342b8)
1load("@fmeum_rules_jni//jni:defs.bzl", "cc_jni_library")
2
3cc_jni_library(
4    name = "native_asan",
5    srcs = [
6        "com_example_ExampleFuzzerWithNative.cpp",
7    ],
8    copts = [
9        "-fsanitize=fuzzer-no-link,address",
10        "-fno-sanitize-blacklist",
11    ],
12    defines = [
13        # Workaround for Windows build failures with VS 2022:
14        # "lld-link: error: /INFERASANLIBS is not allowed in .drectve"
15        # https://github.com/llvm/llvm-project/issues/56300#issuecomment-1214313292
16        "_DISABLE_STRING_ANNOTATION=1",
17        "_DISABLE_VECTOR_ANNOTATION=1",
18    ],
19    linkopts = select({
20        "@platforms//os:windows": [
21            # Windows requires all symbols that should be imported from the main
22            # executable to be defined by an import lib.
23            "/wholearchive:clang_rt.asan_dll_thunk-x86_64.lib",
24        ],
25        "//conditions:default": [
26            "-fsanitize=fuzzer-no-link,address",
27        ],
28    }),
29    visibility = ["//examples:__pkg__"],
30    deps = [
31        "//examples:example_fuzzer_with_native_lib.hdrs",
32    ],
33)
34
35cc_jni_library(
36    name = "native_ubsan",
37    srcs = [
38        "com_example_ExampleFuzzerWithNative.cpp",
39    ],
40    copts = [
41        "-fsanitize=fuzzer-no-link,undefined",
42        "-fno-sanitize-recover=all",
43    ],
44    linkopts = select({
45        "@platforms//os:windows": [
46            # Using the asan thunk is correct here as it contains symbols for
47            # UBSan and SanCov as well.
48            "/wholearchive:clang_rt.asan_dll_thunk-x86_64.lib",
49        ],
50        "//conditions:default": [
51            "-fsanitize=fuzzer-no-link,undefined",
52        ],
53    }),
54    visibility = ["//examples:__pkg__"],
55    deps = [
56        "//examples:example_fuzzer_with_native_lib.hdrs",
57    ],
58)
59