Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1745424
  • 博文数量: 1493
  • 博客积分: 38
  • 博客等级: 民兵
  • 技术积分: 5834
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-19 17:28
文章分类

全部博文(1493)

文章存档

2016年(11)

2015年(38)

2014年(137)

2013年(253)

2012年(1054)

2011年(1)

分类: LINUX

2014-04-15 10:14:32

最近在做一个ARM板子的linux 系统时,发生了一个诡异的问题:busybox失败,定位后发现如果open一个不存在的文件,则会直接产生SIGSEGV异常,而不是open返回-1,如果打开存在的文件,则不会有问题。怀疑失败原因是glibc库与kernel的版本不匹配,于是干脆自己动手做了个toolchain。
经过一个周末的折腾,在""上面script的帮助下,终于制作出了自己的tool chain :)
有了与kernel匹配的glibc库,之前open的问题就消失了。

下面是我的编译脚本:

点击(此处)折叠或打开

  1. #!/bin/bash

  2. # author: fireaxe.hq
  3. # description: The script for building crosstool automatically
  4. # usage: chmod +x crosstool-4.8.2.sh && ./crosstool-4.8.2.sh
  5. # linux-3.12.17
  6. # binutils-2.24 glibc-2.18 glibc-ports-2.16.0 gcc-4.8.2

  7. function set_sys
  8. {
  9.     apt-get update && apt-get install build-essential libncurses5-dev gawk libmpfr-dev -y
  10. }

  11. function set_env
  12. {
  13.     export USRROOT=/home/hao1404/Desktop
  14.     export KRNROOT=${USRROOT}/kernel/linux-3.12.17
  15.     export SRCROOT=${USRROOT}/toolchain

  16.     export TARGET=arm-qhao-linux-gnueabi

  17.     export PREFIX=/opt/mytoolchain
  18.     export BUILD=${SRCROOT}/build-tools
  19.     export TARGET_PREFIX=${PREFIX}/${TARGET}
  20.     export PATH=${PREFIX}/bin:${PATH}
  21. }

  22. function create_dir
  23. {
  24.     mkdir -p ${BUILD}/build-binutils ${BUILD}/build-boot-gcc ${BUILD}/build-gcc ${BUILD}/build-glibc ${BUILD}/build-glibc-headers
  25.     mkdir -p ${TARGET_PREFIX}
  26. }

  27. function install_gmp_mpc_mpfr
  28. {
  29.     cd ${SRCROOT}

  30.     cd gmp-6.0.0
  31.     ./configure --prefix=/usr/local/gmp-6.0.0
  32.     make
  33.     make install
  34.     make distclean

  35.     cd ../mpc-1.0.2
  36.     ./configure --prefix=/usr/local/mpc-1.0.2
  37.     make
  38.     make install
  39.     make distclean

  40.     cd ../mpfr-3.1.2
  41.     ./configure --prefix=/usr/local/mpfr-3.1.2
  42.     make
  43.     make install
  44.     make distclean
  45. }

  46. function install_cross_binutils
  47. {
  48.     cd ${BUILD}
  49.     cd build-binutils
  50.     ../../binutils-2.24/configure --target=${TARGET} --prefix=${PREFIX} --with-sysroot=${TARGET_PREFIX}
  51.     make
  52.     make install
  53. }

  54. function install_cross_gcc
  55. {
  56.     cd ${BUILD}
  57.     rm -rf ../gcc-4.8.2/gmp
  58.     rm -rf ../gcc-4.8.2/mpc
  59.     rm -rf ../gcc-4.8.2/mpfr
  60.     cp -r ../gmp-6.0.0 ../gcc-4.8.2/gmp
  61.     cp -r ../mpc-1.0.2 ../gcc-4.8.2/mpc
  62.     cp -r ../mpfr-3.1.2 ../gcc-4.8.2/mpfr
  63.     cd build-boot-gcc
  64.     ../../gcc-4.8.2/configure --target=${TARGET} --prefix=${PREFIX} --with-sysroot=${TARGET_PREFIX} --with-arch=armv7-a --disable-shared --disable-threads --disable-multilib --without-headers --with-newlib --enable-languages=c,c++ -with-gmp=/usr/local/gmp-6.0.0 -with-mpfr=/usr/local/mpfr-3.1.2 -with-mpc=/usr/local/mpc-1.0.2
  65.     make all-gcc
  66.     make install-gcc
  67.     make all-target-libgcc
  68.     make install-target-libgcc
  69. }

  70. function install_linux_headers
  71. {
  72.     cd ${KRNROOT}
  73.     make headers_install
  74.     cp -r ../obj/linux/tmparm/usr/include ${TARGET_PREFIX}
  75. }

  76. function install_glibc_headers
  77. {
  78.     cd ${BUILD}
  79.     cp -r ../glibc-ports-2.16.0 ../glibc-2.18/ports
  80.     cd build-glibc-headers
  81.     echo "libc_cv_forced_unwind=yes" > config.cache
  82.     echo "libc_cv_c_cleanup=yes" >> config.cache
  83.     echo "libc_cv_arm_tls=yes" >> config.cache
  84.     ../../glibc-2.18/configure --host=${TARGET} --prefix="/usr" --with-sysroot=${TARGET_PREFIX} --enable-add-ons --with-headers=${TARGET_PREFIX}/include --cache-file=config.cache
  85.     make cross-compiling=yes install_root=${TARGET_PREFIX} prefix="" install-headers
  86. }

  87. function install_glibc
  88. {
  89.     cd ${BUILD}/build-glibc
  90.     echo "libc_cv_forced_unwind=yes" > config.cache
  91.     echo "libc_cv_c_cleanup=yes" >> config.cache
  92.     CC=${TARGET}-gcc ../../glibc-2.18/configure --host=${TARGET} --prefix="/usr" --with-sysroot=${TARGET_PREFIX} --enable-add-ons --with-headers=${TARGET_PREFIX}/include --cache-file=config.cache
  93.     ln -s ${PREFIX}/lib/gcc/arm-qhao-linux-gnueabi/4.8.2/libgcc.a ${PREFIX}/lib/gcc/arm-qhao-linux-gnueabi/4.8.2/libgcc_s.a
  94.     ln -s ${PREFIX}/lib/gcc/arm-qhao-linux-gnueabi/4.8.2/libgcc.a ${PREFIX}/lib/gcc/arm-qhao-linux-gnueabi/4.8.2/libgcc_eh.a
  95.     make
  96.     make install_root=${TARGET_PREFIX} prefix="" install
  97. }

  98. function install_gcc
  99. {
  100.     cd ${BUILD}/build-gcc
  101.      mkdir ${TARGET_PREFIX}/usr
  102.     ln -s ${TARGET_PREFIX}/include ${TARGET_PREFIX}/usr/include
  103.     ../../gcc-4.8.2/configure --target=${TARGET} --prefix=${PREFIX} --with-sysroot=${TARGET_PREFIX} --with-arch=armv7-a --enable-shared --enable-__cxa_atexit --disable-nls --enable-c99 --enable-long-long --enable-threads=posix --enable-languages=c,c++ -with-gmp=/usr/local/gmp-6.0.0 -with-mpfr=/usr/local/mpfr-3.1.2 -with-mpc=/usr/local/mpc-1.0.2
  104.     sed -i 's/\/lib\///g' ${TARGET_PREFIX}/lib/libc.so
  105.     sed -i 's/\/lib\///g' ${TARGET_PREFIX}/lib/libpthread.so
  106.     make all
  107.     make install
  108. }

  109. function clean_tempfiles
  110. {
  111.     cd ${SRCROOT}
  112.     rm -rf build-tools
  113.     rm -rf gcc-4.8.2/gmp
  114.     rm -rf gcc-4.8.2/mpc
  115.     rm -rf gcc-4.8.2/mpfr
  116. }

  117. echo =============== set_sys
  118. # set_sys
  119. echo =============== set_env
  120. set_env
  121. echo =============== start create_dir
  122. # create_dir
  123. echo =============== start install_gmp_mpc_mpfr
  124. # install_gmp_mpc_mpfr
  125. echo =============== start install_cross_binutils
  126. # install_cross_binutils
  127. echo =============== install_cross_gcc
  128. # install_cross_gcc
  129. echo =============== start install_glibc
  130. # install_linux_headers
  131. echo =============== start install_glibc_headers
  132. # install_glibc_headers
  133. echo =============== start install_gcc
  134. # install_glibc
  135. echo =============== start install_linux_headers
  136.  install_gcc
  137. echo =============== start test
  138. # clean temp files
  139. echo =============== start cleaning
  140. clean_tempfiles

特别感谢:
其他参考链接:




阅读(606) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~