From a1073c0e07c6ce4544d1d7697986e1ae937ead31 Mon Sep 17 00:00:00 2001
From: Shiz <hi@shiz.me>
Date: Wed, 27 May 2015 00:39:16 +0000
Subject: [PATCH 4/4] Add -print-compiler-rt-file-name.

In analogy to -print-libgcc-file-name, this allows a caller to retrieve the
full file name to the clang_rt part that contains the builtins. This is
particularly useful in -nostdlib situations where the caller still wants to
use compiler-rt.
---
 include/clang/Driver/Options.td | 2 ++
 lib/Driver/Driver.cpp           | 6 ++++++
 2 files changed, 8 insertions(+)

diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td
index dec917b..d44588f 100644
--- a/include/clang/Driver/Options.td
+++ b/include/clang/Driver/Options.td
@@ -1500,6 +1500,8 @@ def pipe : Flag<["-", "--"], "pipe">,
 def prebind__all__twolevel__modules : Flag<["-"], "prebind_all_twolevel_modules">;
 def prebind : Flag<["-"], "prebind">;
 def preload : Flag<["-"], "preload">;
+def print_compiler_rt_file_name : Flag<["-", "--"], "print-compiler-rt-file-name">,
+  HelpText<"Print the library path for \"libclang_rt.builtins.*.a\"">;
 def print_file_name_EQ : Joined<["-", "--"], "print-file-name=">,
   HelpText<"Print the full library path of <file>">, MetaVarName<"<file>">;
 def print_ivar_layout : Flag<["-"], "print-ivar-layout">, Flags<[CC1Option]>,
diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp
index d33f486..1aba60b 100644
--- a/lib/Driver/Driver.cpp
+++ b/lib/Driver/Driver.cpp
@@ -778,6 +778,12 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
     return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_compiler_rt_file_name)) {
+    llvm::outs() << TC.GetRuntimeLibPath(ToolChain::RLT_CompilerRT, "builtins")
+                 << "\n";
+    return false;
+  }
+
   if (C.getArgs().hasArg(options::OPT_print_libgcc_file_name)) {
     llvm::outs() << TC.GetRuntimeLibPath(ToolChain::RLT_Libgcc, "") << "\n";
     return false;
-- 
2.3.6