前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >解决编译mips gcc 5.2.0

解决编译mips gcc 5.2.0

作者头像
10km
发布2019-05-25 22:40:59
2.2K0
发布2019-05-25 22:40:59
举报
文章被收录于专栏:10km的专栏10km的专栏

版权声明:本文为博主原创文章,转载请注明源地址。 https://cloud.tencent.com/developer/article/1433779

因为厂商提供mips交叉编译器不太满足要求,今天在ubuntu 16.04下尝试编译mips交叉编译器(gcc 5.2.0),在编译到mpfr时报了个错:

/bin/bash ./libtool --tag=CC   --mode=compile mips-linux-gnu-gcc -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DTIME_WITH_SYS_TIME=1 -DHAVE_LOCALE_H=1 -DHAVE_WCHAR_H=1 -DHAVE_STDARG=1 -DHAVE_SYS_TIME_H=1 -DHAVE_STDINT_H=1 -DHAVE_VA_COPY=1 -DHAVE_SETLOCALE=1 -DHAVE_GETTIMEOFDAY=1 -DHAVE_LONG_LONG=1 -DHAVE_INTMAX_T=1 -DMPFR_HAVE_FESETROUND=1 -DHAVE_ROUND=1 -DHAVE_TRUNC=1 -DHAVE_FLOOR=1 -DHAVE_CEIL=1 -DHAVE_NEARBYINT=1 -DLT_OBJDIR=\".libs/\" -DHAVE_ATTRIBUTE_MODE=1 -DHAVE_ALLOCA_H=1 -I. -I../.././mpfr   -I/home/gyd/Downloads/gcc-5.2.0/host-mips-linux-gnu/gmp  -g -O2 -MT mul.lo -MD -MP -MF .deps/mul.Tpo -c -o mul.lo ../.././mpfr/mul.c
libtool: compile:  mips-linux-gnu-gcc -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DTIME_WITH_SYS_TIME=1 -DHAVE_LOCALE_H=1 -DHAVE_WCHAR_H=1 -DHAVE_STDARG=1 -DHAVE_SYS_TIME_H=1 -DHAVE_STDINT_H=1 -DHAVE_VA_COPY=1 -DHAVE_SETLOCALE=1 -DHAVE_GETTIMEOFDAY=1 -DHAVE_LONG_LONG=1 -DHAVE_INTMAX_T=1 -DMPFR_HAVE_FESETROUND=1 -DHAVE_ROUND=1 -DHAVE_TRUNC=1 -DHAVE_FLOOR=1 -DHAVE_CEIL=1 -DHAVE_NEARBYINT=1 -DLT_OBJDIR=\".libs/\" -DHAVE_ATTRIBUTE_MODE=1 -DHAVE_ALLOCA_H=1 -I. -I../.././mpfr -I/home/gyd/Downloads/gcc-5.2.0/host-mips-linux-gnu/gmp -g -O2 -MT mul.lo -MD -MP -MF .deps/mul.Tpo -c ../.././mpfr/mul.c -o mul.o
In file included from ../.././mpfr/mpfr-impl.h:87:0,
                 from ../.././mpfr/mul.c:24:
../.././mpfr/mul.c: In function 'mpfr_mul':
../.././mpfr/mpfr-longlong.h:1016:3: error: impossible constraint in 'asm'
   __asm__ ("multu %2,%3" : "=l" (w0), "=h" (w1) : "d" (u), "d" (v))
   ^
../.././mpfr/mul.c:315:11: note: in expansion of macro 'umul_ppmm'
           umul_ppmm (tmp[1], tmp[0], MPFR_MANT (b)[0], MPFR_MANT (c)[0]);
           ^
../.././mpfr/mpfr-longlong.h:1016:3: error: impossible constraint in 'asm'
   __asm__ ("multu %2,%3" : "=l" (w0), "=h" (w1) : "d" (u), "d" (v))
   ^
../.././mpfr/mul.c:322:11: note: in expansion of macro 'umul_ppmm'
           umul_ppmm (tmp[1], tmp[0], MPFR_MANT (b)[0], MPFR_MANT (c)[0]);
           ^
../.././mpfr/mpfr-longlong.h:1016:3: error: impossible constraint in 'asm'
   __asm__ ("multu %2,%3" : "=l" (w0), "=h" (w1) : "d" (u), "d" (v))
   ^
../.././mpfr/mul.c:323:11: note: in expansion of macro 'umul_ppmm'
           umul_ppmm (tmp[2], t, MPFR_MANT (b)[1], MPFR_MANT (c)[0]);
           ^
../.././mpfr/mpfr-longlong.h:1016:3: error: impossible constraint in 'asm'
   __asm__ ("multu %2,%3" : "=l" (w0), "=h" (w1) : "d" (u), "d" (v))
   ^
../.././mpfr/mul.c:332:11: note: in expansion of macro 'umul_ppmm'
           umul_ppmm (tmp[1], tmp[0], MPFR_MANT (b)[0], MPFR_MANT (c)[0]);
           ^
../.././mpfr/mpfr-longlong.h:1016:3: error: impossible constraint in 'asm'
   __asm__ ("multu %2,%3" : "=l" (w0), "=h" (w1) : "d" (u), "d" (v))
   ^
../.././mpfr/mul.c:333:11: note: in expansion of macro 'umul_ppmm'
           umul_ppmm (tmp[2], t1, MPFR_MANT (b)[1], MPFR_MANT (c)[0]);
           ^
../.././mpfr/mpfr-longlong.h:1016:3: error: impossible constraint in 'asm'
   __asm__ ("multu %2,%3" : "=l" (w0), "=h" (w1) : "d" (u), "d" (v))
   ^
../.././mpfr/mul.c:336:11: note: in expansion of macro 'umul_ppmm'
           umul_ppmm (t1, t2, MPFR_MANT (b)[0], MPFR_MANT (c)[1]);
           ^
../.././mpfr/mpfr-longlong.h:1016:3: error: impossible constraint in 'asm'
   __asm__ ("multu %2,%3" : "=l" (w0), "=h" (w1) : "d" (u), "d" (v))
   ^
../.././mpfr/mul.c:337:11: note: in expansion of macro 'umul_ppmm'
           umul_ppmm (tmp[3], t3, MPFR_MANT (b)[1], MPFR_MANT (c)[1]);
           ^
Makefile:729: recipe for target 'mul.lo' failed
make[3]: *** [mul.lo] Error 1
make[3]: Leaving directory '/home/gyd/Downloads/gcc-5.2.0/host-mips-linux-gnu/mpfr'
Makefile:1452: recipe for target 'all-recursive' failed
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory '/home/gyd/Downloads/gcc-5.2.0/host-mips-linux-gnu/mpfr'
Makefile:5001: recipe for target 'all-mpfr' failed
make[1]: *** [all-mpfr] Error 2
make[1]: Leaving directory '/home/gyd/Downloads/gcc-5.2.0'
Makefile:879: recipe for target 'all' failed
make: *** [all] Error 2

貌似问题出在mpfr上,

google上找到了这篇bug report:《Bug 69134 - building a mips-cross compiler with in-tree mpfr-2.4.2 fails》

才搞明白原因是mpr-2.4.2 对mips的支持在高版本gcc下有问题。

文中也附了解决办法,如下图所示修改mpfr-longlong.h,将1014和1027行的#if __GNUC__ > 2 || __GNUC_MINOR__ >= 7改为#if __GNUC__ < 4,目的就是让编译器走#else分支(ubuntu16.04的gcc版本是5.4.0),再重新编译即可

附上编译mips-gcc-5.2.0的脚本

#! /bin/bash
# 基于君正发布的X1000开发板编译器(mips-gcc520-glibc222),编译gcc 5.2.0,增加-ffunction-sections -fdata-sections编译选项
sh_folder=$(dirname $(readlink -f $0))
with_sysroot=true
[ "$1" == "with_sysroot" ] && with_sysroot=true
pushd $sh_folder
# old mips gcc compiler location
mips_gcc=/opt/toolchains/mips-gcc520-glibc222
install_prefix=$sh_folder/release/opt/toolchains/mipsel-gcc520-gdface
old_sysroot=$mips_gcc/mips-linux-gnu/libc
target_sysroot=$old_sysroot
if [ $with_sysroot ];
then
    # 复制原编译器的 build tools 到安装路径
    target_tools=$install_prefix/mipsel-linux-gnu
    target_sysroot=$target_tools/libc
    [ -d "$target_sysroot" ] && rm "$target_sysroot" -fr
    mkdir -p "$target_tools" || exit -1
    echo "copy build tools to $install_prefix"
    cp -arf "$(dirname $old_sysroot)"/* "$target_tools" || exit -1
fi
# download gcc source package
# wget http://ftp.gnu.org/gnu/gcc/gcc-5.2.0/gcc-5.2.0.tar.bz2 || exit -1
# tar xvf gcc-5.2.0.tar.bz2 || exit -1
# gcc source folder
gcc_folder=gcc-5.2.0
pushd $gcc_folder || exit -1
# download dependencies 
# ./contrib/download_prerequisites 
# patch for mpfr-2.4.2
# ../patch_mpfr.sh
[   -d build ] && rm build -fr
[ ! -d build ] && mkdir build
pushd build
# X1000为小端(little endian),所以这里--target要改为mipsel-linux-gnu,否则编译不通过
../configure --with-pkgversion='Gdface 2018.06'\
    --build=x86_64-linux-gnu \
    --host=x86_64-linux-gnu \
    --target=mipsel-linux-gnu \
    --enable-threads \
    --disable-libmudflap \
    --disable-libssp \
    --disable-libstdcxx-pch \
    --with-arch-32=mips32r2 \
    --with-arch-64=mips64r2 \
    --with-float=hard \
    --with-mips-plt \
    --enable-extra-sgxxlite-multilibs \
    --with-specs='-D__CS_SOURCERYGXX_MAJ__=2015 -D__CS_SOURCERYGXX_MIN__=11 -D__CS_SOURCERYGXX_REV__=32' \
    --enable-languages=c,c++ \
    --enable-shared \
    --enable-static \
    --enable-lto \
    --enable-symvers=gnu \
    --enable-__cxa_atexit \
    --with-glibc-version=2.22 \
    --disable-nls \
    --prefix=$install_prefix \
    --with-sysroot=$target_sysroot \
    --with-build-sysroot=$target_sysroot \
    --enable-libgomp \
    --disable-libitm \
    --enable-libatomic \
    --disable-libssp \
    --disable-libcc1 \
    --with-endian=big \
    --enable-poison-system-directories \
    --with-python-dir=mipsel-linux-gnu/share/gdb/python \
    --with-build-time-tools=$mips_gcc/mips-linux-gnu/bin \
    CFLAGS="-ffunction-sections -fdata-sections" \
    CXXFLAGS="-ffunction-sections -fdata-sections" \
    SED=sed || exit -1
make -j8 || exit -1
make install || exit -1
popd
popd
popd

参考资料

《Bug 69134 - building a mips-cross compiler with in-tree mpfr-2.4.2 fails》

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018年06月10日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 参考资料
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档