gcc configuration and building
play

GCC Configuration and Building Uday Khedker - PowerPoint PPT Presentation

Tutorial on Essential Abstractions in GCC GCC Configuration and Building Uday Khedker (www.cse.iitb.ac.in/grc) GCC Resource Center, Department of Computer Science and Engineering, Indian Institute of Technology, Bombay April 2011 EA-GCC,


  1. EA-GCC, Chamonix Configuration & Building: Basic Concepts 12/1 A Native Build on i386 C i386 C i386 i386 Stage 1 Build cc GCC C i386 Source i386 gcc Requirement: BS = HS = TS = i386 • Stage 1 build compiled using cc Uday Khedker GRC, IIT Bombay

  2. EA-GCC, Chamonix Configuration & Building: Basic Concepts 12/1 A Native Build on i386 C i386 C i386 i386 Stage 1 Build cc GCC C i386 Source i386 gcc Requirement: BS = HS = TS = i386 • Stage 1 build compiled using cc Uday Khedker GRC, IIT Bombay

  3. EA-GCC, Chamonix Configuration & Building: Basic Concepts 12/1 A Native Build on i386 C i386 C i386 i386 Stage 1 Build cc GCC C i386 Source i386 Stage 2 Build gcc C i386 Requirement: BS = HS = TS = i386 i386 • Stage 1 build compiled using cc gcc • Stage 2 build compiled using gcc Uday Khedker GRC, IIT Bombay

  4. EA-GCC, Chamonix Configuration & Building: Basic Concepts 12/1 A Native Build on i386 C i386 C i386 i386 Stage 1 Build cc GCC C i386 Source i386 Stage 2 Build gcc C i386 Requirement: BS = HS = TS = i386 i386 • Stage 1 build compiled using cc gcc • Stage 2 build compiled using gcc Uday Khedker GRC, IIT Bombay

  5. EA-GCC, Chamonix Configuration & Building: Basic Concepts 12/1 A Native Build on i386 C i386 C i386 i386 Stage 1 Build cc GCC C i386 Source i386 Stage 2 Build gcc C i386 Requirement: BS = HS = TS = i386 i386 • Stage 1 build compiled using cc gcc • Stage 2 build compiled using gcc Stage 3 Build • Stage 3 build compiled using gcc C i386 i386 gcc Uday Khedker GRC, IIT Bombay

  6. EA-GCC, Chamonix Configuration & Building: Basic Concepts 12/1 A Native Build on i386 C i386 C i386 i386 Stage 1 Build cc GCC C i386 Source i386 Stage 2 Build gcc C i386 Requirement: BS = HS = TS = i386 i386 • Stage 1 build compiled using cc gcc • Stage 2 build compiled using gcc Stage 3 Build • Stage 3 build compiled using gcc C i386 • Stage 2 and Stage 3 Builds must be i386 identical for a successful native build gcc Uday Khedker GRC, IIT Bombay

  7. EA-GCC, Chamonix Configuration & Building: Basic Concepts 13/1 Commands for Configuring and Building GCC This is what we specify • cd $(BUILD) Uday Khedker GRC, IIT Bombay

  8. EA-GCC, Chamonix Configuration & Building: Basic Concepts 13/1 Commands for Configuring and Building GCC This is what we specify • cd $(BUILD) • $(SOURCE D)/configure <options> configure output: customized Makefile Uday Khedker GRC, IIT Bombay

  9. EA-GCC, Chamonix Configuration & Building: Basic Concepts 13/1 Commands for Configuring and Building GCC This is what we specify • cd $(BUILD) • $(SOURCE D)/configure <options> configure output: customized Makefile • make 2> make.err > make.log Uday Khedker GRC, IIT Bombay

  10. EA-GCC, Chamonix Configuration & Building: Basic Concepts 13/1 Commands for Configuring and Building GCC This is what we specify • cd $(BUILD) • $(SOURCE D)/configure <options> configure output: customized Makefile • make 2> make.err > make.log • make install 2> install.err > install.log Uday Khedker GRC, IIT Bombay

  11. EA-GCC, Chamonix Configuration & Building: Basic Concepts 14/1 Build for a Given Target This is what actually happens! • Generation ◮ Generator sources ( $(SOURCE D)/gcc/gen*.c ) are read and generator executables are created in $(BUILD)/gcc/build ◮ MD files are read by the generator executables and back end source code is generated in $(BUILD)/gcc • Compilation Other source files are read from $(SOURCE D) and executables created in corresponding subdirectories of $(BUILD) • Installation Created executables and libraries are copied in $(INSTALL) Uday Khedker GRC, IIT Bombay

  12. EA-GCC, Chamonix Configuration & Building: Basic Concepts 14/1 Build for a Given Target genattr This is what actually happens! gencheck • Generation genconditions genconstants ◮ Generator sources genflags ( $(SOURCE D)/gcc/gen*.c ) are read and genopinit generator executables are created in genpreds $(BUILD)/gcc/build genattrtab ◮ MD files are read by the generator genchecksum gencondmd executables and back end source code is genemit generated in $(BUILD)/gcc gengenrtl genmddeps • Compilation genoutput Other source files are read from genrecog $(SOURCE D) and executables created in genautomata gencodes corresponding subdirectories of $(BUILD) genconfig • Installation genextract Created executables and libraries are copied gengtype genmodes in $(INSTALL) genpeep Uday Khedker GRC, IIT Bombay

  13. EA-GCC, Chamonix Configuration & Building: Basic Concepts 15/1 Building a MIPS Cross Compiler on i386 GCC Source Requirement: BS = HS = i386, TS = mips Uday Khedker GRC, IIT Bombay

  14. EA-GCC, Chamonix Configuration & Building: Basic Concepts 15/1 Building a MIPS Cross Compiler on i386 C i386 i386 cc GCC Source Requirement: BS = HS = i386, TS = mips Uday Khedker GRC, IIT Bombay

  15. EA-GCC, Chamonix Configuration & Building: Basic Concepts 15/1 Building a MIPS Cross Compiler on i386 C i386 mips C i386 cc GCC Source Requirement: BS = HS = i386, TS = mips Uday Khedker GRC, IIT Bombay

  16. EA-GCC, Chamonix Configuration & Building: Basic Concepts 15/1 Building a MIPS Cross Compiler on i386 C i386 mips C i386 cc GCC Source Requirement: BS = HS = i386, TS = mips Uday Khedker GRC, IIT Bombay

  17. EA-GCC, Chamonix Configuration & Building: Basic Concepts 15/1 Building a MIPS Cross Compiler on i386 C i386 mips C i386 Stage 1 Build cc GCC mips C Source i386 gcc Requirement: BS = HS = i386, TS = mips • Stage 1 build compiled using cc Uday Khedker GRC, IIT Bombay

  18. EA-GCC, Chamonix Configuration & Building: Basic Concepts 15/1 Building a MIPS Cross Compiler on i386 C i386 mips C i386 Stage 1 Build cc GCC mips C Source i386 gcc Requirement: BS = HS = i386, TS = mips • Stage 1 build compiled using cc Uday Khedker GRC, IIT Bombay

  19. EA-GCC, Chamonix Configuration & Building: Basic Concepts 15/1 Building a MIPS Cross Compiler on i386 C i386 mips C i386 Stage 1 Build cc GCC mips C Source i386 Stage 2 Build gcc mips C mips Requirement: BS = HS = i386, TS = mips gcc • Stage 1 build compiled using cc • Stage 2 build compiled using gcc Its HS = mips and not i386! Uday Khedker GRC, IIT Bombay

  20. EA-GCC, Chamonix Configuration & Building: Basic Concepts 15/1 Building a MIPS Cross Compiler on i386 C i386 mips C i386 Stage 1 Build cc GCC mips C Source i386 Stage 2 build is Stage 2 Build gcc inappropriate for mips C cross build mips Requirement: BS = HS = i386, TS = mips gcc • Stage 1 build compiled using cc • Stage 2 build compiled using gcc Its HS = mips and not i386! Uday Khedker GRC, IIT Bombay

  21. EA-GCC, Chamonix Configuration & Building: Basic Concepts 16/1 A More Detailed Look at Building Source Program cpp cc1 gcc as GCC glibc/newlib ld Target Program Uday Khedker GRC, IIT Bombay

  22. EA-GCC, Chamonix Configuration & Building: Basic Concepts 16/1 A More Detailed Look at Building Partially generated and downloaded Source Program source is compiled into executables cpp cpp cc1 cc1 gcc gcc as glibc/newlib ld Target Program Uday Khedker GRC, IIT Bombay

  23. EA-GCC, Chamonix Configuration & Building: Basic Concepts 16/1 A More Detailed Look at Building Partially generated and downloaded Source Program source is compiled into executables cpp cpp cc1 cc1 gcc gcc as as glibc/newlib glibc/newlib ld ld Existing executables are directly used Target Program Uday Khedker GRC, IIT Bombay

  24. EA-GCC, Chamonix Configuration & Building: Basic Concepts 17/1 Building a MIPS Cross Compiler on i386: A Closer Look C i386 mips C i386 cc GCC Source Requirement: BS = HS = i386, TS = mips we have not built binutils for mips Uday Khedker GRC, IIT Bombay

  25. EA-GCC, Chamonix Configuration & Building: Basic Concepts 17/1 Building a MIPS Cross Compiler on i386: A Closer Look mips assembly C i386 mips C i386 Stage 1 Build cc GCC mips.a C Source i386 cc1 Requirement: BS = HS = i386, TS = mips • Stage 1 cannot build gcc but can build only cc1 we have not built binutils for mips Uday Khedker GRC, IIT Bombay

  26. EA-GCC, Chamonix Configuration & Building: Basic Concepts 17/1 Building a MIPS Cross Compiler on i386: A Closer Look mips assembly C i386 mips C i386 Stage 1 Build cc GCC mips.a C Source i386 cc1 Requirement: BS = HS = i386, TS = mips • Stage 1 cannot build gcc but can build only cc1 • Stage 1 build cannot create executables • Library sources cannot be compiled for mips we have not built binutils using stage 1 build for mips Uday Khedker GRC, IIT Bombay

  27. EA-GCC, Chamonix Configuration & Building: Basic Concepts 17/1 Building a MIPS Cross Compiler on i386: A Closer Look mips assembly C i386 mips C i386 Stage 1 Build cc GCC mips.a C Source × i386 Stage 2 Build cc1 mips C Requirement: BS = HS = i386, TS = mips mips • Stage 1 cannot build gcc but can build only cc1 gcc • Stage 1 build cannot create executables • Library sources cannot be compiled for mips we have not built binutils using stage 1 build for mips • Stage 2 build is not possible Uday Khedker GRC, IIT Bombay

  28. EA-GCC, Chamonix Configuration & Building: Basic Concepts 17/1 Building a MIPS Cross Compiler on i386: A Closer Look mips assembly C i386 mips C i386 Stage 1 Build cc GCC mips.a C Source × i386 Stage 2 build is Stage 2 Build cc1 infeasible for mips C cross build Requirement: BS = HS = i386, TS = mips mips • Stage 1 cannot build gcc but can build only cc1 gcc • Stage 1 build cannot create executables • Library sources cannot be compiled for mips we have not built binutils using stage 1 build for mips • Stage 2 build is not possible Uday Khedker GRC, IIT Bombay

  29. EA-GCC, Chamonix Configuration & Building: Basic Concepts 18/1 A Closer Look at an Actual Stage 1 Build for C native cc + GCC sources native binutils Uday Khedker GRC, IIT Bombay

  30. EA-GCC, Chamonix Configuration & Building: Basic Concepts 18/1 A Closer Look at an Actual Stage 1 Build for C libraries native cc + GCC sources native binutils Uday Khedker GRC, IIT Bombay

  31. EA-GCC, Chamonix Configuration & Building: Basic Concepts 18/1 A Closer Look at an Actual Stage 1 Build for C libraries native cc + GCC sources native binutils libcpp: c preprocessor zlib: data compression intl: internationalization libdecnumber: decimal floating point numbers libgomp: GNU Open MP Uday Khedker GRC, IIT Bombay

  32. EA-GCC, Chamonix Configuration & Building: Basic Concepts 18/1 A Closer Look at an Actual Stage 1 Build for C libraries libiberty native cc + GCC fixincl sources native binutils gen* cc1 cpp Uday Khedker GRC, IIT Bombay

  33. EA-GCC, Chamonix Configuration & Building: Basic Concepts 18/1 A Closer Look at an Actual Stage 1 Build for C libraries libiberty native cc + GCC fixincl sources native binutils gen* cc1 xgcc cpp Uday Khedker GRC, IIT Bombay

  34. EA-GCC, Chamonix Configuration & Building: Basic Concepts 18/1 A Closer Look at an Actual Stage 1 Build for C libraries libiberty native cc + GCC fixincl sources native binutils target gen* binutils cc1 xgcc libgcc cpp Uday Khedker GRC, IIT Bombay

  35. EA-GCC, Chamonix Configuration & Building: Basic Concepts 18/1 A Closer Look at an Actual Stage 1 Build for C libraries libiberty native cc + cc + binutils GCC fixincl sources native for stage 2 binutils target gen* binutils cc1 xgcc libgcc cpp Uday Khedker GRC, IIT Bombay

  36. EA-GCC, Chamonix Configuration & Building: Basic Concepts 19/1 Difficulty in Building a Cross Compiler Building gcc Uday Khedker GRC, IIT Bombay

  37. EA-GCC, Chamonix Configuration & Building: Basic Concepts 19/1 Difficulty in Building a Cross Compiler Building gcc Requires Compiling libgcc Uday Khedker GRC, IIT Bombay

  38. EA-GCC, Chamonix Configuration & Building: Basic Concepts 19/1 Difficulty in Building a Cross Compiler Building gcc Building binutils Requires Requires Compiling libgcc Uday Khedker GRC, IIT Bombay

  39. EA-GCC, Chamonix Configuration & Building: Basic Concepts 19/1 Difficulty in Building a Cross Compiler Requires Building gcc Building binutils Requires Requires Compiling libgcc Uday Khedker GRC, IIT Bombay

  40. EA-GCC, Chamonix Configuration & Building: Basic Concepts 20/1 Building a MIPS Cross Compiler on i386 GCC Source Uday Khedker GRC, IIT Bombay

  41. EA-GCC, Chamonix Configuration & Building: Basic Concepts 20/1 Building a MIPS Cross Compiler on i386 GCC Native cc Source Uday Khedker GRC, IIT Bombay

  42. EA-GCC, Chamonix Configuration & Building: Basic Concepts 20/1 Building a MIPS Cross Compiler on i386 mips C GCC Native cc Source Uday Khedker GRC, IIT Bombay

  43. EA-GCC, Chamonix Configuration & Building: Basic Concepts 20/1 Building a MIPS Cross Compiler on i386 mips C GCC Native cc Source Uday Khedker GRC, IIT Bombay

  44. EA-GCC, Chamonix Configuration & Building: Basic Concepts 20/1 Building a MIPS Cross Compiler on i386 without headers without libgcc crossgcc1 mips C GCC Native cc Source Uday Khedker GRC, IIT Bombay

  45. EA-GCC, Chamonix Configuration & Building: Basic Concepts 20/1 Building a MIPS Cross Compiler on i386 Installed kernel headers + eglibc crossgcc1 GCC Native cc Source Uday Khedker GRC, IIT Bombay

  46. EA-GCC, Chamonix Configuration & Building: Basic Concepts 20/1 Building a MIPS Cross Compiler on i386 Installed kernel headers + eglibc crossgcc1 Initial libraries GCC Native cc Source Uday Khedker GRC, IIT Bombay

  47. EA-GCC, Chamonix Configuration & Building: Basic Concepts 20/1 Building a MIPS Cross Compiler on i386 Installed kernel headers + eglibc crossgcc1 Initial libraries mips C GCC Native cc Source Uday Khedker GRC, IIT Bombay

  48. EA-GCC, Chamonix Configuration & Building: Basic Concepts 20/1 Building a MIPS Cross Compiler on i386 Installed kernel headers + eglibc crossgcc1 Initial libraries mips C GCC Native cc Source crossgcc2 Uday Khedker GRC, IIT Bombay

  49. EA-GCC, Chamonix Configuration & Building: Basic Concepts 20/1 Building a MIPS Cross Compiler on i386 Installed kernel headers + eglibc crossgcc1 Initial libraries GCC Native cc Source C library source crossgcc2 Uday Khedker GRC, IIT Bombay

  50. EA-GCC, Chamonix Configuration & Building: Basic Concepts 20/1 Building a MIPS Cross Compiler on i386 Installed kernel headers + eglibc crossgcc1 Initial libraries GCC Native cc Source C library source crossgcc2 Final libraries Uday Khedker GRC, IIT Bombay

  51. EA-GCC, Chamonix Configuration & Building: Basic Concepts 20/1 Building a MIPS Cross Compiler on i386 Installed kernel headers + eglibc crossgcc1 Initial libraries mips C GCC Native cc Source C library source crossgcc2 Final libraries Uday Khedker GRC, IIT Bombay

  52. EA-GCC, Chamonix Configuration & Building: Basic Concepts 20/1 Building a MIPS Cross Compiler on i386 Installed kernel headers + eglibc crossgcc1 Initial libraries mips C GCC crossgcc Native cc Source C library source crossgcc2 Final libraries Uday Khedker GRC, IIT Bombay

  53. EA-GCC, Chamonix Configuration & Building: Basic Concepts 20/1 Building a MIPS Cross Compiler on i386 Installed kernel headers + eglibc crossgcc1 C program Initial libraries GCC crossgcc Source Native cc C library source crossgcc2 Final libraries Uday Khedker GRC, IIT Bombay

  54. EA-GCC, Chamonix Configuration & Building: Basic Concepts 20/1 Building a MIPS Cross Compiler on i386 Installed kernel headers + eglibc crossgcc1 C program Initial libraries GCC crossgcc Source Native cc C library source mips executable crossgcc2 Final libraries Uday Khedker GRC, IIT Bombay

  55. EA-GCC, Chamonix Configuration & Building: Basic Concepts 21/1 Common Configuration Options --target • Necessary for cross build • Possible host-cpu-vendor strings: Listed in $(SOURCE D)/config.sub --enable-languages • Comma separated list of language names • Default names: c , c++ , fortran , java , objc • Additional names possible: ada , obj-c++ , treelang --prefix=$(INSTALL) --program-prefix • Prefix string for executable names --disable-bootstrap • Build stage 1 only Uday Khedker GRC, IIT Bombay

  56. EA-GCC, Chamonix Configuration & Building: Basic Concepts 22/1 Building cc1 Only • Add a new target in the Makefile.in .PHONY cc1: cc1: make all-gcc TARGET-gcc=cc1$(exeext) • Configure and build with the command make cc1 . Uday Khedker GRC, IIT Bombay

  57. EA-GCC, Chamonix Configuration & Building: Basic Concepts 23/1 Configuring and Building GCC – Summary • Choose the source language: C ( --enable-languages=c ) • Choose installation directory: ( --prefix=<absolute path> ) • Choose the target for non native builds: ( --target=sparc-sunos-sun ) • Run: configure with above choices • Run: make to ◮ generate target specific part of the compiler ◮ build the entire compiler • Run: make install to install the compiler Tip Redirect all the outputs: $ make > make.log 2> make.err Uday Khedker GRC, IIT Bombay

  58. EA-GCC, Chamonix Configuration & Building: Basic Concepts 24/1 Build failures due to Machine Descriptions Incomplete MD specifications ⇒ Unsuccessful build Incorrect MD specification Successful build but run time ⇒ failures/crashes (either ICE or SIGSEGV ) Uday Khedker GRC, IIT Bombay

  59. Part 2 Detailed Instructions

  60. EA-GCC, Chamonix Configuration & Building: Detailed Instructions 25/1 GCC Code Organization Logical parts are: • Build configuration files • Front end + generic + generator sources • Back end specifications • Emulation libraries (eg. libgcc to emulate operations not supported on the target) • Language Libraries (except C) • Support software (e.g. garbage collector) Uday Khedker GRC, IIT Bombay

  61. EA-GCC, Chamonix Configuration & Building: Detailed Instructions 26/1 GCC Code Organization n o Front End Code i • Source language dir: $(SOURCE D)/<lang dir> t • Source language dir contains a ◮ Parsing code (Hand written) m ◮ Additional AST/Generic nodes, if any ◮ Interface to Generic creation r Except for C – which is the “native” language of the compiler o C front end code in: $(SOURCE D)/gcc f n Optimizer Code and Back End Generator Code I • Source language dir: $(SOURCE D)/gcc Uday Khedker GRC, IIT Bombay

  62. EA-GCC, Chamonix Configuration & Building: Detailed Instructions 27/1 Back End Specification n o i t • $(SOURCE D)/gcc/config/<target dir>/ a Directory containing back end code m • Two main files: <target>.h and <target>.md , e.g. for an i386 target, we have $(SOURCE D)/gcc/config/i386/i386.md and r o $(SOURCE D)/gcc/config/i386/i386.h • Usually, also <target>.c for additional processing code f n (e.g. $(SOURCE D)/gcc/config/i386/i386.c ) • Some additional files I Uday Khedker GRC, IIT Bombay

  63. EA-GCC, Chamonix Configuration & Building: Detailed Instructions 28/1 Registering New Machine Descriptions n o • Define a new system name, typically a triple. e.g. spim-gnu-linux i t • Edit $(SOURCE D)/config.sub to recognize the triple a • Edit $(SOURCE D)/gcc/config.gcc to define m ◮ any back end specific variables ◮ any back end specific files ◮ $(SOURCE D)/gcc/config/<cpu> is used as the back end directory r for recognized system names. o f n Tip I Read comments in $(SOURCE D)/config.sub & $(SOURCE D)/gcc/config/<cpu> . Uday Khedker GRC, IIT Bombay

  64. EA-GCC, Chamonix Configuration & Building: Detailed Instructions 29/1 Order of Steps in Installing GCC 4.5.0 n o • Building pre-requisites i t Build and install in the following order with --prefix=/usr/local a Run ldconfig after each installation ◮ GMP 4.3.2 m CPPFLAGS=-fexceptions ./configure --enable-cxx ... ◮ MPFR 3.0.0 r ◮ MPC 0.8.2 o ◮ PPL 0.10.2 ◮ CLOOG-PPL 0.15.9 f • Building gcc n Follow the usual steps. Disable lto --disable-lto for 4.5.0 I Uday Khedker GRC, IIT Bombay

  65. EA-GCC, Chamonix Configuration & Building: Detailed Instructions 30/1 Overview of Building a Cross Compiler n o 1. crossgcc1. Build a cross compiler with certain facilities disabled i 2. Initial Library. Configure the C library using crossgcc1. Build some t specified C run-time object files, but not rest of the library. Install a the library’s header files and run-time object file, and create dummy m libc.so 3. crossgcc2. Build a second cross-compiler, using the header files and r object files installed in Step 2 o 4. Final Library. Configure, build and install fresh C library, using f crossgcc2 n 5. crossgcc. Build a third cross compiler, based on the C library built I in Step 4 Uday Khedker GRC, IIT Bombay

  66. EA-GCC, Chamonix Configuration & Building: Detailed Instructions 31/1 Downloading Source Tarballs n o i t Download the latest version of source tarballs a Tar File Name Download URL m gcc-4.5.0.tar.gz gcc.cybermirror.org/releases/gcc-4.5.0/ binutils-2.20.tar.gz ftp.gnu.org/gnu/binutils/ r Latest revision of EGLIBC svn co svn://svn.eglibc.org/trunk eglibc o linux-2.6.33.3.tar.gz www.kernel.org/pub/linux/kernel/v2.6/ f n I Uday Khedker GRC, IIT Bombay

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend