0001-build_tools-build_detect_platform-fix-C-tests.patch 14 KB

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