Skip to content

Commit c3e8fd4

Browse files
committed
Fix LLVM build for GCC 14, and for windows
The `-femulated-tls` is to fix the error: ``` /opt/host-x86_64-w64-mingw32/clang/bin/x86_64-w64-mingw32-ld: lib/libLLVMSupport.a(BalancedPartitioning.cpp.obj):BalancedPartitioni:(.text$_ZNSt13__future_base13_State _baseV213_M_set_resultESt8functionIFSt10unique_ptrINS_12_Result_baseENS3_8_DeleterEEvEEb[_ZNSt13__future_base13_State_baseV213_M_set_resultESt8functionIFSt10unique_ptr INS_12_Result_baseENS3_8_DeleterEEvEEb]+0x82): undefined reference to `std::__once_callable' ``` The `libcxx` changes are to fix building for mingw, as there's symbol resolution issues if we don't use `lld` or try to make too many things shared instead of static.
1 parent 54c82ac commit c3e8fd4

File tree

6 files changed

+127
-10
lines changed

6 files changed

+127
-10
lines changed

bootstrap/LLVM/error.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/opt/target-x86_64-w64-mingw32/clang/bin/x86_64-w64-mingw32-ld: cannot export _ZNSt3__122__libcpp_verbose_abortEPKcz: symbol not defined
2+
/opt/target-x86_64-w64-mingw32/clang/bin/x86_64-w64-mingw32-ld: cannot export _ZdaPv: symbol not defined
3+
/opt/target-x86_64-w64-mingw32/clang/bin/x86_64-w64-mingw32-ld: cannot export _ZdaPvRKSt9nothrow_t: symbol wrong type (2 vs 3)
4+
/opt/target-x86_64-w64-mingw32/clang/bin/x86_64-w64-mingw32-ld: cannot export _ZdaPvSt11align_val_t: symbol not defined
5+
/opt/target-x86_64-w64-mingw32/clang/bin/x86_64-w64-mingw32-ld: cannot export _ZdaPvSt11align_val_tRKSt9nothrow_t: symbol wrong type (2 vs 3)
6+
/opt/target-x86_64-w64-mingw32/clang/bin/x86_64-w64-mingw32-ld: cannot export _ZdaPvy: symbol wrong type (2 vs 3)
7+
/opt/target-x86_64-w64-mingw32/clang/bin/x86_64-w64-mingw32-ld: cannot export _ZdaPvySt11align_val_t: symbol wrong type (2 vs 3)
8+
/opt/target-x86_64-w64-mingw32/clang/bin/x86_64-w64-mingw32-ld: cannot export _ZdlPv: symbol not defined
9+
/opt/target-x86_64-w64-mingw32/clang/bin/x86_64-w64-mingw32-ld: cannot export _ZdlPvRKSt9nothrow_t: symbol wrong type (2 vs 3)
10+
/opt/target-x86_64-w64-mingw32/clang/bin/x86_64-w64-mingw32-ld: cannot export _ZdlPvSt11align_val_t: symbol not defined
11+
/opt/target-x86_64-w64-mingw32/clang/bin/x86_64-w64-mingw32-ld: cannot export _ZdlPvSt11align_val_tRKSt9nothrow_t: symbol wrong type (2 vs 3)
12+
/opt/target-x86_64-w64-mingw32/clang/bin/x86_64-w64-mingw32-ld: cannot export _ZdlPvy: symbol wrong type (2 vs 3)
13+
/opt/target-x86_64-w64-mingw32/clang/bin/x86_64-w64-mingw32-ld: cannot export _ZdlPvySt11align_val_t: symbol wrong type (2 vs 3)
14+
/opt/target-x86_64-w64-mingw32/clang/bin/x86_64-w64-mingw32-ld: cannot export _Znay: symbol not defined
15+
/opt/target-x86_64-w64-mingw32/clang/bin/x86_64-w64-mingw32-ld: cannot export _ZnayRKSt9nothrow_t: symbol wrong type (2 vs 3)
16+
/opt/target-x86_64-w64-mingw32/clang/bin/x86_64-w64-mingw32-ld: cannot export _ZnaySt11align_val_t: symbol not defined
17+
/opt/target-x86_64-w64-mingw32/clang/bin/x86_64-w64-mingw32-ld: cannot export _ZnaySt11align_val_tRKSt9nothrow_t: symbol wrong type (2 vs 3)
18+
/opt/target-x86_64-w64-mingw32/clang/bin/x86_64-w64-mingw32-ld: cannot export _Znwy: symbol not defined
19+
/opt/target-x86_64-w64-mingw32/clang/bin/x86_64-w64-mingw32-ld: cannot export _ZnwyRKSt9nothrow_t: symbol wrong type (2 vs 3)
20+
/opt/target-x86_64-w64-mingw32/clang/bin/x86_64-w64-mingw32-ld: cannot export _ZnwySt11align_val_t: symbol not defined
21+
/opt/target-x86_64-w64-mingw32/clang/bin/x86_64-w64-mingw32-ld: cannot export _ZnwySt11align_val_tRKSt9nothrow_t: symbol wrong type (2 vs 3)
22+
/opt/target-x86_64-w64-mingw32/clang/bin/x86_64-w64-mingw32-ld: libcxxabi/src/CMakeFiles/cxxabi_shared_objects.dir/cxa_demangle.cpp.obj:cxa_demangle.cpp:(.text+0xad41): undefined reference to `operator delete(void*)'
23+
/opt/target-x86_64-w64-mingw32/clang/bin/x86_64-w64-mingw32-ld: libcxxabi/src/CMakeFiles/cxxabi_shared_objects.dir/cxa_demangle.cpp.obj:cxa_demangle.cpp:(.text+0xae71): undefined reference to `operator delete(void*)'

bootstrap/LLVM/libcxx.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ build_tarballs(;
2323
if [[ "${target}" == *mingw* ]]; then
2424
CMAKE_FLAGS+=( "-DLIBCXX_HAS_WIN32_THREAD_API=ON" )
2525
CMAKE_FLAGS+=( "-DLIBCXXABI_HAS_WIN32_THREAD_API=ON" )
26+
CMAKE_FLAGS+=( "-DLIBCXX_ENABLE_NEW_DELETE_DEFINITIONS=ON" )
27+
CMAKE_FLAGS+=( "-DLIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS=OFF" )
2628
fi
2729
2830
CMAKE_FLAGS+=( "-DLIBCXXABI_USE_COMPILER_RT=ON" )

bootstrap/LLVM/llvm_common.jl

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ end
2424
# BuildSpec generator for Clang/libLLVM
2525
function clang_build_spec_generator(;is_bootstrap::Bool = false)
2626
vendor = is_bootstrap ? :gcc_bootstrap : :clang_bootstrap
27-
compiler_runtime = :libgcc
2827

2928
return (host, platform) -> begin
29+
# This is a canadian cross, our `platform.target` is always `any`
30+
compiler_runtime = :libgcc
31+
if os(host_if_crossplatform(platform)) ("macos", "freebsd")
32+
compiler_runtime = :compiler_rt
33+
end
3034
specs = [
3135
BuildTargetSpec(
3236
"build",
@@ -63,7 +67,7 @@ function clang_build_spec_generator(;is_bootstrap::Bool = false)
6367
JLLSource(
6468
"Zlib_jll";
6569
repo=Pkg.Types.GitRepo(
66-
rev="bb2/GCC",
70+
rev="main",
6771
source="https://github.com/staticfloat/Zlib_jll.jl"
6872
),
6973
),
@@ -117,8 +121,8 @@ function clang_buildscript(src_version::VersionNumber)
117121
CMAKE_FLAGS+=(-DLLVM_SHLIB_SYMBOL_VERSION:STRING="JL_LLVM_${LLVM_MAJ_VER}.${LLVM_MIN_VER}")
118122
119123
if [[ "${host}" == *mingw* ]]; then
120-
CMAKE_CPP_FLAGS+=(-remap -D__USING_SJLJ_EXCEPTIONS__ -D__CRT__NO_INLINE -pthread -DMLIR_CAPI_ENABLE_WINDOWS_DLL_DECLSPEC -Dmlir_arm_sme_abi_stubs_EXPORTS)
121-
CMAKE_C_FLAGS+=(-pthread -DMLIR_CAPI_ENABLE_WINDOWS_DLL_DECLSPEC)
124+
CMAKE_CPP_FLAGS+=(-remap -D__USING_SJLJ_EXCEPTIONS__ -D__CRT__NO_INLINE -pthread -DMLIR_CAPI_ENABLE_WINDOWS_DLL_DECLSPEC -Dmlir_arm_sme_abi_stubs_EXPORTS -femulated-tls)
125+
CMAKE_C_FLAGS+=(-pthread -DMLIR_CAPI_ENABLE_WINDOWS_DLL_DECLSPEC -femulated-tls)
122126
CMAKE_FLAGS+=(-DCOMPILER_RT_BUILD_SANITIZERS=OFF)
123127
fi
124128
@@ -190,11 +194,10 @@ install_license ${WORKSPACE}/srcdir/llvm-project/LICENSE.TXT
190194
# Disable uname wrapper, because it makes LLVM build confused
191195
rm -f $(which uname)
192196
193-
# Create fake `xcrun` wrapper and `PlistBuddy` wrappers, to make detection of aarch64 support work
197+
# Create fake `PlistBuddy` wrapper to make detection of aarch64 support work
194198
mkdir -p /usr/libexec /usr/local/bin
195-
cp ${WORKSPACE}/srcdir/bundled/xcrun /usr/local/bin/xcrun
196199
cp ${WORKSPACE}/srcdir/bundled/PlistBuddy /usr/libexec/PlistBuddy
197-
chmod +x /usr/local/bin/xcrun /usr/libexec/PlistBuddy
200+
chmod +x /usr/libexec/PlistBuddy
198201
199202
# Apply patches to source
200203
pushd "${WORKSPACE}/srcdir/llvm-project"
@@ -242,17 +245,31 @@ CMAKE_FLAGS+=(
242245
-DLLVM_INCLUDE_EXAMPLES=OFF
243246
-DLLVM_INCLUDE_BENCHMARKS=OFF
244247
-DLIBCXX_INCLUDE_BENCHMARKS=OFF
248+
-DLLVM_ENABLE_LIBEDIT=OFF
249+
-DLLVM_ENABLE_TERMINFO=OFF
250+
-DLLVM_HAVE_LIBXAR=OFF
245251
)
246252
247253
# Turn off XML2
248254
CMAKE_FLAGS+=(-DLLVM_ENABLE_LIBXML2=OFF)
249255
250256
# Manually point to `zlib`, because it doesn't find it automatically properly.
251257
export LDFLAGS="-L ${host_shlibdir}"
252-
if [[ "${target}" != *mingw* ]]; then
253-
export LDFLAGS="${LDFLAGS} -Wl,-rpath,${host_shlibdir} -Wl,-rpath-link,${host_shlibdir}"
258+
259+
# We use this script fragment both in a cross-compile context (where `${host}` is the
260+
# system the compilers are compiling for) and in a normal context (where `${target}` is
261+
# the system the compilers are compiling for).
262+
if [[ -n "${build_prefix:-}" ]]; then
263+
if [[ "${host}" != *mingw* ]] && [[ "${host}" != *darwin* ]]; then
264+
export LDFLAGS="${LDFLAGS} -Wl,-rpath,${host_shlibdir} -Wl,-rpath-link,${host_shlibdir}"
265+
fi
266+
else
267+
if [[ "${target}" != *mingw* ]] && [[ "${target}" != *darwin* ]]; then
268+
export LDFLAGS="${LDFLAGS} -Wl,-rpath,${target_shlibdir} -Wl,-rpath-link,${target_shlibdir}"
269+
fi
254270
fi
255271
272+
256273
CMAKE_FLAGS+=(
257274
-DZLIB_ROOT="${host_prefix}"
258275
-DZLIB_LIBRARY="${host_shlibdir}/libz.${host_dlext}"
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
commit 9eec10409c0cb80d17992153410bb07e41565e2a
2+
Author: Elliot Saba <[email protected]>
3+
Date: Sat May 24 07:15:29 2025 +0000
4+
5+
Backport d54dfdd1b53ff72344287d250c2b67329792c840 to v17.0.6
6+
7+
This fixes the build on GCC 14 for arm
8+
9+
diff --git a/clang/include/clang/Basic/TokenKinds.def b/clang/include/clang/Basic/TokenKinds.def
10+
index ef0dad0f2dcd..849df57126cc 100644
11+
--- a/clang/include/clang/Basic/TokenKinds.def
12+
+++ b/clang/include/clang/Basic/TokenKinds.def
13+
@@ -753,7 +753,7 @@ KEYWORD(__builtin_sycl_unique_stable_name, KEYSYCL)
14+
15+
// Keywords defined by Attr.td.
16+
#ifndef KEYWORD_ATTRIBUTE
17+
-#define KEYWORD_ATTRIBUTE(X) KEYWORD(X, KEYALL)
18+
+#define KEYWORD_ATTRIBUTE(X, EMPTY) KEYWORD(EMPTY ## X, KEYALL)
19+
#endif
20+
#include "clang/Basic/AttrTokenKinds.inc"
21+
22+
diff --git a/clang/include/clang/Basic/TokenKinds.h b/clang/include/clang/Basic/TokenKinds.h
23+
index e4857405bc7f..3c263d6246d2 100644
24+
--- a/clang/include/clang/Basic/TokenKinds.h
25+
+++ b/clang/include/clang/Basic/TokenKinds.h
26+
@@ -109,7 +109,7 @@ bool isPragmaAnnotation(TokenKind K);
27+
28+
inline constexpr bool isRegularKeywordAttribute(TokenKind K) {
29+
return (false
30+
-#define KEYWORD_ATTRIBUTE(X) || (K == tok::kw_##X)
31+
+#define KEYWORD_ATTRIBUTE(X, EMPTY) || (K == tok::kw_##X)
32+
#include "clang/Basic/AttrTokenKinds.inc"
33+
);
34+
}
35+
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp
36+
index b5813c6abc2b..79db17501b64 100644
37+
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
38+
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
39+
@@ -3430,7 +3430,7 @@ void EmitClangAttrTokenKinds(RecordKeeper &Records, raw_ostream &OS) {
40+
"RegularKeyword attributes with arguments are not "
41+
"yet supported");
42+
OS << "KEYWORD_ATTRIBUTE("
43+
- << S.getSpellingRecord().getValueAsString("Name") << ")\n";
44+
+ << S.getSpellingRecord().getValueAsString("Name") << ", )\n";
45+
}
46+
OS << "#undef KEYWORD_ATTRIBUTE\n";
47+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
From 1fa6efaa946243004c45be92e66b324dc980df7d Mon Sep 17 00:00:00 2001
2+
From: Valentin Churavy <[email protected]>
3+
Date: Thu, 17 Sep 2020 23:22:45 +0200
4+
Subject: [PATCH] clang-sa can't determine that !RHS implies !LHS
5+
6+
---
7+
llvm/include/llvm/ADT/FunctionExtras.h | 2 ++
8+
1 file changed, 2 insertions(+)
9+
10+
diff --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h
11+
index 121aa527a5d..b9b6d829b14 100644
12+
--- a/llvm/include/llvm/ADT/FunctionExtras.h
13+
+++ b/llvm/include/llvm/ADT/FunctionExtras.h
14+
@@ -193,9 +193,11 @@ public:
15+
// Copy the callback and inline flag.
16+
CallbackAndInlineFlag = RHS.CallbackAndInlineFlag;
17+
18+
+#ifndef __clang_analyzer__
19+
// If the RHS is empty, just copying the above is sufficient.
20+
if (!RHS)
21+
return;
22+
+#endif
23+
24+
if (!isInlineStorage()) {
25+
// The out-of-line case is easiest to move.
26+
--
27+
2.28.0
28+

bootstrap/LLVM/tblgen.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ build_tarballs(;
4444
JLLSource(
4545
"Zlib_jll";
4646
repo=Pkg.Types.GitRepo(
47-
rev="bb2/GCC",
47+
rev="main",
4848
source="https://github.com/staticfloat/Zlib_jll.jl",
4949
),
5050
),

0 commit comments

Comments
 (0)