2011年5月14日 星期六

GCC-4.6.0 arm-none-linux-gnueabi build script for both little and big endian static toolchain

1) gcc-4.6.0 with arm-none-linux-gnueabi
2) support both -mlittle-endian and -mbig-endian
3) default -mhard-float and multilib for cortex-a9
4) static-build gcc/g++

The patches to gcc-4.6.0:

diff -uNr src/gcc-4.6.0/gcc-4.6.0/gcc/config/arm/linux-eabi.h gcc-4.6.0/gcc/config/arm/linux-eabi.h
--- src/gcc-4.6.0/gcc-4.6.0/gcc/config/arm/linux-eabi.h 2011-01-12 22:29:14.000000000 +0800
+++ gcc-4.6.0/gcc/config/arm/linux-eabi.h       2011-05-11 23:29:29.012044669 +0800
@@ -101,3 +101,6 @@
    is used.  */ 
 #undef  CLEAR_INSN_CACHE
 #define CLEAR_INSN_CACHE(BEG, END) not_used
+
+#undef SYSROOT_SUFFIX_SPEC
+#define SYSROOT_SUFFIX_SPEC "%{mbig-endian:/be}"
diff -uNr src/gcc-4.6.0/gcc-4.6.0/gcc/config/arm/linux-elf.h gcc-4.6.0/gcc/config/arm/linux-elf.h
--- src/gcc-4.6.0/gcc-4.6.0/gcc/config/arm/linux-elf.h  2011-01-15 02:42:32.000000000 +0800
+++ gcc-4.6.0/gcc/config/arm/linux-elf.h        2011-05-14 20:06:44.188276102 +0800
@@ -51,7 +51,7 @@

 #undef  MULTILIB_DEFAULTS
 #define MULTILIB_DEFAULTS \
-       { "marm", "mlittle-endian", "mhard-float", "mno-thumb-interwork" }
+       { "marm", TARGET_ENDIAN_OPTION, "mhard-float", "mno-thumb-interwork" }

 /* Now we define the strings used to build the spec file.  */ 
 #undef  LIB_SPEC
diff -uNr src/gcc-4.6.0/gcc-4.6.0/gcc/config/arm/t-arm-elf gcc-4.6.0/gcc/config/arm/t-arm-elf
--- src/gcc-4.6.0/gcc-4.6.0/gcc/config/arm/t-arm-elf    2011-01-04 04:52:22.000000000 +0800
+++ gcc-4.6.0/gcc/config/arm/t-arm-elf  2011-05-14 21:50:58.517726008 +0800
@@ -36,6 +36,10 @@
 MULTILIB_EXCEPTIONS  =  
 MULTILIB_MATCHES     =  

+MULTILIB_OPTIONS     += mcpu=cortex-a9
+MULTILIB_DIRNAMES    += cortex-a9
+MULTILIB_EXCEPTIONS  +=
+
 #MULTILIB_OPTIONS     += mcpu=fa526/mcpu=fa626/mcpu=fa606te/mcpu=fa626te/mcpu=fmp626/mcpu=fa726te
 #MULTILIB_DIRNAMES    += fa526 fa626 fa606te fa626te fmp626 fa726te
 #MULTILIB_EXCEPTIONS  += *mthumb*/*mcpu=fa526 *mthumb*/*mcpu=fa626
@@ -67,6 +71,10 @@
 # MULTILIB_DIRNAMES    += le be
 # MULTILIB_MATCHES     += mbig-endian=mbe mlittle-endian=mle
 #
+MULTILIB_OPTIONS     += mbig-endian
+MULTILIB_DIRNAMES    += be
+MULTILIB_MATCHES     += mbig-endian=mbe
+#
 # MULTILIB_OPTIONS    += mhard-float/msoft-float
 # MULTILIB_DIRNAMES   += fpu soft
 # MULTILIB_EXCEPTIONS += *mthumb/*mhard-float*
diff -uNr src/gcc-4.6.0/gcc-4.6.0/gcc/config/arm/t-linux gcc-4.6.0/gcc/config/arm/t-linux
--- src/gcc-4.6.0/gcc-4.6.0/gcc/config/arm/t-linux      2009-04-22 03:03:23.000000000 +0800
+++ gcc-4.6.0/gcc/config/arm/t-linux    2011-05-11 23:34:24.503749908 +0800
@@ -28,6 +28,9 @@
 # MULTILIB_OPTIONS = mhard-float/msoft-float
 # MULTILIB_DIRNAMES = hard-float soft-float

+MULTILIB_OPTIONS += mbig-endian
+MULTILIB_DIRNAMES += be
+
 # EXTRA_MULTILIB_PARTS = crtbegin.o crtend.o


 # LIBGCC = stmp-multilib
diff -uNr src/gcc-4.6.0/gcc-4.6.0/gcc/config/arm/t-linux-eabi gcc-4.6.0/gcc/config/arm/t-linux-eabi
--- src/gcc-4.6.0/gcc-4.6.0/gcc/config/arm/t-linux-eabi 2011-01-04 04:52:22.000000000 +0800
+++ gcc-4.6.0/gcc/config/arm/t-linux-eabi       2011-05-14 21:50:19.527668816 +0800
@@ -21,8 +21,22 @@

 # We do not build a Thumb multilib for Linux because the definition of
 # CLEAR_INSN_CACHE in linux-gas.h does not work in Thumb mode.
-MULTILIB_OPTIONS       =
-MULTILIB_DIRNAMES      =
+MULTILIB_OPTIONS     = marm
+MULTILIB_DIRNAMES    = arm
+MULTILIB_EXCEPTIONS  =
+MULTILIB_MATCHES     =
+
+MULTILIB_OPTIONS     += mcpu=cortex-a9
+MULTILIB_DIRNAMES    += cortex-a9
+MULTILIB_EXCEPTIONS  +=
+
+MULTILIB_OPTIONS     += mbig-endian
+MULTILIB_DIRNAMES    += be
+MULTILIB_MATCHES     += mbig-endian=mbe
+
+#MULTILIB_OPTIONS    += mfloat-abi=hard
+#MULTILIB_DIRNAMES   += fpu
+#MULTILIB_EXCEPTIONS += *mthumb/*mfloat-abi=hard*

 #MULTILIB_OPTIONS     += mcpu=fa606te/mcpu=fa626te/mcpu=fmp626/mcpu=fa726te
 #MULTILIB_DIRNAMES    += fa606te fa626te fmp626 fa726te

The build script for arm-none-linux-gnueabi:

[1-build-binutils.sh]
#!/bin/bash
cd ${BUILDPATH}
mkdir -v binutils-build
cd binutils-build
AR=ar AS=as ${BINUTILS_SRC}/configure --build=${HOST} --host=${HOST} --target=${TARGET} --prefix=${PREFIX} --with-lib-path=${PREFIX}/${TARGET}/lib:${PREFIX}/${TARGET}/lib/be --with-sysroot=${PREFIX}/${TARGET} --disable-nls --enable-shared --enable-install-libbfd --enable-interwork --with-v4bx-interworking --enable-multilib
make configure-host
make LDFLAGS="-static"
make install

[3-build-headers.sh]
#!/bin/bash
echo "Prepare Linux kernel headers"

cd ${LINUX_HEADER_SRC}
make ARCH=arm CROSS_COMPILE=${TARGET}- INSTALL_HDR_PATH=${PREFIX}/${TARGET} headers_install

[4-build-gcc.sh]
#!/bin/bash
if test x"${BOOTSTRAP_PREFIX}" != x"${PREFIX}"; then
    mkdir -p ${BOOTSTRAP_PREFIX}/${TARGET}/bin
    for tool in ar as ld strip ranlib; do
        rm -f ${BOOTSTRAP_PREFIX}/${TARGET}/bin/${tool} || true
        ln -s ${PREFIX}/bin/${TARGET}-${tool} ${BOOTSTRAP_PREFIX}/${TARGET}/bin/${tool}
    done
fi

echo "Build bootstrap gcc"

cd ${BUILDPATH}
mkdir -v gcc-build
cd gcc-build

#mkdir -p mpfr
#cp ${GCC_SRC}/gmp/gmp-impl.h ./mpfr
#cp ${GCC_SRC}/gmp/longlong.h ./mpfr

# http://comments.gmane.org/gmane.linux.lfs.devel/10631
# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47836
# need --disable-shared --disable-lto --disable-libquadmath --without-target-libiberty --without-target-zlib
${GCC_SRC}/configure --build=${HOST} --host=${HOST} --target=${TARGET} --prefix=${BOOTSTRAP_PREFIX} --with-local-prefix=${BOOTSTRAP_PREFIX}/${TARGET} --without-target-libiberty --without-target-zlib --disable-libquadmath --disable-lto --disable-libstdcxx-pch --disable-libffi --enable-multilib --disable-nls --disable-libgomp --disable-libmudflap --disable-libssp --enable-gold --enable-ld --enable-symvers=gnu --enable-__cxa_atexit --enable-languages=c --disable-shared --disable-threads --without-headers --disable-decimal-float --enable-mpfr --enable-gmp --without-cloog --without-ppl --with-float=hard --with-v4bx-interworking --with-gnu-as --with-gnu-ld --with-cpu=${DEFAULT_CPU} --with-libelf=${LIBELF_PREFIX} --with-mpc=${MPC_PREFIX}
make
make install

[5-build-glibc.sh]
#!/bin/bash
if test x"${BOOTSTRAP_PREFIX}" != x"${PREFIX}"; then
    ln -s ${PREFIX}/${TARGET}/include ${BOOTSTRAP_PREFIX}/${TARGET}/include
fi

cd ${BUILDPATH}
mkdir -v glibc-build
cd glibc-build
cat > config.cache << EOF
libc_cv_forced_unwind=yes
libc_cv_c_cleanup=yes
libc_cv_arm_tls=yes
libc_cv_gnu89_inline=yes
EOF

# http://newsgroups.derkeiler.com/Archive/Comp/comp.lang.awk/2009-03/msg00088.html
# glibc-2.13 may have [^/], replace it with [^\/] in gen-sorted.awk
# need to install gawk
BUILD_CC="gcc" CC="${TARGET}-gcc" AR="${TARGET}-ar" RANLIB="${TARGET}-ranlib" ${GLIBC_SRC}/configure --prefix=/usr --build=${HOST} --host=${TARGET} --target=${TARGET} --without-cvs --disable-profile --disable-debug --without-gd --with-fp --disable-libunwind-exceptions --cache-file=config.cache --enable-kernel=2.6.38 --with-binutils=${PREFIX}/bin --enable-add-ons=ports,nptl --with-tls --with-__thread --with-arch=${DEFAULT_ARCH} --enable-multilib --enable-sim --enable-shared --enable-multi-arch --with-v4bx-interworking --with-headers=${PREFIX}/${TARGET}/include
make V=1 LD=${TARGET}-ld RANLIB=${TARGET}-ranlib all
make install_root=${PREFIX}/${TARGET} prefix= install

# modify libc.so  libpthread.so
# GROUP ( /lib/libc.so.6 /lib/libc_nonshared.a  AS_NEEDED ( /lib/ld-linux.so.2 ) ) ---> GROUP ( libc.so.6 libc_nonshared.a  AS_NEEDED ( ld-linux.so.2 ) )


cd ${BUILDPATH}
rm -rf glibc-build
mkdir -v glibc-build
cd glibc-build
cat > config.cache << EOF
libc_cv_forced_unwind=yes
libc_cv_c_cleanup=yes
libc_cv_arm_tls=yes
libc_cv_gnu89_inline=yes
libc_cv_slibdir=${PREFIX}/${TARGET}/lib/be
EOF

# http://newsgroups.derkeiler.com/Archive/Comp/comp.lang.awk/2009-03/msg00088.html
# glibc-2.13 may have [^/], replace it with [^\/] in gen-sorted.awk
# need to install gawk
BUILD_CC="gcc" CC="${TARGET}-gcc -mbig-endian -Wl,-EB" AR="${TARGET}-ar" AS="${TARGET}-as -mbig-endian" RANLIB="${TARGET}-ranlib" LD="${TARGET}-ld" ${GLIBC_SRC}/configure --prefix=${PREFIX}/${TARGET} --build=${HOST} --host=${TARGET} --target=${TARGET} --libdir=${PREFIX}/${TARGET}/lib/be --without-cvs --disable-profile --disable-debug --without-gd --with-fp --disable-libunwind-exceptions --cache-file=config.cache --enable-kernel=2.6.38 --with-binutils=${PREFIX}/bin --enable-add-ons=ports,nptl --with-tls --with-__thread --with-arch=${DEFAULT_ARCH} --enable-multilib --enable-sim --enable-shared --enable-multi-arch --with-v4bx-interworking --with-headers=${PREFIX}/${TARGET}/include
make V=1
make install

# modify libc.so  libpthread.so
# GROUP ( /lib/libc.so.6 /lib/libc_nonshared.a  AS_NEEDED ( /lib/ld-linux.so.2 ) ) ---> GROUP ( libc.so.6 libc_nonshared.a  AS_NEEDED ( ld-linux.so.2 ) )

# From crosstool 0.43
# Fix problems in linker scripts.
#
# 1. Remove absolute paths
# Any file in a list of known suspects that isn't a symlink is assumed to be a linker script.
# FIXME: test -h is not portable
# FIXME: probably need to check more files than just these three...
# Need to use sed instead of just assuming we know what's in libc.so because otherwise alpha breaks
#
# 2. Remove lines containing BUG per http://sources.redhat.com/ml/bug-glibc/2003-05/msg00055.html,
# needed to fix gcc-3.2.3/glibc-2.3.2 targeting arm
#
# To make "strip *.so.*" not fail (ptxdist does this), rename to .so_orig rather than .so.orig
for file in libc.so libpthread.so libgcc_s.so; do
    for lib in lib lib/be lib64 usr/lib usr/lib64; do
      if test -f ${PREFIX}/${TARGET}/$lib/$file && test ! -h ${PREFIX}/${TARGET}/$lib/$file; then
        mv ${PREFIX}/${TARGET}/$lib/$file ${PREFIX}/${TARGET}/$lib/${file}_orig
        sed 's,/opt/build/arm-none-linux-gnueabi-4.6.0/arm-none-linux-gnueabi/lib/be/,,g;s,/usr/lib/,,g;s,/usr/lib64/,,g;s,/lib/,,g;s,/lib64/,,g;s,${PREFIX}/${TARGET}/lib/be,,g;/BUG in libc.scripts.output-format.sed/d' < ${PREFIX}/${TARGET}/$lib/${file}_orig > ${PREFIX}/${TARGET}/$lib/$file
        rm -f ${PREFIX}/${TARGET}/$lib/${file}_orig
      fi
    done
done


# link for other multilib options that uses mbig-endian, or they would link to default
# target library that is mlittle-endian

cd ${PREFIX}/${TARGET}/lib; mkdir -p cortex-a9; cd cortex-a9; ln -s ../be be

[6-build-gcc-final.sh]
#!/bin/bash
cd ${BUILDPATH}
mkdir -v gcc-build-final
cd gcc-build-final

#mkdir -p mpfr
#cp ${GCC_SRC}/gmp/gmp-impl.h ./mpfr
#cp ${GCC_SRC}/gmp/longlong.h ./mpfr

AR=ar ${GCC_SRC}/configure --prefix=${PREFIX} --build=${HOST} --host=${HOST} --target=${TARGET} --with-cpu=${DEFAULT_CPU} --with-pkgversion='M.F. C/C++ Compiler Release 20110423' --disable-nls --disable-libssp --disable-libgomp --enable-gold --enable-ld --enable-threads=posix --disable-tls --enable-symvers=gnu --enable-c99 --enable-long-long --enable-multilib --enable-languages=c,c++ --enable-__cxa_atexit --with-float=hard --enable-cxx-flags=-mhard-float --enable-shared --enable-gmp --enable-mpfr --enable-cloog --enable-ppl --with-v4bx-interworking --with-headers=${PREFIX}/${TARGET}/include --with-libelf=${LIBELF_PREFIX} --with-mpc=${MPC_PREFIX}

make AS_FOR_TARGET="${TARGET}-as" LD_FOR_TARGET="${TARGET}-ld" LDFLAGS="-L${PREFIX}/${TARGET}/lib -L${PREFIX}/${TARGET}/lib/be -static" all
make install

rm -f ${PREFIX}/bin/${TARGET}-gccbug
strip ${PREFIX}/bin/*
strip ${PREFIX}/${TARGET}/bin/ar
strip ${PREFIX}/${TARGET}/bin/as
strip ${PREFIX}/${TARGET}/bin/c++
strip ${PREFIX}/${TARGET}/bin/g++
strip ${PREFIX}/${TARGET}/bin/gcc
strip ${PREFIX}/${TARGET}/bin/ld
strip ${PREFIX}/${TARGET}/bin/nm
strip ${PREFIX}/${TARGET}/bin/objcopy
strip ${PREFIX}/${TARGET}/bin/objdump
strip ${PREFIX}/${TARGET}/bin/ranlib
strip ${PREFIX}/${TARGET}/bin/strip
strip ${PREFIX}/libexec/gcc/${TARGET}/${GCC_VER}/cc1
strip ${PREFIX}/libexec/gcc/${TARGET}/${GCC_VER}/cc1plus
strip ${PREFIX}/libexec/gcc/${TARGET}/${GCC_VER}/collect2

[build-all.sh]
#!/bin/bash
set -ex

#HOST=i686-pc-linux-gnu
HOST=x86_64-linux-gnu
TARGET=arm-none-linux-gnueabi
DEFAULT_ARCH=armv7
DEFAULT_CPU=cortex-a9

# Specify the source path of each package
BINUTILS_SRC=/opt/binutils-2.21
GCC_VER=4.6.0
GCC_SRC=/opt/gcc-${GCC_VER}
GLIBC_SRC=/opt/src/glibc-2.13
LINUX_HEADER_SRC=/opt/linux-2.6.38

LOCAL_DIR=${PWD}
BUILDPATH=${LOCAL_DIR}/build
PREFIX=/opt/build/${TARGET}-${GCC_VER}
BOOTSTRAP_PREFIX=${BUILDPATH}/${TARGET}-${GCC_VER}
#MPFR_PREFIX=${PREFIX}/libmpfr
#GMP_PREFIX=${PREFIX}/libgmp
MPFR_PREFIX=/usr
GMP_PREFIX=/usr
MPC_PREFIX=/usr
LIBELF_PREFIX=/usr

unset LD_LIBRARY_PATH
unset LIBRARY_PATH
unset LD_RUN_PATH

if [ -e ${GCC_SRC}/newlib ]; then
  mv ${GCC_SRC}/newlib ${GCC_SRC}/newlib.orig
fi

mkdir -v ${BUILDPATH}
source ${LOCAL_DIR}/1-build-binutils.sh
##source ${LOCAL_DIR}/2-build-gmp-mpfr.sh
source ${LOCAL_DIR}/3-build-headers.sh
if test x"${BOOTSTRAP_PREFIX}" != x"${PREFIX}"; then
    export PATH=${BOOTSTRAP_PREFIX}/bin:${PATH}
fi
export PATH=${PREFIX}/bin:${PATH}
export LD_LIBRARY_PATH=${GMP_PREFIX}/lib:${MPFR_PREFIX}/lib
source ${LOCAL_DIR}/4-build-gcc.sh
source ${LOCAL_DIR}/5-build-glibc.sh
source ${LOCAL_DIR}/6-build-gcc-final.sh

if [ -e ${GCC_SRC}/newlib.orig ]; then
  mv ${GCC_SRC}/newlib.orig ${GCC_SRC}/newlib
fi

沒有留言:

張貼留言