1
votes

I have created a bare-bone Linux ARM system. It boots to a busybox shell without any issues on my ARM system.

Now I want to build a working gcc/glibc environment that I can use on my ARM system.

My development machine is x86. I have read tutorials talking about doing a "cross-compiler", but that does not seem what I want. Seem that is just a compiler that runs on x86, but can generate ARM binaries.

I need to create a compiler that runs on ARM and creates ARM binaries. But I need to build it on my x86 machine and then copy it over to my ARM one. Then going forward, I can extend the system by compiling natively on the ARM machine.

So, I probably need to use "cross-compiling" to create this gcc/glibc, but the result should be ARM for ARM and not a ARM for x86. Am I correct? Is it just a matter of playing around with the "taget", "host" variables?

All tutorials I have read shows how you build the system into an isolated target directory, but they don't explain what parts I need to copy to the target ARM system root.

1
You can install pre-build cross-compile toolchan for ARM, for example with RED-HAT like distros (Fedora/RHEL/CentOS etc) dnf info gcc-c++-arm-linux-gnu for debian like distros (Debian/Ubuntu etc) package called gcc-8-arm-linux-gnueabihf. There is nice how-to article (russian but code mostly).Victor Gubin
You can use the yocto project to build the SDK for your target machine. You get all compilers and a GDB for your platform.Kampi
This is probably too broad a question as written. Also see Installing GCC in the GCC documentation. I believe this is one of the few cases you use --target. I believe you still need --build and --host.jww
@jww I would disagree that it is too broad. It is just the workflow for building different cross types. It maybe a duplicate; except this is phrased with ARM as the cross native. See: Cross or cross native for a good reason to want this compiler.artless noise
Here is a duplicate, but this question is better in my opinon as it mentions the cross needed to build the cross native (or at least wonders about it).artless noise

1 Answers

0
votes

So, I probably need to use "cross-compiling" to create this gcc/glibc, but the result should be ARM for ARM and not a ARM for x86. Am I correct?

This is correct, but not the complete workflow. You need more compilers than you might imagine.

Is it just a matter of playing around with the "target", "host" variables?

This is more complex than you might first imagine. I would like to refer you to crosstool-NG's Toolchain Types and Wikipedia's Canadian Cross for reference.

A little reading will reveal that you are trying to make a cross native compiler with, I assume, build as x86-glibc-linux, host as arm-glibc-linux and target as arm-glibc-linux. You need a native compiler (x86-glibc-linux) to make a cross arm-glibc-linux that runs on x86 (host). This is because the cross native arm-glibc-linux needs to build a glibc as part of the toolchain that will run on the ARM. You need more than a compiler; linker (gold?), libraries (shared/static), etc.

Crosstool-ng supports this and generally yocto and distros use it some where to create their version. There are often more efficient ways to do this than with crosstool-ng as sometimes only a bootstrap compiler will suffice and/or you can reuse code built for a previous compiler build. See for example,

A “cross-native” toolchain can be built as a trivial case of the “canadian” toolchain. It is suboptimal, as it makes crosstool-NG build the tools targeting the host machine twice (first, as a separate toolchain which is a prerequisite for all canadian builds; and second, as a part of temporary toolchain created as a part of the canadian build itself). This will likely be improved in the future.

However, if this is rarely done you can do this building while you are doing other things. I took several days to make a Canadian cross of "x86-64-linux/x86-mingw/arm-linux" to allow Windows development for an ARM Linux device. If you think you will create this compiler many times (to track gcc development for instance) you might want to look at a custom script instead of crosstool-NG.