Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 854
Dave Hylands Avatar asked Sep 03 '16 20:09

Dave Hylands


People also ask

How do I create a .map file?

Select Tools > Generate, or press Ctrl+G. The Generate Mapping File dialog appears. Enter the reader and writer parameters you want to use for the mapping file. Parameters:When you select certain source formats, the Parameters button becomes available.

What is map file linker?

A linker map is a file produced by the linker. The file shows the symbols and sections contained in a binary. The linker also provides the memory address and size for each symbol.

What is map file in embedded system?

The map file is generated by the linker and the format of the file will be different for each linker. Your best bet is the documentation for the linker itself - there is unlikely to be a "general" tutorial. However for the most part a map file is simply a table of symbols, their location and their size.

What is the use of .map file?

More generically, the . MAP extension can be used to denote any file type that indicates relative offsets from a starting point. MAP file types are used in this way, for example, when variables in software are expected to be "mapped" to a specific spot in memory.


1 Answers

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 $@
like image 135
fghj Avatar answered Oct 11 '22 15:10

fghj