mgorny created this revision. mgorny added a reviewer: ddunbar. mgorny added a subscriber: cfe-commits. Herald added a subscriber: dberris.
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. https://reviews.llvm.org/D25338 Files: docs/CommandGuide/clang.rst include/clang/Driver/Options.td lib/Driver/Driver.cpp Index: lib/Driver/Driver.cpp =================================================================== --- lib/Driver/Driver.cpp +++ lib/Driver/Driver.cpp @@ -994,7 +994,15 @@ } 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; } Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -1861,7 +1861,8 @@ 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\" appropriately)">; 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: docs/CommandGuide/clang.rst =================================================================== --- docs/CommandGuide/clang.rst +++ docs/CommandGuide/clang.rst @@ -394,7 +394,8 @@ .. 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" appropriately). .. option:: -print-prog-name=<name>
Index: lib/Driver/Driver.cpp =================================================================== --- lib/Driver/Driver.cpp +++ lib/Driver/Driver.cpp @@ -994,7 +994,15 @@ } 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; } Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -1861,7 +1861,8 @@ 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\" appropriately)">; 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: docs/CommandGuide/clang.rst =================================================================== --- docs/CommandGuide/clang.rst +++ docs/CommandGuide/clang.rst @@ -394,7 +394,8 @@ .. 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" appropriately). .. option:: -print-prog-name=<name>
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits