How to Change the Host Type for a 'Canadian Cross' Compilation of Gcc with Crosstool-Ng

How to use candian in Crosstools-NG in a cross-native fashion to get gcc on an arm board?

This answer is an extension of my original question regarding the general workflow for cross compiling a toolchain.

I had the correct general idea, you have to do a Canadian-Build with the host system tuple being the arm-unknown-linux-gnueabi cross compiler I made earlier. Make sure to include it to your path or do some symlinking into /bin or however else you want to handle that.

I had to wait roughly 30 minutes when doing the build using 3/4 cores of an I5-3570k and ~2GB of ram in a Ubuntu Vmware virtual machine using a normal HDD. Using a SSD will probably bump the speed up significantly.

Once this is done, you should be have an output directory that Crosstools-NG made for you which includes the toolchain for the ARM architectre. You can verify this by running file filename on any of the binaries.

Now, for the library situation which took me a while and gave a decent bit of confusion. In the toolchain output there should be a rootfs folder. That folder contains the expected root file system of the target for which you will be compiling (in this case arm). You need to copy the /lib folder as well as lib's from the user, mirroring the folder hierarchy of this rootfs folder.

You can verify if you have the libraries setup right by doing objdump -p filename and seeing the NEEDED entries which point to required libraries which should be in the rootfs.

If you are using a busybox based rootfs, then assuming you didn't statically compile it then you probably already have the libraries setup correctly since you needed them for busybox. I did a static build of busybox first to make sure I can get the system to boot to a shell, and then made a nonstatic build to have a soft start for libraries, using the libraries from the toolchains rootfs folder. Once I got a dynamically linked busybox system working, simply dropping the cross compiled toolchain into your rootfs at an arbitrary location (/usr/home/toolchain for me) should suffice, after which you should use the toolchain just the same as for an x86 system referring to path and symlinks and whatever you want to do.

Cross Compiling, Crosstool, Makefile , libreadline

Maybe is the variable CROSS_COMPILE what you need.

The toolchain is not only the compiler. They are even basic bin utils needed for the whole build process.

Try this instead:

make CROSS_COMPILE=arm-linux-gnueabihf-

Subtleties dealing with cross compilation, freestanding libgcc, etc

libgcc

This library must be linked in some cases when you compile with GCC. Because GCC produces calls to functions in this library, if the target architecture doesn't support a specific feature.

For example, if you use 64-Bit arithmetic in your kernel and you want compile for i386, then GCC make a call to the specific function which resides in libgcc:

uint64_t div64(uint64_t dividend, uint64_t divisor)
{
return (dividend / divisor);
}

Here you get an undefined reference to __udivdi3 error from the linker when you try to link your kernel without libgcc. On the other side, libgcc also make calls to standard C library functions. So these specific functions must be implemented.

Here is another IMHO good explanation. It's called bare-metal programming here for the ARM architecture, but also valid for x86.



Related Topics



Leave a reply



Submit