]> granicus.if.org Git - clang/commitdiff
[Driver] Make -print-libgcc-file-name print compiler-rt lib when used
authorMichal Gorny <mgorny@gentoo.org>
Fri, 7 Oct 2016 17:08:06 +0000 (17:08 +0000)
committerMichal Gorny <mgorny@gentoo.org>
Fri, 7 Oct 2016 17:08:06 +0000 (17:08 +0000)
Make the -print-libgcc-file-name option print an appropriate compiler
runtime library, that is libgcc.a if gcc runtime is used
and an appropriate compiler-rt library if that runtime is used.

The main use for this is to allow linking executables built with
-nodefaultlibs (e.g. to avoid linking to the standard C++ library) to
the compiler runtime library, e.g. using:

  clang++ ... -nodefaultlibs $(clang++ ... -print-libgcc-file-name)

in which case currently a program built like this linked to the gcc
runtime unconditionally. The patch fixes it to use compiler-rt libraries
instead when compiler-rt is the active runtime.

Differential Revision: https://reviews.llvm.org/D25338

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@283572 91177308-0d34-0410-b5e6-96231b3b80d8

docs/CommandGuide/clang.rst
include/clang/Driver/Options.td
lib/Driver/Driver.cpp
test/Driver/print-libgcc-file-name.c [new file with mode: 0644]

index 14c81270e17d72aa55d2da93e6836d26781a9e84..c71544915e4295991ef38844a95274c657846846 100644 (file)
@@ -394,7 +394,8 @@ Driver Options
 
 .. option:: -print-libgcc-file-name
 
-  Print the library path for "libgcc.a".
+  Print the library path for the currently used compiler runtime library
+  ("libgcc.a" or "libclang_rt.builtins.*.a").
 
 .. option:: -print-prog-name=<name>
 
index a6b006108fc9863ff68c48f6d992376da7f766c3..ad10bcb2737d047f2c1dc9f49f7df69321d7d5e6 100644 (file)
@@ -1861,7 +1861,8 @@ def print_file_name_EQ : Joined<["-", "--"], "print-file-name=">,
 def print_ivar_layout : Flag<["-"], "print-ivar-layout">, Flags<[CC1Option]>,
   HelpText<"Enable Objective-C Ivar layout bitmap print trace">;
 def print_libgcc_file_name : Flag<["-", "--"], "print-libgcc-file-name">,
-  HelpText<"Print the library path for \"libgcc.a\"">;
+  HelpText<"Print the library path for the currently used compiler runtime "
+           "library (\"libgcc.a\" or \"libclang_rt.builtins.*.a\")">;
 def print_multi_directory : Flag<["-", "--"], "print-multi-directory">;
 def print_multi_lib : Flag<["-", "--"], "print-multi-lib">;
 def print_multi_os_directory : Flag<["-", "--"], "print-multi-os-directory">,
index f26d61f1d7d92fbf144e99625de13f425d821f7b..fd0bcfbeba5b9025a9b2234cf30b3b63f81668a4 100644 (file)
@@ -994,7 +994,15 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
   }
 
   if (C.getArgs().hasArg(options::OPT_print_libgcc_file_name)) {
-    llvm::outs() << GetFilePath("libgcc.a", TC) << "\n";
+    ToolChain::RuntimeLibType RLT = TC.GetRuntimeLibType(C.getArgs());
+    switch (RLT) {
+    case ToolChain::RLT_CompilerRT:
+      llvm::outs() << TC.getCompilerRTArgString(C.getArgs(), "builtins") << "\n";
+      break;
+    case ToolChain::RLT_Libgcc:
+      llvm::outs() << GetFilePath("libgcc.a", TC) << "\n";
+      break;
+    }
     return false;
   }
 
diff --git a/test/Driver/print-libgcc-file-name.c b/test/Driver/print-libgcc-file-name.c
new file mode 100644 (file)
index 0000000..46a0808
--- /dev/null
@@ -0,0 +1,15 @@
+// Test that -print-libgcc-file-name correctly respects -rtlib=.
+
+// RUN: %clang -rtlib=libgcc -print-libgcc-file-name 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LIBGCC %s
+// CHECK-LIBGCC: libgcc.a
+
+// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \
+// RUN:     --target=x86_64-pc-linux \
+// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-X8664 %s
+// CHECK-CLANGRT-X8664: libclang_rt.builtins-x86_64.a
+
+// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \
+// RUN:     --target=i686-pc-linux \
+// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-I686 %s
+// CHECK-CLANGRT-I686: libclang_rt.builtins-i686.a