r244407 - Teach mingw toolchain driver to properly emit static or dynamic linking of ligcc.
Yaron Keren via cfe-commits
cfe-commits at lists.llvm.org
Sat Aug 8 17:24:08 PDT 2015
Author: yrnkrn
Date: Sat Aug 8 19:24:07 2015
New Revision: 244407
URL: http://llvm.org/viewvc/llvm-project?rev=244407&view=rev
Log:
Teach mingw toolchain driver to properly emit static or dynamic linking of ligcc.
Implemented in MinGW::Linker::AddLibGCC since AddLibgcc is a logic puzzle even
before adding one more boolean. A first step towards simplification of AddLibgcc
would be to factor out the Android AddLibgcc code into its own routine.
Added:
cfe/trunk/test/Driver/mingw-libgcc.c
Modified:
cfe/trunk/lib/Driver/Tools.cpp
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=244407&r1=244406&r2=244407&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Sat Aug 8 19:24:07 2015
@@ -9083,8 +9083,24 @@ void MinGW::Linker::AddLibGCC(const ArgL
CmdArgs.push_back("-lmingwthrd");
CmdArgs.push_back("-lmingw32");
- // Add libgcc or compiler-rt.
- AddRunTimeLibs(getToolChain(), getToolChain().getDriver(), CmdArgs, Args);
+ // Make use of compiler-rt if --rtlib option is used
+ ToolChain::RuntimeLibType RLT = getToolChain().GetRuntimeLibType(Args);
+ if (RLT == ToolChain::RLT_Libgcc) {
+ bool Static = Args.hasArg(options::OPT_static_libgcc) ||
+ Args.hasArg(options::OPT_static);
+ bool Shared = Args.hasArg(options::OPT_shared);
+ bool CXX = getToolChain().getDriver().CCCIsCXX();
+
+ if (Static || (!CXX && !Shared)) {
+ CmdArgs.push_back("-lgcc");
+ CmdArgs.push_back("-lgcc_eh");
+ } else {
+ CmdArgs.push_back("-lgcc_s");
+ CmdArgs.push_back("-lgcc");
+ }
+ } else {
+ AddRunTimeLibs(getToolChain(), getToolChain().getDriver(), CmdArgs, Args);
+ }
CmdArgs.push_back("-lmoldname");
CmdArgs.push_back("-lmingwex");
Added: cfe/trunk/test/Driver/mingw-libgcc.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/mingw-libgcc.c?rev=244407&view=auto
==============================================================================
--- cfe/trunk/test/Driver/mingw-libgcc.c (added)
+++ cfe/trunk/test/Driver/mingw-libgcc.c Sat Aug 8 19:24:07 2015
@@ -0,0 +1,25 @@
+// Test if mingw toolchain driver emits static linking (-lgcc -lgcc_eh) or dynamic linking (-lgcc_s -lgcc).
+// Verified with gcc version 5.1.0 (i686-posix-dwarf-rev0, Built by MinGW-W64 project).
+
+// gcc, static
+// RUN: %clang -v -target i686-pc-windows-gnu -### %s 2>&1 | FileCheck -check-prefix=CHECK_STATIC %s
+// RUN: %clang -static -v -target i686-pc-windows-gnu -### %s 2>&1 | FileCheck -check-prefix=CHECK_STATIC %s
+// RUN: %clang -static-libgcc -v -target i686-pc-windows-gnu -### %s 2>&1 | FileCheck -check-prefix=CHECK_STATIC %s
+// RUN: %clang -static -shared -v -target i686-pc-windows-gnu -### %s 2>&1 | FileCheck -check-prefix=CHECK_STATIC %s
+// RUN: %clang -static-libgcc -shared -v -target i686-pc-windows-gnu -### %s 2>&1 | FileCheck -check-prefix=CHECK_STATIC %s
+
+// gcc, dynamic
+// RUN: %clang -shared -v -target i686-pc-windows-gnu -### %s 2>&1 | FileCheck -check-prefix=CHECK_DYNAMIC %s
+
+// g++, static
+// RUN: %clang -static --driver-mode=g++ -v -target i686-pc-windows-gnu -### %s 2>&1 | FileCheck -check-prefix=CHECK_STATIC %s
+// RUN: %clang -static-libgcc --driver-mode=g++ -v -target i686-pc-windows-gnu -### %s 2>&1 | FileCheck -check-prefix=CHECK_STATIC %s
+// RUN: %clang -static -shared --driver-mode=g++ -v -target i686-pc-windows-gnu -### %s 2>&1 | FileCheck -check-prefix=CHECK_STATIC %s
+// RUN: %clang -static-libgcc -shared --driver-mode=g++ -v -target i686-pc-windows-gnu -### %s 2>&1 | FileCheck -check-prefix=CHECK_STATIC %s
+
+// g++, dynamic
+// RUN: %clang --driver-mode=g++ -v -target i686-pc-windows-gnu -### %s 2>&1 | FileCheck -check-prefix=CHECK_DYNAMIC %s
+// RUN: %clang -shared --driver-mode=g++ -v -target i686-pc-windows-gnu -### %s 2>&1 | FileCheck -check-prefix=CHECK_DYNAMIC %s
+
+// CHECK_STATIC: "-lgcc" "-lgcc_eh"
+// CHECK_DYNAMIC: "-lgcc_s" "-lgcc"
More information about the cfe-commits
mailing list