How to get the linker to produce a map file using Cargo

▼魔方 西西 提交于 2019-12-10 14:44:45

问题


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 {}

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?


回答1:


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

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

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 $@


来源:https://stackoverflow.com/questions/39310905/how-to-get-the-linker-to-produce-a-map-file-using-cargo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!