Getting the map file

I'm learning about using progmem. How can I see where my data ends up after compiling? So I can make sure I'm really getting it where I want it.

Why does it matter where it is actually placed?

Apply "avr-size" or "avr-objdump" on the .elf file. The ".elf" file is located in the build directory (see description here: http://code.google.com/p/dogm128/wiki/Develop#Arduino_IDE_Build_Files)

Documentation of objdump is here: http://sourceware.org/binutils/docs-2.21/binutils/objdump.html#objdump.

avr-objdump -t project.elf

will generate an output which is usually called "map" file.

Oliver

Thanks olikraus!!!!

@AWOL - SO I can tell what's going to progmem and what's going to sram. To make sure that what I did worked and actually put the data in progmem.

O I can tell what's going to progmem and what's going to sram.

[u]Everything[/u] goes to PROGMEM - there's no other place for it to go.

Everything goes to PROGMEM - there’s no other place for it to go.

Not a very useful comment and not at all accurate.
Does the stack go to PROGMEM?
Initialized data does not go to PROGMEM, it goes to SRAM.
The initializing values are stored in the boot image which happens to overlay PROGMEM.
By default, the bootloader copies those values from flash into SRAM where the .data section resides.
It does this even for data that never changes such as string literals as in:Print("You never change this text");
There are two copies in memory of the string - one on flash and one in sram.
Since sram is such a precious resource, this can make or break whether code will fit on small chips like the Nano’s.

One would think that declaring your data with const would prevent this - you are telling the compiler the data does not change and it should stay in flash, but that’s not the actual meaning of const.

The cpu has a Harvard architecture, which means the program memory space (flash) is not connected to the data memory space (sram). Special instructions (i.e. LPM) can read from flash into a register where it can be used as data. That means code like:

char c = *pgmdataptr;

does not work. The compiler will use instructions that access data memory (i.e. LD)

It is unfortunate that the compiler does not automatically use the correct instructions.
It is also unfortunate that the AVR chips don’t have a reserved section of data memory space that gives access to the program memory space - other chipsets do this (such as all memory above 0x80000000).

When you tell the linker to place const data in PROGMEM, (i.e. using PSTR("this text is in program memory")) the symbol’s address reflects that you have done so. The linker’s .map file tells you whether that was successful. You can also learn how big each part of your code is. That can also be critical for fitting everything into a Nano.

If all this seems arcane, it is. This is why firmware engineers are paid so well. The folks at Arduino have done a great service to the community by creating this very, very easy to use noob environment. I think they can take it a step further by pre-processing the ‘sketch’ and automatically insert the magic that tells the compiler to keep const data and anonymous string literals from consuming sram. (Hint, hint!)

Initialized data does not go to PROGMEM, it goes to SRAM.

Have you ever thought where initialised data comes from? (Answers involving the crt0 fairy are inadmissible)

The initializing values are stored in the boot image which happens to overlay PROGMEM.

A fine and largely irrelevant distinction.

Mynr4TNynr: The folks at Arduino have done a great service to the community

I think you'll find that credit for the behaviour you describe goes to the creators of the GNU tools the IDE uses. The IDE is basically a text editor and graphical front end for the GNU C++ compiler and AVR tools used to upload the sketch (I wouldn't claim that it's especially great at either of those jobs).

Oliver: I know you wrote this a long time ago but the dump file is exactly what I need.

I am putting large amounts of data in PROGMEM and it is causing problems. It would help a lot if I new where the compiler was putting the data.

Where do you put the following code??

avr-objdump -t project.elf

I have tried in "Setup" and at the top of the program and the compiler complains and won't complie the code.

Where do you put the following code?? Code: [Select]

avr-objdump -t project.elf

In a shell command line.

...or modify platforms.txt so the linker includes a map file in its output.

What do you do just add the text "avr-objdump -t project.elf" somewhere in the file near the bottom of the "Platform.txt" file??

Thanks for the input

No. The linker can be commanded to generate map files. You make that change to platforms.txt

OR, you can run avr-objdump from the command-line as a one off.

I'm going to try to do it from the command line. If I can do that, Great.

Thanks for the info

I figured it out!!

Using the "Windows Command line.

First I copied the "avr-objdump.exe file from the location where the "Arduino" compiler is located to the location where the Sketch I wanted tested is located.

Second, I copied the sketch.elf file from the location where the compiler stores the file to the directory where I store the sketch I wanted tested is located.

Using the "Windows command line" I typed in "avr-objdump -t *.elf>dump.txt" (return)

The avr-objdump generated a text file (dump.txt) and put it in the sketch directory for me.

The objdump program generated a wealth of information for me including memory locations of all of my data structures. That was exactly what I was looking for.

The information presented above is for anybody else trying to use the AVR program.

Many thanks for all of your help!!

Excellent. Thank you for the follow-up.

I learned a lot form the report generated. The report answered some questions and generated a bunch more.

Thanks for the help

Apparently this thread ranks well in google search so I decided to share a link which is on point but does not rank as well.

In think link a more Noob oriented guide has been written which help you see the details that can be generated from .elf file without the need to know too much about other stuff.

You may want to check this for more information on what the actual content means:

I hope it helped.