Skip to content

Commit e35ef3b

Browse files
committed
Use -unwindlib=libunwind instead of merging libunwind into libc++
This makes the build of libcxx a bit cleaner, and simplifies later building and testing of libcxx.
1 parent e40ff6a commit e35ef3b

File tree

5 files changed

+29
-10
lines changed

5 files changed

+29
-10
lines changed

build-compiler-rt.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,22 @@ for arch in $ARCHS; do
100100
$BUILDCMD ${CORES+-j$CORES}
101101
$BUILDCMD install
102102
mkdir -p "$PREFIX/$arch-w64-mingw32/bin"
103-
if [ -n "$SANITIZERS" ]; then
103+
if [ -z "$SANITIZERS" ]; then
104+
# Building builtins only. If libunwind isn't built yet, linking of any
105+
# executable will still fail as we're using -unwindlib=libunwind.
106+
# Therefore, create a dummy libunwind.a (unless there's a real
107+
# libunwind installed already) to let linking succeed.
108+
#
109+
# This is a workaround to avoid needing to specify -unwindlib=none
110+
# for all linking until libunwind has been built. This avoids
111+
# needing to build libunwind right away (allowing building plain C
112+
# executables already now) and avoids needing to pass -unwindlib=none
113+
# when configuring the libunwind build.
114+
if [ ! -f $PREFIX/$arch-w64-mingw32/lib/libunwind.a ] && [ ! -f $PREFIX/$arch-w64-mingw32/lib/libunwind.dll.a ]; then
115+
# Create an archive, don't add any members.
116+
llvm-ar rcs $PREFIX/$arch-w64-mingw32/lib/libunwind.a
117+
fi
118+
else
104119
mv "$PREFIX/lib/clang/$CLANG_VERSION/lib/windows/"*.dll "$PREFIX/$arch-w64-mingw32/bin"
105120
fi
106121
cd ..

build-libcxx.sh

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,6 @@ build_all() {
193193
cd build-$arch-$type
194194
$BUILDCMD ${CORES+-j$CORES}
195195
$BUILDCMD install
196-
if [ "$type" = "shared" ]; then
197-
llvm-ar qcsL \
198-
"$PREFIX/$arch-w64-mingw32/lib/libc++.dll.a" \
199-
"$PREFIX/$arch-w64-mingw32/lib/libunwind.dll.a"
200-
else
201-
llvm-ar qcsL \
202-
"$PREFIX/$arch-w64-mingw32/lib/libc++.a" \
203-
"$PREFIX/$arch-w64-mingw32/lib/libunwind.a"
204-
fi
205196
cd ..
206197
done
207198
cd ..
@@ -211,3 +202,13 @@ build_all() {
211202
# work when linking against the DLL, but not vice versa.
212203
[ -z "$BUILD_SHARED" ] || build_all shared
213204
[ -z "$BUILD_STATIC" ] || build_all static
205+
206+
# Remove dummy placeholder libunwind.a. If we've built a static version, it
207+
# already was overwritten with a proper one, but if only building a shared
208+
# version, remove the dummy one to avoid surprises.
209+
for arch in $ARCHS; do
210+
# Only remove the file if it contains no members.
211+
if [ -f $PREFIX/$arch-w64-mingw32/lib/libunwind.a ] && [ "$(llvm-ar t $PREFIX/$arch-w64-mingw32/lib/libunwind.a)" = "" ]; then
212+
rm $PREFIX/$arch-w64-mingw32/lib/libunwind.a
213+
fi
214+
done

build-llvm.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ if [ -n "$HOST" ]; then
157157
# the frontend wrappers, but this makes sure they are enabled by
158158
# default if that wrapper is bypassed as well.
159159
CMAKEFLAGS="$CMAKEFLAGS -DCLANG_DEFAULT_RTLIB=compiler-rt"
160+
CMAKEFLAGS="$CMAKEFLAGS -DCLANG_DEFAULT_UNWINDLIB=libunwind"
160161
CMAKEFLAGS="$CMAKEFLAGS -DCLANG_DEFAULT_CXX_STDLIB=libc++"
161162
CMAKEFLAGS="$CMAKEFLAGS -DCLANG_DEFAULT_LINKER=lld"
162163
BUILDDIR=$BUILDDIR-$HOST

wrappers/clang-target-wrapper.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ int _tmain(int argc, TCHAR* argv[]) {
224224
exec_argv[arg++] = _T("-target");
225225
exec_argv[arg++] = target;
226226
exec_argv[arg++] = _T("-rtlib=compiler-rt");
227+
exec_argv[arg++] = _T("-unwindlib=libunwind");
227228
exec_argv[arg++] = _T("-stdlib=libc++");
228229
exec_argv[arg++] = _T("-fuse-ld=lld");
229230
exec_argv[arg++] = _T("-Qunused-arguments");

wrappers/clang-target-wrapper.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ esac
8484

8585
FLAGS="$FLAGS -target $TARGET"
8686
FLAGS="$FLAGS -rtlib=compiler-rt"
87+
FLAGS="$FLAGS -unwindlib=libunwind"
8788
FLAGS="$FLAGS -stdlib=libc++"
8889
FLAGS="$FLAGS -fuse-ld=lld"
8990
FLAGS="$FLAGS -Qunused-arguments"

0 commit comments

Comments
 (0)