This is an automated email from the ASF dual-hosted git repository. achennaka pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/kudu.git
commit d932324e802aa397324c2181dfc55aaee39f4f69 Author: Alexey Serbin <[email protected]> AuthorDate: Sun Dec 29 11:45:01 2024 -0800 [thirdparty] fix building LLVM/CLANG 11.0.0 with GCC13 GCC13 (G++13) is the default system compiler on contemporary Linux OS flavors such as Ubuntu 24.04 LTS. With this patch it's now possible to compile LLVM/CLANG in Kudu's thirdparty on Ubuntu 24.04 and 24.04.1 LTS. This patch picks up a few relevant updates from the LLVM project's upstream repository [1] with minor tweaks to adapt to the change in the source files layout that happened in LLVM/CLANG 12. The updates prevent the leakage of the parts of the standard library installed on the build machine into the components of the LLVM/CLANG that are supposed to be completely freestanding and standalone. I guess it should help not only with making it possible to build LLVM/CLANG 11 with GCC13, but also address the root cause of the issues we have hit on SLES15 and elsewhere in the codegen that's reported in a few Jira items such as KUDU-3479 and KUDU-3545 [2][3]. However, there might be some extra patches beyond the ones already included. Anyway, I haven't verified this hypothesis yet. We definitely need to upgrade from LLVM 11.0.0 to LLVM 19.1.6 and I suspect it should help us to address [2] and [3] along with other updates and fixes. However, it's a separate task on its own, while this patch focuses on making the current version of LLVM/CLANG in the Kudu's thirdparty buildable on recent Linux OS releases (such as Ubuntu 24.04 LTS). I also snuck in an update to skip building compiler-rt tests since they aren't run in the scope of building LLVM/CLANG as a thirdparty component of the Apache Kudu project. [1] https://github.com/llvm/llvm-project [2] https://issues.apache.org/jira/browse/KUDU-3479 [3] https://issues.apache.org/jira/browse/KUDU-3545 Change-Id: I9b8282c85bbac5f25eae885e4b3ec183104bc540 Reviewed-on: http://gerrit.cloudera.org:8080/22279 Tested-by: Alexey Serbin <[email protected]> Reviewed-by: Ashwani Raina <[email protected]> Reviewed-by: Abhishek Chennaka <[email protected]> --- thirdparty/build-definitions.sh | 1 + thirdparty/download-thirdparty.sh | 12 +- thirdparty/patches/llvm-chrono-duration-00.patch | 34 +++++ thirdparty/patches/llvm-chrono-duration-01.patch | 69 +++++++++ .../llvm-include-llvm-support-signals.patch | 26 ++++ thirdparty/patches/llvm-is-convertible-00.patch | 41 ++++++ thirdparty/patches/llvm-is-convertible-01.patch | 158 +++++++++++++++++++++ thirdparty/patches/llvm-nostdinc-nostdlib-00.patch | 59 ++++++++ thirdparty/patches/llvm-nostdinc-nostdlib-01.patch | 108 ++++++++++++++ thirdparty/patches/llvm-nostdinc-nostdlib-02.patch | 65 +++++++++ 10 files changed, 571 insertions(+), 2 deletions(-) diff --git a/thirdparty/build-definitions.sh b/thirdparty/build-definitions.sh index 01a0f1ecb..fd5cda666 100644 --- a/thirdparty/build-definitions.sh +++ b/thirdparty/build-definitions.sh @@ -212,6 +212,7 @@ build_llvm() { CLANG_TOOL_CLANG_RENAME_BUILD \ CLANG_TOOL_DIAGTOOL_BUILD \ COMPILER_RT_BUILD_LIBFUZZER \ + COMPILER_RT_INCLUDE_TESTS \ LLVM_BUILD_BENCHMARKS \ LLVM_ENABLE_OCAMLDOC \ LLVM_INCLUDE_BENCHMARKS \ diff --git a/thirdparty/download-thirdparty.sh b/thirdparty/download-thirdparty.sh index 4d2de4663..d14459c98 100755 --- a/thirdparty/download-thirdparty.sh +++ b/thirdparty/download-thirdparty.sh @@ -332,7 +332,7 @@ fetch_and_patch \ $PYTHON_SOURCE \ $PYTHON_PATCHLEVEL -LLVM_PATCHLEVEL=5 +LLVM_PATCHLEVEL=6 fetch_and_patch \ llvm-${LLVM_VERSION}-iwyu-${IWYU_VERSION}.src.tar.gz \ $LLVM_SOURCE \ @@ -341,7 +341,15 @@ fetch_and_patch \ "patch -d projects -p1 < $TP_DIR/patches/llvm-remove-cyclades-inclusion-in-sanitizer.patch" \ "patch -p2 < $TP_DIR/patches/llvm-fix-missing-include.patch" \ "patch -d projects -p1 < $TP_DIR/patches/llvm-Sanitizer-built-against-glibc-2_34-doesnt-work.patch" \ - "patch -d tools -p1 < $TP_DIR/patches/llvm-ignore-flto-values.patch" + "patch -d tools -p1 < $TP_DIR/patches/llvm-ignore-flto-values.patch" \ + "patch -p1 < $TP_DIR/patches/llvm-nostdinc-nostdlib-00.patch" \ + "patch -p1 < $TP_DIR/patches/llvm-nostdinc-nostdlib-01.patch" \ + "patch -p1 < $TP_DIR/patches/llvm-nostdinc-nostdlib-02.patch" \ + "patch -p1 < $TP_DIR/patches/llvm-include-llvm-support-signals.patch" \ + "patch -p1 < $TP_DIR/patches/llvm-is-convertible-00.patch" \ + "patch -p1 < $TP_DIR/patches/llvm-is-convertible-01.patch" \ + "patch -p1 < $TP_DIR/patches/llvm-chrono-duration-00.patch" \ + "patch -p1 < $TP_DIR/patches/llvm-chrono-duration-01.patch" LZ4_PATCHLEVEL=0 fetch_and_patch \ diff --git a/thirdparty/patches/llvm-chrono-duration-00.patch b/thirdparty/patches/llvm-chrono-duration-00.patch new file mode 100644 index 000000000..4a6d2806c --- /dev/null +++ b/thirdparty/patches/llvm-chrono-duration-00.patch @@ -0,0 +1,34 @@ +commit eaadc451566f0d1aec873b7fe8b1a9dc3a7b29bd +Author: Tiago Macarios <[email protected]> +Date: Thu Feb 3 10:23:15 2022 -0500 + + [libc++] Fix chrono::duration constructor constraint + + As per [time.duration.cons]/1, the constructor constraint should be on + const Rep2&. As it is now the code will fail to compile in certain + cases, for example (https://godbolt.org/z/c7fPrcTYM): + + struct S{ + operator int() const&& noexcept = delete; + operator int() const& noexcept; + }; + + const S &fun(); + + auto k = std::chrono::microseconds{fun()}; + + Differential Revision: https://reviews.llvm.org/D118902 + +diff --git a/projects/libcxx/include/chrono b/projects/libcxx/include/chrono +index 24801772ec5d..b7d88cb52ea8 100644 +--- a/projects/libcxx/include/chrono ++++ b/projects/libcxx/include/chrono +@@ -1073,7 +1073,7 @@ public: + explicit duration(const _Rep2& __r, + typename enable_if + < +- is_convertible<_Rep2, rep>::value && ++ is_convertible<const _Rep2&, rep>::value && + (treat_as_floating_point<rep>::value || + !treat_as_floating_point<_Rep2>::value) + >::type* = 0) diff --git a/thirdparty/patches/llvm-chrono-duration-01.patch b/thirdparty/patches/llvm-chrono-duration-01.patch new file mode 100644 index 000000000..0daba46eb --- /dev/null +++ b/thirdparty/patches/llvm-chrono-duration-01.patch @@ -0,0 +1,69 @@ +commit 7d9540ea96ecb1e83f19cc68a202e8fa697c513d +Author: Mark de Wever <[email protected]> +Date: Sat Feb 10 14:21:57 2024 +0100 + + [libc++][chrono] Implements duration Rep constraints. (#80539) + + Applies LWG3050 to the constraints of operator*, operator/, and + operator%. The changes to the constructor were done in + https://reviews.llvm.org/D118902, but that patch did not identify the + related LWG-issue, and only adjusted the constructor to the wording in + the Standard. + + Implements: + - LWG 3050: Conversion specification problem in chrono::duration + constructor + + --------- + + Co-authored-by: h-vetinari <[email protected]> + +diff --git a/projects/libcxx/include/chrono b/projects/libcxx/include/chrono +index c80fa78a56ba..f8407419c954 100644 +--- a/projects/libcxx/include/chrono ++++ b/projects/libcxx/include/chrono +@@ -58,7 +58,7 @@ public: + constexpr explicit duration(const Rep2& r, + typename enable_if + < +- is_convertible<Rep2, rep>::value && ++ is_convertible<const Rep2&, rep>::value && + (treat_as_floating_point<rep>::value || + !treat_as_floating_point<rep>::value && !treat_as_floating_point<Rep2>::value) + >::type* = 0); +@@ -1267,7 +1267,7 @@ + _LIBCPP_CONSTEXPR + typename enable_if + < +- is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value, ++ is_convertible<const _Rep2&, typename common_type<_Rep1, _Rep2>::type>::value, + duration<typename common_type<_Rep1, _Rep2>::type, _Period> + >::type + operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s) +@@ -1282,7 +1282,7 @@ + _LIBCPP_CONSTEXPR + typename enable_if + < +- is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value, ++ is_convertible<const _Rep1&, typename common_type<_Rep1, _Rep2>::type>::value, + duration<typename common_type<_Rep1, _Rep2>::type, _Period> + >::type + operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d) +@@ -1298,7 +1298,7 @@ + typename enable_if + < + !__is_duration<_Rep2>::value && +- is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value, ++ is_convertible<const _Rep2&, typename common_type<_Rep1, _Rep2>::type>::value, + duration<typename common_type<_Rep1, _Rep2>::type, _Period> + >::type + operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s) +@@ -1326,7 +1326,7 @@ + typename enable_if + < + !__is_duration<_Rep2>::value && +- is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value, ++ is_convertible<const _Rep2&, typename common_type<_Rep1, _Rep2>::type>::value, + duration<typename common_type<_Rep1, _Rep2>::type, _Period> + >::type + operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s) diff --git a/thirdparty/patches/llvm-include-llvm-support-signals.patch b/thirdparty/patches/llvm-include-llvm-support-signals.patch new file mode 100644 index 000000000..e040fd4af --- /dev/null +++ b/thirdparty/patches/llvm-include-llvm-support-signals.patch @@ -0,0 +1,26 @@ +commit ff1681ddb303223973653f7f5f3f3435b48a1983 +Author: Sergei Trofimovich <[email protected]> +Date: Mon May 23 08:03:23 2022 +0100 + + [Support] Add missing <cstdint> header to Signals.h + + Without the change llvm build fails on this week's gcc-13 snapshot as: + + [ 0%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/Signals.cpp.o + In file included from llvm/lib/Support/Signals.cpp:14: + llvm/include/llvm/Support/Signals.h:119:8: error: variable or field 'CleanupOnSignal' declared void + 119 | void CleanupOnSignal(uintptr_t Context); + | ^~~~~~~~~~~~~~~ + +diff --git a/include/llvm/Support/Signals.h b/include/llvm/Support/Signals.h +index 44f5a750ff5c..937e0572d4a7 100644 +--- a/include/llvm/Support/Signals.h ++++ b/include/llvm/Support/Signals.h +@@ -14,6 +14,7 @@ + #ifndef LLVM_SUPPORT_SIGNALS_H + #define LLVM_SUPPORT_SIGNALS_H + ++#include <cstdint> + #include <string> + + namespace llvm { diff --git a/thirdparty/patches/llvm-is-convertible-00.patch b/thirdparty/patches/llvm-is-convertible-00.patch new file mode 100644 index 000000000..c03807988 --- /dev/null +++ b/thirdparty/patches/llvm-is-convertible-00.patch @@ -0,0 +1,41 @@ +commit 484e64f7e7b2c0494d7b2dbfdd528bcd707ee652 +Author: Roland McGrath <[email protected]> +Date: Thu Apr 27 14:18:18 2023 -0700 + + [libc++] Use __is_convertible built-in when available + + https://github.com/llvm/llvm-project/issues/62396 reports that + GCC 13 barfs on parsing <type_traits> because of the declarations + of `struct __is_convertible`. In GCC 13, `__is_convertible` is a + built-in, but `__is_convertible_to` is not. Clang has both, so + using either should be fine. + + Reviewed By: #libc, philnik + + Differential Revision: https://reviews.llvm.org/D149313 + +projects/libcxx/include/type_traits +diff --git a/projects/libcxx/include/type_traits b/projects/libcxx/include/type_traits +index 873a64b5a486..749d6fd47af9 100644 +--- a/projects/libcxx/include/type_traits ++++ b/projects/libcxx/include/type_traits +@@ -1733,11 +1733,18 @@ + + // is_convertible + +-#if __has_feature(is_convertible_to) && !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK) ++#if __has_builtin(__is_convertible) && !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK) ++ ++template <class _T1, class _T2> ++struct _LIBCPP_TEMPLATE_VIS is_convertible : public integral_constant<bool, __is_convertible(_T1, _T2)> {}; ++ ++#elif __has_builtin(__is_convertible_to) && !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK) + + template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS is_convertible + : public integral_constant<bool, __is_convertible_to(_T1, _T2)> {}; + ++// TODO: Remove this fallback when GCC < 13 support is no longer required. ++// GCC 13 has the __is_convertible built-in. + #else // __has_feature(is_convertible_to) + + namespace __is_convertible_imp diff --git a/thirdparty/patches/llvm-is-convertible-01.patch b/thirdparty/patches/llvm-is-convertible-01.patch new file mode 100644 index 000000000..255961228 --- /dev/null +++ b/thirdparty/patches/llvm-is-convertible-01.patch @@ -0,0 +1,158 @@ +commit 5aa03b648b827128d439f705cd7d57d59673741d +Author: Louis Dionne <[email protected]> +Date: Fri Jun 16 09:49:04 2023 -0400 + + [libc++][NFC] Apply clang-format on large parts of the code base + + This commit does a pass of clang-format over files in libc++ that + don't require major changes to conform to our style guide, or for + which we're not overly concerned about conflicting with in-flight + patches or hindering the git blame. + + This roughly covers: + - benchmarks + - range algorithms + - concepts + - type traits + + I did a manual verification of all the changes, and in particular I + applied clang-format on/off annotations in a few places where the + result was less readable after than before. This was not necessary + in a lot of places, however I did find that clang-format had pretty + bad taste when it comes to formatting concepts. + + Differential Revision: https://reviews.llvm.org/D153140 + +diff --git a/projects/libcxx/include/type_traits b/projects/libcxx/include/type_traits +index 749d6fd47af9..b378a20cedeb 100644 +--- a/projects/libcxx/include/type_traits ++++ b/projects/libcxx/include/type_traits +@@ -1740,76 +1740,75 @@ struct _LIBCPP_TEMPLATE_VIS is_convertible : public integral_constant<bool, __is + + #elif __has_feature(__is_convertible_to) && !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK) + +-template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS is_convertible +- : public integral_constant<bool, __is_convertible_to(_T1, _T2)> {}; ++template <class _T1, class _T2> ++struct _LIBCPP_TEMPLATE_VIS is_convertible : public integral_constant<bool, __is_convertible_to(_T1, _T2)> {}; + + // TODO: Remove this fallback when GCC < 13 support is no longer required. + // GCC 13 has the __is_convertible built-in. +-#else // __has_feature(is_convertible_to) ++#else // __has_builtin(__is_convertible_to) && !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK) + +-namespace __is_convertible_imp +-{ +-template <class _Tp> void __test_convert(_Tp); ++namespace __is_convertible_imp { ++template <class _Tp> ++void __test_convert(_Tp); + + template <class _From, class _To, class = void> + struct __is_convertible_test : public false_type {}; + + template <class _From, class _To> +-struct __is_convertible_test<_From, _To, +- decltype(_VSTD::__is_convertible_imp::__test_convert<_To>(_VSTD::declval<_From>()))> : public true_type +-{}; +- +-template <class _Tp, bool _IsArray = is_array<_Tp>::value, +- bool _IsFunction = is_function<_Tp>::value, +- bool _IsVoid = is_void<_Tp>::value> +- struct __is_array_function_or_void {enum {value = 0};}; +-template <class _Tp> struct __is_array_function_or_void<_Tp, true, false, false> {enum {value = 1};}; +-template <class _Tp> struct __is_array_function_or_void<_Tp, false, true, false> {enum {value = 2};}; +-template <class _Tp> struct __is_array_function_or_void<_Tp, false, false, true> {enum {value = 3};}; +-} ++struct __is_convertible_test<_From, _To, decltype(__is_convertible_imp::__test_convert<_To>(std::declval<_From>()))> ++ : public true_type {}; + ++// clang-format off + template <class _Tp, +- unsigned = __is_convertible_imp::__is_array_function_or_void<typename remove_reference<_Tp>::type>::value> +-struct __is_convertible_check +-{ +- static const size_t __v = 0; ++ bool _IsArray = is_array<_Tp>::value, ++ bool _IsFunction = is_function<_Tp>::value, ++ bool _IsVoid = is_void<_Tp>::value> ++ struct __is_array_function_or_void { enum { value = 0 }; }; ++template <class _Tp> struct __is_array_function_or_void<_Tp, true, false, false> { enum { value = 1 }; }; ++template <class _Tp> struct __is_array_function_or_void<_Tp, false, true, false> { enum { value = 2 }; }; ++template <class _Tp> struct __is_array_function_or_void<_Tp, false, false, true> { enum { value = 3 }; }; ++// clang-format on ++} // namespace __is_convertible_imp ++ ++template <class _Tp, ++ unsigned = __is_convertible_imp::__is_array_function_or_void<typename remove_reference<_Tp>::type>::value> ++struct __is_convertible_check { ++ static const size_t __v = 0; + }; + + template <class _Tp> +-struct __is_convertible_check<_Tp, 0> +-{ +- static const size_t __v = sizeof(_Tp); ++struct __is_convertible_check<_Tp, 0> { ++ static const size_t __v = sizeof(_Tp); + }; + +-template <class _T1, class _T2, +- unsigned _T1_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T1>::value, +- unsigned _T2_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T2>::value> ++template <class _T1, ++ class _T2, ++ unsigned _T1_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T1>::value, ++ unsigned _T2_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T2>::value> + struct __is_convertible +- : public integral_constant<bool, +- __is_convertible_imp::__is_convertible_test<_T1, _T2>::value +- > +-{}; +- +-template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 1> : public false_type {}; +-template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 1> : public false_type {}; +-template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 1> : public false_type {}; +-template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 1> : public false_type {}; +- +-template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 2> : public false_type {}; +-template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 2> : public false_type {}; +-template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 2> : public false_type {}; +-template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 2> : public false_type {}; +- +-template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 3> : public false_type {}; +-template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 3> : public false_type {}; +-template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 3> : public false_type {}; +-template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 3> : public true_type {}; +- +-template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS is_convertible +- : public __is_convertible<_T1, _T2> +-{ +- static const size_t __complete_check1 = __is_convertible_check<_T1>::__v; +- static const size_t __complete_check2 = __is_convertible_check<_T2>::__v; ++ : public integral_constant<bool, __is_convertible_imp::__is_convertible_test<_T1, _T2>::value >{}; ++ ++// clang-format off ++template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 1> : public false_type{}; ++template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 1> : public false_type{}; ++template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 1> : public false_type{}; ++template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 1> : public false_type{}; ++ ++template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 2> : public false_type{}; ++template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 2> : public false_type{}; ++template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 2> : public false_type{}; ++template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 2> : public false_type{}; ++ ++template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 3> : public false_type{}; ++template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 3> : public false_type{}; ++template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 3> : public false_type{}; ++template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 3> : public true_type{}; ++// clang-format on ++ ++template <class _T1, class _T2> ++struct _LIBCPP_TEMPLATE_VIS is_convertible : public __is_convertible<_T1, _T2> { ++ static const size_t __complete_check1 = __is_convertible_check<_T1>::__v; ++ static const size_t __complete_check2 = __is_convertible_check<_T2>::__v; + }; + + #endif // __has_feature(is_convertible_to) diff --git a/thirdparty/patches/llvm-nostdinc-nostdlib-00.patch b/thirdparty/patches/llvm-nostdinc-nostdlib-00.patch new file mode 100644 index 000000000..3b8d95edc --- /dev/null +++ b/thirdparty/patches/llvm-nostdinc-nostdlib-00.patch @@ -0,0 +1,59 @@ +commit 14c4de13e920c497c5275f81f74c453da2b3c957 +Author: Louis Dionne <[email protected]> +Date: Mon Jul 20 13:13:38 2020 -0400 + + [compiler-rt] Use -nostdinc++ in clang_rt.profile to avoid including C++ headers + + Most of the code in compiler_rt is C code. However, clang_rt.profile + contains the InstrProfilingRuntime.cpp file, which builds as C++. This + means that including e.g. <stdint.h> will actually include libc++'s + <stdint.h> and then #include_next the system's <stdint.h>. However, if + the target we're building compiler-rt for isn't supported by libc++, + this will lead to a failure since libc++'s <stdint.h> includes <__config>, + which performs various checks. + + Since the goal seems to *not* be including any header from the C++ Standard + Library in clang_rt.profile, using -nostdinc++ to ensure that doesn't + happen unknowingly seems to make sense. + + rdar://65852694 + + Differential Revision: https://reviews.llvm.org/D84205 + +diff --git a/projects/compiler-rt/cmake/config-ix.cmake b/projects/compiler-rt/cmake/config-ix.cmake +index e713f3c6b7c7..d1e01d956a7f 100644 +--- a/projects/compiler-rt/cmake/config-ix.cmake ++++ b/projects/compiler-rt/cmake/config-ix.cmake +@@ -122,7 +122,8 @@ check_cxx_compiler_flag(/wd4800 COMPILER_RT_HAS_WD4800_FLAG) + check_symbol_exists(__func__ "" COMPILER_RT_HAS_FUNC_SYMBOL) + + # Includes. +-check_include_files("sys/auxv.h" COMPILER_RT_HAS_AUXV) ++check_cxx_compiler_flag(-nostdinc++ COMPILER_RT_HAS_NOSTDINCXX_FLAG) ++check_include_files("sys/auxv.h" COMPILER_RT_HAS_AUXV) + + # Libraries. + check_library_exists(dl dlopen "" COMPILER_RT_HAS_LIBDL) +diff --git a/projects/compiler-rt/lib/profile/CMakeLists.txt b/projects/compiler-rt/lib/profile/CMakeLists.txt +index 63532b72ff82..5ff0e10182b4 100644 +--- a/projects/compiler-rt/lib/profile/CMakeLists.txt ++++ b/projects/compiler-rt/lib/profile/CMakeLists.txt +@@ -97,7 +97,7 @@ if(COMPILER_RT_TARGET_HAS_ATOMICS) + set(EXTRA_FLAGS + ${EXTRA_FLAGS} + -DCOMPILER_RT_HAS_ATOMICS=1) +-endif() ++endif() + + if(COMPILER_RT_TARGET_HAS_FCNTL_LCK) + set(EXTRA_FLAGS +@@ -111,6 +111,9 @@ if(COMPILER_RT_TARGET_HAS_UNAME) + -DCOMPILER_RT_HAS_UNAME=1) + endif() + ++# We don't use the C++ Standard Library here, so avoid including it by mistake. ++append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ EXTRA_FLAGS) ++ + # This appears to be a C-only warning banning the use of locals in aggregate + # initializers. All other compilers accept this, though. + # nonstandard extension used : 'identifier' : cannot be initialized using address of automatic variable diff --git a/thirdparty/patches/llvm-nostdinc-nostdlib-01.patch b/thirdparty/patches/llvm-nostdinc-nostdlib-01.patch new file mode 100644 index 000000000..fc4c17dc2 --- /dev/null +++ b/thirdparty/patches/llvm-nostdinc-nostdlib-01.patch @@ -0,0 +1,108 @@ +commit 11efd002b1e6191d97abfec4e7b3d390d8589197 +Author: Petr Hosek <[email protected]> +Date: Fri Oct 30 20:19:39 2020 -0700 + + [CMake] Avoid accidental C++ standard library dependency in sanitizers + + 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. + + Reviewed By: smeenai, vitalybuka + + Differential Revision: https://reviews.llvm.org/D88922 + +diff --git a/projects/compiler-rt/CMakeLists.txt b/projects/compiler-rt/CMakeLists.txt +index 6209320d36b8..1705a005caef 100644 +--- a/projects/compiler-rt/CMakeLists.txt ++++ b/projects/compiler-rt/CMakeLists.txt +@@ -185,7 +185,11 @@ endif() + pythonize_bool(SANITIZER_CAN_USE_CXXABI) + + macro(handle_default_cxx_lib var) +- if (${var} STREQUAL "default") ++ # Specifying -stdlib= in CMAKE_CXX_FLAGS overrides the defaults. ++ if (CMAKE_CXX_FLAGS MATCHES "-stdlib=([a-zA-Z+]*)") ++ set(${var}_LIBNAME "${CMAKE_MATCH_1}") ++ set(${var}_SYSTEM 1) ++ elseif (${var} STREQUAL "default") + if (APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD") + set(${var}_LIBNAME "libc++") + set(${var}_SYSTEM 1) +@@ -439,6 +443,25 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Fuchsia") + list(APPEND SANITIZER_COMMON_LINK_LIBS zircon) + endif() + ++# TODO: COMPILER_RT_COMMON_CFLAGS and COMPILER_RT_COMMON_LINK_FLAGS are ++# intended for use in non-sanitizer runtimes such as libFuzzer, profile or XRay, ++# move these higher to include common flags, then derive SANITIZER_COMMON_CFLAGS ++# and SANITIZER_COMMON_LINK_FLAGS from those and append sanitizer-specific flags. ++set(COMPILER_RT_COMMON_CFLAGS ${SANITIZER_COMMON_CFLAGS}) ++set(COMPILER_RT_COMMON_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS}) ++ ++# We don't use the C++ standard library, so avoid including it by mistake. ++append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ SANITIZER_COMMON_CFLAGS) ++append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ SANITIZER_COMMON_LINK_FLAGS) ++ ++# Remove -stdlib= which is unused when passing -nostdinc++... ++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}) ++ ++# ...we need it to build some runtimes and tests so readd it where appropriate. ++list(APPEND COMPILER_RT_COMMON_CFLAGS ${stdlib_flag}) ++list(APPEND COMPILER_RT_COMMON_LINK_FLAGS ${stdlib_flag}) ++ + macro(append_libcxx_libs var) + if (${var}_INTREE) + if (SANITIZER_USE_STATIC_LLVM_UNWINDER AND (TARGET unwind_static OR HAVE_LIBUNWIND)) +diff --git a/projects/compiler-rt/lib/fuzzer/CMakeLists.txt b/projects/compiler-rt/lib/fuzzer/CMakeLists.txt +index 48bb7fb956af..3201ed279a62 100644 +--- a/projects/compiler-rt/lib/fuzzer/CMakeLists.txt ++++ b/projects/compiler-rt/lib/fuzzer/CMakeLists.txt +@@ -55,14 +55,13 @@ CHECK_CXX_SOURCE_COMPILES(" + } + " HAS_THREAD_LOCAL) + +-set(LIBFUZZER_CFLAGS ${SANITIZER_COMMON_CFLAGS}) ++set(LIBFUZZER_CFLAGS ${COMPILER_RT_COMMON_CFLAGS}) + + if(OS_NAME MATCHES "Linux|Fuchsia" AND + COMPILER_RT_LIBCXX_PATH AND + COMPILER_RT_LIBCXXABI_PATH) +- list(APPEND LIBFUZZER_CFLAGS -nostdinc++ -D_LIBCPP_ABI_VERSION=Fuzzer) +- # Remove -stdlib= which is unused when passing -nostdinc++. +- string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) ++ list(APPEND LIBFUZZER_CFLAGS -D_LIBCPP_ABI_VERSION=Fuzzer) ++ append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ LIBFUZZER_CFLAGS) + elseif(TARGET cxx-headers OR HAVE_LIBCXX) + # libFuzzer uses C++ standard library headers. + set(LIBFUZZER_DEPS cxx-headers) +diff --git a/projects/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt b/projects/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt +index 96c845d81cf4..92e8513db6d3 100644 +--- a/projects/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt ++++ b/projects/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt +@@ -210,9 +210,7 @@ if(ANDROID) + $<TARGET_OBJECTS:RTSanitizerCommon.${arch}> + $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}> + $<TARGET_OBJECTS:RTSanitizerCommonSymbolizer.${arch}>) +- set_target_compile_flags(SanitizerTest +- ${SANITIZER_COMMON_CFLAGS} +- ${SANITIZER_TEST_CFLAGS_COMMON}) ++ set_target_compile_flags(SanitizerTest ${SANITIZER_TEST_CFLAGS_COMMON}) + # Setup correct output directory and link flags. + set_target_properties(SanitizerTest PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +diff --git a/projects/compiler-rt/lib/xray/CMakeLists.txt b/projects/compiler-rt/lib/xray/CMakeLists.txt +index 1b738d0ff5bf..54f2ad8f7ec1 100644 +--- a/projects/compiler-rt/lib/xray/CMakeLists.txt ++++ b/projects/compiler-rt/lib/xray/CMakeLists.txt +@@ -132,7 +132,7 @@ endforeach() + include_directories(..) + include_directories(../../include) + +-set(XRAY_CFLAGS ${SANITIZER_COMMON_CFLAGS}) ++set(XRAY_CFLAGS ${COMPILER_RT_COMMON_CFLAGS}) + set(XRAY_COMMON_DEFINITIONS XRAY_HAS_EXCEPTIONS=1) + + # We don't need RTTI in XRay, so turn that off. diff --git a/thirdparty/patches/llvm-nostdinc-nostdlib-02.patch b/thirdparty/patches/llvm-nostdinc-nostdlib-02.patch new file mode 100644 index 000000000..2ba08a99a --- /dev/null +++ b/thirdparty/patches/llvm-nostdinc-nostdlib-02.patch @@ -0,0 +1,65 @@ +commit 59d503159134de548c3958efb597db545bdef650 +Author: Petr Hosek <[email protected]> +Date: Fri Oct 30 16:16:09 2020 -0700 + + [CMake] Add -fno-rtti into tsan unittests + + And some other NFC parts of D88922 + +diff --git a/projects/compiler-rt/cmake/config-ix.cmake b/projects/compiler-rt/cmake/config-ix.cmake +index 38a1a2bdfac5..88a874f20ec2 100644 +--- a/projects/compiler-rt/cmake/config-ix.cmake ++++ b/projects/compiler-rt/cmake/config-ix.cmake +@@ -123,6 +123,7 @@ check_symbol_exists(__func__ "" COMPILER_RT_HAS_FUNC_SYMBOL) + + # Includes. + check_cxx_compiler_flag(-nostdinc++ COMPILER_RT_HAS_NOSTDINCXX_FLAG) ++check_cxx_compiler_flag(-nostdlib++ COMPILER_RT_HAS_NOSTDLIBXX_FLAG) + check_include_files("sys/auxv.h" COMPILER_RT_HAS_AUXV) + + # Libraries. +diff --git a/projects/compiler-rt/lib/fuzzer/CMakeLists.txt b/projects/compiler-rt/lib/fuzzer/CMakeLists.txt +index b98c27145687..48bb7fb956af 100644 +--- a/projects/compiler-rt/lib/fuzzer/CMakeLists.txt ++++ b/projects/compiler-rt/lib/fuzzer/CMakeLists.txt +@@ -64,6 +64,7 @@ if(OS_NAME MATCHES "Linux|Fuchsia" AND + # Remove -stdlib= which is unused when passing -nostdinc++. + string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) + elseif(TARGET cxx-headers OR HAVE_LIBCXX) ++ # libFuzzer uses C++ standard library headers. + set(LIBFUZZER_DEPS cxx-headers) + endif() + +diff --git a/projects/compiler-rt/lib/tsan/tests/CMakeLists.txt b/projects/compiler-rt/lib/tsan/tests/CMakeLists.txt +index 61b01a8b4da1..5d27e134555a 100644 +--- a/projects/compiler-rt/lib/tsan/tests/CMakeLists.txt ++++ b/projects/compiler-rt/lib/tsan/tests/CMakeLists.txt +@@ -5,13 +5,14 @@ set_target_properties(TsanUnitTests PROPERTIES + FOLDER "Compiler-RT Tests") + + set(TSAN_UNITTEST_CFLAGS +- ${TSAN_CFLAGS} + ${COMPILER_RT_UNITTEST_CFLAGS} + ${COMPILER_RT_GTEST_CFLAGS} + -I${COMPILER_RT_SOURCE_DIR}/include + -I${COMPILER_RT_SOURCE_DIR}/lib + -I${COMPILER_RT_SOURCE_DIR}/lib/tsan/rtl +- -DGTEST_HAS_RTTI=0) ++ -DGTEST_HAS_RTTI=0 ++ -fno-rtti ++) + + set(TSAN_TEST_ARCH ${TSAN_SUPPORTED_ARCH}) + +diff --git a/projects/compiler-rt/lib/xray/CMakeLists.txt b/projects/compiler-rt/lib/xray/CMakeLists.txt +index 3798f557c42c..1b738d0ff5bf 100644 +--- a/projects/compiler-rt/lib/xray/CMakeLists.txt ++++ b/projects/compiler-rt/lib/xray/CMakeLists.txt +@@ -149,6 +149,7 @@ set(XRAY_COMMON_RUNTIME_OBJECT_LIBS + RTSanitizerCommon + RTSanitizerCommonLibc) + ++# XRay uses C++ standard library headers. + if (TARGET cxx-headers OR HAVE_LIBCXX) + set(XRAY_DEPS cxx-headers) + endif()
