This is an archive of the discontinued LLVM Phabricator instance.

Implement -Map
ClosedPublic

Authored by rafael on Jan 12 2017, 10:40 AM.

Details

Reviewers
ruiu
pcc
Summary

This is not exactly the same format as bfd ld, but should serve a similar purpose.

Diff Detail

Event Timeline

rafael retitled this revision from to Implement -Map.
rafael updated this object.
rafael added a reviewer: ruiu.
rafael added a subscriber: llvm-commits.
ruiu edited edge metadata.Jan 12 2017, 12:43 PM

Is there any reason we can't print out in the exact same format as ld.bfd? Because LLD is basically a drop-in replacement, compatible output would be generally appreciated.

lld/ELF/MapFile.cpp
8

This needs a file comment. At least it should mention that this is for -Map and what kind of information is printed, at the granularity of the ld man page.

25–28

nit: maybe this style is more common?

OS << ...
   << ...;

as opposed to

OS << ...;
OS << ...;
100

Do you need this temporary variable?

106–113

This seems like a pretty common pattern. We probably should have a class that does this (open with a temporary file name and rename on close) automatically.

lld/ELF/MapFile.h
2

Not directly related to this patch, but we have many instances of this kind of "effectively one line" .h files in LLD. In some case, some declarations are piggy backed to a somewhat unrelated header (e.g. markLive's declaration is in Writer.h.)

I once wondered if we should create a header for miscellaneous functions, say, LLD.h, to aggregate them. What do you think?

davide added a subscriber: davide.Jan 12 2017, 1:51 PM

Take this with a grain of salt, Rui, but last I checked --map as emitted by bfd wasn't particularly informative.
I also personally don't think we should really stick with compatibility for debugging options, assuming we can provide a better output.

rafael updated this revision to Diff 84173.Jan 12 2017, 2:00 PM
rafael edited edge metadata.
ruiu added a reviewer: pcc.Jan 12 2017, 2:08 PM

Added pcc as he implemented a similar feature for COFF. It is good for us to make him take a look.

lld/ELF/MapFile.cpp
14

An example of an output would be appreciated. You can copy some part of the test here.

16

Add a blank line.

pcc edited edge metadata.Jan 12 2017, 2:40 PM

I have to say that I prefer this style of output to what I implemented for /lldmap in the COFF linker. At some point we should make the COFF linker use this format or something similar.

I wonder whether it would be worth making absolute symbols show up in the map file.

lld/test/ELF/map-file.s
33

You probably want to use regexes to match the paths here and below.

rafael updated this revision to Diff 84302.Jan 13 2017, 6:55 AM
rafael edited edge metadata.
ruiu accepted this revision.Jan 13 2017, 10:45 AM
ruiu edited edge metadata.

LGTM with these changes as everybody seems happy with this output format.

lld/ELF/Driver.cpp
515

Move the definitions of -Map and -Map= in Options.td so that they are not under the comment saying that they are for compatibility and silently ignored.

lld/ELF/MapFile.cpp
38

For 64-bit output, you want to write Address in 64 bit.

39

This and in other write* functions probably should print out a trailing "\n" so that you don't need to do that in writeMapFile2.

This revision is now accepted and ready to land.Jan 13 2017, 10:45 AM
ruiu added a comment.Jan 13 2017, 10:57 AM

Why do you want this feature by the way? I wonder if you have a plan to use that soon.

ruiu added a comment.Jan 13 2017, 11:17 AM

I wonder if printing out meta info (such as all command line options, time stamp, etc.) as a header of a map file is useful. What do you think?

espindola closed this revision.Mar 14 2018, 4:21 PM
espindola added a subscriber: espindola.

291958