[PATCH] Add EXPERIMENTAL --rtlib=compiler-rt to GNU Clang
Renato Golin
renato.golin at linaro.org
Tue Feb 11 08:23:35 PST 2014
Hi eugenis, samsonov, ddunbar,
This commit is not strictly correct nor accounts for all uses (shared
objects, for example), but it allows one to test the compiler-rt library
on GNU targets.
Using this patch to run the test-suite has already shown me problems
on ARM. Since this is a Darwin-only flag, nobody is using it, so it
shouldn't be a problem.
I will need extension to deal with the shared cases, but since we're
not compiling libclang_rt.so, that's not yet applicable. Many other
problems will have to be fixed first in compiler-rt (such as removing
the 'arch' name from it and making it trully multi-arch, moving it to
the default lib directory, make both .a and .so variants, etc).
http://llvm-reviews.chandlerc.com/D2740
Files:
lib/Driver/Tools.cpp
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -1738,6 +1738,18 @@
return TC.getArchName();
}
+static void addClangRTLinux(
+ const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs) {
+ // The runtime is located in the Linux library directory and has name
+ // "libclang_rt.<ArchName>.a".
+ SmallString<128> LibProfile(TC.getDriver().ResourceDir);
+ llvm::sys::path::append(
+ LibProfile, "lib", "linux",
+ Twine("libclang_rt.") + getArchNameForCompilerRTLib(TC) + ".a");
+
+ CmdArgs.push_back(Args.MakeArgString(LibProfile));
+}
+
static void addProfileRTLinux(
const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs) {
if (!(Args.hasArg(options::OPT_fprofile_arcs) ||
@@ -6690,7 +6702,19 @@
CmdArgs.push_back("-lrt");
}
- AddLibgcc(ToolChain.getTriple(), D, CmdArgs, Args);
+ // Make use of compiler-rt if --rtlib option is used
+ ToolChain::RuntimeLibType RLT = ToolChain.GetRuntimeLibType(Args);
+
+ switch(RLT) {
+ case ToolChain::RLT_CompilerRT:
+ addClangRTLinux(ToolChain, Args, CmdArgs);
+ break;
+ case ToolChain::RLT_Libgcc:
+ AddLibgcc(ToolChain.getTriple(), D, CmdArgs, Args);
+ break;
+ default:
+ llvm_unreachable("Unknown RT-Lib type");
+ }
if (Args.hasArg(options::OPT_pthread) ||
Args.hasArg(options::OPT_pthreads) || OpenMP)
@@ -6700,8 +6724,12 @@
if (Args.hasArg(options::OPT_static))
CmdArgs.push_back("--end-group");
- else
+ else if (RLT == ToolChain::RLT_Libgcc)
AddLibgcc(ToolChain.getTriple(), D, CmdArgs, Args);
+ else if (RLT == ToolChain::RLT_CompilerRT)
+ addClangRTLinux(ToolChain, Args, CmdArgs);
+ else
+ llvm_unreachable("Unknown RT-Lib type");
}
if (!Args.hasArg(options::OPT_nostartfiles)) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2740.1.patch
Type: text/x-patch
Size: 1971 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140211/afaf1bc0/attachment.bin>
More information about the cfe-commits
mailing list