What are gcc linker map files used for?

让人想犯罪 __ 提交于 2019-12-03 01:07:53

I recommend generating a map file and keeping a copy for any software you put into production.

It can be useful for deciphering crash reports. Depending on the system, you likely can get a stack dump from the crash. The stack dump will include memory addresses and one of the registers will include the Instruction Pointer. That tells you the memory address code was executing at. On some systems, code addresses can be moved around (when loading dynamic libraries, hence, dynamic), but the lower order bytes should remain the same.

The map file is a MAP from memory location -> code location. It gives you the name of the function at a given memory address. Due to optimizations, it may not be extremely accurate, but it gives you a place to start in terms of looking for bugs that cause the crash.

Now, in 30 years of writing commercial software, this is the only thing I've used the map files for. Twice successfully.

What are the ".map" files generated by gcc/g++ linker option "-Map" used for?

There is no such thing as 'gcc linker' -- GCC and linker are independent and separate projects.

Usually the map is used for understanding decisions that ld made while linking the binary. From man ld:

-M
   --print-map
       Print a link map to the standard output.
       A link map provides information about the link, including the following:
       ·   Where object files are mapped into memory.
       ·   How common symbols are allocated.
       ·   All archive members included in the link, with a mention of the symbol which caused the archive member to be brought in.
       ·   The values assigned to symbols.
       ...

If you don't understand what that means, you likely don't (yet) have the questions that this output answers, and hence have no need to read it.

The compiler gcc is one program that generates object code files, the linker ld is a second program to combine the object code files into an executable. The two can be combined into a single command line.

If you are generating a program to run on an ARM processor you need to use arm-none-eabi-gcc and arm-none-eabi-ld so that the code will be correct for the ARM architecture. Gcc and ld will generate code for your host computer.

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