1From 23739c6f9694d7fc436967439f170173dbb4c6b4 Mon Sep 17 00:00:00 2001 2From: Fabrice Fontaine <fontaine.fabrice@gmail.com> 3Date: Mon, 24 Feb 2020 10:22:13 +0100 4Subject: [PATCH] build_tools/build_detect_platform: fix C++ tests 5 6Replace -o /dev/null by -o test.o when testing for C++ features such as 7-faligned-new otherwise tests will fail with some bugged binutils 8(https://sourceware.org/bugzilla/show_bug.cgi?id=19526): 9 10output/host/bin/xtensa-buildroot-linux-uclibc-g++ -faligned-new -x c++ - -o /dev/null <<EOF 11 struct alignas(1024) t {int a;}; 12 int main() {} 13EOF 14/home/fabrice/buildroot/output/host/lib/gcc/xtensa-buildroot-linux-uclibc/8.3.0/../../../../xtensa-buildroot-linux-uclibc/bin/ld: final link failed: file truncated 15 16Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com> 17[Upstream status: https://github.com/facebook/rocksdb/pull/6479] 18--- 19 build_tools/build_detect_platform | 66 +++++++++++++++---------------- 20 1 file changed, 33 insertions(+), 33 deletions(-) 21 22diff --git a/build_tools/build_detect_platform b/build_tools/build_detect_platform 23index 2535d8124..64a0ae76c 100755 24--- a/build_tools/build_detect_platform 25+++ b/build_tools/build_detect_platform 26@@ -172,7 +172,7 @@ case "$TARGET_OS" in 27 PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -lpthread -lrt -ldl" 28 if test $ROCKSDB_USE_IO_URING; then 29 # check for liburing 30- $CXX $PLATFORM_CXXFLAGS -x c++ - -luring -o /dev/null 2>/dev/null <<EOF 31+ $CXX $PLATFORM_CXXFLAGS -x c++ - -luring -o test.o 2>/dev/null <<EOF 32 #include <liburing.h> 33 int main() { 34 struct io_uring ring; 35@@ -245,7 +245,7 @@ if [ "$CROSS_COMPILE" = "true" -o "$FBCODE_BUILD" = "true" ]; then 36 else 37 if ! test $ROCKSDB_DISABLE_FALLOCATE; then 38 # Test whether fallocate is available 39- $CXX $PLATFORM_CXXFLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF 40+ $CXX $PLATFORM_CXXFLAGS -x c++ - -o test.o 2>/dev/null <<EOF 41 #include <fcntl.h> 42 #include <linux/falloc.h> 43 int main() { 44@@ -261,7 +261,7 @@ EOF 45 if ! test $ROCKSDB_DISABLE_SNAPPY; then 46 # Test whether Snappy library is installed 47 # http://code.google.com/p/snappy/ 48- $CXX $PLATFORM_CXXFLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF 49+ $CXX $PLATFORM_CXXFLAGS -x c++ - -o test.o 2>/dev/null <<EOF 50 #include <snappy.h> 51 int main() {} 52 EOF 53@@ -276,7 +276,7 @@ EOF 54 # Test whether gflags library is installed 55 # http://gflags.github.io/gflags/ 56 # check if the namespace is gflags 57- if $CXX $PLATFORM_CXXFLAGS -x c++ - -o /dev/null 2>/dev/null << EOF 58+ if $CXX $PLATFORM_CXXFLAGS -x c++ - -o test.o 2>/dev/null << EOF 59 #include <gflags/gflags.h> 60 using namespace GFLAGS_NAMESPACE; 61 int main() {} 62@@ -323,7 +323,7 @@ EOF 63 COMMON_FLAGS="$COMMON_FLAGS -DGFLAGS=1" 64 PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -lgflags" 65 # check if namespace is gflags 66- elif $CXX $PLATFORM_CXXFLAGS -x c++ - -o /dev/null 2>/dev/null << EOF 67+ elif $CXX $PLATFORM_CXXFLAGS -x c++ - -o test.o 2>/dev/null << EOF 68 #include <gflags/gflags.h> 69 using namespace gflags; 70 int main() {} 71@@ -285,7 +285,7 @@ EOF 72 COMMON_FLAGS="$COMMON_FLAGS -DGFLAGS=1 -DGFLAGS_NAMESPACE=gflags" 73 PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -lgflags" 74 # check if namespace is google 75- elif $CXX $PLATFORM_CXXFLAGS -x c++ - -o /dev/null 2>/dev/null << EOF 76+ elif $CXX $PLATFORM_CXXFLAGS -x c++ - -o test.o 2>/dev/null << EOF 77 #include <gflags/gflags.h> 78 using namespace google; 79 int main() {} 80@@ -299,7 +299,7 @@ EOF 81 82 if ! test $ROCKSDB_DISABLE_ZLIB; then 83 # Test whether zlib library is installed 84- $CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF 85+ $CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS -x c++ - -o test.o 2>/dev/null <<EOF 86 #include <zlib.h> 87 int main() {} 88 EOF 89@@ -312,7 +312,7 @@ EOF 90 91 if ! test $ROCKSDB_DISABLE_BZIP; then 92 # Test whether bzip library is installed 93- $CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF 94+ $CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS -x c++ - -o test.o 2>/dev/null <<EOF 95 #include <bzlib.h> 96 int main() {} 97 EOF 98@@ -325,7 +325,7 @@ EOF 99 100 if ! test $ROCKSDB_DISABLE_LZ4; then 101 # Test whether lz4 library is installed 102- $CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF 103+ $CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS -x c++ - -o test.o 2>/dev/null <<EOF 104 #include <lz4.h> 105 #include <lz4hc.h> 106 int main() {} 107@@ -339,7 +339,7 @@ EOF 108 109 if ! test $ROCKSDB_DISABLE_ZSTD; then 110 # Test whether zstd library is installed 111- $CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF 112+ $CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS -x c++ - -o test.o 2>/dev/null <<EOF 113 #include <zstd.h> 114 int main() {} 115 EOF 116@@ -352,7 +352,7 @@ EOF 117 118 if ! test $ROCKSDB_DISABLE_NUMA; then 119 # Test whether numa is available 120- $CXX $PLATFORM_CXXFLAGS -x c++ - -o /dev/null -lnuma 2>/dev/null <<EOF 121+ $CXX $PLATFORM_CXXFLAGS -x c++ - -o test.o -lnuma 2>/dev/null <<EOF 122 #include <numa.h> 123 #include <numaif.h> 124 int main() {} 125@@ -366,7 +366,7 @@ EOF 126 127 if ! test $ROCKSDB_DISABLE_TBB; then 128 # Test whether tbb is available 129- $CXX $PLATFORM_CXXFLAGS $LDFLAGS -x c++ - -o /dev/null -ltbb 2>/dev/null <<EOF 130+ $CXX $PLATFORM_CXXFLAGS $LDFLAGS -x c++ - -o test.o -ltbb 2>/dev/null <<EOF 131 #include <tbb/tbb.h> 132 int main() {} 133 EOF 134@@ -379,7 +379,7 @@ EOF 135 136 if ! test $ROCKSDB_DISABLE_JEMALLOC; then 137 # Test whether jemalloc is available 138- if echo 'int main() {}' | $CXX $PLATFORM_CXXFLAGS -x c++ - -o /dev/null -ljemalloc \ 139+ if echo 'int main() {}' | $CXX $PLATFORM_CXXFLAGS -x c++ - -o test.o -ljemalloc \ 140 2>/dev/null; then 141 # This will enable some preprocessor identifiers in the Makefile 142 JEMALLOC=1 143@@ -400,7 +400,7 @@ EOF 144 fi 145 if ! test $JEMALLOC && ! test $ROCKSDB_DISABLE_TCMALLOC; then 146 # jemalloc is not available. Let's try tcmalloc 147- if echo 'int main() {}' | $CXX $PLATFORM_CXXFLAGS -x c++ - -o /dev/null \ 148+ if echo 'int main() {}' | $CXX $PLATFORM_CXXFLAGS -x c++ - -o test.o \ 149 -ltcmalloc 2>/dev/null; then 150 PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -ltcmalloc" 151 JAVA_LDFLAGS="$JAVA_LDFLAGS -ltcmalloc" 152@@ -409,7 +409,7 @@ EOF 153 154 if ! test $ROCKSDB_DISABLE_MALLOC_USABLE_SIZE; then 155 # Test whether malloc_usable_size is available 156- $CXX $PLATFORM_CXXFLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF 157+ $CXX $PLATFORM_CXXFLAGS -x c++ - -o test.o 2>/dev/null <<EOF 158 #include <malloc.h> 159 int main() { 160 size_t res = malloc_usable_size(0); 161@@ -424,7 +424,7 @@ EOF 162 163 if ! test $ROCKSDB_DISABLE_MEMKIND; then 164 # Test whether memkind library is installed 165- $CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS -lmemkind -x c++ - -o /dev/null 2>/dev/null <<EOF 166+ $CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS -lmemkind -x c++ - -o test.o 2>/dev/null <<EOF 167 #include <memkind.h> 168 int main() { 169 memkind_malloc(MEMKIND_DAX_KMEM, 1024); 170@@ -486,7 +486,7 @@ EOF 171 172 if ! test $ROCKSDB_DISABLE_PTHREAD_MUTEX_ADAPTIVE_NP; then 173 # Test whether PTHREAD_MUTEX_ADAPTIVE_NP mutex type is available 174- $CXX $PLATFORM_CXXFLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF 175+ $CXX $PLATFORM_CXXFLAGS -x c++ - -o test.o 2>/dev/null <<EOF 176 #include <pthread.h> 177 int main() { 178 int x = PTHREAD_MUTEX_ADAPTIVE_NP; 179@@ -439,7 +439,7 @@ EOF 180 181 if ! test $ROCKSDB_DISABLE_BACKTRACE; then 182 # Test whether backtrace is available 183- $CXX $PLATFORM_CXXFLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF 184+ $CXX $PLATFORM_CXXFLAGS -x c++ - -o test.o 2>/dev/null <<EOF 185 #include <execinfo.h> 186 int main() { 187 void* frames[1]; 188@@ -451,7 +451,7 @@ EOF 189 COMMON_FLAGS="$COMMON_FLAGS -DROCKSDB_BACKTRACE" 190 else 191 # Test whether execinfo library is installed 192- $CXX $PLATFORM_CXXFLAGS -lexecinfo -x c++ - -o /dev/null 2>/dev/null <<EOF 193+ $CXX $PLATFORM_CXXFLAGS -lexecinfo -x c++ - -o test.o 2>/dev/null <<EOF 194 #include <execinfo.h> 195 int main() { 196 void* frames[1]; 197@@ -468,7 +468,7 @@ EOF 198 199 if ! test $ROCKSDB_DISABLE_PG; then 200 # Test if -pg is supported 201- $CXX $PLATFORM_CXXFLAGS -pg -x c++ - -o /dev/null 2>/dev/null <<EOF 202+ $CXX $PLATFORM_CXXFLAGS -pg -x c++ - -o test.o 2>/dev/null <<EOF 203 int main() { 204 return 0; 205 } 206@@ -480,7 +480,7 @@ EOF 207 208 if ! test $ROCKSDB_DISABLE_SYNC_FILE_RANGE; then 209 # Test whether sync_file_range is supported for compatibility with an old glibc 210- $CXX $PLATFORM_CXXFLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF 211+ $CXX $PLATFORM_CXXFLAGS -x c++ - -o test.o 2>/dev/null <<EOF 212 #include <fcntl.h> 213 int main() { 214 int fd = open("/dev/null", 0); 215@@ -494,7 +494,7 @@ EOF 216 217 if ! test $ROCKSDB_DISABLE_SCHED_GETCPU; then 218 # Test whether sched_getcpu is supported 219- $CXX $PLATFORM_CXXFLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF 220+ $CXX $PLATFORM_CXXFLAGS -x c++ - -o test.o 2>/dev/null <<EOF 221 #include <sched.h> 222 int main() { 223 int cpuid = sched_getcpu(); 224@@ -508,7 +508,7 @@ EOF 225 226 if ! test $ROCKSDB_DISABLE_AUXV_GETAUXVAL; then 227 # Test whether getauxval is supported 228- $CXX $PLATFORM_CXXFLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF 229+ $CXX $PLATFORM_CXXFLAGS -x c++ - -o test.o 2>/dev/null <<EOF 230 #include <sys/auxv.h> 231 int main() { 232 uint64_t auxv = getauxval(AT_HWCAP); 233@@ -522,7 +522,7 @@ EOF 234 235 if ! test $ROCKSDB_DISABLE_ALIGNED_NEW; then 236 # Test whether c++17 aligned-new is supported 237- $CXX $PLATFORM_CXXFLAGS -faligned-new -x c++ - -o /dev/null 2>/dev/null <<EOF 238+ $CXX $PLATFORM_CXXFLAGS -faligned-new -x c++ - -o test.o 2>/dev/null <<EOF 239 struct alignas(1024) t {int a;}; 240 int main() {} 241 EOF 242@@ -536,7 +536,7 @@ fi 243 # -Wshorten-64-to-32 breaks compilation on FreeBSD i386 244 if ! [ "$TARGET_OS" = FreeBSD -a "$TARGET_ARCHITECTURE" = i386 ]; then 245 # Test whether -Wshorten-64-to-32 is available 246- $CXX $PLATFORM_CXXFLAGS -x c++ - -o /dev/null -Wshorten-64-to-32 2>/dev/null <<EOF 247+ $CXX $PLATFORM_CXXFLAGS -x c++ - -o test.o -Wshorten-64-to-32 2>/dev/null <<EOF 248 int main() {} 249 EOF 250 if [ "$?" = 0 ]; then 251@@ -603,7 +603,7 @@ if test "$TRY_SSE_ETC"; then 252 TRY_LZCNT="-mlzcnt" 253 fi 254 255-$CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS $TRY_SSE42 -x c++ - -o /dev/null 2>/dev/null <<EOF 256+$CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS $TRY_SSE42 -x c++ - -o test.o 2>/dev/null <<EOF 257 #include <cstdint> 258 #include <nmmintrin.h> 259 int main() { 260@@ -617,7 +617,7 @@ elif test "$USE_SSE"; then 261 echo "warning: USE_SSE specified but compiler could not use SSE intrinsics, disabling" >&2 262 fi 263 264-$CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS $TRY_PCLMUL -x c++ - -o /dev/null 2>/dev/null <<EOF 265+$CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS $TRY_PCLMUL -x c++ - -o test.o 2>/dev/null <<EOF 266 #include <cstdint> 267 #include <wmmintrin.h> 268 int main() { 269@@ -634,7 +634,7 @@ elif test "$USE_SSE"; then 270 echo "warning: USE_SSE specified but compiler could not use PCLMUL intrinsics, disabling" >&2 271 fi 272 273-$CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS $TRY_AVX2 -x c++ - -o /dev/null 2>/dev/null <<EOF 274+$CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS $TRY_AVX2 -x c++ - -o test.o 2>/dev/null <<EOF 275 #include <cstdint> 276 #include <immintrin.h> 277 int main() { 278@@ -649,7 +649,7 @@ elif test "$USE_SSE"; then 279 echo "warning: USE_SSE specified but compiler could not use AVX2 intrinsics, disabling" >&2 280 fi 281 282-$CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS $TRY_BMI -x c++ - -o /dev/null 2>/dev/null <<EOF 283+$CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS $TRY_BMI -x c++ - -o test.o 2>/dev/null <<EOF 284 #include <cstdint> 285 #include <immintrin.h> 286 int main(int argc, char *argv[]) { 287@@ -739,7 +739,7 @@ elif test "$USE_SSE"; then 288 echo "warning: USE_SSE specified but compiler could not use BMI intrinsics, disabling" >&2 289 fi 290 291-$CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS $TRY_LZCNT -x c++ - -o /dev/null 2>/dev/null <<EOF 292+$CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS $TRY_LZCNT -x c++ - -o test.o 2>/dev/null <<EOF 293 #include <cstdint> 294 #include <immintrin.h> 295 int main(int argc, char *argv[]) { 296@@ -753,7 +753,7 @@ elif test "$USE_SSE"; then 297 echo "warning: USE_SSE specified but compiler could not use LZCNT intrinsics, disabling" >&2 298 fi 299 300-$CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF 301+$CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS -x c++ - -o test.o 2>/dev/null <<EOF 302 #include <cstdint> 303 int main() { 304 uint64_t a = 0xffffFFFFffffFFFF; 305@@ -666,7 +666,7 @@ fi 306 # succeed because the cross-compiler flags are added by the Makefile, not this 307 # script. 308 if [ "$PLATFORM" != IOS ]; then 309- $CXX $COMMON_FLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF 310+ $CXX $COMMON_FLAGS -x c++ - -o test.o 2>/dev/null <<EOF 311 #if defined(_MSC_VER) && !defined(__thread) 312 #define __thread __declspec(thread) 313 #endif 314@@ -685,7 +685,7 @@ if [ "$FBCODE_BUILD" != "true" -a "$PLATFORM" = OS_LINUX ]; then 315 void dummy_func() {} 316 EOF 317 if [ "$?" = 0 ]; then 318- $CXX $COMMON_FLAGS $PLATFORM_SHARED_LDFLAGS test_dl.o -o /dev/null 2>/dev/null 319+ $CXX $COMMON_FLAGS $PLATFORM_SHARED_LDFLAGS test_dl.o -o test.o 2>/dev/null 320 if [ "$?" = 0 ]; then 321 EXEC_LDFLAGS+="-ldl" 322 rm -f test_dl.o 323-- 3242.25.0 325 326