This is an archive of the discontinued LLVM Phabricator instance.

Support cross-compiling for Arm on x86
Needs ReviewPublic

Authored by msriram on Oct 28 2013, 1:57 PM.
This revision needs review, but all specified reviewers are disabled or inactive.

Details

Summary
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

Diff Detail

Event Timeline

I'll leave the review for others that know Clang better, but the summary is misleading. Cross-compiling to ARM is already possible, including on x86 Ubuntu machines. This patch probably only makes it easier, so the commit message should emphasise that.

Good catch Renato. I didn't update the summary. I stuck to the original one from the old patch.. Here is the updated one

Summary:
This patch extends cross-compiling facility for Arm devices on x86 linux machine particularly for .cpp source files. It adds appropriate include paths containing headers for cross-compilation. On Ubuntu (possibly Debian), this will be in /usr/arm-linux-gnueabi

Sorry, the patch adding support for linking got reverted and
reimplemented. Could you rebase this patch on top of current trunk?

msriram updated this revision to Unknown Object (????).Oct 30 2013, 7:14 AM

Rebased with master

Hi Sriram,

Chandler should probably be the one to review this. Can you add him as
a reviewer?

Hi Rafael,
I added Chandler as reviewer, as per your suggestion.

chandlerc added inline comments.Oct 30 2013, 10:29 AM
lib/Driver/ToolChains.cpp
2704–2711

This looks completely wrong. It is adding the first version of the headers that happens to be found by walking the directory. This isn't even going to be the newest, it could be literally *any* version.

What problem are you actually trying to solve? Is it that the GCC installation is under a Major.Minor directory, and the headers are under a Major.Minor.Patch directory? Why on earth would that happen? It doesn't make any sense to me and so doesn't seem like something we should really support. I expect the GCC installation to have the same version number spelling as the libstdc++ installation, which seems like a sane place to be. Anything else and we're running the risk of version skew.

What problem are you actually trying to solve? Is it that the GCC installation is under a Major.Minor directory, and the headers are under a Major.Minor.Patch directory? Why on earth would that happen? It doesn't make any sense to me and so doesn't seem like something we should really support. I expect the GCC installation to have the same version number spelling as the libstdc++ installation, which seems like a sane place to be. Anything else and we're running the risk of version skew.

Commenting only on the problem, not the patch:

Something like that yes. On a vanilla 13.10 installation + arm cross
compiler we have /usr/lib/gcc-cross/arm-linux-gnueabihf/4.8 being a
symbolic link to 4.8.1, but in /usr/arm-linux-gnueabihf/include/c++/
there is only a 4.8.1.

The net result is that arm-linux-gnueabihf-g++-4.8 searches headers in

/usr/arm-linux-gnueabihf/include/c++/4.8.1
/usr/arm-linux-gnueabihf/include/c++/4.8.1/arm-linux-gnueabihf
/usr/arm-linux-gnueabihf/include/c++/4.8.1/backward
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/include
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/include-fixed
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/include
/usr/include

but libraries in

-L/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8
-L/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib
-L/lib/../lib
-L/usr/lib/../lib
-L/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib

Cheers,
Rafael

Hi Chandler, The case is similar on Ubuntu 13.04. In the patch, I reused the idea of finding the gcc installation directories in the ToolChains.cpp file, as a part of identifying lib paths under ScanLibDirForGCCTriple(). It seemed to be the simplest way to identify the directories of the form Major.Minor.Patch (4.8.1 or 4.7.3) in order to look up the header files.
I agree that we will look at all the directories in the path, i.e. 4.8.1, 4.8, 4.7.3, 4.7, but will stop as soon as one of the directories exist.

chandlerc resigned from this revision.Mar 29 2015, 11:26 AM
chandlerc removed a reviewer: chandlerc.
espindola edited reviewers, added: espindola; removed: rafael.Mar 15 2018, 11:08 AM