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

Compiling pre-processed sourcecode with CCache loses path information

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 6.0.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Fully Compatible
    • ALL
    • Dev Platform 2022-01-24, Dev Platform 2022-03-21, Dev Platform 2022-04-04

      Compiling with scons+ccache+UBSAN results in binaries which do not appear to respect the contents of etc/ubsan.denylist.

      python ./buildscripts/scons.py --variables-files=etc/scons/developer_versions.vars --variables-files=etc/scons/mongodbtoolchain_v4_clang.vars --dbg=on --opt=on --allocator=system --sanitize=address,undefined  --link-model=dynamic --linker=lld ICECC= CCACHE=/opt/mongodbtoolchain/v4/bin/ccache MONGO_GIT_HASH="unknown" VERBOSE=1 +message_compressor_manager_test
      
      ...
      
      t":"FullNormalCompression","rep":1,"reps":1}}
      {"t":{"$date":"2021-12-29T23:11:41.301Z"},"s":"I",  "c":"TEST",     "id":23059,   "ctx":"thread1","msg":"Running","attr":{"test":"SERVER_28008","rep":1,"reps":1}}
      src/third_party/zstandard-1.4.4/zstd/lib/compress/zstd_compress.c:1326:46: runtime error: applying non-zero offset 1 to null pointer
          #0 0x7f5ccee84436 in ZSTD_reset_matchState /home/ubuntu/mongo/src/third_party/zstandard-1.4.4/zstd/lib/compress/zstd_compress.c:1326:46
          #1 0x7f5ccee82b52 in ZSTD_resetCCtx_internal /home/ubuntu/mongo/src/third_party/zstandard-1.4.4/zstd/lib/compress/zstd_compress.c:1527:9
          #2 0x7f5ccee79877 in ZSTD_compressBegin_internal /home/ubuntu/mongo/src/third_party/zstandard-1.4.4/zstd/lib/compress/zstd_compress.c:2946:5
      
      

      Checking the ccache diagnostics we can see entries like:

      [2021-12-29T22:22:41.356333 8593 ] Running real compiler
      [2021-12-29T22:22:41.356383 8593 ] Executing /opt/mongodbtoolchain/v4/bin/clang -std=c11 -fasynchronous-unwind-tables -ggdb -Wall -Wsign-compare -Wno-unknown-pragmas -Winvalid-pch -fno-omit-frame-pointer -fno-strict-aliasing -O2 -march=sandybridge -mtune=generic -mprefer-vector-width=128 -Wno-unused-local-typedefs -Wno-unused-function -Wno-unused-private-field -Wno-deprecated-declarations -Wno-tautological-constant-out-of-range-compare -Wno-tautological-constant-compare -Wno-tautological-unsigned-zero-compare -Wno-tautological-unsigned-enum-zero-compare -Wno-unused-const-variable -Wno-missing-braces -Wno-inconsistent-missing-override -Wno-potentially-evaluated-expression -Wno-unused-lambda-capture -fstack-protector-strong -fsanitize=address,undefined -fno-omit-frame-pointer -fsanitize-blacklist=etc/ubsan.denylist -fno-sanitize-recover -fno-sanitize=vptr -Qunused-arguments -fPIC -Werror -DPCRE_STATIC -DMONGO_USE_VISIBILITY -D_XOPEN_SOURCE=700 -D_GNU_SOURCE -DADDRESS_SANITIZER -DUNDEFINED_BEHAVIOR_SANITIZER -DBOOST_THREAD_VERSION=5 -DBOOST_THREAD_USES_DATETIME -DBOOST_SYSTEM_NO_DEPRECATED -DBOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS -DBOOST_ENABLE_ASSERT_DEBUG_HANDLER -DBOOST_LOG_NO_SHORTHAND_NAMES -DBOOST_LOG_USE_NATIVE_SYSLOG -DBOOST_LOG_WITHOUT_THREAD_ATTR -DABSL_FORCE_ALIGNED_ACCESS -DBOOST_LOG_DYN_LINK -Ibuild/optdebug/third_party/zstandard-1.4.4/zstd/lib/common -Isrc/third_party/zstandard-1.4.4/zstd/lib/common -Isrc/third_party/zstandard-1.4.4/zstd/lib -x c -c -fcolor-diagnostics -o build/optdebug/third_party/zstandard-1.4.4/zstd/lib/compress/zstd_compress.dyn.o /run/user/1000/ccache-tmp/tmp.cpp_stdout.G03F6m.i
      

      Note that this compiler invocation created build/optdebug/third_party/zstandard-1.4.4/zstd/lib/compress/zstd_compress.dyn.o and consumed /run/user/1000/ccache-tmp/tmp.cpp_stdout.G03F6m.i. Because clang is not running against the true source tree, I believe clang cannot apply the following relative path based suppression from etc/ubsan.denylist:

      # TODO(SERVER-49230) Remove this after upgrading to 1.5 per
      # https://github.com/facebook/zstd/issues/2110#issuecomment-996146316
      [pointer-overflow]
      src:src/third_party/zstandard-*/*
      

      I believe CCache chooses to run this way because we've disabled CCACHE_CPP2. According to CCache's docs:

      If true, ccache will first run the preprocessor to preprocess the source code (see The preprocessor mode) and then on a cache miss run the compiler on the source code to get hold of the object file.

      When that logic is excised, the following invokations results in functioning test binaries:

      python ./buildscripts/scons.py --variables-files=etc/scons/developer_versions.vars --variables-files=etc/scons/mongodbtoolchain_v4_clang.vars --dbg=on --opt=on --allocator=system --sanitize=address,undefined  --link-model=dynamic --linker=lld ICECC= CCACHE=/opt/mongodbtoolchain/v4/bin/ccache MONGO_GIT_HASH="unknown" VERBOSE=1 +message_compressor_manager_test
      ...
      {"t":{"$date":"2021-12-29T22:58:18.571Z"},"s":"I",  "c":"TEST",     "id":4680101, "ctx":"thread1","msg":"Result","attr":{"suite":{"name":"ZstdMessageCompressor","tests":2,"fails":0,"asserts":0,"time":{"durationMillis":0},"failures":[]}}}
      {"t":{"$date":"2021-12-29T22:58:18.571Z"},"s":"I",  "c":"TEST",     "id":23065,   "ctx":"thread1","msg":"Totals","attr":{"totals":{"name":"TOTALS","tests":17,"fails":0,"asserts":0,"time":{"durationMillis":1},"failures":[]}}}
      {"t":{"$date":"2021-12-29T22:58:18.571Z"},"s":"I",  "c":"TEST",     "id":23069,   "ctx":"thread1","msg":"SUCCESS - All tests in all suites passed"}
      scons: done building targets.
      

            Assignee:
            andrew.morrow@mongodb.com Andrew Morrow (Inactive)
            Reporter:
            spencer.jackson@mongodb.com Spencer Jackson
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: