1

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.

jww
  • 97,681
  • 90
  • 411
  • 885
Daniele Testa
  • 1,538
  • 3
  • 16
  • 34
  • 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](https://habr.com/ru/post/319736/) (russian but code mostly). – Victor Gubin Jun 14 '19 at 10:12
  • You can use the [yocto project](https://www.yoctoproject.org/docs/2.1/sdk-manual/sdk-manual.html) to build the SDK for your target machine. You get all compilers and a GDB for your platform. – Kampi Jun 14 '19 at 10:21
  • This is probably too broad a question as written. Also see [Installing GCC](https://gcc.gnu.org/install/) 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 Jun 14 '19 at 10:33
  • @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](https://stackoverflow.com/questions/16403461/cross-compile-or-compile-native-for-cpu-arch) for a good reason to want this compiler. – artless noise Jun 14 '19 at 15:44
  • [Here is a duplicate](https://stackoverflow.com/questions/7663684/compiling-native-gcc-for-arm-using-cross-compiler), 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 Jun 14 '19 at 15:49
  • @old_timer Not sure I understand what you mean. I DO have an operating system. I clearly wrote that I have an ARM system that boots just fine to the shell, but it's lacking gcc/glibc. That's what I am now trying to build on another system and then add to it. – Daniele Testa Jun 14 '19 at 17:50
  • sorry saw bare bone thought bare metal. – old_timer Jun 14 '19 at 17:58
  • you have a bootstrap problem or basically a chicken and egg problem you dont have a compiler on the system to build a compiler on the system – old_timer Jun 14 '19 at 17:59
  • so you have to build a compiler on another system or take a compiler built on another system and get it to run on yours, with linux that unfortunately means a ton of libraries which means you have to make your system resemble theirs. or modify the toolchain to not need those libraries, or build static and reduce the dependencies – old_timer Jun 14 '19 at 17:59
  • a cross compiler is not what you want but it may be possible to use a cross compiler to build your native compiler. thats too many balls in the air to juggle, so you may want to either use an emulator or a real arm system with an already ported distro. you will find that many of the allwinner based boards the nano-pis and such as well as some others like the beaglebones, there are some linux ports for those that are built on qemu in a generic-ish way, you might be able to capitalize on what they are building. dont know if they have – old_timer Jun 14 '19 at 18:02
  • the toolchain running on the target though or if they are just building an os to run binaries but not to develop on. – old_timer Jun 14 '19 at 18:03

1 Answers1

0

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.

artless noise
  • 21,212
  • 6
  • 68
  • 105
  • Your host gcc may not have all the features needed to build the cross/cross native gcc tool suite. A bootstrap compiler tries to resolve this but it may fail due to some new compiler features used especially related binaries code which throw errors when compiling with some other gcc version. For this reason it is safer to build a native compiler that matches; but obviously this takes more time. – artless noise Jun 14 '19 at 15:31
  • But as far as I understand, I don't really have to build the "ARM compiler that runs on x86" myself. That can easily be installed with "apt" in Debian. What I need is to create the "ARM for ARM" gcc/glibc combo. Pretty much want to end up with a directory that has all gcc/glibc stuff it in that I can just copy to the root of my ARM computer root and then boot the ARM computer and start compiling stuff. – Daniele Testa Jun 14 '19 at 15:34
  • @DanieleTesta See comment above. The safest route is to build three compilers. GCC host, GCC cross and GCC cross native. When language features/extentions match (ie, same elf format, same multi-lib format, etc) you will have the best luck at getting a clean build. Other methods can work in theory, but you will probably have to do some small patch to get something to build. Ie, some deprecated compiler option, etc. – artless noise Jun 14 '19 at 15:34
  • Sure, I get that. Just don't understand why there are not simple scripts that does this already. If someone already solved it, it should just be a matter of downloading the sources to a working distribution and then do the 3 step compile. Maybe even in a docker container to separate it from the rest of the system. I looked at crosstool-NG, but looks like it can only produce a cross-compiler, not a native-compiler. – Daniele Testa Jun 14 '19 at 16:04
  • Crosstool-ng does support this. You have to run it multiple times. With `ct-ng menuconfig`, go to *paths and misc options* and you have host and build compiler options. You need to set these to compilers you download (or better built) when you build the cross native. It is a very complex process so it is not a **simple** script. This is why distributions are successful. It is hard to build a rootfs. But for embedded people, there are benefits. Also, there is also `ct-ng list-samples` which might be helpful. – artless noise Jun 14 '19 at 16:20
  • Do you know how I can add option to use a local path or tar-ball for the linux kernel headers option? The kernel I am using is not on the list and even if it was, I have lots of unofficial patches in mine. – Daniele Testa Jun 14 '19 at 18:07
  • The system uses 'menuconfig' and you can use '/' to search for 'kernel'. Go to "operating system", select "linux" and then in version, it has custom (at then end of the list) where you can specify the directory. See: [kbuild tag](https://stackoverflow.com/tags/kbuild/info) – artless noise Jun 15 '19 at 19:46
  • I don't have the option "custom" in my list. It's just a list of like 10 different kernels. – Daniele Testa Jun 16 '19 at 04:58
  • Ah, I had to enable the "experimental" features to see the "custom" option. You forgot to mention that :) – Daniele Testa Jun 17 '19 at 06:12