Make Bitrig's clang understand -stdlib= correctly.

With this patch Bitrig can use a different c++ library without pain and
within the normal commandline parameters.

Original patch by David Hill, with lots of fixes and cleanup by me.

llvm-svn: 165430
This commit is contained in:
Chandler Carruth 2012-10-08 21:31:38 +00:00
parent 99b0092a40
commit c0f5cd1928
2 changed files with 46 additions and 8 deletions

View File

@ -1664,19 +1664,43 @@ void Bitrig::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
DriverArgs.hasArg(options::OPT_nostdincxx))
return;
std::string Triple = getTriple().str();
if (Triple.substr(0, 5) == "amd64")
Triple.replace(0, 5, "x86_64");
addSystemInclude(DriverArgs, CC1Args, "/usr/include/c++/4.6.2");
addSystemInclude(DriverArgs, CC1Args, "/usr/include/c++/4.6.2/backward");
addSystemInclude(DriverArgs, CC1Args, "/usr/include/c++/4.6.2/" + Triple);
switch (GetCXXStdlibType(DriverArgs)) {
case ToolChain::CST_Libcxx:
addSystemInclude(DriverArgs, CC1Args,
getDriver().SysRoot + "/usr/include/c++/");
break;
case ToolChain::CST_Libstdcxx:
addSystemInclude(DriverArgs, CC1Args,
getDriver().SysRoot + "/usr/include/c++/stdc++");
addSystemInclude(DriverArgs, CC1Args,
getDriver().SysRoot + "/usr/include/c++/stdc++/backward");
StringRef Triple = getTriple().str();
if (Triple.startswith("amd64"))
addSystemInclude(DriverArgs, CC1Args,
getDriver().SysRoot + "/usr/include/c++/stdc++/x86_64" +
Triple.substr(5));
else
addSystemInclude(DriverArgs, CC1Args,
getDriver().SysRoot + "/usr/include/c++/stdc++/" +
Triple);
break;
}
}
void Bitrig::AddCXXStdlibLibArgs(const ArgList &Args,
ArgStringList &CmdArgs) const {
CmdArgs.push_back("-lstdc++");
switch (GetCXXStdlibType(Args)) {
case ToolChain::CST_Libcxx:
CmdArgs.push_back("-lc++");
CmdArgs.push_back("-lcxxrt");
// Include supc++ to provide Unwind until provided by libcxx.
CmdArgs.push_back("-lgcc");
break;
case ToolChain::CST_Libstdcxx:
CmdArgs.push_back("-lstdc++");
break;
}
}
/// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly.

View File

@ -0,0 +1,14 @@
// RUN: %clang -no-canonical-prefixes -ccc-clang-archs "" -target amd64-pc-bitrig %s -### 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-LD-C %s
// CHECK-LD-C: clang{{.*}}" "-cc1" "-triple" "amd64-pc-bitrig"
// CHECK-LD-C: ld{{.*}}" {{.*}} "-lc" "-lclang_rt.amd64"
// RUN: %clangxx -no-canonical-prefixes -ccc-clang-archs "" -target amd64-pc-bitrig %s -### 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-LD-CXX %s
// CHECK-LD-CXX: clang{{.*}}" "-cc1" "-triple" "amd64-pc-bitrig"
// CHECK-LD-CXX: ld{{.*}}" {{.*}} "-lstdc++" "-lm" "-lc" "-lclang_rt.amd64"
// RUN: %clangxx -stdlib=libc++ -no-canonical-prefixes -ccc-clang-archs "" -target amd64-pc-bitrig %s -### 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-LD-CXX-STDLIB %s
// CHECK-LD-CXX-STDLIB: clang{{.*}}" "-cc1" "-triple" "amd64-pc-bitrig"
// CHECK-LD-CXX-STDLIB: ld{{.*}}" {{.*}} "-lc++" "-lcxxrt" "-lgcc" "-lm" "-lc" "-lclang_rt.amd64"