• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

RUST交叉编译arm64的浮点函数问题

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

最近在把一个项目迁移到支持 arm64(aarch64) 时,遇到了个 rust 编译器的问题,由于 rust 有部分函数没实现,会出现找不到符号的情况,如

...
vfprintf.c:(.text.fmt_fp+0x178): undefined reference to `__addtf3'
vfprintf.c:(.text.fmt_fp+0x20c): undefined reference to `__multf3'
vfprintf.c:(.text.fmt_fp+0x240): undefined reference to `__subtf3'
vfprintf.c:(.text.fmt_fp+0x250): undefined reference to `__addtf3'
vfprintf.c:(.text.fmt_fp+0x278): undefined reference to `__addtf3'
vfprintf.c:(.text.fmt_fp+0x284): undefined reference to `__subtf3'
vfprintf.c:(.text.fmt_fp+0x33c): undefined reference to `__subtf3'
vfprintf.c:(.text.fmt_fp+0x344): undefined reference to `__multf3'
vfprintf.c:(.text.fmt_fp+0x4e8): undefined reference to `__multf3'
vfprintf.c:(.text.fmt_fp+0x548): undefined reference to `__subtf3'
vfprintf.c:(.text.fmt_fp+0x550): undefined reference to `__multf3'
vfprintf.c:(.text.fmt_fp+0x828): undefined reference to `__addtf3'
...

这个问题是比较普遍的问题,原因在于 rust 的实现中并没有 f128 相关的内容 (tf3 表示 triple float),基本上做 aarch64 时都会遇到。

github 上的 issue 见 https://github.com/rust-lang/rust/issues/46651 。问题来自于 rust 的实现,但是还是要处理掉的,方法是静态链接 c 库实现。

具体操作如下:

1. 把交叉编译器的 libgcc.a 的所在目录添加到 rust 链接时搜索目录
2. 加入链接参数 -lgcc

可以在命令行上加,但是每次都要打命令行不方便,加到项目下的 .cargo/config 中,以下是使用了 musl 工具链的配置,见 https://www.cnblogs.com/fengyc/p/12861259.html

[target.aarch64-unknown-linux-musl]
linker = "aarch64-linux-musl-ld"
ar = "aarch64-linux-musl-ar"
rustflags = ["-C", "target-feature=+crt-static", "-L", "/opt/aarch64-linux-musl-cross/lib/gcc/aarch64-linux-musl/9.2.1", "-C", "link-arg=-lgcc"]
strip = {path="aarch64-linux-musl-strip"}
objcopy = {path = "aarch64-linux-musl-objcopy"}

-L 后的参数即为 libgcc.a 所在的目录,可通过 find <交叉编译工具链所在目录> -name libgcc.a 找到。

如果各个路径都正确,加上之后再次 cargo build 问题都会消失。

如果使用了其它的工具链,也基本是这个原理,只要目录和附加的链接参数正确,链接器能正确找到了函数符号,就能解决这个问题。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
用matlab绘制中国地图 - limanjihe发布时间:2022-07-18
下一篇:
matlab绘制中国地图发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap