From e35ef3b7d796a174eeb35fc2595281a3285a38ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Thu, 4 Mar 2021 22:14:13 +0200 Subject: [PATCH] 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. --- build-compiler-rt.sh | 17 ++++++++++++++++- build-libcxx.sh | 19 ++++++++++--------- build-llvm.sh | 1 + wrappers/clang-target-wrapper.c | 1 + wrappers/clang-target-wrapper.sh | 1 + 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/build-compiler-rt.sh b/build-compiler-rt.sh index e9e677a..c9f335b 100755 --- a/build-compiler-rt.sh +++ b/build-compiler-rt.sh @@ -100,7 +100,22 @@ for arch in $ARCHS; do $BUILDCMD ${CORES+-j$CORES} $BUILDCMD install mkdir -p "$PREFIX/$arch-w64-mingw32/bin" - if [ -n "$SANITIZERS" ]; then + if [ -z "$SANITIZERS" ]; then + # Building builtins only. If libunwind isn't built yet, linking of any + # executable will still fail as we're using -unwindlib=libunwind. + # Therefore, create a dummy libunwind.a (unless there's a real + # libunwind installed already) to let linking succeed. + # + # This is a workaround to avoid needing to specify -unwindlib=none + # for all linking until libunwind has been built. This avoids + # needing to build libunwind right away (allowing building plain C + # executables already now) and avoids needing to pass -unwindlib=none + # when configuring the libunwind build. + if [ ! -f $PREFIX/$arch-w64-mingw32/lib/libunwind.a ] && [ ! -f $PREFIX/$arch-w64-mingw32/lib/libunwind.dll.a ]; then + # Create an archive, don't add any members. + llvm-ar rcs $PREFIX/$arch-w64-mingw32/lib/libunwind.a + fi + else mv "$PREFIX/lib/clang/$CLANG_VERSION/lib/windows/"*.dll "$PREFIX/$arch-w64-mingw32/bin" fi cd .. diff --git a/build-libcxx.sh b/build-libcxx.sh index fbede0c..6fdde00 100755 --- a/build-libcxx.sh +++ b/build-libcxx.sh @@ -193,15 +193,6 @@ build_all() { cd build-$arch-$type $BUILDCMD ${CORES+-j$CORES} $BUILDCMD install - if [ "$type" = "shared" ]; then - llvm-ar qcsL \ - "$PREFIX/$arch-w64-mingw32/lib/libc++.dll.a" \ - "$PREFIX/$arch-w64-mingw32/lib/libunwind.dll.a" - else - llvm-ar qcsL \ - "$PREFIX/$arch-w64-mingw32/lib/libc++.a" \ - "$PREFIX/$arch-w64-mingw32/lib/libunwind.a" - fi cd .. done cd .. @@ -211,3 +202,13 @@ build_all() { # work when linking against the DLL, but not vice versa. [ -z "$BUILD_SHARED" ] || build_all shared [ -z "$BUILD_STATIC" ] || build_all static + +# Remove dummy placeholder libunwind.a. If we've built a static version, it +# already was overwritten with a proper one, but if only building a shared +# version, remove the dummy one to avoid surprises. +for arch in $ARCHS; do + # Only remove the file if it contains no members. + if [ -f $PREFIX/$arch-w64-mingw32/lib/libunwind.a ] && [ "$(llvm-ar t $PREFIX/$arch-w64-mingw32/lib/libunwind.a)" = "" ]; then + rm $PREFIX/$arch-w64-mingw32/lib/libunwind.a + fi +done diff --git a/build-llvm.sh b/build-llvm.sh index c5f05e3..0f0b5ef 100755 --- a/build-llvm.sh +++ b/build-llvm.sh @@ -157,6 +157,7 @@ if [ -n "$HOST" ]; then # the frontend wrappers, but this makes sure they are enabled by # default if that wrapper is bypassed as well. CMAKEFLAGS="$CMAKEFLAGS -DCLANG_DEFAULT_RTLIB=compiler-rt" + CMAKEFLAGS="$CMAKEFLAGS -DCLANG_DEFAULT_UNWINDLIB=libunwind" CMAKEFLAGS="$CMAKEFLAGS -DCLANG_DEFAULT_CXX_STDLIB=libc++" CMAKEFLAGS="$CMAKEFLAGS -DCLANG_DEFAULT_LINKER=lld" BUILDDIR=$BUILDDIR-$HOST diff --git a/wrappers/clang-target-wrapper.c b/wrappers/clang-target-wrapper.c index 1305be9..cd03d87 100644 --- a/wrappers/clang-target-wrapper.c +++ b/wrappers/clang-target-wrapper.c @@ -224,6 +224,7 @@ int _tmain(int argc, TCHAR* argv[]) { exec_argv[arg++] = _T("-target"); exec_argv[arg++] = target; exec_argv[arg++] = _T("-rtlib=compiler-rt"); + exec_argv[arg++] = _T("-unwindlib=libunwind"); exec_argv[arg++] = _T("-stdlib=libc++"); exec_argv[arg++] = _T("-fuse-ld=lld"); exec_argv[arg++] = _T("-Qunused-arguments"); diff --git a/wrappers/clang-target-wrapper.sh b/wrappers/clang-target-wrapper.sh index 5d75702..4cac061 100755 --- a/wrappers/clang-target-wrapper.sh +++ b/wrappers/clang-target-wrapper.sh @@ -84,6 +84,7 @@ esac FLAGS="$FLAGS -target $TARGET" FLAGS="$FLAGS -rtlib=compiler-rt" +FLAGS="$FLAGS -unwindlib=libunwind" FLAGS="$FLAGS -stdlib=libc++" FLAGS="$FLAGS -fuse-ld=lld" FLAGS="$FLAGS -Qunused-arguments"