[PATCH] Support cross-compiling for Arm on x86
Sriram Murali
sriram.murali at intel.com
Mon Oct 28 13:57:31 PDT 2013
Hi rafael, rafael.espindola,
Summary:
This patch enables cross-compiling for Arm devices on x86 linux machine.
It adds include and lib path to the environment looked up by Clang. On
Ubuntu (possibly Debian), this will be in /usr/arm-linux-gnueabi
http://llvm-reviews.chandlerc.com/D2040
Files:
lib/Driver/ToolChains.cpp
test/Driver/Inputs/ubuntu_13.04_multiarch_tree/usr/arm-linux-gnueabihf/include/c++/4.7.3/arm-linux-gnueabihf/.keep
test/Driver/Inputs/ubuntu_13.04_multiarch_tree/usr/arm-linux-gnueabihf/include/c++/4.7.3/backward/.keep
test/Driver/Inputs/ubuntu_13.04_multiarch_tree/usr/arm-linux-gnueabihf/lib/crt1.o
test/Driver/Inputs/ubuntu_13.04_multiarch_tree/usr/arm-linux-gnueabihf/lib/crti.o
test/Driver/Inputs/ubuntu_13.04_multiarch_tree/usr/arm-linux-gnueabihf/lib/crtn.o
test/Driver/Inputs/ubuntu_13.04_multiarch_tree/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7.3/crtbegin.o
test/Driver/Inputs/ubuntu_13.04_multiarch_tree/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7.3/crtend.o
test/Driver/Inputs/ubuntu_13.04_multiarch_tree/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7/crtend.o
test/Driver/linux-header-search.cpp
Index: lib/Driver/ToolChains.cpp
===================================================================
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -2691,6 +2691,21 @@
StringRef MultiLibSuffix = GCCInstallation.getMultiLibSuffix();
StringRef BiarchSuffix = GCCInstallation.getBiarchSuffix();
const GCCVersion &Version = GCCInstallation.getVersion();
+ const std::string GCCMultiArchDir =
+ LibDir.str() + "/../" + TripleStr.str() + "/include/c++/";
+
+ // On Ubuntu, find include files for cross-compiler for GCC Version of the
+ // form {Major.Minor.Patch} by probing the lib path.
+ StringRef ParentPath = llvm::sys::path::parent_path(InstallDir);
+ llvm::error_code EC;
+ for (llvm::sys::fs::directory_iterator LI(ParentPath.str(), EC), LE;
+ !EC && LI != LE; LI = LI.increment(EC)) {
+ StringRef VersionText = llvm::sys::path::filename(LI->path());
+ if (addLibStdCXXIncludePaths(GCCMultiArchDir + VersionText.str(),
+ TripleStr + MultiLibSuffix + BiarchSuffix,
+ DriverArgs, CC1Args))
+ break;
+ }
if (addLibStdCXXIncludePaths(
LibDir.str() + "/../include", "/c++/" + Version.Text, TripleStr,
@@ -2704,7 +2719,9 @@
Version.MinorStr,
InstallDir.str() + "/include/g++-v" + Version.MajorStr,
// Android standalone toolchain has C++ headers in yet another place.
- LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text,
+ // FIXME: Retain this line only if toolchains has the form Major.Minor
+ // instead of Major.Minor.Patch
+ GCCMultiArchDir + Version.Text,
// Freescale SDK C++ headers are directly in <sysroot>/usr/include/c++,
// without a subdirectory corresponding to the gcc version.
LibDir.str() + "/../include/c++",
@@ -2716,6 +2733,7 @@
TripleStr + MultiLibSuffix + BiarchSuffix, DriverArgs, CC1Args))
break;
}
+
}
bool Linux::isPIEDefault() const {
Index: test/Driver/Inputs/ubuntu_13.04_multiarch_tree/usr/arm-linux-gnueabihf/lib/crt1.o
===================================================================
--- /dev/null
+++ test/Driver/Inputs/ubuntu_13.04_multiarch_tree/usr/arm-linux-gnueabihf/lib/crt1.o
@@ -0,0 +1 @@
+empty
Index: test/Driver/Inputs/ubuntu_13.04_multiarch_tree/usr/arm-linux-gnueabihf/lib/crti.o
===================================================================
--- /dev/null
+++ test/Driver/Inputs/ubuntu_13.04_multiarch_tree/usr/arm-linux-gnueabihf/lib/crti.o
@@ -0,0 +1 @@
+empty
Index: test/Driver/Inputs/ubuntu_13.04_multiarch_tree/usr/arm-linux-gnueabihf/lib/crtn.o
===================================================================
--- /dev/null
+++ test/Driver/Inputs/ubuntu_13.04_multiarch_tree/usr/arm-linux-gnueabihf/lib/crtn.o
@@ -0,0 +1 @@
+empty
Index: test/Driver/Inputs/ubuntu_13.04_multiarch_tree/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7.3/crtbegin.o
===================================================================
--- /dev/null
+++ test/Driver/Inputs/ubuntu_13.04_multiarch_tree/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7.3/crtbegin.o
@@ -0,0 +1 @@
+empty
Index: test/Driver/Inputs/ubuntu_13.04_multiarch_tree/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7.3/crtend.o
===================================================================
--- /dev/null
+++ test/Driver/Inputs/ubuntu_13.04_multiarch_tree/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7.3/crtend.o
@@ -0,0 +1 @@
+empty
Index: test/Driver/Inputs/ubuntu_13.04_multiarch_tree/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7/crtend.o
===================================================================
--- /dev/null
+++ test/Driver/Inputs/ubuntu_13.04_multiarch_tree/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7/crtend.o
@@ -0,0 +1 @@
+empty
Index: test/Driver/linux-header-search.cpp
===================================================================
--- test/Driver/linux-header-search.cpp
+++ test/Driver/linux-header-search.cpp
@@ -37,6 +37,9 @@
// RUN: | FileCheck --check-prefix=CHECK-UBUNTU-13-04-CROSS %s
// CHECK-UBUNTU-13-04-CROSS: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
// CHECK-UBUNTU-13-04-CROSS: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-UBUNTU-13-04-CROSS: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7/../../../../arm-linux-gnueabihf/include/c++/4.7.3"
+// CHECK-UBUNTU-13-04-CROSS: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7/../../../../arm-linux-gnueabihf/include/c++/4.7.3/arm-linux-gnueabihf"
+// CHECK-UBUNTU-13-04-CROSS: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7/../../../../arm-linux-gnueabihf/include/c++/4.7.3/backward"
// CHECK-UBUNTU-13-04-CROSS: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7/../../../../include/c++/4.7"
// CHECK-UBUNTU-13-04-CROSS: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7/../../../../include/c++/4.7/backward"
// CHECK-UBUNTU-13-04-CROSS: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7/../../../../include/arm-linux-gnueabihf/c++/4.7"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2040.1.patch
Type: text/x-patch
Size: 5094 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131028/42ea17aa/attachment.bin>
More information about the cfe-commits
mailing list