forked from OSchip/llvm-project
Add EXPERIMENTAL --rtlib=compiler-rt to GNU Clang
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). llvm-svn: 201307
This commit is contained in:
parent
f6cb35abb4
commit
c4b4924a13
|
@ -1737,6 +1737,24 @@ static StringRef getArchNameForCompilerRTLib(const ToolChain &TC) {
|
||||||
return TC.getArchName();
|
return TC.getArchName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This adds the static libclang_rt.arch.a directly to the command line
|
||||||
|
// FIXME: Make sure we can also emit shared objects if they're requested
|
||||||
|
// and available, check for possible errors, etc.
|
||||||
|
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));
|
||||||
|
CmdArgs.push_back("-lgcc_s");
|
||||||
|
if (TC.getDriver().CCCIsCXX())
|
||||||
|
CmdArgs.push_back("-lgcc_eh");
|
||||||
|
}
|
||||||
|
|
||||||
static void addProfileRTLinux(
|
static void addProfileRTLinux(
|
||||||
const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs) {
|
const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs) {
|
||||||
if (!(Args.hasArg(options::OPT_fprofile_arcs) ||
|
if (!(Args.hasArg(options::OPT_fprofile_arcs) ||
|
||||||
|
@ -6534,6 +6552,23 @@ static StringRef getLinuxDynamicLinker(const ArgList &Args,
|
||||||
return "/lib64/ld-linux-x86-64.so.2";
|
return "/lib64/ld-linux-x86-64.so.2";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void AddRunTimeLibs(const ToolChain &TC, const Driver &D,
|
||||||
|
ArgStringList &CmdArgs, const ArgList &Args) {
|
||||||
|
// Make use of compiler-rt if --rtlib option is used
|
||||||
|
ToolChain::RuntimeLibType RLT = TC.GetRuntimeLibType(Args);
|
||||||
|
|
||||||
|
switch(RLT) {
|
||||||
|
case ToolChain::RLT_CompilerRT:
|
||||||
|
addClangRTLinux(TC, Args, CmdArgs);
|
||||||
|
break;
|
||||||
|
case ToolChain::RLT_Libgcc:
|
||||||
|
AddLibgcc(TC.getTriple(), D, CmdArgs, Args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
llvm_unreachable("Unknown RT-Lib type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void gnutools::Link::ConstructJob(Compilation &C, const JobAction &JA,
|
void gnutools::Link::ConstructJob(Compilation &C, const JobAction &JA,
|
||||||
const InputInfo &Output,
|
const InputInfo &Output,
|
||||||
const InputInfoList &Inputs,
|
const InputInfoList &Inputs,
|
||||||
|
@ -6737,7 +6772,7 @@ void gnutools::Link::ConstructJob(Compilation &C, const JobAction &JA,
|
||||||
CmdArgs.push_back("-lrt");
|
CmdArgs.push_back("-lrt");
|
||||||
}
|
}
|
||||||
|
|
||||||
AddLibgcc(ToolChain.getTriple(), D, CmdArgs, Args);
|
AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
|
||||||
|
|
||||||
if (Args.hasArg(options::OPT_pthread) ||
|
if (Args.hasArg(options::OPT_pthread) ||
|
||||||
Args.hasArg(options::OPT_pthreads) || OpenMP)
|
Args.hasArg(options::OPT_pthreads) || OpenMP)
|
||||||
|
@ -6748,7 +6783,7 @@ void gnutools::Link::ConstructJob(Compilation &C, const JobAction &JA,
|
||||||
if (Args.hasArg(options::OPT_static))
|
if (Args.hasArg(options::OPT_static))
|
||||||
CmdArgs.push_back("--end-group");
|
CmdArgs.push_back("--end-group");
|
||||||
else
|
else
|
||||||
AddLibgcc(ToolChain.getTriple(), D, CmdArgs, Args);
|
AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Args.hasArg(options::OPT_nostartfiles)) {
|
if (!Args.hasArg(options::OPT_nostartfiles)) {
|
||||||
|
|
|
@ -35,6 +35,46 @@
|
||||||
//
|
//
|
||||||
// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
|
// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
|
||||||
// RUN: --target=x86_64-unknown-linux \
|
// RUN: --target=x86_64-unknown-linux \
|
||||||
|
// RUN: --sysroot=%S/Inputs/basic_linux_tree \
|
||||||
|
// RUN: --rtlib=compiler-rt \
|
||||||
|
// RUN: | FileCheck --check-prefix=CHECK-LD-RT %s
|
||||||
|
// CHECK-LD-RT-NOT: warning:
|
||||||
|
// CHECK-LD-RT: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
|
||||||
|
// CHECK-LD-RT: "--eh-frame-hdr"
|
||||||
|
// CHECK-LD-RT: "-m" "elf_x86_64"
|
||||||
|
// CHECK-LD-RT: "-dynamic-linker"
|
||||||
|
// CHECK-LD-RT: "{{.*}}/usr/lib/gcc/x86_64-unknown-linux/4.6.0{{/|\\\\}}crtbegin.o"
|
||||||
|
// CHECK-LD-RT: "-L[[SYSROOT]]/usr/lib/gcc/x86_64-unknown-linux/4.6.0"
|
||||||
|
// CHECK-LD-RT: "-L[[SYSROOT]]/usr/lib/gcc/x86_64-unknown-linux/4.6.0/../../../../x86_64-unknown-linux/lib"
|
||||||
|
// CHECK-LD-RT: "-L[[SYSROOT]]/usr/lib/gcc/x86_64-unknown-linux/4.6.0/../../.."
|
||||||
|
// CHECK-LD-RT: "-L[[SYSROOT]]/lib"
|
||||||
|
// CHECK-LD-RT: "-L[[SYSROOT]]/usr/lib"
|
||||||
|
// CHECK-LD-RT: libclang_rt.x86_64.a" "-lgcc_s"
|
||||||
|
// CHECK-LD-RT: "-lc"
|
||||||
|
// CHECK-LD-RT: libclang_rt.x86_64.a" "-lgcc_s"
|
||||||
|
//
|
||||||
|
// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
|
||||||
|
// RUN: --target=x86_64-unknown-linux \
|
||||||
|
// RUN: --sysroot=%S/Inputs/basic_linux_tree \
|
||||||
|
// RUN: --rtlib=libgcc \
|
||||||
|
// RUN: | FileCheck --check-prefix=CHECK-LD-GCC %s
|
||||||
|
// CHECK-LD-GCC-NOT: warning:
|
||||||
|
// CHECK-LD-GCC: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
|
||||||
|
// CHECK-LD-GCC: "--eh-frame-hdr"
|
||||||
|
// CHECK-LD-GCC: "-m" "elf_x86_64"
|
||||||
|
// CHECK-LD-GCC: "-dynamic-linker"
|
||||||
|
// CHECK-LD-GCC: "{{.*}}/usr/lib/gcc/x86_64-unknown-linux/4.6.0{{/|\\\\}}crtbegin.o"
|
||||||
|
// CHECK-LD-GCC: "-L[[SYSROOT]]/usr/lib/gcc/x86_64-unknown-linux/4.6.0"
|
||||||
|
// CHECK-LD-GCC: "-L[[SYSROOT]]/usr/lib/gcc/x86_64-unknown-linux/4.6.0/../../../../x86_64-unknown-linux/lib"
|
||||||
|
// CHECK-LD-GCC: "-L[[SYSROOT]]/usr/lib/gcc/x86_64-unknown-linux/4.6.0/../../.."
|
||||||
|
// CHECK-LD-GCC: "-L[[SYSROOT]]/lib"
|
||||||
|
// CHECK-LD-GCC: "-L[[SYSROOT]]/usr/lib"
|
||||||
|
// CHECK-LD-GCC "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed"
|
||||||
|
// CHECK-LD-GCC: "-lc"
|
||||||
|
// CHECK-LD-GCC: "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed"
|
||||||
|
//
|
||||||
|
// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
|
||||||
|
// RUN: --target=x86_64-unknown-linux \
|
||||||
// RUN: -static-libgcc \
|
// RUN: -static-libgcc \
|
||||||
// RUN: --sysroot=%S/Inputs/basic_linux_tree \
|
// RUN: --sysroot=%S/Inputs/basic_linux_tree \
|
||||||
// RUN: | FileCheck --check-prefix=CHECK-LD-64-STATIC-LIBGCC %s
|
// RUN: | FileCheck --check-prefix=CHECK-LD-64-STATIC-LIBGCC %s
|
||||||
|
|
Loading…
Reference in New Issue