I am a beginner in programming and wanted to download a good C compiler to practice coding. So I thought of GCC and started a small research on it. I read a Wikipedia article on it. The article mentioned something about target architecture,which I do not know. Can anyone tell me what it means, and any source I can refer for more information. Thanks in advance.
The target architecture is the architecture which the compiler creates binary files for.
Common architectures are: i386 (Intel 32-bit), x86_64 (Intel 64-bit), armv7, arm64, etc...
GCC compiles C code (after the preprocessing stage) to assembly code,
and the assembly code varies depending on the CPU architecture.
The assembly code is then "assembled" to a binary file.
Something to keep in mind:
Two binary files are not guaranteed to be compatible across different operating systems despite sharing the same architecture.
A program compiled on Ubuntu Linux (let's say with arch x86_64) won't work on Windows (with same arc x86_64).
GCC identifies architectures by "triplets", like:
x86_64-apple-darwin14.0.0
i386-pc-mingw32
i686-pc-linux-gnu
Format is:
machine-vendor-operatingsystem (not always followed though)
They contain infos on both the architecture and the operating system.
Related
I've done all my development work for an embedded linux device (gumstix) in a linux VM and I would like to move the code base to my host Linux computer. The cross-compiler was setup prior to me inheriting the codebase, so I'm not sure how the compiler was set up. I have some questions concerning how to set up the cross-compiler.
The compiler on the VM is a arm-linux-gnueabihf-gcc.
Is the cross-compiler kernel specific? (Using linux kernel 3.17)
Is the cross-compiler target device specific; i.e. do I need to use a gumstix compiler or is the arm-linux-gnueabihf-gcc satisfactory. Does this compiler need to be configured manually.
Is there a way to see/import the configuration setting of the working VM compiler?
Does the arm-linux-gnueabihf-gcc use the same standard library source code as the gcc compiler?
I've seen varying approaches to setting up cross-compilers on web. Where can I find comprehensive information for setting up a cross-compiler (More than a how-to, but also explains why).
Thank you
The cross compiler is not kernel specific nor target device specific. It is specific to the architecture of the SoC or processor you are targeting. So if your current compiler is arm-linux-gnueabihf-gcc it implies it can compile code for ARM32 processors which have floating point support in hardware. Depending on your host Linux system, you can install a similar compiler using the package manager or you may also download it from here.
Different people probably will recommend different approaches and also on whether a particular approach is easy or difficult. Regardless I tend to recommend building the complete target image and generating an SDK for doing development using something like Yocto/Openembedded or Buildroot.
Not sure exactly what you mean by Q4.
Hopefully this hasn't been asked and answered already, but I just had a quick question on ARM.
Specifically, if when compiling Android (which has a lot of C and C++), you use GCC to compile, doesn't that create x86 based code? How is it that an ARM processor, which uses a reduced instruction set, can interpret this code and run like it does?
Thanks!
GCC doesn't just compile for x86. It actually compiles to any instruction set. If you wanted to you could create a new one just by adding a few files.
And ARM isn't a reduced instruction set. Its a completely different instruction set. There's some things ARM has that x86 doesn't and vice versa.
Building gcc goes through a configuration step, part of this is to specify a back-end. The back-end is responsible for op-code generation. The typical compiler is many phases. Briefly,
Parser - convert text to a data representation.
Front end - Optimize by changing code constructs, possibly language specific.
Middle end - Performs computer science optimization that are common to any compiler.
Back end - Performs optimization specific to the target CPU.
See stackoverflow compiler wiki for more.
So parts one to three are common for the x86 and the ARM versions of gcc (or any gcc). The Android compiler is a version of gcc which has been configured to generate ARM code. It is a different compiler than the one that normally runs on an x86. You maybe running an ARM emulator on a PC and then believe that this code is run by the x86. However, this is a virtual ARM machine running this code. An x86 processor can not run ARM code natively.
The Android gcc is an ARM configured gcc. A normal Linux distributions gcc is configured for an x86 or x86_64.
Something is missing above: Who compiles the compiler? In both cases, an x86 compiler compile the new compiler. The difference is the selected back-end. One is x86, the other ARM. Both compilers run on an x86, but they generate code for different targets. Gcc can only generate code for an ARM or an x86; never both via any sort of command line switch. A compiler build usually refers to three different CPU types.
Build - Machine where the compiler is built. This is the compiler's compiler.
Host - the machine the compiler runs on. Not it's output, but the compiler itself.
Target - the machine the back-end targets. The one code is generated for.
I think maybe people are thinking because they both run on the same host, they must generate code for the same target. But that is not true; it is a little mind bending at first. Depending on the setup, you may need compilers for each of these machines to make a final compiler.
The first compiler for any machine is usually a cross compiler. Except for some people who made primitive compilers long ago in assembler.
See also: Cross compiler.
to put it simply, when you're building for ARM on your x86 computer you're using a cross-compiler - a compiler that runs on one platform but generates code for another. This is extremely common when developing for embedded or mobile platforms.
I intend to cross compile for Raspberry Pi, basically a small ARM computer. The host will be an i686 box running Arch Linux.
My first instinct is to use cross compiler provided by Arch Linux, arm-elf-gcc-base and arm-elf-binutils. However, every wiki and post I read seems to use some version of custom gcc build. They seem to spend significant time on cooking their own gcc. Problem is that they never say WHY it is important to use their gcc over another.
Can stock distro provided cross compilers be used for building Raspberry Pi or ARM in general kernels and apps?
Is it necessary to have multiple compilers for ARM architecture? If so, why, since single gcc can support all x86 variants?
If 2), then how can I deduce what target subset is supported by a particular version of gcc?
More general question, what general use cases call for custom gcc build?
Please be as technical as you can, I'd like to know WHY as well as how.
When developers talk about building software (cross compiling) for a different machine (target) compared to their own (host) they use the term toolchain to describe the set of tools necessary to build binary files. That's because when you need to build an executable binary, you need more than a compiler.
You need routines (crt0.o) to initialize runtime according to requirements of operating system and standard libraries. You need standard set of libraries and those libraries need to be aware of the kernel on target because of the system calls API and several os level configurations (f.e. page size) and data structures (f.e. time structures).
On the hardware side, there are different set of ARM architectures. Architectures can be backward compatible but a toolchain by nature is binary and targeted for a specific architecture. You can have the most widespread architecture by default but then that won't be too fruitful for an already constraint environment (embedded device). If you have the latest architecture, then it won't be useful for older architecture based targets.
When you build a binary on your host for your host, compiler can look up all the necessary bits from its own environment or use what's on the host - so most of the above details are invisible to developer. However when you build for a different target than your host type, toolchain must know about hardware, os and standard library details. The way you tell these to toolchain is... by building it according to those details which might require some level of bootstrapping. (or you can do this via extensive set of parameters if toolchain supports / built for it.)
So when there is a generic (stock) cross compile toolchain, it has already some target specifics set and that might not meet your requirements. Please see this recent question about the situation on Ubuntu for an example.
I have tried to understand the naming conventions behind the gcc cross-compilers, but there seems to be conflicting answers. I have the following three cross-compilers in my system:
arm-none-linux-gnueabi (CodeSourcery ARM compiler for linux)
arm-none-eabi (CodeSourcery ARM compiler for bare-metal systems)
arm-eabi (Android ARM compiler)
When reading through the GNU libtool manual, it specifies the cross-compiler naming convention as:
cpu-vendor-os (os = system / kernel-system)
This does not seem completely accurate with the compilers in my system. Is the information in the GNU manual old, or have the compiler distributors simply stopped following it?
The naming comes down to this:
arch-vendor-(os-)abi
So for example:
x86_64-w64-mingw32 = x86_64 architecture (=AMD64), w64 (=mingw-w64 as "vendor"), mingw32 (=win32 API as seen by GCC)
i686-pc-msys = 32-bit (pc=generic name) msys binary
i686-unknown-linux-gnu = 32-bit GNU/linux
And your example specifically:
arm-none-linux-gnueabi = ARM architecture, no vendor, linux OS, and the gnueabi ABI.
The arm-eabi is alike you say, used for Android native apps.
One caveat: Debian uses a different naming, just to be difficult, so be careful if you're on a Debian-based system, as they have different names for eg. i686-pc-mingw32.
The fact is that, there is a rule, and it is the one described above from rubenvb. But in several cases the naming you will find is incorrect, as:
gcc-pippotron-6.3.1-2017.05-x86_64_arm-linux-gnueabihf
gcc-pippotron-arm-none-eabi-4.8-2013.11_linux
This maming above are 2 examples that are not respecting the rule.
I wanna port Linux kernel 2.6.x to new MIPS board. Unfortunatelly, I can't find good actual documentation with step by step explaination. Hope, you'll help me. Paper books are OK too.
Thank you in advance!
First, get your hands on a MIPS toolchain. You're going to need it to compile the kernel. I've used buildroot a few times, including for building a MIPS toolchain.
But buildroot offers a lot more than just that:
Buildroot can generate any or all of a
cross-compilation toolchain, a root
filesystem, a kernel image and a
bootloader image. Buildroot is useful
mainly for people working with small
or embedded systems, using various CPU
architectures (x86, ARM, MIPS,
PowerPC, etc.) : it automates the
building process of your embedded
system and eases the cross-compilation
process.
If you would like to do this process manually, I suggest you take a look at this. It's not for MIPS but it shows the generic formula (you'll probably have to find and apply MIPS patches to the Kernel before compiling it). Try buildroot, it does all of this automagically!
I must also recommend reading Jun Sun's Linux MIPS Porting Guide.