如何让链接器使用 Cargo 生成地图文件 [英] How to get the linker to produce a map file using Cargo

查看:51
本文介绍了如何让链接器使用 Cargo 生成地图文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用锌编写针对 STM32F407 处理器的 Rust 程序.我希望能够生成链接器映射文件.我发现我可以将以下内容放入我的 main.rs 中,这给了我想要的结果:

I'm writing a Rust program targeted for an STM32F407 processor using zinc. I'd like to be able to produce a linker map file. I've found that I can put the following in my main.rs and this gives me the desired result:

#![feature(link_args)]
#[link_args = "-Wl,-Map=blink_stm32f4.map"]
extern {}

但是,link_args 建议不要使用这种方法.

However, the documentation for link_args suggests not to use this method.

还有哪些其他方法可以让链接器生成地图文件?

What other methods exist to get the linker to produce a map file?

推荐答案

link-args 可以通过 rustc -C link-args 传递给 rustc="-Wl,-Map=blink_stm32f4.map" test.rs.

link-args is possible to pass to rustc via rustc -C link-args="-Wl,-Map=blink_stm32f4.map" test.rs.

并且在 build 部分有 cargo rustflags 选项.请参阅货物配置.它是这样工作的:

And there is option of cargo rustflags in build section. See cargo config. It works like this:

$ cargo new --bin testbin
$ cd testbin
$ cat .cargo/config 
[build]
rustflags = ["-Clink-args=-Wl,-Map=/tmp/blink_f7.map"]
$ cargo build

cargo 配置中还有 linker 选项.我不试图通过这个选项gcc加上flags,只有gcc,但是你可以写gcc包装脚本,如:

Also there is linker option in cargo config. I don't try to pass via this option gcc plus flags, only gcc, but you can write gcc wrapper script like:

$ cat my-linker.sh
#!/bin/sh

arm-...-gcc -Wl,-Map=blink_stm32f4.map $@

这篇关于如何让链接器使用 Cargo 生成地图文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆