jazzer icon indicating copy to clipboard operation
jazzer copied to clipboard

Jazzer does not use libc++

Open chrismgrayftsinc opened this issue 3 years ago • 7 comments

I tried adding jazzer test rules as a http_archive to my WORKSPACE file:

http_archive(
    name = "rules_jazzer",
    sha256 = "c2b26f80618f51fd7d75e2e8067084f3776f321b596ca2fb19c585f836739bf9",
    strip_prefix = "jazzer-0.9.1",
    urls = ["https://github.com/CodeIntelligenceTesting/jazzer/archive/refs/tags/v0.9.1.tar.gz"],
)

and then using java_fuzz_target_test as a test in one of my BUILD files

load("@rules_jazzer//bazel:fuzz_target.bzl", "java_fuzz_target_test")

java_fuzz_target_test(
    name = "gateway_controller_fuzz",
  ....
)

However, it seems that java_fuzz_target_test adds dependencies on internal targets (e.g. //agent/src/main/java/com/code_intelligence/jazzer/api), which means that it can't be used in this way.

FWIW, I also suggested that jazzer rules could be added to bazelbuild/rules_fuzzing, so that might be a better place to fix this problem.

chrismgrayftsinc avatar Apr 19 '21 20:04 chrismgrayftsinc

Indeed, the current macro is mostly meant for regression testing within Jazzer.

I am quite interested in proper rules_fuzzing though and will see what I can contribute to it.

fmeum avatar Apr 20 '21 16:04 fmeum

Jazzer has been integrated into rules_fuzzing with https://github.com/bazelbuild/rules_fuzzing/pull/143. The java_fuzz_test macro provided by these rules is even more convenient than java_fuzz_target_test and can be used by other projects.

fmeum avatar May 11 '21 14:05 fmeum

@chrismgrayftsinc Have you managed to set up rules_fuzzing?

fmeum avatar Jul 08 '21 15:07 fmeum

Thanks for checking in! I tried to set up a test today but I'm running into issues with C++ compilation. I don't do much C++ development so it's likely I don't have the correct toolchain setup.

(The specific error is to do with std::filesystem not being found at link time, which appears to be an issue with a too-old libstdc++)

chrismgrayftsinc avatar Jul 08 '21 23:07 chrismgrayftsinc

I will look into ways to resolve this on our end. Some versions of libstdc++ are indeed known to cause problems since they claim to have C++17 support but then don't include std::filesystem.

fmeum avatar Jul 09 '21 20:07 fmeum

Fixing this is blocked by https://github.com/bazelbuild/bazel/issues/13071.

fmeum avatar Jul 09 '21 21:07 fmeum

Verified that this issue is resolved by https://github.com/bazelbuild/bazel/pull/13666. Let's see whether we can that merged upstream.

@chrismgrayftsinc If you still want to give this a try, the following should work with latest stable Bazel (4.1.0):

  1. Add a dependency on Jazzer at commit 41d8027ac73311e129e6227d9205248800af8eb6 before loading the rules_fuzzing dependencies.
  2. Execute Bazel with the arguments given in https://github.com/CodeIntelligenceTesting/jazzer/pull/147#issuecomment-878231839.

I'm sorry that this is so difficult right now, but the Bazel story around libc++ is just not very polished.

fmeum avatar Jul 12 '21 12:07 fmeum

We are no longer relying on std::filesystem and am in the process of restoring C++1 compatibility, so this shouldn't be necessary anymore.

fmeum avatar Aug 18 '22 08:08 fmeum