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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
EA-GCC, Chamonix Configuration & Building: Basic Concepts 19/1 Difficulty in Building a Cross Compiler Building gcc Uday Khedker GRC, IIT Bombay
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
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
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
EA-GCC, Chamonix Configuration & Building: Basic Concepts 20/1 Building a MIPS Cross Compiler on i386 GCC Source Uday Khedker GRC, IIT Bombay
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Part 2 Detailed Instructions
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
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
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
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
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
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
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
Recommend
More recommend