__init__.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. from devtools.yamaker.modules import Linkable, Switch
  2. from devtools.yamaker.platform_macros import LLVM_VERSION
  3. from devtools.yamaker.project import CMakeNinjaNixProject
  4. # as of 15.0.x, libfuzzer makes use of
  5. #
  6. # ATTRIBUTE_NO_SANITIZE_ALL
  7. # size_t ForEachNonZeroByte()
  8. #
  9. # which invokes undefined behavior,
  10. # which is not disabled by ATTRIBUTE_NO_SANITIZE_ALL
  11. S1 = """
  12. IF (SANITIZER_TYPE == "undefined")
  13. NO_SANITIZE()
  14. ENDIF()
  15. """
  16. def post_install(self):
  17. with self.yamakes["."] as m:
  18. m.NO_SANITIZE_COVERAGE = True
  19. m.after("CFLAGS", S1)
  20. m.before(
  21. "NO_SANITIZE_COVERAGE",
  22. Switch(
  23. {
  24. 'SANITIZE_COVERAGE MATCHES "trace-pc"': 'MESSAGE(FATAL_ERROR "I will crash you with trace-pc or trace-pc-guard. Use inline-8bit-counters.")'
  25. }
  26. ),
  27. )
  28. m.SET.append(["SANITIZER_CFLAGS"])
  29. m.after(
  30. "SRCS",
  31. Switch(
  32. OS_WINDOWS=Linkable(SRCS=["lib/fuzzer/standalone/StandaloneFuzzTargetMain.c"]),
  33. default=Linkable(SRCS=m.SRCS),
  34. ),
  35. )
  36. m.SRCS = []
  37. m.PEERDIR.add("library/cpp/sanitizer/include")
  38. with self.yamakes["lib/fuzzer/afl"] as m:
  39. m.NO_SANITIZE = True
  40. m.PEERDIR = ["contrib/libs/afl/llvm_mode"]
  41. llvm_libfuzzer = CMakeNinjaNixProject(
  42. owners=["g:cpp-contrib"],
  43. nixattr=f"llvmPackages_{LLVM_VERSION}.compiler-rt",
  44. arcdir="contrib/libs/libfuzzer",
  45. build_targets=["clang_rt.fuzzer-x86_64", "libfuzzer-afl.so"],
  46. copy_sources=[
  47. "include/fuzzer/FuzzedDataProvider.h",
  48. "lib/fuzzer/standalone/StandaloneFuzzTargetMain.c",
  49. ],
  50. put={
  51. "clang_rt.fuzzer-x86_64": ".",
  52. "fuzzer-afl": "lib/fuzzer/afl",
  53. },
  54. post_install=post_install,
  55. )