一个关于编译器浮点问题 use hard float,but .use soft float的探讨

 

作者:shenghuo456

联系:shenghuo456@163.com, qq:82475491

欢迎大家来到我的网站:www.embedlinux.cn ,主要讨论嵌入式ecos,连带的arm和交叉编译技术!

我前段时间在编译mysql的时候出现过一个错误具体的记不清楚了,大致是”arm-elf-ld errorstdlibc++ use hard floatbut *.elf2flt use soft float”的错误,另外我在下载最新的uclinux2.4.32的时候编译也会出现这个错误,解决的办法是去掉了makefile里面的-msoft-float 选项,但是一直没找到什么原因。

我的硬件环境为:arm7:w90p710,无硬件浮点支持。编译链:gcc3.3.4,uclibc-9.28和自己写的pthread库。
我以前自己编译的一款编译器,配置选项其中默认有UCLIBC_HAS_FLOATS=nHAS_FPU=y,这样的配置不支持软件浮点。编译gcc库的时候,我看了makefile也没有做任何浮点指定,这样都默认为有硬件浮点。

此外我们在编译应用程序的时候,不做任何浮点选项指定,程序都是默认硬件浮点。

但是现在问题就来了,在uclinux2.4.32的时候我看了linux下面的makefile里面有指定的浮点的选项-msoft-float,这就是说编译内核程序的时候用软件浮点的支持,但是gcc库被编译的时候用的是硬件浮点的支持,所以在二者链接的时候会出现”arm-elf-ld errorlibgcc++ use hard floatbut *.elf2flt use soft float”的错误吧!

通过以上的分析,这样的话你把-msoft-float拿掉,使编译内核的时候也默认的是硬件浮点的支持,与gcc库匹配,所以就ok了,貌似合情合理的解释:)

当我用我自己编译的编译器编译mysql的时候,我发现测试的时候是凡涉及到浮点的函数我都无法正常利用,得不到正常的结果,根本没有浮点操作的支持啊,所以我只能找编译器的原因,后来我配置了UCLIBC_HAS_FLOATS=y,HAS_FPU=n,UCLIBC_HAS_SOFT_FLOAT=y这样的话我的uclibc的所有库被编译的时候都是软件浮点的支持了,但是还有个问题就是我的gcc的库还是默认的硬件浮点支持哦,所以编译链接的时候肯定过不了出现”arm-elf-ld errorstdlibgcc use hard floatbut *.elf2flt use soft float”的错误,结果正如我所料的那样链接错误!

所以我开始着手把gcc编译的时候也用软件浮点,找到编译gcc库的makefile(gcc相关的库很多,所以要找的makefile也挺多的),加进去了-msoft-float选项,重新再做编译器,花了我很长的时间啊!

做好后,迫不及待的编译mysql了,结果是关于浮点的测试函数和命令各个好用啊!

接着我想测试一下编译别的应用程序好用不,拿出helloword程序,make,恩?结果还是出现那个链接错误啊?恍然大悟了应用的makefile没有指定-msoft-float选项哦!呵呵,加进去,编译成功!运行成功!

其实这个问题困扰我很久了,google了N遍也没找到解决的办法,baidu了M遍都是有现象没结果的帖子,最后只能自己debug,自己解决,现在的问题已经很显然了!一切ok了。上述描述可能有些术语不够准确,请指教!

投 票

觉得本文不错,投一票   

评 论

  • 葉子  2007-6-15 16:48:38
  • 葉子
    你好,看完你的文章之後想請教你幾個問題 我目前想把Asterisk cross compiler 成embedded ARM linux 之前使用arm-linux-gcc 3.3.2來build是ok的 但是後來發現asterisk在處理浮點運算時的效能很差 網路上看到gcc3.4以上的版本可以支援新的軟體浮點運算,效能比較好 所以就去試了gcc3.4.4 在build toolchan時有指定加入軟體浮點運算功能,方法如下面網址 http://ftp.snapgear.org/pub/snapgear/tools/arm-linux/build-arm-linux-3.4.4 之後我就把asterisk裡的Makefile的-msoft-float打開 卻出現了下面這些問題 想請教你是否了解...謝謝 可以回信到 jackie@welltech.com
  • 葉子  2007-6-15 16:51:11
  • 葉子
    /usr/local/lib/gcc/arm-linux/3.4.4/../../../../arm-linux/bin/ld.real: ERROR: /usr/local/arm-linux/lib/be/libc_nonshared.a(stat.oS) uses hardware FP, whereas asterisk uses software FP /usr/local/lib/gcc/arm-linux/3.4.4/../../../../arm-linux/bin/ld.real: failed to merge target specific data of file /usr/local/arm-linux/lib/be/libc_nonshared.a(stat.oS) /usr/local/lib/gcc/arm-linux/3.4.4/../../../../arm-linux/bin/ld.real: ERROR: /usr/local/arm-linux/lib/be/libc_nonshared.a(fstat.oS) uses hardware FP, whereas asterisk uses software FP /usr/local/lib/gcc/arm-linux/3.4.4/../../../../arm-linux/bin/ld.real: failed to merge target specific data of file /usr/local/arm-linux/lib/be/libc_nonshared.a(fstat.oS) /usr/local/lib/gcc/arm-linux/3.4.4/../../../../arm-linux/bin/ld.real: ERROR: /usr/local/arm-linux/lib/be/libc_nonshared.a(stat64.oS) uses hardware FP, whereas asterisk uses software FP /usr/local/lib/gcc/arm-linux/3.4.4/../../../../arm-linux/bin/ld.real: failed to merge target specific data of file /usr/local/arm-linux/lib/be/libc_nonshared.a(stat64.oS) /usr/local/lib/gcc/arm-linux/3.4.4/../../../../arm-linux/bin/ld.real: ERROR: /usr/local/lib/gcc/arm-linux/3.4.4/be/crtend.o uses hardware FP, whereas asterisk uses software FP /usr/local/lib/gcc/arm-linux/3.4.4/../../../../arm-linux/bin/ld.real: failed to merge target specific data of file /usr/local/lib/gcc/arm-linux/3.4.4/be/crtend.o /usr/local/lib/gcc/arm-linux/3.4.4/../../../../arm-linux/bin/ld.real: ERROR: /usr/local/lib/gcc/arm-linux/3.4.4/be/crtn.o uses hardware FP, whereas asterisk uses software FP /usr/local/lib/gcc/arm-linux/3.4.4/../../../../arm-linux/bin/ld.real: failed to merge target specific data of file /usr/local/lib/gcc/arm-linux/3.4.4/be/crtn.o collect2: ld returned 1 exit status


验证码: 看不清?换一张