Page MenuHomePhabricator

[CMake] Avoid accidental C++ standard library dependency in sanitizers
ClosedPublic

Authored by phosek on Oct 6 2020, 1:26 PM.

Details

Summary

While sanitizers don't use C++ standard library, we could still end
up accidentally including or linking it just by the virtue of using
the C++ compiler. Pass -nostdinc++ and -nostdlib++ to avoid these
accidental dependencies.

Diff Detail

Event Timeline

phosek created this revision.Oct 6 2020, 1:26 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 6 2020, 1:26 PM
Herald added subscribers: Restricted Project, mgorny. · View Herald Transcript
phosek requested review of this revision.Oct 6 2020, 1:26 PM

LGTM, but I'll give the sanitizer folks a bit of time to review as well.

smeenai accepted this revision.Oct 14 2020, 6:15 PM

This is needed to avoid potential race conditions where some of the C++ headers have been copied but not all of them, and some other runtime that doesn't depend on the C++ headers sees this incomplete state and gets a spurious build failure, so LGTM.

This revision is now accepted and ready to land.Oct 14 2020, 6:15 PM
This revision was landed with ongoing or failed builds.Oct 14 2020, 6:27 PM
This revision was automatically updated to reflect the committed changes.
vitalybuka added a comment.EditedOct 14 2020, 6:28 PM

ninja check-tsan

1 error generated.
[18/23] Generating TsanUnitTestsObjects.tsan_clock_test.cpp.x86_64.o
FAILED: projects/compiler-rt/lib/tsan/tests/unit/TsanUnitTestsObjects.tsan_clock_test.cpp.x86_64.o 
cd /usr/local/google/home/vitalybuka/src/llvm.git/out/z/projects/compiler-rt/lib/tsan/tests/unit && /usr/local/google/home/vitalybuka/src/llvm.git/out/z/./bin/clang -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -Wno-non-virtual-dtor -nostdinc++ -fPIE -fno-rtti -Wno-covered-switch-default -DGTEST_NO_LLVM_SUPPORT=1 -DGTEST_HAS_RTTI=0 -I/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/llvm/utils/unittest/googletest/include -I/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/llvm/utils/unittest/googletest -I/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/include -I/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib -I/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/tsan/rtl -DGTEST_HAS_RTTI=0 -m64 -c -o TsanUnitTestsObjects.tsan_clock_test.cpp.x86_64.o /usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/tsan/tests/unit/tsan_clock_test.cpp
In file included from /usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/tsan/tests/unit/tsan_clock_test.cpp:14:
/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/llvm/utils/unittest/googletest/include/gtest/gtest.h:54:10: fatal error: 'limits' file not found
#include <limits>
         ^~~~~~~~
1 error generated.
phosek reopened this revision.Oct 14 2020, 6:46 PM

ninja check-tsan

1 error generated.
[18/23] Generating TsanUnitTestsObjects.tsan_clock_test.cpp.x86_64.o
FAILED: projects/compiler-rt/lib/tsan/tests/unit/TsanUnitTestsObjects.tsan_clock_test.cpp.x86_64.o 
cd /usr/local/google/home/vitalybuka/src/llvm.git/out/z/projects/compiler-rt/lib/tsan/tests/unit && /usr/local/google/home/vitalybuka/src/llvm.git/out/z/./bin/clang -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -Wno-non-virtual-dtor -nostdinc++ -fPIE -fno-rtti -Wno-covered-switch-default -DGTEST_NO_LLVM_SUPPORT=1 -DGTEST_HAS_RTTI=0 -I/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/llvm/utils/unittest/googletest/include -I/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/llvm/utils/unittest/googletest -I/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/include -I/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib -I/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/tsan/rtl -DGTEST_HAS_RTTI=0 -m64 -c -o TsanUnitTestsObjects.tsan_clock_test.cpp.x86_64.o /usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/tsan/tests/unit/tsan_clock_test.cpp
In file included from /usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/tsan/tests/unit/tsan_clock_test.cpp:14:
/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/llvm/utils/unittest/googletest/include/gtest/gtest.h:54:10: fatal error: 'limits' file not found
#include <limits>
         ^~~~~~~~
1 error generated.

Reverted, I'll update the change to avoid using -nostdinc++ for tests.

This revision is now accepted and ready to land.Oct 14 2020, 6:46 PM

Also android bot is likely will complain. You can reproduce according to:
https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild
BUILDBOT_REVISION= BUILDBOT_MONO_REPO_PATH=<my llvm checkout path>/llvm-project BUILDBOT_CLOBBER= zorg/zorg/buildbot/builders/sanitizers/buildbot_android.sh

Or just ping me and I try myself.

phosek updated this revision to Diff 298308.Oct 14 2020, 11:14 PM

Also android bot is likely will complain. You can reproduce according to:
https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild
BUILDBOT_REVISION= BUILDBOT_MONO_REPO_PATH=<my llvm checkout path>/llvm-project BUILDBOT_CLOBBER= zorg/zorg/buildbot/builders/sanitizers/buildbot_android.sh

Or just ping me and I try myself.

@vitalybuka I tried it locally but that script failed with CMake Error: The source directory "/src/clang-llvm/llvm_build_android_i686/llvm-project/llvm" does not exist. error, would it be possible to run it on your side?

smeenai added inline comments.Oct 14 2020, 11:55 PM
compiler-rt/lib/tsan/tests/CMakeLists.txt
17 ↗(On Diff #298308)

Won't this also need the cxx-headers dep?

Also android bot is likely will complain. You can reproduce according to:
https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild
BUILDBOT_REVISION= BUILDBOT_MONO_REPO_PATH=<my llvm checkout path>/llvm-project BUILDBOT_CLOBBER= zorg/zorg/buildbot/builders/sanitizers/buildbot_android.sh

Or just ping me and I try myself.

@vitalybuka I tried it locally but that script failed with CMake Error: The source directory "/src/clang-llvm/llvm_build_android_i686/llvm-project/llvm" does not exist. error, would it be possible to run it on your side?

Probably earier step failed. It does not stop on errors.

I still see errors.
Probably related to compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt:214

[219/440] Building CXX object lib/sanitizer_common/tests/CMakeFiles/SanitizerTest.dir/sanitizer_stacktrace_printer_test.cpp.o
FAILED: lib/sanitizer_common/tests/CMakeFiles/SanitizerTest.dir/sanitizer_stacktrace_printer_test.cpp.o 
/usr/local/google/home/vitalybuka/slow/bbot/llvm_build64/bin/clang++   -I/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/sanitizer_common/.. -I/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/sanitizer_common/tests/.. -I/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/sanitizer_common/tests/../.. --target=i686-linux-android --sysroot=/usr/local/google/home/vitalybuka/slow/bbot/android_ndk/standalone-i686/sysroot -B/usr/local/google/home/vitalybuka/slow/bbot/android_ndk/standalone-i686  -Wall -Werror -std=c++14 -Wno-unused-parameter -O3 -DNDEBUG    -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -Wno-non-virtual-dtor -nostdinc++ --target=i686-linux-android --sysroot=/usr/local/google/home/vitalybuka/slow/bbot/android_ndk/standalone-i686/sysroot -B/usr/local/google/home/vitalybuka/slow/bbot/android_ndk/standalone-i686 -Wno-covered-switch-default -Wno-suggest-override -DGTEST_NO_LLVM_SUPPORT=1 -DGTEST_HAS_RTTI=0 -I/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/llvm/utils/unittest/googletest/include -I/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/llvm/utils/unittest/googletest -I/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/include -I/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib -I/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/sanitizer_common -fno-rtti -O2 -Werror=sign-compare -Wno-non-virtual-dtor -Wno-gnu-zero-variadic-macro-arguments -gline-tables-only -MD -MT lib/sanitizer_common/tests/CMakeFiles/SanitizerTest.dir/sanitizer_stacktrace_printer_test.cpp.o -MF lib/sanitizer_common/tests/CMakeFiles/SanitizerTest.dir/sanitizer_stacktrace_printer_test.cpp.o.d -o lib/sanitizer_common/tests/CMakeFiles/SanitizerTest.dir/sanitizer_stacktrace_printer_test.cpp.o -c /usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_printer_test.cpp
In file included from /usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_printer_test.cpp:14:
/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/llvm/utils/unittest/googletest/include/gtest/gtest.h:54:10: fatal error: 'limits' file not found
#include <limits>

this helped to fix sanitizer_common

diff --git a/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt b/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt
index 96c845d81cf4..d8cc089c6c25 100644
--- a/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt
+++ b/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt
@@ -202,6 +202,12 @@ if(COMPILER_RT_CAN_EXECUTE_TESTS AND NOT ANDROID)
   endforeach()
 endif()
 
+set(SANITIZER_UNITTEST_CFLAGS
+  ${SANITIZER_COMMON_CFLAGS}
+  ${SANITIZER_TEST_CFLAGS_COMMON}
+  -stdlib=libstdc++)
+list_filter(SANITIZER_UNITTEST_CFLAGS "-nostdinc++")
+
 if(ANDROID)
   foreach(arch ${SANITIZER_COMMON_SUPPORTED_ARCH})
     add_executable(SanitizerTest
@@ -211,8 +217,7 @@ if(ANDROID)
       $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
       $<TARGET_OBJECTS:RTSanitizerCommonSymbolizer.${arch}>)
     set_target_compile_flags(SanitizerTest
-      ${SANITIZER_COMMON_CFLAGS}
-      ${SANITIZER_TEST_CFLAGS_COMMON})
+      ${SANITIZER_UNITTEST_CFLAGS})
     # Setup correct output directory and link flags.
     set_target_properties(SanitizerTest PROPERTIES
       RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

then libFuzzer fails

FAILED: lib/fuzzer/CMakeFiles/RTfuzzer.i386.dir/FuzzerFork.cpp.o 
/usr/local/google/home/vitalybuka/slow/bbot/llvm_build64/bin/clang++   -I/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/fuzzer/../../include --target=i686-linux-android --sysroot=/usr/local/google/home/vitalybuka/slow/bbot/android_ndk/standalone-i686/sysroot -B/usr/local/google/home/vitalybuka/slow/bbot/android_ndk/standalone-i686  -Wall -Werror -std=c++14 -Wno-unused-parameter -O3 -DNDEBUG    -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -Wno-non-virtual-dtor -Dthread_local=__thread -MD -MT lib/fuzzer/CMakeFiles/RTfuzzer.i386.dir/FuzzerFork.cpp.o -MF lib/fuzzer/CMakeFiles/RTfuzzer.i386.dir/FuzzerFork.cpp.o.d -o lib/fuzzer/CMakeFiles/RTfuzzer.i386.dir/FuzzerFork.cpp.o -c /usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/fuzzer/FuzzerFork.cpp
In file included from /usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/fuzzer/FuzzerFork.cpp:11:
In file included from /usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/fuzzer/FuzzerCommand.h:15:
/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/fuzzer/FuzzerDefs.h:14:10: fatal error: 'cassert' file not found
#include <cassert>
phosek updated this revision to Diff 298556.Oct 16 2020, 12:09 AM
FAILED: lib/fuzzer/CMakeFiles/RTfuzzer.i386.dir/FuzzerFork.cpp.o 
/usr/local/google/home/vitalybuka/slow/bbot/llvm_build64/bin/clang++   -I/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/fuzzer/../../include --target=i686-linux-android --sysroot=/usr/local/google/home/vitalybuka/slow/bbot/android_ndk/standalone-i686/sysroot -B/usr/local/google/home/vitalybuka/slow/bbot/android_ndk/standalone-i686  -Wall -Werror -std=c++14 -Wno-unused-parameter -O3 -DNDEBUG    -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -Wno-non-virtual-dtor -Dthread_local=__thread -MD -MT lib/fuzzer/CMakeFiles/RTfuzzer.i386.dir/FuzzerFork.cpp.o -MF lib/fuzzer/CMakeFiles/RTfuzzer.i386.dir/FuzzerFork.cpp.o.d -o lib/fuzzer/CMakeFiles/RTfuzzer.i386.dir/FuzzerFork.cpp.o -c /usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/fuzzer/FuzzerFork.cpp
In file included from /usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/fuzzer/FuzzerFork.cpp:11:
In file included from /usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/fuzzer/FuzzerCommand.h:15:
/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/fuzzer/FuzzerDefs.h:14:10: fatal error: 'cassert' file not found
#include <cassert>

I couldn't reproduce this failure locally. There's also no -nostdinc++ flag being used here so it's not clear to me why this is failing. Do you know if Android provides C++ standard library as part of its sysroot?

phosek marked an inline comment as done.Oct 16 2020, 12:22 AM
FAILED: lib/fuzzer/CMakeFiles/RTfuzzer.i386.dir/FuzzerFork.cpp.o 
/usr/local/google/home/vitalybuka/slow/bbot/llvm_build64/bin/clang++   -I/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/fuzzer/../../include --target=i686-linux-android --sysroot=/usr/local/google/home/vitalybuka/slow/bbot/android_ndk/standalone-i686/sysroot -B/usr/local/google/home/vitalybuka/slow/bbot/android_ndk/standalone-i686  -Wall -Werror -std=c++14 -Wno-unused-parameter -O3 -DNDEBUG    -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -Wno-non-virtual-dtor -Dthread_local=__thread -MD -MT lib/fuzzer/CMakeFiles/RTfuzzer.i386.dir/FuzzerFork.cpp.o -MF lib/fuzzer/CMakeFiles/RTfuzzer.i386.dir/FuzzerFork.cpp.o.d -o lib/fuzzer/CMakeFiles/RTfuzzer.i386.dir/FuzzerFork.cpp.o -c /usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/fuzzer/FuzzerFork.cpp
In file included from /usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/fuzzer/FuzzerFork.cpp:11:
In file included from /usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/fuzzer/FuzzerCommand.h:15:
/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/fuzzer/FuzzerDefs.h:14:10: fatal error: 'cassert' file not found
#include <cassert>

I couldn't reproduce this failure locally. There's also no -nostdinc++ flag being used here so it's not clear to me why this is failing. Do you know if Android provides C++ standard library as part of its sysroot?

did you try zorg script ?

FAILED: lib/fuzzer/CMakeFiles/RTfuzzer.i386.dir/FuzzerFork.cpp.o 
/usr/local/google/home/vitalybuka/slow/bbot/llvm_build64/bin/clang++   -I/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/fuzzer/../../include --target=i686-linux-android --sysroot=/usr/local/google/home/vitalybuka/slow/bbot/android_ndk/standalone-i686/sysroot -B/usr/local/google/home/vitalybuka/slow/bbot/android_ndk/standalone-i686  -Wall -Werror -std=c++14 -Wno-unused-parameter -O3 -DNDEBUG    -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -Wno-non-virtual-dtor -Dthread_local=__thread -MD -MT lib/fuzzer/CMakeFiles/RTfuzzer.i386.dir/FuzzerFork.cpp.o -MF lib/fuzzer/CMakeFiles/RTfuzzer.i386.dir/FuzzerFork.cpp.o.d -o lib/fuzzer/CMakeFiles/RTfuzzer.i386.dir/FuzzerFork.cpp.o -c /usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/fuzzer/FuzzerFork.cpp
In file included from /usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/fuzzer/FuzzerFork.cpp:11:
In file included from /usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/fuzzer/FuzzerCommand.h:15:
/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/fuzzer/FuzzerDefs.h:14:10: fatal error: 'cassert' file not found
#include <cassert>

I couldn't reproduce this failure locally. There's also no -nostdinc++ flag being used here so it's not clear to me why this is failing. Do you know if Android provides C++ standard library as part of its sysroot?

did you try zorg script ?

Yes, I have finally managed to get it working. Turned you have to pass all paths as absolute. I think I understand what the problem is now.

phosek updated this revision to Diff 301197.Oct 28 2020, 1:43 AM

After many experiments, I finally got something that seems to be building with the buildbot_android.sh script.

phosek updated this revision to Diff 301203.Oct 28 2020, 2:14 AM

it fails check-tsan on linux with -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;compiler-rt;lld;libcxx;libcxxabi"

[23/32] Generating TsanUnitTestsObjects.tsan_clock_test.cpp.x86_64.o
FAILED: projects/compiler-rt/lib/tsan/tests/unit/TsanUnitTestsObjects.tsan_clock_test.cpp.x86_64.o 
cd /usr/local/google/home/vitalybuka/src/llvm.git/out/z/projects/compiler-rt/lib/tsan/tests/unit && /usr/local/google/home/vitalybuka/src/llvm.git/out/z/./bin/clang -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -Wno-non-virtual-dtor -nostdinc++ -fPIE -fno-rtti -Wno-covered-switch-default -DGTEST_NO_LLVM_SUPPORT=1 -DGTEST_HAS_RTTI=0 -I/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/llvm/utils/unittest/googletest/include -I/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/llvm/utils/unittest/googletest -I/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/include -I/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib -I/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/tsan/rtl -DGTEST_HAS_RTTI=0 -m64 -c -o TsanUnitTestsObjects.tsan_clock_test.cpp.x86_64.o /usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/tsan/tests/unit/tsan_clock_test.cpp
In file included from /usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/lib/tsan/tests/unit/tsan_clock_test.cpp:14:
/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/llvm/utils/unittest/googletest/include/gtest/gtest.h:54:10: fatal error: 'limits' file not found
#include <limits>

and Android script fails to run tests on emulator

******************** TEST 'cfi-standalone-thinlto-newpm-i386 :: vtable-may-alias.cpp' FAILED ********************
Script:
--
: 'RUN: at line 1';     /usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/test/sanitizer_common/android_commands/android_compile.py  /usr/local/google/home/vitalybuka/slow/bbot/llvm_build64/bin/clang   -pie -fuse-ld=gold --target=i686-linux-android;--sysroot=/usr/local/google/home/vitalybuka/slow/bbot/android_ndk/standalone-i686/sysroot;-B/usr/local/google/home/vitalybuka/slow/bbot/android_ndk/standalone-i686 -fuse-ld=gold -flto=thin -fexperimental-new-pass-manager  -fsanitize=cfi --driver-mode=g++ -stdlib=libstdc++ -fvisibility=hidden -o /usr/local/google/home/vitalybuka/slow/bbot/compiler_rt_build_android_i686/test/cfi/Standalone-thinlto-newpm-i386/Output/vtable-may-alias.cpp.tmp /usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/test/cfi/vtable-may-alias.cpp
: 'RUN: at line 2';    /usr/local/google/home/vitalybuka/slow/bbot/compiler_rt_build_android_i686/test/cfi/Standalone-thinlto-newpm-i386/Output/vtable-may-alias.cpp.tmp
--
Exit Code: 127

Command Output (stdout):
--
No output file name!

--
Command Output (stderr):
--
/usr/local/google/home/vitalybuka/slow/bbot/compiler_rt_build_android_i686/test/cfi/Standalone-thinlto-newpm-i386/Output/vtable-may-alias.cpp.script: line 1: --sysroot=/usr/local/google/home/vitalybuka/slow/bbot/android_ndk/standalone-i686/sysroot: No such file or directory
/usr/local/google/home/vitalybuka/slow/bbot/compiler_rt_build_android_i686/test/cfi/Standalone-thinlto-newpm-i386/Output/vtable-may-alias.cpp.script: line 1: -B/usr/local/google/home/vitalybuka/slow/bbot/android_ndk/standalone-i686: No such file or directory

Maybe we can try to land obviously safe pieces?

phosek updated this revision to Diff 302002.Oct 30 2020, 1:07 PM

rebase on master

a lot of these, something wrong with regex

: 'RUN: at line 1';     /usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/test/sanitizer_common/android_commands/android_compile.py  /usr/local/google/home/vitalybuka/slow/bbot/llvm_build64/bin/clang   -pie -fuse-ld=gold --target=i686-linux-android;--sysroot=/usr/local/google/home/vitalybuka/slow/bbot/android_ndk/standalone-i686/sysroot;-B/usr/local/google/home/vitalybuka/slow/bbot/android_ndk/standalone-i686 -fuse-ld=gold -flto=thin -fexperimental-new-pass-manager  -fsanitize=cfi --driver-mode=g++ -stdlib=libstdc++ -fvisibility=hidden -o /usr/local/google/home/vitalybuka/slow/bbot/compiler_rt_build_android_i686/test/cfi/Standalone-thinlto-newpm-i386/Output/vtable-may-alias.cpp.tmp /usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/compiler-rt/test/cfi/vtable-may-alias.cpp
: 'RUN: at line 2';    /usr/local/google/home/vitalybuka/slow/bbot/compiler_rt_build_android_i686/test/cfi/Standalone-thinlto-newpm-i386/Output/vtable-may-alias.cpp.tmp
--
Exit Code: 127

Command Output (stdout):
--
No output file name!

--
Command Output (stderr):
--
/usr/local/google/home/vitalybuka/slow/bbot/compiler_rt_build_android_i686/test/cfi/Standalone-thinlto-newpm-i386/Output/vtable-may-alias.cpp.script: line 1: --sysroot=/usr/local/google/home/vitalybuka/slow/bbot/android_ndk/standalone-i686/sysroot: No such file or directory
/usr/local/google/home/vitalybuka/slow/bbot/compiler_rt_build_android_i686/test/cfi/Standalone-thinlto-newpm-i386/Output/vtable-may-alias.cpp.script: line 1: -B/usr/local/google/home/vitalybuka/slow/bbot/android_ndk/standalone-i686: No such file or directory

fix android

vitalybuka accepted this revision.Oct 31 2020, 2:37 AM
vitalybuka added inline comments.
compiler-rt/CMakeLists.txt
513

this line converted COMPILER_RT_TEST_COMPILER_CFLAGS into a list which caused problems on android

This revision was landed with ongoing or failed builds.Oct 31 2020, 2:37 AM
This revision was automatically updated to reflect the committed changes.

Thanks a lot for landing this!

compiler-rt/CMakeLists.txt
513

Thanks for catching that.

This still broke building for mingw targets:

../lib/ubsan/ubsan_type_hash_win.cpp:20:10: fatal error: 'typeinfo' file not found
#include <typeinfo>
         ^~~~~~~~~~
1 error generated.

It looks like mingw targets maybe should use the code from ubsan_type_hash_itanium.cpp instead (how do I exercise this bit of ubsan?

But even with that changed, I'm getting this:

lld-link: error: undefined symbol: ___dynamic_cast
lld-link: error: undefined symbol: vtable for __cxxabiv1::__class_type_info
lld-link: error: undefined symbol: vtable for __cxxabiv1::__si_class_type_info

Is this a case where the SO is left with undefined references to those, on ELF platforms? On windows, a DLL can't have undefined references.

But even with that changed, I'm getting this:

lld-link: error: undefined symbol: ___dynamic_cast
lld-link: error: undefined symbol: vtable for __cxxabiv1::__class_type_info
lld-link: error: undefined symbol: vtable for __cxxabiv1::__si_class_type_info

Is this a case where the SO is left with undefined references to those, on ELF platforms? On windows, a DLL can't have undefined references.

Ok, I can fix that by setting SANITIZER_CXX_ABI=libc++ when building, if the ifdefs are changed to use the itanium implementation.

But the base issue remains - ubsan_type_hash_win.cpp can't be built with -nostdinc++ as it includes typeinfo.

As a side effect of this (well, 6db314e86b26741c2e29ce51d88a6a5dca35336c), ninja all after configuring with compiler-rt, clang, and libcxx enabled, the libcxx headers no longer get copied to where clang looks for them, which means clang can't compile programs like #include <string> after this change on macOS.

This mostly worked by accident since the compiler-rt build files had targets that depended on cxx-headers, but it did work for years and it seems like something that should work. I guess the Right Fix is to make the all target depend on cxx-headers. It's not clear to me why it doesn't.

As a side effect of this (well, 6db314e86b26741c2e29ce51d88a6a5dca35336c), ninja all after configuring with compiler-rt, clang, and libcxx enabled, the libcxx headers no longer get copied to where clang looks for them, which means clang can't compile programs like #include <string> after this change on macOS.

This mostly worked by accident since the compiler-rt build files had targets that depended on cxx-headers, but it did work for years and it seems like something that should work. I guess the Right Fix is to make the all target depend on cxx-headers. It's not clear to me why it doesn't.

8954fd436c729796615bac11b3553c4341f01a82 should fix this.

pjeeva01 added a subscriber: pjeeva01.EditedNov 2 2020, 1:19 PM

Commit 6db314e86b26741c2e29ce51d88a6a5dca35336c causes following failure:

Generating TsanUnitTestsObjects.tsan_clock_test.cpp.powerpc64le.o
FAILED: compiler-rt/lib/tsan/tests/unit/TsanUnitTestsObjects.tsan_clock_test.cpp.powerpc64le.o
cd …/runtimes/runtimes-bins/compiler-rt/lib/tsan/tests/unit && …/bin/clang -fPIC -fvisibility-inlines-hidden -Werror -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -fdiagnostics-color -ffunction-sections -fdata-sections -Wall -Werror -std=c++14 -Wno-unused-parameter -Wno-unknown-warning-option -Wno-covered-switch-default -Wno-suggest-override -DGTEST_NO_LLVM_SUPPORT=1 -DGTEST_HAS_RTTI=0 -I/…/llvm-project/llvm/utils/unittest/googletest/include -I/…/llvm-project/llvm/utils/unittest/googletest -I/…/llvm-project/compiler-rt/include -I/…/llvm-project/compiler-rt/lib -I/…/llvm-project/compiler-rt/lib/tsan/rtl -DGTEST_HAS_RTTI=0 -fno-rtti -m64 -fno-function-sections -c -o TsanUnitTestsObjects.tsan_clock_test.cpp.powerpc64le.o …/llvm-project/compiler-rt/lib/tsan/tests/unit/tsan_clock_test.cpp
In file included from …/llvm-project/compiler-rt/lib/tsan/tests/unit/tsan_clock_test.cpp:13:
In file included from …/llvm-project/compiler-rt/lib/tsan/rtl/tsan_rtl.h:32:
…/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_deadlock_detector_interface.h:63:8: error: '__sanitizer::DDCallback' has virtual functions but non-virtual destructor [-Werror,-Wnon-virtual-dtor]
struct DDCallback {

…/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_deadlock_detector_interface.h:71:8: error: '__sanitizer::DDetector' has virtual functions but non-virtual destructor [-Werror,-Wnon-virtual-dtor]
struct DDetector {

In file included from …/llvm-project/compiler-rt/lib/tsan/tests/unit/tsan_clock_test.cpp:13:
In file included from …/llvm-project/compiler-rt/lib/tsan/rtl/tsan_rtl.h:35:
…/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.h:42:3: error: '__sanitizer::ThreadContextBase' has virtual functions but non-virtual destructor [-Werror,-Wnon-virtual-dtor]

~ThreadContextBase();  // Should never be called.

In file included from …/llvm-project/compiler-rt/lib/tsan/tests/unit/tsan_clock_test.cpp:13:
…/llvm-project/compiler-rt/lib/tsan/rtl/tsan_rtl.h:483:3: error: '__tsan::ThreadContext' has virtual functions but non-virtual destructor [-Werror,-Wnon-virtual-dtor]

~ThreadContext();

4 errors generated.

This should help https://github.com/llvm/llvm-project/commit/8b37a4e6caac61c55bc413ab43c1becf906474d6

Commit 6db314e86b26741c2e29ce51d88a6a5dca35336c causes following failure:

Generating TsanUnitTestsObjects.tsan_clock_test.cpp.powerpc64le.o
FAILED: compiler-rt/lib/tsan/tests/unit/TsanUnitTestsObjects.tsan_clock_test.cpp.powerpc64le.o
cd …/runtimes/runtimes-bins/compiler-rt/lib/tsan/tests/unit && …/bin/clang -fPIC -fvisibility-inlines-hidden -Werror -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -fdiagnostics-color -ffunction-sections -fdata-sections -Wall -Werror -std=c++14 -Wno-unused-parameter -Wno-unknown-warning-option -Wno-covered-switch-default -Wno-suggest-override -DGTEST_NO_LLVM_SUPPORT=1 -DGTEST_HAS_RTTI=0 -I/…/llvm-project/llvm/utils/unittest/googletest/include -I/…/llvm-project/llvm/utils/unittest/googletest -I/…/llvm-project/compiler-rt/include -I/…/llvm-project/compiler-rt/lib -I/…/llvm-project/compiler-rt/lib/tsan/rtl -DGTEST_HAS_RTTI=0 -fno-rtti -m64 -fno-function-sections -c -o TsanUnitTestsObjects.tsan_clock_test.cpp.powerpc64le.o …/llvm-project/compiler-rt/lib/tsan/tests/unit/tsan_clock_test.cpp
In file included from …/llvm-project/compiler-rt/lib/tsan/tests/unit/tsan_clock_test.cpp:13:
In file included from …/llvm-project/compiler-rt/lib/tsan/rtl/tsan_rtl.h:32:
…/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_deadlock_detector_interface.h:63:8: error: '__sanitizer::DDCallback' has virtual functions but non-virtual destructor [-Werror,-Wnon-virtual-dtor]
struct DDCallback {

…/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_deadlock_detector_interface.h:71:8: error: '__sanitizer::DDetector' has virtual functions but non-virtual destructor [-Werror,-Wnon-virtual-dtor]
struct DDetector {

In file included from …/llvm-project/compiler-rt/lib/tsan/tests/unit/tsan_clock_test.cpp:13:
In file included from …/llvm-project/compiler-rt/lib/tsan/rtl/tsan_rtl.h:35:
…/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.h:42:3: error: '__sanitizer::ThreadContextBase' has virtual functions but non-virtual destructor [-Werror,-Wnon-virtual-dtor]

~ThreadContextBase();  // Should never be called.

In file included from …/llvm-project/compiler-rt/lib/tsan/tests/unit/tsan_clock_test.cpp:13:
…/llvm-project/compiler-rt/lib/tsan/rtl/tsan_rtl.h:483:3: error: '__tsan::ThreadContext' has virtual functions but non-virtual destructor [-Werror,-Wnon-virtual-dtor]

~ThreadContext();

4 errors generated.

Any update regarding the fact that it now builds ubsan_type_hash_win.cpp with -nostdinc++, despite the fact that the file does include <typeinfo>?

phosek added a comment.Nov 5 2020, 1:20 PM

Any update regarding the fact that it now builds ubsan_type_hash_win.cpp with -nostdinc++, despite the fact that the file does include <typeinfo>?

We currently use just C++ ABI for UBSan but it seems like we really need full C++ library there. So two thing we probably need to do there is to filter out -stdinc++ and -nostdlib++ from flags and require full C++ library in https://github.com/llvm/llvm-project/blob/71e108cd86e70b06c5fa3a63689dcb3555c3d13f/compiler-rt/CMakeLists.txt#L212.

@vitalybuka do you know if anyone uses libcxxabi as SANITIZER_CXX_ABI? Could we remove libcxxabi from the list and rename SANITIZER_CXX_ABI to SANITIZER_CXX_LIBRARY (and potentially even combine it with SANITIZER_TEST_CXX)?

Any update regarding the fact that it now builds ubsan_type_hash_win.cpp with -nostdinc++, despite the fact that the file does include <typeinfo>?

We currently use just C++ ABI for UBSan but it seems like we really need full C++ library there. So two thing we probably need to do there is to filter out -stdinc++ and -nostdlib++ from flags and require full C++ library in https://github.com/llvm/llvm-project/blob/71e108cd86e70b06c5fa3a63689dcb3555c3d13f/compiler-rt/CMakeLists.txt#L212.

@vitalybuka do you know if anyone uses libcxxabi as SANITIZER_CXX_ABI? Could we remove libcxxabi from the list and rename SANITIZER_CXX_ABI to SANITIZER_CXX_LIBRARY (and potentially even combine it with SANITIZER_TEST_CXX)?

@eugenis @oontvoo Android NDK uses SANITIZER_CXX_ABI=libcxxabi, so we are on http://lab.llvm.org:8011/#/builders/77. Builder is easy to change, but not sure who to ask about actual NDK.

@eugenis @oontvoo Android NDK uses SANITIZER_CXX_ABI=libcxxabi, so we are on http://lab.llvm.org:8011/#/builders/77. Builder is easy to change, but not sure who to ask about actual NDK.

The NDK build uses it here[0]. I suppose you could send them a patch to add a new defines[SANITIZER_CXX_LIBRARY]

[0] https://android.googlesource.com/toolchain/llvm_android/+/master/builders.py#266

@vitalybuka do you know if anyone uses libcxxabi as SANITIZER_CXX_ABI? Could we remove libcxxabi from the list and rename SANITIZER_CXX_ABI to SANITIZER_CXX_LIBRARY (and potentially even combine it with SANITIZER_TEST_CXX)?

If renaming cmake options, please keep the old name around for at least one major release, for build script compatibility.

stella.stamenova added inline comments.
compiler-rt/CMakeLists.txt
458

This does not work correctly when CMAKE_CXX_FLAGS is not set. The solution that other projects use is to quote the property like so:

string(REGEX MATCHALL "-stdlib=[a-zA-Z+]*" stdlib_flag "${CMAKE_CXX_FLAGS}")
string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

I can send a separate review for this if you can't, just let me know.