使用 printf 打印 float/double 会使程序崩溃
我正在为 PowerPc 实现系统调用。 我已经测试了一些 gcc 函数,它们似乎都可以工作(例如 sqrt sin cos pow printf malloc...)
我最近意识到 printf 的问题。只要我打印一些整数/字符,它就可以正常工作,但是当我尝试 printf %f/lf 打印浮点/双精度时,程序崩溃。 (它似乎在不应该执行的地方执行)
我检查了 makefile,它使用:
# use soft float
CFLAGS += -msoft-float
在制作程序时,我可以看到许多 nof (无浮动)库被链接。
gnu/powerpc-eabi/3pp.ronetix.powerpc-eabi/bin/../lib/gcc/powerpc-eabi/4.3.3/../../../../powerpc-eabi/lib/nof\libm.a)lib_a-s_sin.o
我还知道堆栈/堆中有足够的空间,所以这不应该成为问题。 打印浮动时 printf 是否还有崩溃的原因?
I am working on a syscall implementation for a PowerPc.
I have tested some gcc functions and they all seem to work (e.g. sqrt sin cos pow printf malloc...)
I recently realised a problem with the printf. it works fine as long as I print some integer/char but when I try to printf %f/lf to print float/double the program crashes. (it seems to be executing somewhere it should not be)
I have checked the makefile, it uses:
# use soft float
CFLAGS += -msoft-float
and when making the program I can see many nof (no float) libraries being linked.
gnu/powerpc-eabi/3pp.ronetix.powerpc-eabi/bin/../lib/gcc/powerpc-eabi/4.3.3/../../../../powerpc-eabi/lib/nof\libm.a)lib_a-s_sin.o
I also know that I have enough space in stack/heap so that should not be a problem.
It there still a reason why printf should crash when printing float?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 newlib 可能是在不支持浮点 IO 的情况下构建的。这对于嵌入式系统来说相当常见,因为它节省了大量的代码空间。您也许可以重建 newlib 以支持浮点 IO。我认为配置选项是
--enable-newlib-io-float
和--enable-newlib-io-long-double
。您可以通过运行./configure --help
来确定。Your newlib is probably built without support for floating-point IO. This is fairly common for embedded systems as it saves a lot of code space. You can probably rebuild newlib to support floating-point IO. I think the configure options are
--enable-newlib-io-float
and--enable-newlib-io-long-double
. You can probably find out for sure by running./configure --help
.