From 53c8f739fd266bb9e755eccceea7adb4d5126083 Mon Sep 17 00:00:00 2001 From: Fabrice Fontaine Date: Fri, 14 Jan 2022 14:08:05 -0800 Subject: [PATCH] build_tools/build_detect_platform: fix C++ tests (#6479) Summary: Replace `-o /dev/null` by `-o test.o` when testing for C++ features such as -faligned-new otherwise tests will fail with some bugged binutils (https://sourceware.org/bugzilla/show_bug.cgi?id=19526): ``` output/host/bin/xtensa-buildroot-linux-uclibc-g++ -faligned-new -x c++ - -o /dev/null < Pull Request resolved: https://github.com/facebook/rocksdb/pull/6479 Reviewed By: ajkr Differential Revision: D33574136 Pulled By: riversand963 fbshipit-source-id: 12b48658b17e36013042c98219b89ddf71161d3c --- build_tools/build_detect_platform | 66 ++++++++++++++++--------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/build_tools/build_detect_platform b/build_tools/build_detect_platform index 8e2107036..17ea8bbdd 100755 --- a/build_tools/build_detect_platform +++ b/build_tools/build_detect_platform @@ -176,7 +176,7 @@ case "$TARGET_OS" in fi if test "$ROCKSDB_USE_IO_URING" -ne 0; then # check for liburing - $CXX $PLATFORM_CXXFLAGS -x c++ - -luring -o /dev/null 2>/dev/null </dev/null < int main() { struct io_uring ring; @@ -284,7 +284,7 @@ if [ "$CROSS_COMPILE" = "true" -o "$FBCODE_BUILD" = "true" ]; then else if ! test $ROCKSDB_DISABLE_FALLOCATE; then # Test whether fallocate is available - $CXX $PLATFORM_CXXFLAGS -x c++ - -o /dev/null 2>/dev/null </dev/null < #include int main() { @@ -300,7 +300,7 @@ EOF if ! test $ROCKSDB_DISABLE_SNAPPY; then # Test whether Snappy library is installed # http://code.google.com/p/snappy/ - $CXX $PLATFORM_CXXFLAGS -x c++ - -o /dev/null 2>/dev/null </dev/null < int main() {} EOF @@ -315,7 +315,7 @@ EOF # Test whether gflags library is installed # http://gflags.github.io/gflags/ # check if the namespace is gflags - if $CXX $PLATFORM_CXXFLAGS -x c++ - -o /dev/null 2>/dev/null << EOF + if $CXX $PLATFORM_CXXFLAGS -x c++ - -o test.o 2>/dev/null << EOF #include using namespace GFLAGS_NAMESPACE; int main() {} @@ -324,7 +324,7 @@ EOF COMMON_FLAGS="$COMMON_FLAGS -DGFLAGS=1" PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -lgflags" # check if namespace is gflags - elif $CXX $PLATFORM_CXXFLAGS -x c++ - -o /dev/null 2>/dev/null << EOF + elif $CXX $PLATFORM_CXXFLAGS -x c++ - -o test.o 2>/dev/null << EOF #include using namespace gflags; int main() {} @@ -333,7 +333,7 @@ EOF COMMON_FLAGS="$COMMON_FLAGS -DGFLAGS=1 -DGFLAGS_NAMESPACE=gflags" PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -lgflags" # check if namespace is google - elif $CXX $PLATFORM_CXXFLAGS -x c++ - -o /dev/null 2>/dev/null << EOF + elif $CXX $PLATFORM_CXXFLAGS -x c++ - -o test.o 2>/dev/null << EOF #include using namespace google; int main() {} @@ -346,7 +346,7 @@ EOF if ! test $ROCKSDB_DISABLE_ZLIB; then # Test whether zlib library is installed - $CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS -x c++ - -o /dev/null 2>/dev/null </dev/null < int main() {} EOF @@ -359,7 +359,7 @@ EOF if ! test $ROCKSDB_DISABLE_BZIP; then # Test whether bzip library is installed - $CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS -x c++ - -o /dev/null 2>/dev/null </dev/null < int main() {} EOF @@ -372,7 +372,7 @@ EOF if ! test $ROCKSDB_DISABLE_LZ4; then # Test whether lz4 library is installed - $CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS -x c++ - -o /dev/null 2>/dev/null </dev/null < #include int main() {} @@ -399,7 +399,7 @@ EOF if ! test $ROCKSDB_DISABLE_NUMA; then # Test whether numa is available - $CXX $PLATFORM_CXXFLAGS -x c++ - -o /dev/null -lnuma 2>/dev/null </dev/null < #include int main() {} @@ -413,7 +413,7 @@ EOF if ! test $ROCKSDB_DISABLE_TBB; then # Test whether tbb is available - $CXX $PLATFORM_CXXFLAGS $LDFLAGS -x c++ - -o /dev/null -ltbb 2>/dev/null </dev/null < int main() {} EOF @@ -426,7 +426,7 @@ EOF if ! test $ROCKSDB_DISABLE_JEMALLOC; then # Test whether jemalloc is available - if echo 'int main() {}' | $CXX $PLATFORM_CXXFLAGS -x c++ - -o /dev/null -ljemalloc \ + if echo 'int main() {}' | $CXX $PLATFORM_CXXFLAGS -x c++ - -o test.o -ljemalloc \ 2>/dev/null; then # This will enable some preprocessor identifiers in the Makefile JEMALLOC=1 @@ -447,7 +447,7 @@ EOF fi if ! test $JEMALLOC && ! test $ROCKSDB_DISABLE_TCMALLOC; then # jemalloc is not available. Let's try tcmalloc - if echo 'int main() {}' | $CXX $PLATFORM_CXXFLAGS -x c++ - -o /dev/null \ + if echo 'int main() {}' | $CXX $PLATFORM_CXXFLAGS -x c++ - -o test.o \ -ltcmalloc 2>/dev/null; then PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -ltcmalloc" JAVA_LDFLAGS="$JAVA_LDFLAGS -ltcmalloc" @@ -456,7 +456,7 @@ EOF if ! test $ROCKSDB_DISABLE_MALLOC_USABLE_SIZE; then # Test whether malloc_usable_size is available - $CXX $PLATFORM_CXXFLAGS -x c++ - -o /dev/null 2>/dev/null </dev/null < int main() { size_t res = malloc_usable_size(0); @@ -471,7 +471,7 @@ EOF if ! test $ROCKSDB_DISABLE_MEMKIND; then # Test whether memkind library is installed - $CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS -lmemkind -x c++ - -o /dev/null 2>/dev/null </dev/null < int main() { memkind_malloc(MEMKIND_DAX_KMEM, 1024); @@ -487,7 +487,7 @@ EOF if ! test $ROCKSDB_DISABLE_PTHREAD_MUTEX_ADAPTIVE_NP; then # Test whether PTHREAD_MUTEX_ADAPTIVE_NP mutex type is available - $CXX $PLATFORM_CXXFLAGS -x c++ - -o /dev/null 2>/dev/null </dev/null < int main() { int x = PTHREAD_MUTEX_ADAPTIVE_NP; @@ -502,7 +502,7 @@ EOF if ! test $ROCKSDB_DISABLE_BACKTRACE; then # Test whether backtrace is available - $CXX $PLATFORM_CXXFLAGS -x c++ - -o /dev/null 2>/dev/null </dev/null < int main() { void* frames[1]; @@ -514,7 +514,7 @@ EOF COMMON_FLAGS="$COMMON_FLAGS -DROCKSDB_BACKTRACE" else # Test whether execinfo library is installed - $CXX $PLATFORM_CXXFLAGS -lexecinfo -x c++ - -o /dev/null 2>/dev/null </dev/null < int main() { void* frames[1]; @@ -531,7 +531,7 @@ EOF if ! test $ROCKSDB_DISABLE_PG; then # Test if -pg is supported - $CXX $PLATFORM_CXXFLAGS -pg -x c++ - -o /dev/null 2>/dev/null </dev/null </dev/null </dev/null < int main() { int fd = open("/dev/null", 0); @@ -557,7 +557,7 @@ EOF if ! test $ROCKSDB_DISABLE_SCHED_GETCPU; then # Test whether sched_getcpu is supported - $CXX $PLATFORM_CXXFLAGS -x c++ - -o /dev/null 2>/dev/null </dev/null < int main() { int cpuid = sched_getcpu(); @@ -571,7 +571,7 @@ EOF if ! test $ROCKSDB_DISABLE_AUXV_GETAUXVAL; then # Test whether getauxval is supported - $CXX $PLATFORM_CXXFLAGS -x c++ - -o /dev/null 2>/dev/null </dev/null < int main() { uint64_t auxv = getauxval(AT_HWCAP); @@ -585,7 +585,7 @@ EOF if ! test $ROCKSDB_DISABLE_ALIGNED_NEW; then # Test whether c++17 aligned-new is supported - $CXX $PLATFORM_CXXFLAGS -faligned-new -x c++ - -o /dev/null 2>/dev/null </dev/null </dev/null </dev/null </dev/null </dev/null < #include int main() { @@ -737,7 +737,7 @@ elif test "$USE_SSE"; then echo "warning: USE_SSE specified but compiler could not use SSE intrinsics, disabling" >&2 fi -$CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS $TRY_PCLMUL -x c++ - -o /dev/null 2>/dev/null </dev/null < #include int main() { @@ -754,7 +754,7 @@ elif test "$USE_SSE"; then echo "warning: USE_SSE specified but compiler could not use PCLMUL intrinsics, disabling" >&2 fi -$CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS $TRY_AVX2 -x c++ - -o /dev/null 2>/dev/null </dev/null < #include int main() { @@ -769,7 +769,7 @@ elif test "$USE_SSE"; then echo "warning: USE_SSE specified but compiler could not use AVX2 intrinsics, disabling" >&2 fi -$CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS $TRY_BMI -x c++ - -o /dev/null 2>/dev/null </dev/null < #include int main(int argc, char *argv[]) { @@ -783,7 +783,7 @@ elif test "$USE_SSE"; then echo "warning: USE_SSE specified but compiler could not use BMI intrinsics, disabling" >&2 fi -$CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS $TRY_LZCNT -x c++ - -o /dev/null 2>/dev/null </dev/null < #include int main(int argc, char *argv[]) { @@ -797,7 +797,7 @@ elif test "$USE_SSE"; then echo "warning: USE_SSE specified but compiler could not use LZCNT intrinsics, disabling" >&2 fi -$CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS -x c++ - -o /dev/null 2>/dev/null </dev/null < int main() { uint64_t a = 0xffffFFFFffffFFFF; @@ -814,7 +814,7 @@ fi # succeed because the cross-compiler flags are added by the Makefile, not this # script. if [ "$PLATFORM" != IOS ]; then - $CXX $COMMON_FLAGS -x c++ - -o /dev/null 2>/dev/null </dev/null </dev/null + $CXX $COMMON_FLAGS $PLATFORM_SHARED_LDFLAGS test_dl.o -o test.o 2>/dev/null if [ "$?" = 0 ]; then EXEC_LDFLAGS+="-ldl" rm -f test_dl.o @@ -842,6 +842,8 @@ EOF fi fi +rm -f test.o + PLATFORM_CCFLAGS="$PLATFORM_CCFLAGS $COMMON_FLAGS" PLATFORM_CXXFLAGS="$PLATFORM_CXXFLAGS $COMMON_FLAGS"