How to read Linker Map file

DJ Delorie dj@redhat.com
Tue Apr 3 17:54:00 GMT 2007


"Steven Woody" <narkewoody@gmail.com> writes:
> i produced a linker map file using -M flag to 'ld'. but i found the
> file is hard to understand to me.  is there a readme file or any
> documents describing the file format in details?  thanks.

You mean, besides the linker's existing documentation?

> especially, in the map file, what is common symbols? how does it
> differ with other symbols?

A common symbol is one where one or more modules tell the linker, "I
need a block of memory N bytes long called 'foo', please arrange it
for me, and share it with other modules".  The linker collects all
these requests, and allocates memory from a common pool for them.

The C equivalent is an uninitialized global variable:

        int j;

If you do "int j;" in multiple files, they all refer to the same
memory, essentially creating one variable "j" that's common to all the
objects.

The alternatives are (1) initialized variables, where the object
itself allocates memory for it (other objects may share this memory if
they request a suitable common block), and (2) static variables, which
aren't shared.  Uninitialized static variables may come from the
common pool (without being shared) or from the .bss segment, depending
on how you specify them.



More information about the Binutils mailing list