Clang is nice
for a holiday but I wouldn't want to live
there
If you have GCC installed in a non-standard location or are
using a Linux distro Clang doesn't know about then the
following patch is needed to get a working compiler, where
/your/gcc/prefix is the location of your gcc
installation, and X.Y.Z is the output of
'/your/gcc/prefix/bin/gcc -dumpversion'
(This should all possible for configure to detect
from the output of 'gcc -print-libgcc-file-name' so
you don't need to hack the code, but Clang prefers to
hardcode the paths for various known distros ... I expect
better from the core clang devs, so I assume they only care
about supporting apple and the linux hacks have been added
by distro packagers, who only care about making their
specific packages work.)
Without this hack, clang can't figure out where to find
crtbegin.o and crtend.o and so it invokes
ld incorrectly, in the worst case this results in
/usr/bin/ld: crtbegin.o: No such file: No such file or directory
clang: error: linker command failed with exit code 1 (use -v
to see invocation)
I don't plan to improve on my hack, because it's
difficult to test the results on my Fedora box, where the
existing hardcoded hacks make clang appear to work correctly
(but actually it's
finding the system compiler not the one I want it to use.)
As a GCC maintainer I'm not going to uninstall my system gcc
just to help fix a competitor's hack ;-)
Determining header and library search paths properly would
probably speed up clang a little, as it wouldn't need to
check for dozens of nonexistent directories that might exist
if you were using a different distro and/or gcc release.
Not that clang needs any help running faster than gcc.
(mod_virgule will mangle this patch but maybe
it'll still be useful to someone)
Index: lib/Frontend/InitHeaderSearch.cpp
===================================================================
--- lib/Frontend/InitHeaderSearch.cpp (revision 121966)
+++ lib/Frontend/InitHeaderSearch.cpp (working copy)
@@ -612,6 +612,10 @@
AddPath("/usr/include/c++/4.1", System, true, false,
false);
break;
case llvm::Triple::Linux:
+
AddGnuCPlusPlusIncludePaths("/your/gcc/prefix/include/c++/X.Y.Z",
+ "x86_64-unknown-linux-gnu", "32", "", triple);
+
AddGnuCPlusPlusIncludePaths("/your/gcc/prefix/include/c++/X.Y.Z",
+ "x86_64-unknown-linux-gnu", "", "", triple);
//===------------------------------------------------------------------===//
// Debian based distros.
// Note: these distros symlink /usr/include/c++/X.Y.Z
-> X.Y
Index: lib/Driver/ToolChains.cpp
===================================================================
--- lib/Driver/ToolChains.cpp (revision 121966)
+++ lib/Driver/ToolChains.cpp (working copy)
@@ -1321,6 +1321,11 @@
if
(llvm::sys::Path("/usr/lib/gcc/arm-linux-gnueabi").exists())
GccTriple = "arm-linux-gnueabi";
} else if (Arch == llvm::Triple::x86_64) {
+
+ if
(llvm::sys::Path("/your/gcc/prefix/lib/gcc/x86_64-unknown-linux-gnu").exists())
+ GccTriple = "x86_64-unknown-linux-gnu";
+ else
+
if
(llvm::sys::Path("/usr/lib/gcc/x86_64-linux-gnu").exists())
GccTriple = "x86_64-linux-gnu";
else if
(llvm::sys::Path("/usr/lib/gcc/x86_64-unknown-linux-gnu").exists())
@@ -1349,7 +1354,7 @@
std::string Base = "";
for (unsigned i = 0; i <
sizeof(GccVersions)/sizeof(char*); ++i) {
std::string Suffix = GccTriple + "/" + GccVersions[i];
- std::string t1 = "/usr/lib/gcc/" + Suffix;
+ std::string t1 = "/your/gcc/prefix/lib/gcc/" + Suffix;
if (llvm::sys::Path(t1 + "/crtbegin.o").exists()) {
Base = t1;
break;