220 likes | 403 Views
Make Toolchain. Speaker: Yi-Ji Jheng Date: 2007.11.21. Outline. Make Toolchain. Make Toolchain. Compiler of envirnoment. Compiler envirnoment need : Binutil ( Assembler and linker ) Gcc ( C compiler ) Glibc ( C library ) Difficult point when implement:. Solve questions of menthod.
E N D
Make Toolchain Speaker: Yi-Ji Jheng Date: 2007.11.21
Outline • Make Toolchain
Compiler ofenvirnoment • Compiler envirnomentneed: • Binutil(Assembler and linker) • Gcc(Ccompiler) • Glibc(Clibrary) • Difficultpointwhenimplement:
Solvequestionsofmenthod • 1.Usenewlibreplaceglibc • 2.Stealsomecodefromglibctocompilergcc • 3.(a)Compiletinygccfirst (b)Usetinygcctocompileglibc (c)Useglibctocompilecompletegcc
Install Flow Make Kernel Header Install binutils Install gcc (temporary) Install glibc Key Install gcc (complete) Packet Toolchain
Source Of Environment • /root/ |-linux-2.4.25.tar.gz • toolchain/ |-binutils-2.14.tar.gz |-gcc-3.2.3.tar.gz |-glibc-2.2.5.tar.gz |-glibc-2.2.5.patch |-glibc-linuxthreads-2.2.5.tar.gz |-t-linux.final |-t-linux.temp
Make Kernel Header • #tar zxvf linux-2.4.25.tar.gz • #cd ./linux-2.4.25 • #make clean && make mrproper • #cp -a /boot/config-2.4.20-8 ./.config • #make menuconfig linux-2.4.25/include/linux/ |-autoconf.h |-version.h
Backup • #mv /usr/local /usr/local.bak • #mkdir -p /usr/local • Default install path (gcc、glibc、binutils) is in /usr/local/
Install Binutils • #tar zxvf binutils-2.14.tar.gz • #cd ./binutils-2.14 • #mkdir i586-linux&&cd ./i586-linux/ • #../configure --target=i586-linux • #make && make install • #ll /usr/local/bin |-i586-linux-ld |-i586-linux-as . .
Install GCC (temporary) (1/2) • #tar zxvf gcc-3.2.3.tar.gz • #cd ./gcc-3.2.3 • #cp -f ../t-linux.temp gcc/config/t-linux • #mkdir i586-linux-temp • #cd ./i586-linux-temp
Install GCC (temporary) (2/2) • #../configure \ --target=i586-linux \ --disable-shared \ --disable-threads \ --with-headers=/root/linux-2.4.25/include \ --enable-languages=c • #make && make install • #ll /usr/local/bin |-i586-linux-cpp |-i586-linux-gcc .
Install Glibc (1/2) • #tar zxvf glibc-2.2.5.tar.gz • #tar zxvf glibc-linuxthreads-2.2.5.tar.gz \ -C ./glibc-2.2.5 • #cd ./glibc-2.2.5 • #patch -p1 < ../glibc-2.2.5.patch • #mkdir i586-linux • #cd ./i586-linux/
Install Glibc (2/2) • #CC=i586-linux-gcc && \ AS=i586-linux-as && \ LD=i586-linux-ld • #../configure i586-linux \ --with-headers=/root/linux-2.4.25/include \ --enable-add-ons \ --enable-shared \ --prefix=/usr/local/i586-linux • #make && make install
Install GCC (complete) (1/2) • #cd gcc-3.2.3 • #cp -f ../t-linux.final gcc/config/t-linux • #mkdir i586-linux-final • #cd i586-linux-final
Install GCC (complete) (2/2) • #../configure \ --target=i586-linux \ --disable-shared \ --with-headers=/root/linux-2.4.25/include \ --with-gnu-as \ --with-gnu-ld \ --enable-multilib \ --enable-languages="c,c++" • #make && make install
Packet Toolchain • #tar cvzf i586-linux-tools.tar.gz /usr/local/
Test • Compile a program(hello world) with i386-toolchain • Put it on the floppy linux • Execute it
t-linux.temp • STMP_FIXPROTO = • CRTSTUFF_T_CFLAGS_S = -fPIC • TARGET_LIBGCC2_CFLAGS = -fPIC -Dinhibit_libc -D__gthr_posix_h • T_CFLAGS = -Dinhibit_libc -D__gthr_posix_h • SHLIB_MAPFILES += $(srcdir)/config/libgcc-glibc.ver • LIB2ADDEH = $(srcdir)/unwind-dw2.c $(srcdir)/unwind-dw2-fde-glibc.c $(srcdir)/unwind-sjlj.c • LIB2ADDEHDEP = unwind.incunwind-dw2-fde.h unwind-dw2-fde.c
errlist.os • #vi sysdeps/unix/sysv/linux/errlist.c strong_alias(__old_sys_nerr,_old_sys_nerr); weak_alias(__old_sys_nerr, _old_sys_nerr) Change to : weak_alias(__old_sys_nerr, _old_sys_nerr) strong_alias(__old_sys_nerr,_old_sys_nerr);
t-linux.final • STMP_FIXPROTO = • CRTSTUFF_T_CFLAGS_S = -fPIC • TARGET_LIBGCC2_CFLAGS = -fPIC -D__gthr_posix_h • T_CFLAGS = -D__gthr_posix_h • SHLIB_MAPFILES += $(srcdir)/config/libgcc-glibc.ver • LIB2ADDEH = $(srcdir)/unwind-dw2.c $(srcdir)/unwind-dw2-fde-glibc.c $(srcdir)/unwind-sjlj.c • LIB2ADDEHDEP = unwind.incunwind-dw2-fde.h unwind-dw2-fde.c