Commit Graph

66 Commits

Author SHA1 Message Date
Rui Ueyama 4e150c4c88 Make "Size" column in the map file one characters shorter.
Previously, "size" column is 9 characters long which is too long
at least for 32-bit (because at maximum it needs 8 columns). This
patch make it one column shorter than before. That's also a reasonable
default for 64-bit.

llvm-svn: 329317
2018-04-05 17:20:18 +00:00
Rui Ueyama 16a130bc78 Fix column size in the map file.
Size can be narrow, but LMA should be the same width as VMA.

llvm-svn: 329312
2018-04-05 16:45:37 +00:00
George Rimar e88b76a989 [ELF] - Reveal more information in -Map file about assignments.
Currently, LLD print symbol assignment commands to the map file,
but it does not do that for assignments that are outside of the section
descriptions. Such assignments can affect the layout though.

The patch implements the following:

* Teaches LLD to print symbol assignments outside of section declaration.
* Teaches LLD to print PROVIDE/HIDDEN/PROVIDE hidden commands.

In case when symbol is not provided, nothing will be printed.

Differential revision: https://reviews.llvm.org/D44894

llvm-svn: 329272
2018-04-05 11:25:58 +00:00
George Rimar ee01b1d390 [ELF] - Print LMA in a -Map file.
Currently, LLD prints VA, but not LMA in a map file.
It seems can be useful to print both to reveal layout
details and patch implements it.

Differential revision: https://reviews.llvm.org/D44899

llvm-svn: 329271
2018-04-05 10:51:06 +00:00
Rui Ueyama 5a9529f4a2 Do not show alignment 0 because that is equivalent to 1.
Differential Revision: https://reviews.llvm.org/D44991

llvm-svn: 329233
2018-04-04 21:25:37 +00:00
George Rimar 4d2740c6ed [ELF] - Cleanup. NFCI.
Rename field, added comments.

This is splitted from the D44894. 
Requested to be committed as independent cleanup.

llvm-svn: 329162
2018-04-04 09:39:05 +00:00
Rafael Espindola 4f058a2c6b Add a SectionBase::getVA helper. NFC.
There were a few too many places duplicating this.

llvm-svn: 328402
2018-03-24 00:35:11 +00:00
George Rimar 84bcabcb86 [ELF] - Show data and assignment commands in the map file.
Patch teaches LLD to print BYTE/SHORT/LONG/QUAD and
location move commands to the map file.

Differential revision: https://reviews.llvm.org/D44004

llvm-svn: 327612
2018-03-15 09:16:40 +00:00
Rui Ueyama a5c1ed340f [ELF] Add .eh_frame pieces to map file
This patch is a simplified version of https://reviews.llvm.org/D42960
written by Andrew Ng.

Differential Revision: https://reviews.llvm.org/D44168

llvm-svn: 327574
2018-03-14 21:18:18 +00:00
Rui Ueyama db46a62e2b Implement --cref.
This is an option to print out a table of symbols and filenames.
The output format of this option is the same as GNU, so that it can be
processed by the same scripts as before after migrating from GNU to lld.

This option is mildly useful; we can live without it. But it is pretty
convenient sometimes, and it can be implemented in 50 lines of code, so
I think lld should support this option.

Differential Revision: https://reviews.llvm.org/D44336

llvm-svn: 327565
2018-03-14 20:29:45 +00:00
Rui Ueyama e1847da924 Rename Indent{1,2} -> Indent{8,16}.
llvm-svn: 326912
2018-03-07 17:15:15 +00:00
Rui Ueyama 9e0171fbb6 Do not create temporary strings just to print out spaces. NFC.
llvm-svn: 326841
2018-03-06 22:48:46 +00:00
Rui Ueyama ee17371897 Merge {COFF,ELF}/Strings.cpp to Common/Strings.cpp.
This should resolve the issue that lld build fails in some hosts
that uses case-insensitive file system.

Differential Revision: https://reviews.llvm.org/D43788

llvm-svn: 326339
2018-02-28 17:38:19 +00:00
George Rimar 563e4f2f58 [ELF] - Introduce getInputSections() helper.
We sometimes need to iterate over input sections for a given
output section. It is not very convinent because we have to iterate
over section descriptions.
Patch introduces getInputSections helper, it simplifies things.

Differential revision: https://reviews.llvm.org/D43574

llvm-svn: 325763
2018-02-22 09:55:28 +00:00
Rafael Espindola d26b52fd34 Remove some includes from InputFiles.h.
They were not used in InputFiles.h and it was getting too easy to add
circular includes.

llvm-svn: 320256
2017-12-09 16:56:18 +00:00
George Rimar ba7afd7043 [ELF] - Show .plt symbols in -Map output.
As mentioned in PR35471, shared functions for which
.plt entry address is used shows up in bfd's map files. 
Patch teaches LLD to do the same.

Differential revision: https://reviews.llvm.org/D40839

llvm-svn: 319879
2017-12-06 08:36:21 +00:00
George Rimar 31cd5da582 Recommit r319747 "[ELF] - Show copy relocated symbols in a --Map file output."
With fix:
Specify -soname for input dso to fix up the .dynstr section
size in different environments.

Original commit message:

As mentioned in PR35471, copied symbols did not show
in --Map output. Patch fixes that.

Differential revision: https://reviews.llvm.org/D40785

llvm-svn: 319769
2017-12-05 14:23:18 +00:00
George Rimar fe52e0064b [ELF] - Revert r319747 "[ELF] - Show copy relocated symbols in a --Map file output.".
It broke bots:
http://lab.llvm.org:8011/builders/lld-x86_64-darwin13/builds/15570/steps/test_lld/logs/stdio
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/10930/steps/check-lld%20asan/logs/stdio
http://lab.llvm.org:8011/builders/lld-x86_64-win7/builds/16336/steps/test%20lld/logs/stdio

According to outputs,
.dynstr section has different sizes for some reason.

llvm-svn: 319749
2017-12-05 09:38:05 +00:00
George Rimar d9ae97cdb6 [ELF] - Show copy relocated symbols in a --Map file output.
As mentioned in PR35471, copied symbols did not show
in --Map output. Patch fixes that.

Differential revision: https://reviews.llvm.org/D40785

llvm-svn: 319747
2017-12-05 09:13:45 +00:00
Rafael Espindola dfebd3601d Use Symbol::File directly.
We are already paying the cost of storing a InputFile in every
Symbol, so use it uniformly.

llvm-svn: 319378
2017-11-29 22:47:35 +00:00
Rafael Espindola 07b7ee4394 Simplify. NFC.
llvm-svn: 319370
2017-11-29 22:20:03 +00:00
Peter Collingbourne e9a9e0a1e7 ELF: Merge DefinedRegular and Defined.
Now that DefinedRegular is the only remaining derived class of
Defined, we can merge the two classes.

Differential Revision: https://reviews.llvm.org/D39667

llvm-svn: 317448
2017-11-06 04:35:31 +00:00
Rui Ueyama f52496e1e0 Rename SymbolBody -> Symbol
Now that we have only SymbolBody as the symbol class. So, "SymbolBody"
is a bit strange name now. This is a mechanical change generated by

  perl -i -pe s/SymbolBody/Symbol/g $(git grep -l SymbolBody lld/ELF lld/COFF)

nd clang-format-diff.

Differential Revision: https://reviews.llvm.org/D39459

llvm-svn: 317370
2017-11-03 21:21:47 +00:00
Rui Ueyama 4a22edabec Do not handle DefinedCommon symbols in the MapFile writer.
Because of r314495 which converts DefinedCommon symbols to DefinedRegular
symbols, common symbols are no longer reachable to the MapFile writer.
So the code to handle common symbols is now dead.

llvm-svn: 316846
2017-10-28 21:11:38 +00:00
Rui Ueyama 7f9694a42d Pass symbol attributes instead of ElfSym to Shared symbol ctor.
This change allows us to use less templates for Shared symbol and
the functions that deals with shared symbols.

llvm-svn: 316841
2017-10-28 20:15:56 +00:00
Bob Haarman 4f5c8c29ac [lld] Move Threads to Common
Summary:
This will allow using the functionality from other linkers. It is also
a prerequisite for sharing the error logging code.

Reviewers: ruiu

Reviewed By: ruiu

Subscribers: emaste, mgorny, llvm-commits

Differential Revision: https://reviews.llvm.org/D38822

llvm-svn: 315725
2017-10-13 18:22:55 +00:00
Rui Ueyama 6b394caaf1 Rename Commands -> SectionCommands.
"Commands" was ambiguous because in the linker script, everything is
a command. We used to handle only SECTIONS commands, and at the time,
it might make sense to call them the commands, but it is no longer
the case. We handle not only SECTIONS but also MEMORY, PHDRS, VERSION,
etc., and they are all commands.

llvm-svn: 315409
2017-10-11 01:50:56 +00:00
George Rimar 696a7f9ac6 [ELF] - Introduce std::vector<InputFile *> global arrays.
This patch removes lot of static Instances arrays from different input file 
classes and introduces global arrays for access instead. Similar to arrays we
have for InputSections/OutputSectionCommands.

It allows to iterate over input files in a non-templated code.

Differential revision: https://reviews.llvm.org/D35987

llvm-svn: 313619
2017-09-19 09:20:54 +00:00
Dmitry Mikulin 1e30f07ce7 Currently lld creates a single section to collect all commons. There is no way
to separate commons based on file name patterns. The following linker script
construct does not work because commons are allocated before section placement
is done and the only synthesized BssSection that holds all commons has no file
associated with it:
SECTIONS { .common_0 : { *file0.o(COMMON) }}

This patch changes the allocation of commons to create a section per common
symbol and let the section logic do the layout.

Differential revision: https://reviews.llvm.org/D37489

llvm-svn: 312796
2017-09-08 16:22:43 +00:00
George Rimar 45d2767ca7 [ELF] - Fixing buildbot.
http://lab.llvm.org:8011/builders/lld-x86_64-darwin13/builds/11517/steps/build_Lld/logs/stdio

llvm-svn: 310705
2017-08-11 11:46:56 +00:00
George Rimar f2fe963d83 [ELF] - Do not omit common symbols when -Map is given.
This is PR33886,

previously we did not output common symbols to map,
patch fixes that.

Differential revision: https://reviews.llvm.org/D36466

llvm-svn: 310703
2017-08-11 11:34:04 +00:00
Rafael Espindola 6e93d0546a Move File from SymbolBody to Symbol.
With this Symbol has the same size as before, but DefinedRegular goes
from 72 to 64 bytes.

I also find this a bit easier to read. There are fewer places
initializing File for example.

This has a small but measurable speed improvement on all tests (1%
max).

llvm-svn: 310142
2017-08-04 22:31:42 +00:00
Rafael Espindola f456f5729a Simplify. NFC.
llvm-svn: 310090
2017-08-04 18:42:04 +00:00
George Rimar 7b30dd1c53 [ELF] - Cleanup MapFile.cpp. NFC.
* Removed redundant templating.
* Added missing `static` keyword.

llvm-svn: 309376
2017-07-28 11:13:21 +00:00
Rafael Espindola 8c022ca783 Merge OutputSectionCommand and OutputSection.
This is a bit of a hack, but it is *so* convenient.

Now that we create synthetic linker scripts when none is provided, we
always have to handle paired OutputSection and OutputsectionCommand and
keep a mapping from one to the other.

This patch simplifies things by merging them and creating what used to
be OutputSectionCommands really early.

llvm-svn: 309311
2017-07-27 19:22:43 +00:00
Rui Ueyama 709fb2bb10 Rename ObjectFile -> ObjFile.
Rename it because it was too easy to conflict with llvm::object::ObjectFile
which broke buildbots several times.

llvm-svn: 309199
2017-07-26 22:13:32 +00:00
Rafael Espindola b4b485370c Try to fix the windows build.
llvm-svn: 309161
2017-07-26 19:39:40 +00:00
Rafael Espindola 244ef98161 Detemplate SymbolTable.
NFC, just makes it easier to access from non templated code.

llvm-svn: 309152
2017-07-26 18:42:48 +00:00
Peter Collingbourne b069a36f27 ELF: Exclude dead symbols from -Map output.
This was previously erroring out if one of the dead symbols was a
TLS symbol and we were able to discard all TLS sections.

Differential Revision: https://reviews.llvm.org/D35397

llvm-svn: 307984
2017-07-14 00:31:56 +00:00
Rafael Espindola 2d9a3be2ab Keep a list of all OutputSectionCommands.
Now that we are trying to use the linker script representation as the
canonycal one, there are a few loops looking for just OutputSectionCommands.

Create a vector with just the OutputSectionCommands once that is
stable to simplify the rest of the code.

llvm-svn: 304181
2017-05-30 01:30:14 +00:00
Rafael Espindola aeb4b7d217 Clear OutSec->Sections.
Once the dummy linker script is created, we want it to be used for
everything to avoid having two redundant representations that can get
out of sync.

We were already clearing OutputSections. With this patch we clear the
Sections vector of every OutputSection.

llvm-svn: 303703
2017-05-23 22:54:06 +00:00
Rafael Espindola a46f688e8f Use linker script commands in writeMapFile.
This converts the last (chronologically) user of OutputSections to use
the linker script commands instead.

The idea is to convert all uses after fabricateDefaultCommands, so
that we have a single representation.

llvm-svn: 303384
2017-05-18 21:30:14 +00:00
Rafael Espindola 1b41409079 Use a forward declaration. NFC.
llvm-svn: 303363
2017-05-18 17:26:00 +00:00
Rui Ueyama 33d903d1b0 Rename parallelFor -> parallelForEachN.
So that it is clear that the function is a wrapper for for_each_n.

llvm-svn: 302718
2017-05-10 20:02:19 +00:00
Rui Ueyama 3781137909 Fix comments.
llvm-svn: 301778
2017-04-30 20:58:20 +00:00
Rui Ueyama 3151958cbd Replace PrettyPrinter class in MapFile.cpp with a few non-member functions.
Since the output format has been simplified, the class to print
out a map file doesn't seem to be needed anymore. We can replace
it with a few non-member functions.

llvm-svn: 301715
2017-04-28 23:29:15 +00:00
Rui Ueyama 3012b371fd Change the format of the map file.
Previously, we printed out input sections and input files in
separate columns as shown below.

  Address          Size             Align Out     In      File    Symbol
  0000000000201000 0000000000000015     4 .text
  0000000000201000 000000000000000e     4         .text
  0000000000201000 000000000000000e     4                 foo.o
  0000000000201000 0000000000000000     0                         _start
  0000000000201005 0000000000000000     0                         f(int)
  000000000020100e 0000000000000000     0                         local
  0000000000201010 0000000000000002     4                 bar.o
  0000000000201010 0000000000000000     0                         foo
  0000000000201011 0000000000000000     0                         bar

This format doesn't make much sense because for each input section,
there's always exactly one input file. This patch changes the format
to this.

  Address          Size             Align Out     In      Symbol
  0000000000201000 0000000000000015     4 .text
  0000000000201000 000000000000000e     4         foo.o:(.text)
  0000000000201000 0000000000000000     0                 _start
  0000000000201005 0000000000000000     0                 f(int)
  000000000020100e 0000000000000000     0                 local
  0000000000201010 0000000000000002     4         bar.o:(.text)
  0000000000201010 0000000000000000     0                 foo
  0000000000201011 0000000000000000     0                 bar

Differential Revision: https://reviews.llvm.org/D32657

llvm-svn: 301683
2017-04-28 20:38:27 +00:00
Rui Ueyama 72408fb2ac Remove trailing whitespace from the -Map output.
If a string is shorter than 7 characters, we used to print out
trailing whitespace characters.

llvm-svn: 301668
2017-04-28 18:54:08 +00:00
Rui Ueyama 2634d0ff5c Remove a redundant local variable.
llvm-svn: 301661
2017-04-28 17:50:23 +00:00
Rui Ueyama b882e5910d Speed up the -Map option.
We found that some part of code for the -Map option takes O(m*n)
where m is the number of input sections in some file and n is
the number of symbols in the same file. If you do LTO, we usually
have only a few object files as inputs for the -Map option
feature, so this performance characteristic was worse than I
expected.

This patch rewrites the -Map option feature to speed it up.
I eliminated the O(m*n) bottleneck and also used multi-threading.

As a result, clang link time with the -Map option improved from
18.7 seconds to 11.2 seconds. Without -Map, it takes 7.7 seconds,
so the -Map option is now about 3x faster than before for this
test case (from 11.0 seconds to 3.5 seconds.) The generated output
file size was 223 MiB, and the file contains 1.2M lines.

Differential Revision: https://reviews.llvm.org/D32631

llvm-svn: 301659
2017-04-28 17:19:13 +00:00