Home >

Buried Treasure and Map Files

Elecia White - Watch Now - Duration: 35:18

Often overlooked, the map file can provide a wealth of information to the intrepid developer. Map files can help:

  • optimizing for RAM usage and/or code space
  • updating firmware (with or without a bootloader)
  • debugging difficult crash bugs
  • statistical profiling

With so much information, how can you use it? Where do you look? How do you turn the wall of text and numbers into a true map of the code?

Elecia will demonstrate how to use map files. She will focus on an ARM Cortex-M but it will be relevant to other processors.

M↓ MARKDOWN HELP
italicssurround text with
*asterisks*
boldsurround text with
**two asterisks**
hyperlink
[hyperlink](https://example.com)
or just a bare URL
code
surround text with
`backticks`
strikethroughsurround text with
~~two tilde characters~~
quote
prefix with
>

DS
Score: 0 | 5 months ago | no reply

Only 1 minute into your presentation and I realized that we are kindred spirits! :) I totally identified with what you said about the joy of eking out a few more processor cycles, efficiently writing a hardware driver, or reducing memory consumption! I'm glad to hear that there are still other people out there that enjoy this.

This was an excellent presentation!

Dimitri
Score: 1 | 5 months ago | no reply

It's an interesting idea to use the map-file for analyzing the firmware size. Most of the time I was experimenting with "bloaty" (https://github.com/google/bloaty). Although this tool is parsing the elf file and not the map-file. Maybe also interesting to look at.

Thanks for the great talk and some cool insights into map-files.

billionai
Score: -1 | 5 months ago | no reply

That's a very cool memory map! I love it. Just one thing that may sound like a nitpick, but might confuse people with map-making experience: Rivers never split. So when I saw the .cinit area, and the river of initialization, I immediately though that the .bss influenced .cinit, not the other way around. A better way to represent what you want would probably be making .cinit be surronded by 2 rivers, one going to the ocean, the other to the lake.

regardless, that map is a huge help, thank you for sharing it!

AllenMoore
Score: 0 | 5 months ago | no reply

Your map of the map file was very clever. I might have to find a space on my wall for it. Very well done presentation on a formidable topic. I found map files inscrutable initially and struggled to make sense of them, but over the years the information they contained was invaluable in debugging.

Pete
Score: 0 | 5 months ago | no reply

Nice Job Elecia, That colorful map is a great way to highlight what a .map file is all about. Really makes the point.

acarvalho
Score: 0 | 5 months ago | 1 reply

How can I access "the map"? I reeeeally need to print and frame it. For work.

EleciaWhiteSpeaker
Score: 0 | 5 months ago | no reply

My website has the HD image (click on the map):
http://embedded.fm/blog/MapFiles
And when I asked a graphic designer friend where they should be printed, Society6 was the recommendation so I put it there (with a 1% markup, the minimum I could do). So if you want to print it elsewhere, go ahead. Maybe send me a pic of it in your lab/office/above your fireplace.
https://society6.com/embeddedfm

Tarik Ku
Score: 1 | 5 months ago | 2 replies

Hi Elecia, that was a great talk!
I still remember having to troubleshoot missing startup code (no zeroing, no initialized variables) in my final uni project. This taught me the answer to that eternal interview question of "what happens before main".
How often have you had to write or adapt your startup code in real-world projects?

EleciaWhiteSpeaker
Score: 0 | 5 months ago | 2 replies

Some... but less in the last few years. Now that most systems have a startup.s and weak bindings for the interrupt vectors, startup code is more canned... that said, one area I used it on recently involved reading constants (specially marked section) from the spi flash into fast RAM for graphic assets for boot time imagery.

Mikael Albertsson
Score: 0 | 5 months ago | no reply

Interesting, do you simply modify the startup.s and call your own function to add your code, or how do you add it to the startup?

Tarik Ku
Score: 0 | 5 months ago | no reply

That's an elegant solution, will keep it in my toolbox

Mikael Albertsson
Score: 1 | 5 months ago | no reply

Oh, that reminds me. I created a small hobby project on an 8 bit avr about 6-7 years ago, written in C++. My first, trivial hello world-type code loaded and worked fine. But very soon when adding a bit of code, everything would compile, load fine, but the micro just seemed completely dead after loading. With no debugger I tried to light an LED in line 1 of main, nothing. Having no better resort, I used objdump to get a disassembly of the code and in part of the pre-main startup code linked in by avrgcc I found that a trivial file would do some memory clearing and then jump to another piece of initialization code, but with my non-working code, it instead jumped miles outside of any available memory. It was in a function called something with "ctors", so on a hunch I tried moving the one global object I had into main instead, so that it got allocated on the stack, suddenly everything worked perfectly!

Gerhard
Score: 1 | 5 months ago | 1 reply

For address/symbol lookup you can also use nm and addr2line (at least in the gcc toolchain).

Mikael Albertsson
Score: 0 | 5 months ago | 1 reply

addr2line, very nice when you're running a debugger in an environment that doesn't have access to the sources. A quick one-liner immediately tells you where in the code you are.

EleciaWhiteSpeaker
Score: 0 | 5 months ago | 1 reply

I'm going to add JeanLabrosse's suggestion of elfread as that seems quite useful.

Mikael Albertsson
Score: 1 | 5 months ago | no reply

Definitely, I believe the name is readelf by the way.

WillHsiung
Score: 0 | 5 months ago | 1 reply

Saw that Embedded.fm is on YouTube. Will you be doing video podcasts and interviews? Thought you could be very creative with them after seeing this presentation.

EleciaWhiteSpeaker
Score: 0 | 5 months ago | no reply

Probably not... Video is a really hard medium. It would require too much time so we'd have to make money from it but I'd rather share information freely and get paid to do engineering.

TomDavies
Score: 1 | 5 months ago | 2 replies

Any plans to produce the map as a print we could buy? :)

EleciaWhiteSpeaker
Score: 2 | 5 months ago | 2 replies

Sure! My website has the HD image (click on the map):
http://embedded.fm/blog/MapFiles
And when I asked a graphic designer friend where they should be printed, Society6 was the recommendation so I put it there (with a 1% markup, the minimum I could do). So if you want to print it elsewhere, go ahead. Maybe send me a pic of it in your lab/office/above your fireplace.
https://society6.com/embeddedfm

TomDavies
Score: 0 | 5 months ago | no reply

Thanks Elecia, and thanks again for the presentation. Loved the style and take on what could have been a real snooze fest! Hope to see more presentations in the future.

Mikael Albertsson
Score: 0 | 5 months ago | no reply

You should definitely make it into a board game. "Come on kids, let's play hard fault!"

Tarik Ku
Score: 0 | 5 months ago | 1 reply

It's available here as it seems: https://society6.com/embeddedfm
You can even change the currency. It would be cool if the € price means prints are shipped from within Europe :)

TomDavies
Score: 0 | 5 months ago | no reply

Awesome, thanks Tarik

JeremyS
Score: 1 | 5 months ago | 1 reply

Hi Elecia! Great talk! Long-time-listener-first-time-caller. Gcc and other compilers have been around for a while now and I've wrestled with them (and linker scripts) myself. Why do you think these files are still so difficult to read? Do compiler vendors not realize that they could help developers a lot by making them more user-friendly?

EleciaWhiteSpeaker
Score: 0 | 5 months ago | no reply

Not enough people ask for them to better... It is one of those areas that isn't as spiffy as 2% faster compiles or better security for their licenses.

mgaron
Score: 1 | 5 months ago | no reply

Very original. Loved "the map"!
Thanks!

JeanLabrosse
Score: 0 | 5 months ago | 1 reply

Do you like to 'name sections' to allow you to determine where your section is located or do you simply always let the linker place memory? Naming sections is important if you use an MPU but not as critical for non-MPU systems.

EleciaWhiteSpeaker
Score: 0 | 5 months ago | no reply

Naming sections is also important if you have something that needs specific placement: bootloader, non-volatile storage, config information to pass between images. But if I don't have to, I'll let the linker do the work.

OUR SPONSORS