英文文法可能有若干錯誤請見諒.
若有誤請不吝指教.
PS: 一個充份發揮ARM platform performance的gcc不只做文中所做patch.
若要轉載, 請告知, 並註明作者. Thanks.
- 代碼: 選擇全部
compile cross-compiler gcc-3.4.3 wth glibc-2.3.4 for ARM(920, v4) platform mini howto
Author: Andylin (andylin@wellsyn.com)
1. Require files
Compile cross-compiler need four components -- binutils, gcc, glibc, kernel source
(1) binutils -- binary utility
current latest version -- 2.14
file name: binutils-2.14.tar.gz
where to get:
http://ftp.gnu.org/gnu/binutils/binutils-2.14.tar.gz
(2) gcc -- GNU compiler collection
<1> gcc-core version, which only include c language support. It is be used in first stage gcc compile.
current latest version -- 3.4.3
file name: gcc-core-3.4.3.tar.bz2
where to get:
ftp://ftp.gnu.org/gnu/gcc/gcc-3.4.3/gcc-core-3.4.3.tar.bz2
<2> normal gcc version, which support multi-language. It is be used in final stage gcc compile.
current latest version -- 3.4.3
file name: gcc-3.4.3.tar.bz2
where to get:
ftp://ftp.gnu.org/gnu/gcc/gcc-3.4.3/gcc-3.4.3.tar.bz2
(3) glibc -- GNU library collection
<1> gcc library
current latest version -- 2.3.4
file name: glibc-2.3.4.tar.gz
where to get:
http://ftp.gnu.org/gnu/glibc/glibc-2.3.4.tar.gz
<2> gcc library add on for glibc
current latest version -- 2.3.4
file name: glibc-linuxthreads-2.3.4.tar.bz2
http://ftp.gnu.org/gnu/glibc/glibc-linuxthreads-2.3.4.tar.bz2
(4) Kernel source
<1> Linux kernel source -- appropriate kernel version for compipling cross-compiler we using.
version -- 2.4.26
file name: linux-2.4.26.tar.bz2
where to get:
http://www.kernel.org/pub/linux/kernel/v2.4/linux-2.4.26.tar.bz2
<2> Linux kernel source patch for ARM
version -- 2.4.26-vrs1
file name: patch-2.4.26-vrs1.bz2
where to get:
ftp://ftp.arm.linux.org.uk/pub/armlinux/source/kernel-patches/v2.4/patch-2.4.26-vrs1.bz2
(5) Other utility
<1> Install "info2man" package which is include pod2man utility to produce manunal page.
=======================================================================================================
2. Require directory
We need three directory of types.
(1) tarball source directory -- storage tarball source from GNU website
(2) extra source directory -- storage had de-compressed tarball source
(3) building work directory -- these directories are working directory when we compile toolchain
=======================================================================================================
3. Require environment variable
Because we compile cross-compiler for ARM platform on x86 machine, we must know machine name for variable platform.
Note: the format of a GNU target specification is CPU-PLATFORM-OS
x86/i386 target machine's name : i686-pc-linux-gnu/i686-host_pc-linux-gnu
arm platform target machine's name : arm-linux
We must decide "instalation" directory for install our compiled finish toolchain.
For example: we install my toolchain to "/usr/local/mytoolchain".
therefore, we define and export some environment variable for convenience later.
export TARGET=arm-linux
export PREFIX=/usr/local/mytoolchain
export TARGET_PREFIX=$PREFIX/$TARGET
export PATH=$PATH:$TARGET/bin
note:
If you had install previous version of arm-linux toolchain, you must remove search patch for it from PATH environment variable first.
=======================================================================================================
4. De-compress linux kernel source, patch kernel source and configure kernel source
# tar -jxvf linux-2.4.26.tar.bz2
# bzip2 -cd patch-2.4.26-vrs1.bz2|(cd linux-2.4.26;patch -p1 -s -E)
# cd linux-2.4.26
# make ARCH=arm CROSS_COMPILE=arm-linux- menuconfig
(And then do not modify any thing, Save and exit.)
# make dep
======================================================================================================
5. Copy kernel header file to "installation" directory
# mkdir -p $TARGET_PREFIX/include
# cd linux-2.4.26/include
# cp -a linux $TARGET_PREFIX/include
# cp -a asm-arm $TARGET_PREFIX/include/asm
# cp -a asm-generic $TARGET_PREFIX/include
# cd $TARGET_PREFIX
# ln -s include sys-include
======================================================================================================
6. De-compress other tarball source
<1> De-compress gcc-core
# tar -jxvf gcc-core-3.4.3.tar.bz2
# mv gcc-3.4.3 gcc-core-3.4.3
<2> De-compress gcc
# tar -jxvf gcc-3.4.3.tar.bz2
<3> De-compress glibc and linuxthreads package
# tar -zxvf glibc-2.3.4.tar.gz
# cd glibc-2.3.4
# tar -jxvf ../tar_source/glibc-linuxthreads-2.3.4.tar.bz2
<4> De-compress binutls
# tar -zxvf binutils-2.14.tar.gz
======================================================================================================
7. Patch tarball source
<1> Pach glibc source
Problem : "BUS_ISA" undeclared
Solution: patch ioperm.c
File location:
glibc-2.3.4/sysdeps/unix/sysv/linux/arm/ioperm.c
From:
static int iobase_name[] = { CTL_BUS, BUS_ISA, BUS_ISA_PORT_BASE };
static int ioshift_name[] = { CTL_BUS, BUS_ISA, BUS_ISA_PORT_SHIFT };
To:
static int iobase_name[] = { CTL_BUS, CTL_BUS_ISA, BUS_ISA_PORT_BASE };
static int ioshift_name[] = { CTL_BUS, CTL_BUS_ISA, BUS_ISA_PORT_SHIFT };
<2> Patch glibc source
Problem : ld: cannot find -lgcc_eh
Descript: gcc_eh library is not found.
Solution: patch Makeconfig
File location:
glibc-2.3.4/Makeconfig
From:
libgcc_eh := -lgcc_eh $(libunwind)
To:
libgcc_eh := $(libunwind)
From:
static-gnulib := -lgcc -lgcc_eh $(libunwind)
To:
static-gnulib := -lgcc $(libunwind)
<3> Patch gcc source ( Apply to gcc-3.4.3 and gcc-core-3.4.3)
Problem :
../sysdeps/generic/s_fmax.c:28: internal compiler error: in elim_reg_cond, at flow.c:3257
Please submit a full bug report,
with preprocessed source if appropriate.
Solution: patch flow.c
File location:
gcc-3.4.3/gcc/flow.c
In line 1878, add
enum rtx_code inv_cond;
Like bellow:
rtx set_src = SET_SRC (pc_set (BB_END (bb)));
rtx cond_true = XEXP (set_src, 0);
rtx reg = XEXP (cond_true, 0);
enum rtx_code inv_cond; <---- Add
In line 1886, replace from:
in the form of a comparison of a register against zero.
If the condition is more complex than that, then it is safe
not to record any information. */
if (GET_CODE (reg) == REG
Replace to:
in the form of a reversible comparison of a register against
zero. If the condition is more complex than that, then it is
safe not to record any information. */
inv_cond = reversed_comparison_code (cond_true, BB_END (bb));
if (inv_cond != UNKNOWN
&& GET_CODE (reg) == REG
In line 1893, replace from:
= gen_rtx_fmt_ee (reverse_condition (GET_CODE (cond_true)),
Replace to:
= gen_rtx_fmt_ee (inv_cond,
========================================================================================================================
8. Compile binary utility
# cd build_binutils
# rm -fr *
# ../binutils-2.14/configure --target=$TARGET --prefix=$PREFIX --disable-nls
# make all
# make install
=============================================================================================================
9. Compile first stage gcc
# cd build_gcc
# rm -fr *
# ../gcc-core-3.4.3/configure --target=$TARGET --prefix=$PREFIX --enable-languages=c --disable-threads --disable-shared
# make all
# make install
==============================================================================================================
10. Compile glibc
# cd build_glibc
# rm -fr *
# CC=$TARGET-gcc AR=$TARGET-ar LD=$TARGET-ld AS=$TARGET-as RANLIB=$TARGET-ranlib ../glibc-2.3.4/configure $TARGET --host=$TARGET --build=i686-host_pc-linux-gnu --prefix=$TARGET_PREFIX --enable-add-ons=linuxthreads --enable-shared
# make all
# make install
=======================================================================================================================
11. Compile final stage gcc
# cd build_gcc
# rm -fr *
# ../gcc-3.4.3/configure --target=$TARGET --host=i686-host_pc-linux-gnu --prefix=$PREFIX -with-headers=$TARGET_PREFIX/include --with-local-prefix=$TARGET_PREFIX --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-__cxa_atexit --enable-languages=c,c++ --enable-shared --enable-c99 --enable-long-long
# make all
# make install
========================================================================================================
Appendix A.
/* Read gcc configuration setting */
# arm-linux-gcc -v
Reading specs from /usr/local/mytoolchain/lib/gcc/arm-linux/3.4.3/specs
Configured with: ../gcc-3.4.3/configure --target=arm-linux --host=i686-host_pc-linux-gnu --prefix=/usr/local/mytoolchain -with-headers=/usr/local/mytoolchain/arm-linux/include --with-local-prefix=/usr/local/mytoolchain/arm-linux --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-__cxa_atexit --enable-languages=c,c++ --enable-shared --enable-c99 --enable-long-long
Thread model: posix
gcc version 3.4.3
GCC related document
gcc-3.4.3/gcc/doc/gccinstall.info
GLIBC related document
/glibc-2.3.4/INSTALL