gcc code organization
play

GCC Code Organization Emulation libraries (eg. libgcc to emulate - PowerPoint PPT Presentation

30 June 2011 Config and Build: Outline 1/53 Outline Workshop on Essential Abstractions in GCC GCC Configuration and Building Code Organization of GCC GCC Resource Center Configuration and Building (www.cse.iitb.ac.in/grc)


  1. 30 June 2011 Config and Build: Outline 1/53 Outline Workshop on Essential Abstractions in GCC GCC Configuration and Building • Code Organization of GCC GCC Resource Center • Configuration and Building (www.cse.iitb.ac.in/grc) • Registering New Machine Descriptions Department of Computer Science and Engineering, • Building a Cross Compiler Indian Institute of Technology, Bombay • Testing GCC 30 June 2011 Essential Abstractions in GCC GCC Resource Center, IIT Bombay 30 June 2011 Config and Build: GCC Code Organization 2/53 GCC Code Organization Logical parts are: • Build configuration files Part 1 • Front end + generic + generator sources • Back end specifications GCC Code Organization • Emulation libraries (eg. libgcc to emulate operations not supported on the target) • Language Libraries (except C) • Support software (e.g. garbage collector) Essential Abstractions in GCC GCC Resource Center, IIT Bombay

  2. 30 June 2011 Config and Build: GCC Code Organization 3/53 30 June 2011 Config and Build: GCC Code Organization 4/53 GCC Code Organization Back End Specification Front End Code • Source language dir: $(SOURCE D)/gcc/<lang dir> • $(SOURCE D)/gcc/config/<target dir>/ • Source language dir contains Directory containing back end code ◮ Parsing code (Hand written) • Two main files: <target>.h and <target>.md , ◮ Additional AST/Generic nodes, if any ◮ Interface to Generic creation e.g. for an i386 target, we have $(SOURCE D)/gcc/config/i386/i386.md and Except for C – which is the “native” language of the compiler $(SOURCE D)/gcc/config/i386/i386.h C front end code in: $(SOURCE D)/gcc • Usually, also <target>.c for additional processing code (e.g. $(SOURCE D)/gcc/config/i386/i386.c ) Optimizer Code and Back End Generator Code • Some additional files • Source language dir: $(SOURCE D)/gcc Essential Abstractions in GCC GCC Resource Center, IIT Bombay Essential Abstractions in GCC GCC Resource Center, IIT Bombay 30 June 2011 Config and Build: Configuration and Building: Basic Concepts 5/53 Configuration Preparing the GCC source for local adaptation: • The platform on which it will be compiled Part 2 • The platform on which the generated compiler will execute • The platform for which the generated compiler will generate code Configuration and Building: • The directory in which the source exists Basic Concepts • The directory in which the compiler will be generated • The directory in which the generated compiler will be installed • The input languages which will be supported • The libraries that are required • etc. Essential Abstractions in GCC GCC Resource Center, IIT Bombay

  3. 30 June 2011 Config and Build: Configuration and Building: Basic Concepts 6/53 30 June 2011 Config and Build: Configuration and Building: Basic Concepts 7/53 Pre-requisites for Configuring and Building GCC 4.6.0 Our Conventions for Directory Names • ISO C90 Compiler / GCC 2.95 or later • GNU bash: for running configure etc • Awk: creating some of the generated source file for GCC • GCC source directory : $(SOURCE D) • bzip/gzip/untar etc. For unzipping the downloaded source file • GCC build directory : $(BUILD) • GNU make version 3.8 (or later) • GCC install directory : $(INSTALL) • GNU Multiple Precision Library (GMP) version 4.3.2 (or later) • Important • mpfr Library version 3.0.0 (or later) ◮ $(SOURCE D) � = $(BUILD) � = $(INSTALL) (multiple precision floating point with correct rounding) ◮ None of the above directories should be contained in any of the • mpc Library version 0.8.2 (or later) above directories • Parma Polyhedra Library (ppl) version 0.11 • CLooG-PPL (Chunky Loop Generator) version 0.15.11 • jar, or InfoZIP (zip and unzip) • libelf version 0.8.12 (or later) (for LTO) Essential Abstractions in GCC GCC Resource Center, IIT Bombay Essential Abstractions in GCC GCC Resource Center, IIT Bombay 30 June 2011 Config and Build: Configuration and Building: Basic Concepts 8/53 30 June 2011 Config and Build: Configuration and Building: Basic Concepts 9/53 Commands for Configuring and Building GCC Order of Steps in Installing GCC 4.6.0 • Building pre-requisites Build and install in the following order with --prefix=/usr/local This is what we specify Run ldconfig after each installation • cd $(BUILD) ◮ GMP 4.3.2 • $(SOURCE D)/configure <options> CPPFLAGS=-fexceptions ./configure --enable-cxx ... ◮ mpfr 3.0.0 configure output: customized Makefile ◮ mpc 0.8.2 • make 2> make.err > make.log ◮ ppl 0.11 ◮ cloog-ppl 0.15.11 • make install 2> install.err > install.log ◮ libelf 0.8.12 • Building gcc Follow the usual steps. Essential Abstractions in GCC GCC Resource Center, IIT Bombay Essential Abstractions in GCC GCC Resource Center, IIT Bombay

  4. 30 June 2011 Config and Build: Configuration and Building: Basic Concepts 10/53 30 June 2011 Config and Build: Configuration and Building: Basic Concepts 11/53 Configuring GCC Steps in Configuration and Building configure.in config/* Usual steps for a Steps for GCC config.guess config.sub other than GCC • Download and untar the source • Download and untar the source configure • cd $(SOURCE D) • cd $(BUILD) config.h.in Makefile.in • ./configure • $(SOURCE D)/configure • make • make config.log config.cache config.status • make install • make install GCC generates a large part of source code during a build! config.h Makefile Essential Abstractions in GCC GCC Resource Center, IIT Bombay Essential Abstractions in GCC GCC Resource Center, IIT Bombay 30 June 2011 Config and Build: Configuration and Building: Basic Concepts 12/53 30 June 2011 Config and Build: Configuration and Building: Basic Concepts 13/53 Building a Compiler: Terminology Variants of Compiler Builds • The sources of a compiler are compiled (i.e. built) on Build system , BS = HS = TS Native Build denoted BS. BS = HS � = TS Cross Build • The built compiler runs on the Host system , denoted HS. BS � = HS � = TS Canadian Cross • The compiler compiles code for the Target system , denoted TS. Example Native i386: built on i386, hosted on i386, produces i386 code. The built compiler itself runs on HS and generates executables that run on TS. Sparc cross on i386: built on i386, hosted on i386, produces Sparc code. Essential Abstractions in GCC GCC Resource Center, IIT Bombay Essential Abstractions in GCC GCC Resource Center, IIT Bombay

  5. 30 June 2011 Config and Build: Configuration and Building: Basic Concepts 14/53 30 June 2011 Config and Build: Configuration and Building: Basic Concepts 15/53 T Notation for a Compiler Bootstrapping: The Conventional View input language output language C i386 implementation language i386 input language output language cc implementation or name of the translator execution language ass m/c Machine language Machine language m/c Assembly language Assembly language Essential Abstractions in GCC GCC Resource Center, IIT Bombay Essential Abstractions in GCC GCC Resource Center, IIT Bombay 30 June 2011 Config and Build: Configuration and Building: Basic Concepts 15/53 30 June 2011 Config and Build: Configuration and Building: Basic Concepts 15/53 Bootstrapping: The Conventional View Bootstrapping: The Conventional View implementation language Level 1 C implementation language input language output language m/c C 1 C 0 m/c C 0 input language output language ass Level 0 C Essential Abstractions in GCC GCC Resource Center, IIT Bombay Essential Abstractions in GCC GCC Resource Center, IIT Bombay

  6. 30 June 2011 Config and Build: Configuration and Building: Basic Concepts 15/53 30 June 2011 Config and Build: Configuration and Building: Basic Concepts 16/53 Bootstrapping: The Conventional View Bootstrapping: GCC View Level n C implementation language C n m/c • Language need not change, but the compiler may change Compiler is improved, bugs are fixed and newer versions are released • To build a new version of a compiler given a built old version: ◮ Stage 1: Build the new compiler using the old compiler ◮ Stage 2: Build another new compiler using compiler from stage 1 ◮ Stage 3: Build another new compiler using compiler from stage 2 C n − 1 Stage 2 and stage 3 builds must result in identical compilers input language output language ⇒ Building cross compilers stops after Stage 1! Essential Abstractions in GCC GCC Resource Center, IIT Bombay Essential Abstractions in GCC GCC Resource Center, IIT Bombay 30 June 2011 Config and Build: Configuration and Building: Basic Concepts 17/53 30 June 2011 Config and Build: Configuration and Building: Basic Concepts 17/53 A Native Build on i386 A Native Build on i386 C i386 C i386 C i386 Execution language C i386 i386 i386 Stage 1 Build cc cc GCC GCC C i386 Source Source i386 gcc Requirement: BS = HS = TS = i386 Requirement: BS = HS = TS = i386 • Stage 1 build compiled using cc • Stage 1 build compiled using cc • Stage 2 build compiled using gcc • Stage 2 build compiled using gcc • Stage 3 build compiled using gcc • Stage 3 build compiled using gcc • Stage 2 and Stage 3 Builds must be • Stage 2 and Stage 3 Builds must be identical for a successful native build identical for a successful native build Essential Abstractions in GCC GCC Resource Center, IIT Bombay Essential Abstractions in GCC GCC Resource Center, IIT Bombay

Recommend


More recommend