Author: mgorny
Date: Mon Oct 10 07:23:40 2016
New Revision: 283746

URL: http://llvm.org/viewvc/llvm-project?rev=283746&view=rev
Log:
[Driver] Make -print-libgcc-file-name print compiler-rt lib when used

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

Added:
    cfe/trunk/test/Driver/print-libgcc-file-name-clangrt.c
    cfe/trunk/test/Driver/print-libgcc-file-name-libgcc.c
Modified:
    cfe/trunk/docs/CommandGuide/clang.rst
    cfe/trunk/include/clang/Driver/Options.td
    cfe/trunk/lib/Driver/Driver.cpp
    cfe/trunk/test/Driver/montavista-gcc-toolchain.c
    cfe/trunk/test/lit.cfg

Modified: cfe/trunk/docs/CommandGuide/clang.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/CommandGuide/clang.rst?rev=283746&r1=283745&r2=283746&view=diff
==============================================================================
--- cfe/trunk/docs/CommandGuide/clang.rst (original)
+++ cfe/trunk/docs/CommandGuide/clang.rst Mon Oct 10 07:23:40 2016
@@ -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>
 

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=283746&r1=283745&r2=283746&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Mon Oct 10 07:23:40 2016
@@ -1861,7 +1861,8 @@ def print_file_name_EQ : Joined<["-", "-
 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">,

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=283746&r1=283745&r2=283746&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Mon Oct 10 07:23:40 2016
@@ -994,7 +994,15 @@ bool Driver::HandleImmediateArgs(const 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.getCompilerRT(C.getArgs(), "builtins") << "\n";
+      break;
+    case ToolChain::RLT_Libgcc:
+      llvm::outs() << GetFilePath("libgcc.a", TC) << "\n";
+      break;
+    }
     return false;
   }
 

Modified: cfe/trunk/test/Driver/montavista-gcc-toolchain.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/montavista-gcc-toolchain.c?rev=283746&r1=283745&r2=283746&view=diff
==============================================================================
--- cfe/trunk/test/Driver/montavista-gcc-toolchain.c (original)
+++ cfe/trunk/test/Driver/montavista-gcc-toolchain.c Mon Oct 10 07:23:40 2016
@@ -1,6 +1,6 @@
 // Test that the montavista gcc-toolchain is correctly detected
 //
-// RUN: %clang -print-libgcc-file-name 2>&1 \
+// RUN: %clang -rtlib=platform -print-libgcc-file-name 2>&1 \
 // RUN:     --target=i686-montavista-linux \
 // RUN:     --gcc-toolchain=%S/Inputs/montavista_i686_tree/usr \
 // RUN:   | FileCheck %s

Added: cfe/trunk/test/Driver/print-libgcc-file-name-clangrt.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/print-libgcc-file-name-clangrt.c?rev=283746&view=auto
==============================================================================
--- cfe/trunk/test/Driver/print-libgcc-file-name-clangrt.c (added)
+++ cfe/trunk/test/Driver/print-libgcc-file-name-clangrt.c Mon Oct 10 07:23:40 
2016
@@ -0,0 +1,11 @@
+// Test that -print-libgcc-file-name correctly respects -rtlib=compiler-rt.
+
+// 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

Added: cfe/trunk/test/Driver/print-libgcc-file-name-libgcc.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/print-libgcc-file-name-libgcc.c?rev=283746&view=auto
==============================================================================
--- cfe/trunk/test/Driver/print-libgcc-file-name-libgcc.c (added)
+++ cfe/trunk/test/Driver/print-libgcc-file-name-libgcc.c Mon Oct 10 07:23:40 
2016
@@ -0,0 +1,7 @@
+// Test that -print-libgcc-file-name correctly respects -rtlib=libgcc.
+
+// REQUIRES: libgcc
+
+// RUN: %clang -rtlib=libgcc -print-libgcc-file-name 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LIBGCC %s
+// CHECK-LIBGCC: libgcc.a

Modified: cfe/trunk/test/lit.cfg
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/lit.cfg?rev=283746&r1=283745&r2=283746&view=diff
==============================================================================
--- cfe/trunk/test/lit.cfg (original)
+++ cfe/trunk/test/lit.cfg Mon Oct 10 07:23:40 2016
@@ -375,6 +375,11 @@ if platform.system() not in ['Windows']:
 if platform.system() not in ['Windows']:
     config.available_features.add('utf8-capable-terminal')
 
+# Support for libgcc runtime. Used to rule out tests that require
+# clang to run with -rtlib=libgcc.
+if platform.system() not in ['Darwin', 'Fuchsia']:
+    config.available_features.add('libgcc')
+
 # Native compilation: Check if triples match.
 # FIXME: Consider cases that target can be executed
 # even if host_triple were different from target_triple.


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to