Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-90130

Figure out why Bazel is expanding -fsanitize=undefined in Clang

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Build

      When adding -fsanitize=undefined to a bazel target's copt, it invokes clang with a series of options instead of -fsanitize=undefined:

       /home/ubuntu/mongo/build/bazelisk build --//bazel/config:compiler_type=clang --//bazel/config:build_mode=opt_debug --//bazel/config:separate_debug=False --//bazel/config:libunwind=auto --//bazel/config:use_gdbserver=False --//bazel/config:spider_monkey_dbg=False --//bazel/config:allocator=system --//bazel/config:use_lldbserver=False --//bazel/config:use_wait_for_debugger=False --//bazel/config:use_ocsp_stapling=True --//bazel/config:use_disable_ref_track=False --//bazel/config:use_wiredtiger=True --//bazel/config:use_glibcxx_debug=False --//bazel/config:build_grpc=False --//bazel/config:use_libcxx=False --//bazel/config:detect_odr_violations=False --//bazel/config:linkstatic=True --//bazel/config:use_diagnostic_latches=False --//bazel/config:shared_archive=False --//bazel/config:linker=lld --//bazel/config:streams_release_build=True --//bazel/config:build_enterprise=False --//bazel/config:visibility_support=auto --platforms=//bazel/platforms:linux_arm64_clang --host_platform=//bazel/platforms:linux_arm64_clang --compilation_mode=dbg --//bazel/config:http_client=True --//bazel/config:ubsan=True --//bazel/config:asan=False //src/mongo/platform:visibility_test1 --config=local
      
      -fsanitize=alignment,array-bounds,bool,builtin,enum,float-cast-overflow,integer-divide-by-zero,nonnull-attribute,null,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,signed-integer-overflow,unreachable,vla-bound,vptr
      

      It's possible there's logic in bazel's internals to perform this switch, but it's unclear why it's doing it and if it is actually equivalent to -fsanitize=undefined.

      A symptom of this issue appears to be that -fno-sanitize on specific suboptions of ubsan is also ignored. We can work around this issue by manually expanding -fsanitize=undefined ourselves, but it's messy.

      The list of sanitizers bazel is passing in is functionally identical to -fsanitize=undefined:
      https://github.com/llvm-mirror/clang/blob/master/include/clang/Basic/Sanitizers.def#L134 so we won't lose/gain any coverage unintentionally.

            Assignee:
            Unassigned Unassigned
            Reporter:
            zack.winter@mongodb.com Zack Winter
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: