Skip to content

Commit e0964ce

Browse files
committed
Revert use of Clang config files
This reverts commit 49db4a3, 9f1f010, 4f95c14, c34dc64, 570fdcd, 4bff029 and 6939aee. When relying on Clang config files, two issues appeared: - Running the compiler-rt tests fails, because the compiler-rt tests disable any default config files, breaking the compiler in this case: https://github.com/llvm/llvm-project/blob/llvmorg-19.1.1/compiler-rt/test/lit.common.cfg.py#L983 - Wine fails to build using llvm-mingw as cross compiler, because Wine adds the --no-default-config flag to Clang while compiling, if supported: https://gitlab.winehq.org/wine/wine/-/blob/wine-9.19/configure.ac?ref_type=tags#L866-868 This causes llvm-mingw to omit the -rtlib=compiler-rt option (specified in a config file), making the compiler look for libgcc instead. Doing a check to see that linking succeeds doesn't necessarily help here - such a check already exists, but it tests linking with -nostdlib -nodefaultlibs: https://gitlab.winehq.org/wine/wine/-/blob/wine-9.19/aclocal.m4?ref_type=tags#L193-L206
1 parent 49db4a3 commit e0964ce

14 files changed

+119
-31
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ARG CFGUARD_ARGS=--enable-cfguard
2424

2525
# Build everything that uses the llvm monorepo. We need to build the mingw runtime before the compiler-rt/libunwind/libcxxabi/libcxx runtimes.
2626
COPY build-llvm.sh build-lldb-mi.sh strip-llvm.sh install-wrappers.sh build-mingw-w64.sh build-mingw-w64-tools.sh build-compiler-rt.sh build-libcxx.sh build-mingw-w64-libraries.sh build-openmp.sh ./
27-
COPY wrappers/*.sh wrappers/*.c wrappers/*.h wrappers/*.cfg ./wrappers/
27+
COPY wrappers/*.sh wrappers/*.c wrappers/*.h ./wrappers/
2828
RUN ./build-llvm.sh $TOOLCHAIN_PREFIX && \
2929
./build-lldb-mi.sh $TOOLCHAIN_PREFIX && \
3030
./strip-llvm.sh $TOOLCHAIN_PREFIX && \

Dockerfile.cross

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ ARG TOOLCHAIN_ARCHS="i686 x86_64 armv7 aarch64"
5454
COPY build-mingw-w64.sh build-mingw-w64-tools.sh ./
5555
RUN ./build-mingw-w64-tools.sh $CROSS_TOOLCHAIN_PREFIX --skip-include-triplet-prefix --host=$HOST
5656

57-
COPY wrappers/*.sh wrappers/*.c wrappers/*.h wrappers/*.cfg ./wrappers/
57+
COPY wrappers/*.sh wrappers/*.c wrappers/*.h ./wrappers/
5858
COPY install-wrappers.sh .
5959
RUN ./install-wrappers.sh $CROSS_TOOLCHAIN_PREFIX --host=$HOST
6060

Dockerfile.dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ RUN ./strip-llvm.sh $TOOLCHAIN_PREFIX
3737
ARG TOOLCHAIN_ARCHS="i686 x86_64 armv7 aarch64"
3838

3939
# Install the usual $TUPLE-clang binaries
40-
COPY wrappers/*.sh wrappers/*.c wrappers/*.h wrappers/*.cfg ./wrappers/
40+
COPY wrappers/*.sh wrappers/*.c wrappers/*.h ./wrappers/
4141
COPY install-wrappers.sh ./
4242
RUN ./install-wrappers.sh $TOOLCHAIN_PREFIX
4343

build-llvm.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,17 @@ if [ -n "$COMPILER_LAUNCHER" ]; then
242242
CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_CXX_COMPILER_LAUNCHER=$COMPILER_LAUNCHER"
243243
fi
244244

245+
if [ -n "$TARGET_WINDOWS" ]; then
246+
# Custom, llvm-mingw specific defaults. We normally set these in
247+
# the frontend wrappers, but this makes sure they are enabled by
248+
# default if that wrapper is bypassed as well.
249+
CMAKEFLAGS="$CMAKEFLAGS -DCLANG_DEFAULT_RTLIB=compiler-rt"
250+
CMAKEFLAGS="$CMAKEFLAGS -DCLANG_DEFAULT_UNWINDLIB=libunwind"
251+
CMAKEFLAGS="$CMAKEFLAGS -DCLANG_DEFAULT_CXX_STDLIB=libc++"
252+
CMAKEFLAGS="$CMAKEFLAGS -DCLANG_DEFAULT_LINKER=lld"
253+
CMAKEFLAGS="$CMAKEFLAGS -DLLD_DEFAULT_LD_LLD_IS_MINGW=ON"
254+
fi
255+
245256
if [ -n "$LTO" ]; then
246257
CMAKEFLAGS="$CMAKEFLAGS -DLLVM_ENABLE_LTO=$LTO"
247258
fi

install-wrappers.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,6 @@ fi
123123

124124
mkdir -p "$PREFIX/bin"
125125
cp wrappers/*-wrapper.sh "$PREFIX/bin"
126-
cp wrappers/mingw32-common.cfg $PREFIX/bin
127-
for arch in $ARCHS; do
128-
cp wrappers/$arch-w64-windows-gnu.cfg $PREFIX/bin
129-
done
130126
if [ -n "$HOST" ] && [ -n "$EXEEXT" ]; then
131127
# TODO: If building natively on msys, pick up the default HOST value from there.
132128
WRAPPER_FLAGS="$WRAPPER_FLAGS -DDEFAULT_TARGET=\"$HOST\""
@@ -142,18 +138,16 @@ if [ -n "$EXEEXT" ]; then
142138
# when invoked from outside of MSYS.
143139
CTW_SUFFIX=$EXEEXT
144140
CTW_LINK_SUFFIX=$EXEEXT
145-
CSDW=clang-scan-deps-wrapper$EXEEXT
146141
else
147142
CTW_SUFFIX=.sh
148-
CSDW=clang-scan-deps
149143
fi
150144
cd "$PREFIX/bin"
151145
for arch in $ARCHS; do
152146
for target_os in $TARGET_OSES; do
153147
for exec in clang clang++ gcc g++ c++ as; do
154148
ln -sf clang-target-wrapper$CTW_SUFFIX $arch-w64-$target_os-$exec$CTW_LINK_SUFFIX
155149
done
156-
ln -sf $CSDW $arch-w64-$target_os-clang-scan-deps$CTW_LINK_SUFFIX
150+
ln -sf clang-scan-deps-wrapper$CTW_SUFFIX $arch-w64-$target_os-clang-scan-deps$CTW_LINK_SUFFIX
157151
for exec in addr2line ar ranlib nm objcopy readelf size strings strip llvm-ar llvm-ranlib; do
158152
if [ -n "$EXEEXT" ]; then
159153
link_target=llvm-wrapper

wrappers/aarch64-w64-windows-gnu.cfg

Lines changed: 0 additions & 3 deletions
This file was deleted.

wrappers/armv7-w64-windows-gnu.cfg

Lines changed: 0 additions & 3 deletions
This file was deleted.

wrappers/clang-scan-deps-wrapper.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ int _tmain(int argc, TCHAR *argv[]) {
6363
if (sep)
6464
*sep = '\0';
6565
TCHAR *dash = _tcsrchr(cmd_exe, '-');
66-
int has_target = 0;
66+
const TCHAR *target = NULL;
6767
if (dash) {
6868
*dash = '\0';
6969
const TCHAR *cmd_exe_suffix = dash + 1;
@@ -76,15 +76,14 @@ int _tmain(int argc, TCHAR *argv[]) {
7676
!_tcscmp(cmd_exe_suffix, _T("cc")) ||
7777
!_tcscmp(cmd_exe_suffix, _T("c99")) ||
7878
!_tcscmp(cmd_exe_suffix, _T("c11"))) {
79-
has_target = 1;
79+
target = cmd_exe;
8080
}
8181
}
82-
const TCHAR *target = NULL;
8382
#ifdef _WIN32
8483
// On Windows, we want to set our default target even if no target
8584
// was found in cmd_exe, as we want to support running with a foreign
8685
// clang-scan-deps-real.exe binary, that could have any default.
87-
if (!has_target)
86+
if (!target)
8887
target = _T(DEFAULT_TARGET);
8988
#endif
9089

@@ -93,6 +92,7 @@ int _tmain(int argc, TCHAR *argv[]) {
9392
// -target after cmd_exe.
9493
exec_argv[arg++] = _T("-target");
9594
exec_argv[arg++] = target;
95+
exec_argv[arg++] = _T("-stdlib=libc++");
9696
}
9797
}
9898

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (c) 2024 Martin Storsjo
4+
#
5+
# Permission to use, copy, modify, and/or distribute this software for any
6+
# purpose with or without fee is hereby granted, provided that the above
7+
# copyright notice and this permission notice appear in all copies.
8+
#
9+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15+
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16+
17+
get_dir() {
18+
target="$1"
19+
while [ -L "$target" ]; do
20+
cd "$(dirname "$target")"
21+
target="$(readlink "$(basename "$target")")"
22+
done
23+
cd "$(dirname "$target")"
24+
pwd
25+
}
26+
27+
DIR="$(get_dir "$0")"
28+
29+
# If changing this wrapper, change clang-scan-deps-wrapper.c accordingly.
30+
EXE="$DIR/clang-scan-deps"
31+
FLAGS=()
32+
while [ $# -gt 0 ]; do
33+
if [ -n "$got_flags" ]; then
34+
CMD_EXE="$1"
35+
FLAGS+=("$1")
36+
shift
37+
break
38+
elif [ "$1" = "--" ]; then
39+
got_flags=1
40+
FLAGS+=("$1")
41+
else
42+
FLAGS+=("$1")
43+
fi
44+
shift
45+
done
46+
47+
if [ -n "$CMD_EXE" ]; then
48+
# If CMD_EXE is a <triple>-<exe> style command, pick up the
49+
# target triple from there.
50+
CMD_BASENAME="$(basename "$CMD_EXE")"
51+
CMD_BASENAME="${CMD_BASENAME%.*}"
52+
CMD_TARGET="${CMD_BASENAME%-*}"
53+
CMD_EXE_SUFFIX="${CMD_BASENAME##*-}"
54+
if [ "$CMD_TARGET" != "$CMD_BASENAME" ]; then
55+
case $CMD_EXE_SUFFIX in
56+
clang|clang++|gcc|g++|c++|as|cc|c99|c11)
57+
TARGET="$CMD_TARGET"
58+
;;
59+
esac
60+
fi
61+
fi
62+
63+
if [ -n "$TARGET" ]; then
64+
"$EXE" "${FLAGS[@]}" -target $TARGET -stdlib=libc++ "$@"
65+
else
66+
"$EXE" "${FLAGS[@]}" "$@"
67+
fi

wrappers/clang-target-wrapper.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ int _tmain(int argc, TCHAR* argv[]) {
5050
}
5151
}
5252

53-
int max_arg = argc + 18;
53+
int max_arg = argc + 22;
5454
const TCHAR **exec_argv = malloc((max_arg + 1) * sizeof(*exec_argv));
5555
int arg = 0;
5656
if (getenv("CCACHE"))
@@ -66,6 +66,16 @@ int _tmain(int argc, TCHAR* argv[]) {
6666
else if (!_tcscmp(exe, _T("c11")))
6767
exec_argv[arg++] = _T("-std=c11");
6868

69+
if (!_tcscmp(arch, _T("i686"))) {
70+
// Dwarf is the default for i686.
71+
} else if (!_tcscmp(arch, _T("x86_64"))) {
72+
// SEH is the default for x86_64.
73+
} else if (!_tcscmp(arch, _T("armv7"))) {
74+
// SEH is the default for armv7.
75+
} else if (!_tcscmp(arch, _T("aarch64"))) {
76+
// SEH is the default for aarch64.
77+
}
78+
6979
if (target_os && !_tcscmp(target_os, _T("mingw32uwp"))) {
7080
// the UWP target is for Windows 10
7181
exec_argv[arg++] = _T("-D_WIN32_WINNT=0x0A00");
@@ -80,6 +90,10 @@ int _tmain(int argc, TCHAR* argv[]) {
8090

8191
exec_argv[arg++] = _T("-target");
8292
exec_argv[arg++] = target;
93+
exec_argv[arg++] = _T("-rtlib=compiler-rt");
94+
exec_argv[arg++] = _T("-unwindlib=libunwind");
95+
exec_argv[arg++] = _T("-stdlib=libc++");
96+
exec_argv[arg++] = _T("-fuse-ld=lld");
8397
exec_argv[arg++] = _T("--end-no-unused-arguments");
8498

8599
for (int i = 1; i < argc; i++)

0 commit comments

Comments
 (0)