]> git.bitcoin.ninja Git - ldk-c-bindings/commitdiff
Correctly detect non-default LLD usage
authorMatt Corallo <git@bluematt.me>
Mon, 20 Dec 2021 06:13:55 +0000 (06:13 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 20 Dec 2021 06:26:37 +0000 (06:26 +0000)
Passing `-flto=ld*.lld-X` only appears to actually work on debian
testing. The correct argument for an alternative version of LLD is
`-flto=lld-X`.

genbindings.sh

index 61fd24327b77c046654f132ee8d3cf5c0040b2f8..44491f85458b532ab4f38e00c8d87bab39994380 100755 (executable)
@@ -367,7 +367,12 @@ if [ "$HOST_PLATFORM" = "host: x86_64-apple-darwin" ]; then
 else
        CLANG_LLVM_V=$(clang --version | head -n1 | awk '{ print substr($4, 0, 2); }')
        if [ -x "$(which ld.lld)" ]; then
-               LLD_LLVM_V="$(ld.lld --version | awk '{ print substr($2, 0, 2); }')"
+               LLD_LLVM_V="$(ld.lld --version | awk '{ print $2; }')"
+               if [ "$LLD_LLVM_V" = "LLD" ]; then # eg if the output is "Debian LLD ..."
+                       LLD_LLVM_V="$(ld.lld --version | awk '{ print substr($3, 0, 2); }')"
+               else
+                       LLD_LLVM_V="$(ld.lld --version | awk '{ print substr($2, 0, 2); }')"
+               fi
        fi
 fi
 
@@ -387,8 +392,14 @@ elif [ -x "$(which clang-$RUSTC_LLVM_V)" ]; then
                unset CLANGPP
        fi
        if [ "$LLD_LLVM_V" != "$RUSTC_LLVM_V" ]; then
-               LLD="$(which lld-$RUSTC_LLVM_V || echo lld)"
-               LLD_LLVM_V="$(ld.$LLD --version | awk '{ print substr($2, 0, 2); }')"
+               LLD="lld"
+               [ -x "$(which lld-$RUSTC_LLVM_V)" ] && LLD="lld-$RUSTC_LLVM_V"
+               LLD_LLVM_V="$(ld.lld-$RUSTC_LLVM_V --version | awk '{ print $2; }')"
+               if [ "$LLD_LLVM_V" = "LLD" ]; then # eg if the output is "Debian LLD ..."
+                       LLD_LLVM_V="$(ld.lld-$RUSTC_LLVM_V --version | awk '{ print substr($3, 0, 2); }')"
+               else
+                       LLD_LLVM_V="$(ld.lld-$RUSTC_LLVM_V --version | awk '{ print substr($2, 0, 2); }')"
+               fi
                if [ "$LLD_LLVM_V" != "$RUSTC_LLVM_V" ]; then
                        echo "Could not find a workable version of lld, not using cross-language LTO"
                        unset LLD
@@ -513,7 +524,7 @@ if [ "$CLANGPP" != "" -a "$LLD" != "" ]; then
        CARGO_PROFILE_RELEASE_LTO=true cargo rustc -v --release -- -C linker-plugin-lto -C lto -C linker=$CLANG $LINK_ARG_FLAGS -C link-arg=-march=sandybridge -C link-arg=-mcpu=sandybridge -C link-arg=-mtune=sandybridge
 
        if [ "$2" = "true" ]; then
-               $CLANGPP $LOCAL_CFLAGS -flto -fuse-ld=lld -O2 demo.cpp target/release/libldk.a -ldl
+               $CLANGPP $LOCAL_CFLAGS -flto -fuse-ld=$LLD -O2 demo.cpp target/release/libldk.a -ldl
                strip ./a.out
                echo "C++ Bin size and runtime with cross-language LTO:"
                ls -lha a.out