[PATCH] D98023: [clang] Don't make the g++ driver imply an explicitly shared libunwind

Martin Storsjö via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 5 02:12:49 PST 2021


mstorsjo created this revision.
mstorsjo added reviewers: mati865, rnk, saugustine, phosek.
mstorsjo requested review of this revision.
Herald added a project: clang.

The logic in getLibGccType, to have the g++ driver mode imply a shared libgcc, originally was to match GCC driver behaviour for libgcc.

For cases when using -rtlib=compiler-rt or -unwindlib=libunwind, there's no distinction between SharedLibGcc and UnspecifiedLibGcc for platforms other than MinGW.

For MinGW targets, we distinguish between an explicitly shared unwinder library (requested via -shared-libgcc), an explicitly static one (requested via -static-libgcc or -static) and the default case (which just passes -lunwind to the linker, which will pick either shared or static depending on what's available, with the normal linker logic).

This makes the implicit default case (as added in D79995 <https://reviews.llvm.org/D79995>) actually work as it was intended, when using the g++ driver (which is the main usecase for libunwind as far as I know).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98023

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
@@ -69,5 +69,9 @@
 // RUN:     --target=x86_64-w64-mingw32 -rtlib=compiler-rt --unwindlib=libunwind \
 // RUN:     --gcc-toolchain="" \
 // RUN:   | FileCheck --check-prefix=MINGW-RTLIB-COMPILER-RT-UNWINDLIB-COMPILER-RT %s
+// RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN:     --target=x86_64-w64-mingw32 -rtlib=compiler-rt --unwindlib=libunwind \
+// RUN:     --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=MINGW-RTLIB-COMPILER-RT-UNWINDLIB-COMPILER-RT %s
 // MINGW-RTLIB-COMPILER-RT-UNWINDLIB-COMPILER-RT: "{{.*}}libclang_rt.builtins-x86_64.a"
 // MINGW-RTLIB-COMPILER-RT-UNWINDLIB-COMPILER-RT: "{{.*}}lunwind"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===================================================================
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1382,7 +1382,8 @@
   // The Android NDK only provides libunwind.a, not libunwind.so.
   if (TC.getTriple().isAndroid())
     return LibGccType::StaticLibGcc;
-  if (D.CCCIsCXX())
+  ToolChain::RuntimeLibType RLT = TC.GetRuntimeLibType(Args);
+  if (D.CCCIsCXX() && RLT == ToolChain::RLT_Libgcc)
     return LibGccType::SharedLibGcc;
   return LibGccType::UnspecifiedLibGcc;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98023.328450.patch
Type: text/x-patch
Size: 1441 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210305/42328bf9/attachment.bin>


More information about the cfe-commits mailing list