解决编译mips gcc 5.2.0版本时报错:mpfr/mpfr-longlong.h:1016:3: error: impossible constraint in 'asm'

因为厂商提供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版本时报错:mpfr/mpfr-longlong.h:1016:3: error: impossible constraint in 'asm'_第1张图片

附上编译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》

你可能感兴趣的:(开发工具,embedded,mips,gcc,mpfr)