Building a Cross Compiler Assembler and Linker Designed

Building a Cross Compiler, Assembler and Linker Designed by Prof. Peng-Sheng Chen

What can You Learn? v. During embedded-system development, why do we need to use cross compiler, assembler / linker and C standard library v. How to build cross compiler、assembler / linker v. How to build cross C standard library 2

Equipment Requirement v. PC with Ø Linux OS installed Ø Native gcc compiler installed Ø Internet access 3

Software Requirement v GNU binutils source code (version 2. 16. 1) Ø ftp: //sources. redhat. com/pub/binutils/releases/binutils 2. 16. 1. tar. gz Ø http: //ftp. gnu. org/gnu/binutils-2. 16. 1. tar. gz v GNU C/C++ compiler (version 3. 3. 6) Ø ftp: //sources. redhat. com/pub/gcc/releases/gcc-3. 3. 6/gcc 3. 3. 6. tar. gz Ø ftp: //ftp. nctu. edu. tw/computer-languages/C/gcc/releases/gcc 3. 3. 6/gcc-3. 3. 6. tar. gz v GNU newlib (version 1. 14. 0) Ø ftp: //sources. redhat. com/pub/newlib-1. 14. 0. tar. gz 4

Outline v. Introduction v. Basic Linux commands v. Build cross assembler / linker v. Build cross compiler v. Build cross C standard library v. Testing 5

Outline v. Introduction v. Basic Linux commands v. Build cross assembler / linker v. Build cross compiler v. Build cross C standard library v. Testing 6

Introduction v A total solution for embedded system development Ø Hardware Ø Software => software-development tools, applications v Software-development tools Ø Compiler, assembler, linker, debugger and C standard library Ø Commercial => very high cost Ø Open source => free. Users can modify, distribute and use the software 7

GNU Binutils v The GNU binutils are a collection of binary tools ld - the GNU linker Ø as - the GNU assembler Ø Other binary tools Ø n n n ar - A utility for creating, modifying and extracting from archives gprof - Displays profiling information objcopy - Copys and translates object files objdump - Displays information from object files … v Easy to port binutils to other platforms v Suitable for embedded-system development 8

GNU C/C++ Compiler v Retargettable v Available from the Free Software Foundation Ø GPL Licensed Ø Free v Written by Richard Stallman originally (FSF) v Front-end, back-end system with support for many of each v Code quality is better than some known compiler, very close to DEC’s compiler on Alpha v Supplied as vendor compiler by Ne. XT, Be. OS, Linux, BSD 9

Front Ends v C、C++、Objective C v Ada 95 (GNAT) v Fortran 77、Fortran 95 v Pascal v Modula-2、Modula-3 v Java (supported from gcc 3. 0) Java->Bytecode, Bytecode->native code Ø Java->Native code v Cobol v Chill (Cygnus, a language in the Modula II family used in European telecommunications ) Ø 10

Machines Supported by GCC v Essentially all machines in widespread. v Acorn (Advanced) RISC Machine. v Alpha (DEC) v Intel x 86 Families、i 860、i 960. v Motorola 680 x 0、68 C 11、DSP 56000 v Hitachi SH、H 8300 v MIPS、IBM Power. PC、HP PA-RISC、SUN SPARC v …… v Intel IA 64, AMD x 86 -64 v Cell processor (used by PS 3) 11

GCC Execution 12

GNU C Standard Library v. GLIBC v. Newlib ØA C standard library intended for use on embedded systems Ø Usually work on any architecture with the addition of a few low-level routines 13

Cross System-Development Tools v The characteristics of most embedded systems Ø Limited memory Ø Diskless Ø No output screen Ø Poor performance Ø … v Sometimes, it is impossible to execute compiler, assembler / linker and debugger on target platform v For embedded system, we need cross systemdevelopment tools to help software development 14

Machine Classification v. Build machine Ø The machine builds cross-toolchains v. Host machine Ø The machine cross-toolchains will execute on v. Target machine Ø The assembly code of the machine crosstoolchains will produce output for 15

Machine Identification v. Three items to identify machine Ø CPU type Ø Company name Ø System type v. Example Ø vax-dec-ultrix 4. 2 Ø i 386 -redhat-linux Ø m 68 k-coff Ø arm-elf 16

Outline v. Introduction v. Basic Linux commands v. Build cross assembler / linker v. Build cross compiler v. Build cross C standard library v. Testing 17

Basic Linux Commands (1) Command cd cd /home Description Change directory Change the current working directory to /home cd. . Move to the parent directory of the current directory Move to the user's home directory cd ~ cp Copy files cp file 1 file 2 Copy the file “file 1” to the file “file 2” 18

Basic Linux Commands (2) Command df Description Show the amount of disk space used on each mounted filesystem ls ls List files in the current working directory except those starting with. and only show the file name ls -al List all files in the current working directory in long listing format showing permissions, ownership, size, and time and date stamp 19

Basic Linux Commands (3) Command cat Description Sends file contents to standard output cat /etc/hosts Sends the contents of the “/etc/hosts" file to the screen less Similar to the more command, but the user can page up and down through the file less file 1 The example displays the contents of file 1 20

Basic Linux Commands (4) Command more Description Allows file contents or piped output to be sent to the screen one page at a time more /etc/hosts Lists the contents of the "/etc/profile" file to the screen one page at a time ls –al |more Performs a directory listing of all files and pipes the output of the listing through more. If the directory listing is longer than a page, it will be listed one page at a time 21

Basic Linux Commands (5) Command rm rm file 1 Description Delete the files Delete the file “file 1” mv Move or rename files mv file 1 file 2 Move the file from “file 1" to “file 2". This effectively changes the name of “file 1" to “file 2” mv file 1. Locates binaries and manual pages for the ls command 22

Basic Linux Commands (6) Command pwd Description Show the name of the current working directory whereis Show where the binary, source and manual page files are for a command whereis ls Locates binaries and manual pages for the ls command man format and display the on-line manual pages man ls Display the on-line manual of “ls” 23

Setting Environment Variables (1) Command ps Description Report process status v. Which shell do you use? $ ps PID TTY 13580 pts/11 13626 pts/11 $ TIME CMD 00: 00 bash 00: 00 ps $ ps PID TTY 13580 pts/11 13626 pts/11 $ TIME CMD 00: 00 csh 00: 00 ps Bash Shell C shell 24

Setting Environment Variables (2) v. Set PATH Ø Ex: Add “/foo/bin” to PATH $ export PATH=/foo/bin: $PATH Bash Shell $ setenv PATH /foo/bin: $PATH C shell 25

Log Information: Redirection v. Before a command is executed, its input and output may be redirected Ø Executable file: myexec Ø Log file: log. txt Ø Direct both standard output and standard error to the file “log. txt” Bash Shell $ myexec >& log. txt 2>&1 C Shell 26

Outline v. Introduction v. Basic Linux commands v. Build cross assembler / linker v. Build cross compiler v. Build cross C standard library v. Testing 27

Build Cross-Binutils v download source code of GNU binutils v uncompress source code v configure binutils Ø This step will detect system status, adjust related building parameters and generate corresponding Makefile Ø --target=arm-elf sets target machine for ARM, and supported file format for ELF Ø --prefix=/foo sets the package will be installed in directory /foo configure --target=arm-elf --prefix=/foo v make install 28

Outline v. Introduction v. Basic Linux commands v. Build cross assembler / linker v. Build cross compiler v. Build cross C standard library v. Testing 29

Build Cross-Compiler (1) v Add the directory of binutils executable to PATH v download source code of GNU gcc v uncompress source code v configure gcc Ø Ø Ø This step will detect system status, adjust related building parameters and generate corresponding Makefile --target=arm-elf sets target machine for ARM, and supported file format for ELF (The setting should consist with the setting in binutils) --prefix=/foo sets the package will be installed in directory /foo (The setting should consist with the setting in binutils) --enable-languages=c sets front-end will support C (That is we will build C compiler only) --with-newlib sets the compiler will use newlib as standard C library 30

Build Cross-Compiler (2) configure --target=arm-elf --prefix=/foo --enable-languages=c --with-newlib v make install 31

Outline v. Introduction v. Basic Linux commands v. Build cross assembler / linker v. Build cross compiler v. Build cross C standard library v. Testing 32

Build Cross-Newlib v Add the directory of binutils、gcc executable to PATH v download source code of GNU newlib v uncompress source code v configure newlib This step will detect system status, adjust related building parameters and generate corresponding Makefile Ø --target=arm-elf sets target machine for ARM, and supported file format for ELF (The setting should consist with the setting in binutils and gcc) Ø --prefix=/foo sets the package will be installed in directory /foo (The setting should consist with the setting in binutils and gcc) Ø configure --target=arm-elf --prefix=/foo v make install 33

Directory Structure 34

Outline v. Introduction v. Basic Linux commands v. Build cross assembler / linker v. Build cross compiler v. Build cross C standard library v. Testing 35

Testing v/foo/bin/arm-elf-gcc -S test 1. c 36

Reference v. Linux/UNIX commands Ø http: //www. computerhope. com/unix. htm#04 v. GNU binutils Ø http: //sources. redhat. com/binutils v. GCC Ø http: //gcc. gnu. org v. GNU newlib Ø http: //sources. redhat. com/newlib 37
- Slides: 37