jkz created this revision. jkz added reviewers: saugustine, sivachandra. Herald added a project: clang.
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. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D70416 Files: clang/lib/Driver/ToolChains/CommonArgs.cpp clang/test/Driver/compiler-rt-unwind.c Index: clang/test/Driver/compiler-rt-unwind.c =================================================================== --- clang/test/Driver/compiler-rt-unwind.c +++ 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 \ Index: clang/lib/Driver/ToolChains/CommonArgs.cpp =================================================================== --- clang/lib/Driver/ToolChains/CommonArgs.cpp +++ clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -1209,7 +1209,10 @@ 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; }
Index: clang/test/Driver/compiler-rt-unwind.c =================================================================== --- clang/test/Driver/compiler-rt-unwind.c +++ 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 \ Index: clang/lib/Driver/ToolChains/CommonArgs.cpp =================================================================== --- clang/lib/Driver/ToolChains/CommonArgs.cpp +++ clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -1209,7 +1209,10 @@ 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; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits