UQC 122 S 3 RealTime and Embedded Systems
UQC 122 S 3 Real-Time and Embedded Systems GCC as a cross compiler 1
GCC • Long standing compiler development – Developed an editor emacs, compiler suite gcc and UNIX-like OS Hurd. Plus many other tools and utilities. – emacs and gcc have been the most successful and central to many developments – BSD, Linux – Developed by Richard Stallman and the Free Software Foundation 2
The GCC suite • The development tools are made up of – gcc , a set of compilers for C, C++, Ada, Java – The gnu linker, ld and assembler, as – Binutils, a collection of useful code development tools • ar, nm, objcopy, objdump, ranlib, size, strings, strip, addr 2 line 3
GCC • The gcc compiler has front ends to provide different language capabilities • It also has a gcc core which allows it to generate the actual code • The code generation is done through an intermediate language called RTL – Register Transfer Language – a LISP variant 4
RTL • The front end generates a parse tree which checks the syntax for the target language and any supporting data structures • This tree is then used to generate RTL which expresses the structure of the code – The RTL code is then used to do optimisation • Finally assembler code is generated from the RTL 5
gcc passes gcc Language Specific Front end RTL code Assembler Code 6
gcc output formats • Although the gcc compiler can be installed on one host it can create outputs for many targets and formats • The normal situation is that the host and the target are the same. – A Intel 686 running Linux with ELF output would generate ELF 686 binaries that would run under Linux 7
BFD • In order to allow the compiler to create a number of different formats gcc use Binary File Definitions – BFD • BFD allows the compiler and linker to have descriptions of different file and machine formats • This then means that object files can be converted from one format to another 8
BFD • When gcc is created it will, by default, use the host machine as the basis for its target code generation. – The format is CPU-MACHINE-SYSTEM • i 386 -sunos 4 – So host and target might be m 68 k-hp-netbsdelf • Conversion between formats may lose information or not be possible 9
Using gcc as a cross compiler • gcc is popular as a cross compiler • This requires the installation to distinguish between the system the compiler run upon and the code it generates for another system • More care is required when configuring and installing 10
A gcc cross compiler Library files ccc compiler Host binary Generated code Binary output Startup code Target binary 11
- Slides: 11