Index: compiler-rt/CMakeLists.txt =================================================================== --- compiler-rt/CMakeLists.txt +++ compiler-rt/CMakeLists.txt @@ -579,6 +579,9 @@ # Unittests need access to C++ standard library. string(APPEND COMPILER_RT_TEST_COMPILER_CFLAGS " ${stdlib_flag}") +if (COMPILER_RT_HAS_SYSROOT_FLAG AND CMAKE_SYSROOT) + string(APPEND COMPILER_RT_TEST_COMPILER_CFLAGS " --sysroot=${CMAKE_SYSROOT}") +endif() # When cross-compiling, COMPILER_RT_TEST_COMPILER_CFLAGS help in compilation # and linking of unittests. Index: compiler-rt/lib/tsan/go/buildgo.sh =================================================================== --- compiler-rt/lib/tsan/go/buildgo.sh +++ compiler-rt/lib/tsan/go/buildgo.sh @@ -220,7 +220,7 @@ fi $CC $DIR/gotsan.cpp -c -o $DIR/race_$SUFFIX.syso $FLAGS $CFLAGS -$CC $OSCFLAGS $ARCHCFLAGS test.c $DIR/race_$SUFFIX.syso -g -o $DIR/test $OSLDFLAGS $LDFLAGS +$CC $OSCFLAGS $ARCHCFLAGS test.c $DIR/race_$SUFFIX.syso -g -o $DIR/test $OSLDFLAGS $LDFLAGS $EXTRA_CFLAGS # Verify that no libc specific code is present. if [ "$DEPENDS_ON_LIBC" != "1" ]; then Index: compiler-rt/lib/tsan/rtl/CMakeLists.txt =================================================================== --- compiler-rt/lib/tsan/rtl/CMakeLists.txt +++ compiler-rt/lib/tsan/rtl/CMakeLists.txt @@ -113,6 +113,7 @@ if("${CMAKE_C_FLAGS}" MATCHES "-Wno-(error=)?unused-command-line-argument") set(EXTRA_CFLAGS "-Wno-error=unused-command-line-argument ${EXTRA_CFLAGS}") endif() +set(EXTRA_CFLAGS "${COMPILER_RT_TEST_COMPILER_CFLAGS} ${EXTRA_CFLAGS}") if(APPLE) # Ideally we would check the SDK version for the actual platform we are Index: compiler-rt/test/fuzzer/lit.cfg.py =================================================================== --- compiler-rt/test/fuzzer/lit.cfg.py +++ compiler-rt/test/fuzzer/lit.cfg.py @@ -69,7 +69,7 @@ def generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True, msan_enabled=False): compiler_cmd = config.clang - extra_cmd = config.target_flags + extra_cmd = config.target_flags + config.target_cflags if is_cpp: std_cmd = '--driver-mode=g++' Index: compiler-rt/test/safestack/lit.cfg.py =================================================================== --- compiler-rt/test/safestack/lit.cfg.py +++ compiler-rt/test/safestack/lit.cfg.py @@ -12,8 +12,8 @@ config.suffixes = ['.c', '.cpp', '.m', '.mm', '.ll', '.test'] # Add clang substitutions. -config.substitutions.append( ("%clang_nosafestack ", config.clang + " -O0 -fno-sanitize=safe-stack ") ) -config.substitutions.append( ("%clang_safestack ", config.clang + " -O0 -fsanitize=safe-stack ") ) +config.substitutions.append( ("%clang_nosafestack ", config.clang + config.target_cflags + " -O0 -fno-sanitize=safe-stack ") ) +config.substitutions.append( ("%clang_safestack ", config.clang + config.target_cflags + " -O0 -fsanitize=safe-stack ") ) if config.lto_supported: config.substitutions.append((r"%clang_lto_safestack ", ' '.join([config.clang] + config.lto_flags + ['-fsanitize=safe-stack ']))) Index: compiler-rt/test/tsan/CMakeLists.txt =================================================================== --- compiler-rt/test/tsan/CMakeLists.txt +++ compiler-rt/test/tsan/CMakeLists.txt @@ -40,6 +40,7 @@ string(REPLACE ";" " " LIBDISPATCH_CFLAGS_STRING " ${COMPILER_RT_TEST_LIBDISPATCH_CFLAGS}") string(APPEND TSAN_TEST_TARGET_CFLAGS ${LIBDISPATCH_CFLAGS_STRING}) + string(APPEND TSAN_TEST_TARGET_CFLAGS ${COMPILER_RT_TEST_COMPILER_CFLAGS}) if (COMPILER_RT_HAS_MSSE4_2_FLAG) string(APPEND TSAN_TEST_TARGET_CFLAGS " -msse4.2 ")