FW: [PATCH] Support cross-compiling for Arm on a x86 Linux machine

Murali, Sriram sriram.murali at intel.com
Thu Oct 3 14:14:04 PDT 2013

Hi there,
I am attempting to cross-compile for Arm devices on a x86 machine. Looks like clang is picking up library paths in the wrong order, that it chose a different library file in /usr/lib32 directory, since I am compiling for arm. So, I worked around it by choosing the libpath of GNU cross compiler for arm instead. 

Further, there was a problem including the right header files from bits/ directory. So, I made sure clang picked it up from the GNU cross compiler include directory. However, clang did not have support to pick up include files from GCC version with no Patch, for example "4.8.0", where GCC version is of the format "Major.Minor.Patch". It looks at 4.8 instead. But, gnu cross compiler is packed such that the include files are in a directory with name 4.8.0. So, if the Version.Patch is -1 (which is unset for versions with no Patch) , we should pick the directory with Patch = 0.

Please review the patch, and see if it can be improved.


-----Original Message-----
From: Sriram Murali [mailto:sriram.murali at intel.com] 
Sent: Thursday, October 03, 2013 5:06 PM
To: Murali, Sriram; t.p.northover at gmail.com
Cc: amara.emerson at arm.com
Subject: [PATCH] Support cross-compiling for Arm on a x86 Linux machine

Hi msriram,

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. Clang chose a different path instead.

Tested on Ubuntu



Index: lib/Driver/ToolChains.cpp
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -2320,6 +2320,9 @@
+    // Add correct path for library crt1.o used for cross-compiling arm on
+    // Debian (Ubuntu)
+    addPathIfExists(LibPath + "/../" + GCCTriple.str() + "/lib/", 
+ Paths);
     // If the GCC installation we found is inside of the sysroot, we want to
     // prefer libraries installed in the parent prefix of the GCC installation.
     // It is important to *not* use these paths when the GCC installation is @@ -2590,6 +2593,23 @@
   StringRef BiarchSuffix = GCCInstallation.getBiarchSuffix();
   const GCCVersion &Version = GCCInstallation.getVersion();
+  // Find include files for cross-compiler in GCC Version 
+ {Major.Minor.0},  // instead of just {Major.Minor} for versions with 
+ no patch, i.e Patch = -1  if (Version.Patch == -1) {
+    if (addLibStdCXXIncludePaths(LibDir.str() + "/../" + TripleStr + "/include",
+                                 "/c++/" + Version.Text + ".0", TripleStr,
+                                 MultiLibSuffix + BiarchSuffix, DriverArgs,
+                                 CC1Args)
+        )
+      return;
+  } else {
+    if (addLibStdCXXIncludePaths(LibDir.str() + "/../" + TripleStr + "/include",
+                                 "/c++/" + Version.Text, TripleStr,
+                                 MultiLibSuffix + BiarchSuffix, DriverArgs,
+                                 CC1Args))
+      return;
+  }
   if (addLibStdCXXIncludePaths(
           LibDir.str() + "/../include", "/c++/" + Version.Text, TripleStr,
           MultiLibSuffix + BiarchSuffix, DriverArgs, CC1Args))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1823.1.patch
Type: text/x-patch
Size: 1801 bytes
Desc: D1823.1.patch
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131003/743c0629/attachment.bin>

More information about the cfe-commits mailing list