Cross compiler & Assembler & Linker.ppt

March 31, 2018 | Author: varun2313676 | Category: Compiler, Library (Computing), Computer File, Unix, Operating System Technology


Comments



Description

Building a Cross Compiler, Assembler and Linker Designed by Prof. Peng-Sheng Chen What can You Learn? During embedded-system development, why do we need to use cross compiler, assembler / linker and C standard library How to build cross compiler、assembler / linker How to build cross C standard library 2 Equipment Requirement PC with  Linux OS installed  Native gcc compiler installed  Internet access 3 gz  http://ftp.nctu.com/pub/gcc/releases/gcc-3.com/pub/newlib/newlib-1.gnu.1.edu.3.1)  ftp://sources.tar.redhat.Software Requirement  GNU binutils source code (version 2.3.tar.16.gz  GNU C/C++ compiler (version 3.6)  ftp://sources.tar.tar.tw/computer-languages/C/gcc/releases/gcc3.com/pub/binutils/releases/binutils2.tar.14.6/gcc-3.1.16.3.6.3.gz 4 .redhat.6.0)  ftp://sources.3.0.14.6/gcc3.gz  ftp://ftp.16.gz  GNU newlib (version 1.redhat.org/gnu/binutils/binutils-2. Outline Introduction Basic Linux commands Build cross assembler / linker Build cross compiler Build cross C standard library Testing 5 . Outline Introduction Basic Linux commands Build cross assembler / linker Build cross compiler Build cross C standard library Testing 6 . assembler.Introduction  A total solution for embedded system development  Hardware  Software => software-development tools. debugger and C standard library  Commercial => very high cost  Open source => free. linker. Users can modify. distribute and use the software 7 . applications  Software-development tools  Compiler. GNU Binutils  The GNU binutils are a collection of binary tools  ld .A utility for creating.Displays profiling information objcopy .the GNU linker  as .Displays information from object files …  Easy to port binutils to other platforms  Suitable for embedded-system development 8 . modifying and extracting from archives gprof .the GNU assembler  Other binary tools      ar .Copys and translates object files objdump . back-end system with support for many of each  Code quality is better than some known compiler. BSD 9 .GNU C/C++ Compiler  Retargettable  Available from the Free Software Foundation  GPL Licensed  Free  Written by Richard Stallman originally (FSF)  Front-end. very close to DEC’s compiler on Alpha  Supplied as vendor compiler by NeXT. BeOS. Linux. a language in the Modula II family used in European telecommunications ) 10 .0)  Java->Bytecode. Bytecode->native code  Java->Native code  Cobol  Chill (Cygnus.Front Ends  C、C++、Objective C  Ada 95 (GNAT)  Fortran77、Fortran95  Pascal  Modula-2、Modula-3  Java (supported from gcc 3.  Alpha (DEC)  Intel x86 Families、i860、i960.  Motorola 680x0、68C11、DSP56000  Hitachi SH、H8300  MIPS、IBM PowerPC、HP PA-RISC、SUN SPARC  ……  Intel IA64.  Acorn (Advanced) RISC Machine.Machines Supported by GCC  Essentially all machines in widespread. AMD x86-64  Cell processor (used by PS3) 11 . GCC Execution gcc cpp cc1 g++ gas (assembler) Input file output file ld (linker) 12 . GNU C Standard Library GLIBC 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 . assembler / linker and debugger on target platform  For embedded system. it is impossible to execute compiler.Cross System-Development Tools  The characteristics of most embedded systems  Limited memory  Diskless  No output screen  Poor performance  … Cross-compiler Remote debug  Sometimes. we need cross systemdevelopment tools to help software development 14 . Machine Classification Build machine  The machine builds cross-toolchains Host machine  The machine cross-toolchains will execute on Target machine  The assembly code of the machine crosstoolchains will produce output for 15 . 2  i386-redhat-linux  m68k-coff  arm-elf 16 .Machine Identification Three items to identify machine  CPU type  Company name  System type Example  vax-dec-ultrix4. Outline Introduction Basic Linux commands Build cross assembler / linker Build cross compiler Build cross C standard library 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 file1 file2 Copy the file “file1” to the file “file2” 18 . and only show the file name List all files in the current working directory in long listing format showing permissions. size. and time and date stamp ls -al 19 .Basic Linux Commands (2) Command df Description Show the amount of disk space used on each mounted filesystem ls ls List files List files in the current working directory except those starting with . ownership. 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 file1 The example displays the contents of file1 20 . If the directory listing is longer than a page.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. it will be listed one page at a time 21 . Basic Linux Commands (5) Command rm rm file1 Description Delete the files Delete the file “file1” mv Move or rename files mv file1 file2 Move the file from “file1" to “file2". Locates binaries and manual pages for the ls command 22 . This effectively changes the name of “file1" to “file2” mv file1 . 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 Locates binaries and manual pages for the ls command whereis ls man man ls format and display the on-line manual pages Display the on-line manual of “ls” 23 . Setting Environment Variables (1) Command ps Description Report process status Which shell do you use? $ ps PID TTY 13580 pts/11 13626 pts/11 $ TIME CMD 00:00:00 bash 00:00:00 ps $ ps PID TTY 13580 pts/11 13626 pts/11 $ TIME CMD 00:00:00 csh 00:00:00 ps Bash Shell C shell 24 . Setting Environment Variables (2) Set PATH  Ex: Add “/foo/bin” to PATH $ export PATH=/foo/bin:$PATH Bash Shell $ setenv PATH /foo/bin:$PATH C shell 25 . txt log.Log Information: Redirection Before a command is executed.txt  Direct both standard output and standard error to the file “log. its input and output may be redirected  Executable file: myexec  Log file: log.txt 2>&1 C Shell 26 .txt” Bash Shell $ myexec > $ myexec >& log. Outline Introduction Basic Linux commands Build cross assembler / linker Build cross compiler Build cross C standard library Testing 27 . adjust related building parameters and generate corresponding Makefile file  --target=arm-elf sets target machine for ARM.Build Cross-Binutils  download source code of GNU binutils  uncompress source code  configure binutils  This step will detect system status. and supported file format for ELF  --prefix=/foo sets the package will be installed in directory /foo configure --target=arm-elf --prefix=/foo  make  make install 28 . Outline Introduction Basic Linux commands Build cross assembler / linker Build cross compiler Build cross C standard library Testing 29 . 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 (1)  Add the directory of binutils executable to PATH  download source code of GNU gcc  uncompress source code  configure gcc      This step will detect system status. adjust related building parameters and generate corresponding Makefile file --target=arm-elf sets target machine for ARM. Build Cross-Compiler (2) configure --target=arm-elf --prefix=/foo --enable-languages=c --with-newlib  make  make install 31 . Outline Introduction Basic Linux commands Build cross assembler / linker Build cross compiler Build cross C standard library Testing 32 . 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  make  make install 33 . adjust related building parameters and generate corresponding Makefile file --target=arm-elf sets target machine for ARM.Build Cross-Newlib  Add the directory of binutils、gcc executable to PATH  download source code of GNU newlib  uncompress source code  configure newlib    This step will detect system status. Directory Structure /foo bin include lib gcc-lib arm-elf bin man include info lib share 34 . Outline Introduction Basic Linux commands Build cross assembler / linker Build cross compiler Build cross C standard library Testing 35 . . #0 mov r0. uses_anonymous_args = 0 mov ip.LC0: main: .file "test1. pc} .word .type "Hello World\n\000" 2 main main. {fp.L2: . #4 ldr r0. .global . {fp.c */ #include <stdio. %function @ args = 0.text .h> int main(void) { printf(“Hello World\n”).c /* test1. sp.c" .section .size .-main "GCC: (GNU) 3.rodata . sp stmfd sp!.L2 bl printf mov r3. lr.align 2 .ident . pretend = 0. ip.align 2 .3.ascii . ip. r3 ldmea fp. } .Testing /foo/bin/arm-elf-gcc -S test1.L3: .LC0 main. return 0.6" 36 . frame = 0 @ frame_needed = 1.align . pc} sub fp. computerhope.htm#04 GNU binutils  http://sources.gnu.com/binutils GCC  http://gcc.redhat.com/unix.redhat.Reference Linux/UNIX commands  http://www.org GNU newlib  http://sources.com/newlib 37 .
Copyright © 2024 DOKUMEN.SITE Inc.