From 26bba774fe0d11aad2483d09fd65834a33527747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Tue, 28 Nov 2017 22:45:34 +0200 Subject: [PATCH] Merge libpsapi.a into libunwind.a This avoids having to manually add -lpsapi when linking in libc++.a. This requires using a new script to merge libraries using ar -M with a small MRI script. The script merge_archives.py in libcxx does the merge by manually extracting all object files and creating a new archive out of them. The import libraries created by LLVM have more than one object file with the same file name (just like MSVC tools do), so extracting them doesn't work as intended - but merging using a MRI script works. --- Dockerfile | 12 +++++++----- merge_archives.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) create mode 100755 merge_archives.sh diff --git a/Dockerfile b/Dockerfile index 902a51c..3b39ee0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -157,6 +157,7 @@ RUN git clone -b master https://github.com/llvm-mirror/libcxx.git && \ cd ../libunwind && \ git checkout 2ddcf2461daa5d61c543474aed06b12a8b9ad816 +COPY merge_archives.sh /build RUN cd libunwind && \ for arch in $TOOLCHAIN_ARCHS; do \ mkdir build-$arch && cd build-$arch && cmake \ @@ -179,6 +180,9 @@ RUN cd libunwind && \ -DCMAKE_CXX_FLAGS="-I/build/libcxx/include" \ .. && \ make -j4 && make install && \ + /build/merge_archives.sh \ + $TOOLCHAIN_PREFIX/$arch-w64-mingw32/lib/libunwind.a \ + $TOOLCHAIN_PREFIX/$arch-w64-mingw32/lib/libpsapi.a && \ cd .. || exit 1; \ done @@ -239,9 +243,7 @@ RUN cd libcxx && \ -DCMAKE_CXX_FLAGS="-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS" \ .. && \ make -j4 && make install && \ - ../utils/merge_archives.py \ - --ar llvm-ar \ - -o $TOOLCHAIN_PREFIX/$arch-w64-mingw32/lib/libc++.a \ + /build/merge_archives.sh \ $TOOLCHAIN_PREFIX/$arch-w64-mingw32/lib/libc++.a \ $TOOLCHAIN_PREFIX/$arch-w64-mingw32/lib/libunwind.a && \ cd .. || exit 1; \ @@ -258,12 +260,12 @@ RUN cd hello && \ RUN cd hello && \ for arch in $TOOLCHAIN_ARCHS; do \ - $arch-w64-mingw32-clang++ hello.cpp -o hello-cpp-$arch.exe -fno-exceptions -lpsapi || exit 1; \ + $arch-w64-mingw32-clang++ hello.cpp -o hello-cpp-$arch.exe -fno-exceptions || exit 1; \ done RUN cd hello && \ for arch in $TOOLCHAIN_ARCHS; do \ - $arch-w64-mingw32-clang++ hello-exception.cpp -o hello-exception-$arch.exe -lpsapi || exit 1; \ + $arch-w64-mingw32-clang++ hello-exception.cpp -o hello-exception-$arch.exe || exit 1; \ done ENV AR=llvm-ar diff --git a/merge_archives.sh b/merge_archives.sh new file mode 100755 index 0000000..92de3a5 --- /dev/null +++ b/merge_archives.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +set -e + +if [ $# -lt 2 ]; then + echo $0 lib add1 [add2...] + exit 1 +fi + +: ${AR:=llvm-ar} +: ${RANLIB:=llvm-ranlib} + +SCRIPT=merge.mri +OUT=tmp.a +TARGET=$1 + +rm -f $SCRIPT + +echo "CREATE $OUT" >> $SCRIPT +while [ $# -gt 0 ]; do + echo "ADDLIB $1" >> $SCRIPT + shift +done +echo "SAVE" >> $SCRIPT +echo "END" >> $SCRIPT +$AR -M < $SCRIPT +rm -f $SCRIPT +$RANLIB $OUT +mv $OUT $TARGET