Author: Josh Kunz Date: 2019-11-22T15:33:13-08:00 New Revision: 6551ac7489fe070a2edcfac88f68c93321cba9a9
URL: https://github.com/llvm/llvm-project/commit/6551ac7489fe070a2edcfac88f68c93321cba9a9 DIFF: https://github.com/llvm/llvm-project/commit/6551ac7489fe070a2edcfac88f68c93321cba9a9.diff LOG: [Driver] Make -static-libgcc imply static libunwind In the GNU toolchain, `-static-libgcc` implies that the unwindlib will be linked statically. However, when `--unwindlib=libunwind`, this flag is ignored, and a bare `-lunwind` is added to the linker args. Unfortunately, this means that if both `libunwind.so`, and `libunwind.a` are present in the library path, `libunwind.so` will be chosen in all cases where `-static` is not set. This change makes `-static-libgcc` affect the `-l` flag produced by `--unwindlib=libunwind`. After this patch, providing `-static-libgcc --unwindlib=libunwind` will cause the driver to explicitly emit `-l:libunwind.a` to statically link libunwind. For all other cases it will emit `-l:libunwind.so` matching current behavior with a more explicit link line. https://reviews.llvm.org/D70416 Added: Modified: clang/lib/Driver/ToolChains/CommonArgs.cpp clang/test/Driver/compiler-rt-unwind.c Removed: ################################################################################ diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 58705a2aa933..37ec73468570 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -1209,7 +1209,10 @@ static void AddUnwindLibrary(const ToolChain &TC, const Driver &D, break; } case ToolChain::UNW_CompilerRT: - CmdArgs.push_back("-lunwind"); + if (LGT == LibGccType::StaticLibGcc) + CmdArgs.push_back("-l:libunwind.a"); + else + CmdArgs.push_back("-l:libunwind.so"); break; } diff --git a/clang/test/Driver/compiler-rt-unwind.c b/clang/test/Driver/compiler-rt-unwind.c index 0ec067cbfc6d..652a48c6ad78 100644 --- a/clang/test/Driver/compiler-rt-unwind.c +++ b/clang/test/Driver/compiler-rt-unwind.c @@ -13,7 +13,15 @@ // RUN: --gcc-toolchain="" \ // RUN: | FileCheck --check-prefix=RTLIB-GCC-UNWINDLIB-COMPILER-RT %s // RTLIB-GCC-UNWINDLIB-COMPILER-RT: "{{.*}}lgcc" -// RTLIB-GCC-UNWINDLIB-COMPILER-RT: "{{.*}}lunwind" +// RTLIB-GCC-UNWINDLIB-COMPILER-RT: "{{.*}}l:libunwind.so" +// +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +// RUN: --target=x86_64-unknown-linux -rtlib=libgcc --unwindlib=libunwind \ +// RUN: -static-libgcc \ +// RUN: --gcc-toolchain="" \ +// RUN: | FileCheck --check-prefix=RTLIB-GCC-STATIC-UNWINDLIB-COMPILER-RT %s +// RTLIB-GCC-STATIC-UNWINDLIB-COMPILER-RT: "{{.*}}lgcc" +// RTLIB-GCC-STATIC-UNWINDLIB-COMPILER-RT: "{{.*}}l:libunwind.a" // // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ // RUN: --target=x86_64-unknown-linux -rtlib=compiler-rt \ _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits