Commit Graph

619 Commits

Author SHA1 Message Date
Rui Ueyama dd368fcb05 Pass all buffers to BuildId hash function at once. NFC.
This change simplifies the BuildId classes by removing a few member
functions and variables from them. It should also make it easy to
parallelize hash computation in future because now each BuildId object
see all inputs rather than one at a time.

llvm-svn: 268333
2016-05-02 23:35:59 +00:00
Simon Atanasyan 63dcba05b7 Replace non-ascii character.
llvm-svn: 268218
2016-05-02 09:49:03 +00:00
Peter Collingbourne f643fc10d1 Further MSVC appeasement.
llvm-svn: 268185
2016-05-01 05:39:02 +00:00
Peter Collingbourne 4f9527065c ELF: New symbol table design.
This patch implements a new design for the symbol table that stores
SymbolBodies within a memory region of the Symbol object. Symbols are mutated
by constructing SymbolBodies in place over existing SymbolBodies, rather
than by mutating pointers. As mentioned in the initial proposal [1], this
memory layout helps reduce the cache miss rate by improving memory locality.

Performance numbers:

           old(s) new(s)
Without debug info:
chrome      7.178  6.432 (-11.5%)
LLVMgold.so 0.505  0.502 (-0.5%)
clang       0.954  0.827 (-15.4%)
llvm-as     0.052  0.045 (-15.5%)
With debug info:
scylla      5.695  5.613 (-1.5%)
clang      14.396 14.143 (-1.8%)

Performance counter results show that the fewer required indirections is
indeed the cause of the improved performance. For example, when linking
chrome, stalled cycles decreases from 14,556,444,002 to 12,959,238,310, and
instructions per cycle increases from 0.78 to 0.83. We are also executing
many fewer instructions (15,516,401,933 down to 15,002,434,310), probably
because we spend less time allocating SymbolBodies.

The new mechanism by which symbols are added to the symbol table is by calling
add* functions on the SymbolTable.

In this patch, I handle local symbols by storing them inside "unparented"
SymbolBodies. This is suboptimal, but if we do want to try to avoid allocating
these SymbolBodies, we can probably do that separately.

I also removed a few members from the SymbolBody class that were only being
used to pass information from the input file to the symbol table.

This patch implements the new design for the ELF linker only. I intend to
prepare a similar patch for the COFF linker.

[1] http://lists.llvm.org/pipermail/llvm-dev/2016-April/098832.html

Differential Revision: http://reviews.llvm.org/D19752

llvm-svn: 268178
2016-05-01 04:55:03 +00:00
Rafael Espindola a85efd985c Don't create dynamic relocations to ro segments.
These would just crash at runtime.

If we ever decide to support rw text segments this should make it easier
to implement as there is now a single point where we notice the problem.

I have tested this with a freebsd buildworld. It found a non pic
assembly file being linked into a .so,. With that fixed, buildworld
finished.

llvm-svn: 268149
2016-04-30 01:15:17 +00:00
Simon Atanasyan ae77ab71d8 [ELF][MIPS] Accept MIPS 64-bit binaries
LLD accepts MIPS 64-bit binaries, supports corresponding eulation (-m)
arguments and emits 64-bit specific ELF flags.

llvm-svn: 268024
2016-04-29 10:39:17 +00:00
Rui Ueyama 2b6fb80384 Skip scanRelocs for non-alloc sections.
Relocations against sections with no SHF_ALLOC bit are R_ABS relocations.
Currently we are creating Relocations vector for them, but that is wasteful.
This patch is to skip vector construction and to directly apply relocations
in place.

This patch seems to be pretty effective for large executables with debug info.
r266158 (Rafael's patch to change the way how we apply relocations) caused a
temporary performance degradation for such executables, but this patch makes
it even faster than before.

Time to link clang with debug info (output size is 1070 MB):

  before r266158: 15.312 seconds (0%)
  r266158:        17.301 seconds (+13.0%)
  Head:           16.484 seconds (+7.7%)
  w/patch:        13.166 seconds (-14.0%)

Differential Revision: http://reviews.llvm.org/D19645

llvm-svn: 267917
2016-04-28 18:42:04 +00:00
Rafael Espindola b8ff59ac12 Rename isRelRelative
It was never a particularly good name and is now completely out of date.

llvm-svn: 267886
2016-04-28 14:34:39 +00:00
George Rimar 959d180fa6 Fixed mistype in comment. NFC.
llvm-svn: 267878
2016-04-28 13:38:10 +00:00
Rui Ueyama e5c1ec4716 Add comment.
llvm-svn: 267847
2016-04-28 03:04:15 +00:00
Peter Collingbourne 21a12fc69a ELF: Create .gnu.version and .gnu.version_r sections when linking against versioned DSOs.
Differential Revision: http://reviews.llvm.org/D19464

llvm-svn: 267775
2016-04-27 20:22:31 +00:00
Rafael Espindola 7ac9628648 Reduce usage of isRelRelative.
It is now used only for relocations that only set the low bits inside a
page. Everything else is handled by getRelExpr.

I will send a another review renaming and better documenting
isRelRelative.

llvm-svn: 267705
2016-04-27 12:47:30 +00:00
Rafael Espindola 520ed3a621 Create a .got when PPC64 uses a TOC.
This simplifies the logic for computing the value of the toc base.

llvm-svn: 267701
2016-04-27 12:21:27 +00:00
Rafael Espindola 365e5f69c9 Simplify handling of R_PPC64_TOC. NFC.
llvm-svn: 267698
2016-04-27 11:54:07 +00:00
George Rimar 5f85732738 [ELF] - Align sections file offsets correctly.
System V ABI 4.1 specifies that program header's p_vaddr should equal p_offset, modulo p_align. 
(https://docs.oracle.com/cd/E19683-01/816-1386/chapter6-83432/index.html).
It was possible to violate this using the linkerscript.
Patch fixes the issue.

Differential revision: http://reviews.llvm.org/D19416

llvm-svn: 267684
2016-04-27 09:16:28 +00:00
Rui Ueyama 389aa8e91e Simplify. NFC.
llvm-svn: 267663
2016-04-27 03:04:56 +00:00
Peter Collingbourne 892d498017 ELF: Re-implement -u directly and remove CanKeepUndefined flag.
The semantics of the -u flag are to load the lazy symbol named by the flag. We
were previously relying on this behavior falling out of symbol resolution
against a synthetic undefined symbol, but that didn't quite give us the
correct behavior, so we needed a flag to mark symbols created with -u so
we could treat them specially in the writer. However, it's simpler and less
error prone to implement the required behavior directly and remove the flag.

This fixes an issue where symbols loaded with -u would receive hidden
visibility even when the definition in an object file had wider visibility.

Differential Revision: http://reviews.llvm.org/D19560

llvm-svn: 267639
2016-04-27 00:05:03 +00:00
Peter Collingbourne 676c7cd1ed ELF: Move code to where it is used, and related cleanups. NFC.
Differential Revision: http://reviews.llvm.org/D19490

llvm-svn: 267637
2016-04-26 23:52:44 +00:00
Rafael Espindola 1763dc44b9 Return R_GOTREL for R_MIPS_GPREL*.
This lets Writer.cpp know that they are got relative, which will allow
further simplifications.

llvm-svn: 267613
2016-04-26 22:00:04 +00:00
Rafael Espindola 6c75238aca Call repl in getSymbolBody. NFC.
Every caller was doing it.

llvm-svn: 267603
2016-04-26 20:45:31 +00:00
Rafael Espindola 0baa73f317 Handle --as-needed with symbols, not relocations.
This matches the behavior of both gold and bfd.

llvm-svn: 267558
2016-04-26 13:56:26 +00:00
Rafael Espindola 9e32e4fe86 Store the binding in the Symbol.
This remove a fixme, cleans up the weak undef interaction with archives and
lets us keep weak undefs still weak if they resolve to shared.

llvm-svn: 267555
2016-04-26 13:50:46 +00:00
Rafael Espindola a6c4d2f197 Delete needsCopyRelImpl. It is redundant with getRelExpr.
llvm-svn: 267394
2016-04-25 12:05:56 +00:00
Simon Atanasyan c245d84213 [ELF] Delete extra line. NFC
llvm-svn: 267391
2016-04-25 10:18:48 +00:00
Peter Collingbourne 6d01a35ef6 ELF: Forbid undefined symbols with non-default visibility in DSOs.
llvm-svn: 267315
2016-04-24 02:31:04 +00:00
Rafael Espindola 0b9531c8e6 Bring r267164 back with a fix.
The fix is to handle local symbols referring to SHF_MERGE sections.

Original message:

GC entries of SHF_MERGE sections.

It is a fairly direct extension of the gc algorithm. For merge sections
instead of remembering just a live bit, we remember which offsets
were used.

This reduces the .rodata sections in chromium from 9648861 to 9477472
bytes.

llvm-svn: 267233
2016-04-22 22:09:35 +00:00
Peter Collingbourne dadcc17ead ELF: Move Visibility, IsUsedInRegularObj and MustBeInDynSym flags to Symbol.
These are properties of a symbol name, rather than a particular instance
of a symbol in an object file. We can simplify the code by collecting these
properties in Symbol.

The MustBeInDynSym flag has been renamed ExportDynamic, as its semantics
have been changed to be the same as those of --dynamic-list and
--export-dynamic-symbol, which do not cause hidden symbols to be exported.

Differential Revision: http://reviews.llvm.org/D19400

llvm-svn: 267183
2016-04-22 18:42:48 +00:00
Rui Ueyama 467dbdd030 Remove SymPair and instead use two DefinedRegulars instead.
I noticed that I was looking for the definition of SymPair when hacking
the Writer, only to find that it is just a pair of DefinedRegular symbols.
I don't think it provides more values than the cost of using brainpower
to memorize the type. I didn't roll back r266317, which introduced SymPair,
because the patch removes code repetitions. I ported that change to new
code.

llvm-svn: 267047
2016-04-21 20:50:15 +00:00
Rafael Espindola ae605c1b0c Start adding support for internalizing shared libraries.
llvm-svn: 267045
2016-04-21 20:35:25 +00:00
Rafael Espindola e26b50e71a Reduce templating. NFC.
llvm-svn: 267018
2016-04-21 17:37:11 +00:00
Rafael Espindola b312a740ae Delete the needsPlt target hook.
It can be made redundant with getRelExpr.

llvm-svn: 267012
2016-04-21 17:30:24 +00:00
Rafael Espindola 34b335bdf7 Don't recompute getRelExpr. NFC.
llvm-svn: 267005
2016-04-21 16:59:25 +00:00
Rafael Espindola 0c869a752e Moves needsPlt to Writer.cpp.
It was only used there.

llvm-svn: 267002
2016-04-21 16:57:32 +00:00
Simon Atanasyan ca58a8ff5b [ELF][MIPS] Create GOT entries for R_MIPS_REL32 dynamic relocations
MIPS ABI turns using of GOT and dynamic relocations inside out. While
regular ABI uses dynamic relocations to fill up GOT entries MIPS ABI
requires dynamic linker to fills up GOT entries using specially sorted
dynamic symbol table. This affects even dynamic relocations against
symbols which do not require GOT entries creation explicitly, i.e. do
not have any GOT-relocations. So if a preemptible symbol has a dynamic
relocation we anyway have to create a GOT entry for it.

If a non-preemptible symbol has a dynamic relocation against it, dynamic
linker takes it st_value, adds offset and writes down result of the
dynamic relocation. In case of preemptible symbol dynamic linker
performs symbol resolution, writes the symbol value to the GOT entry and
reads the GOT entry when it needs to perform a dynamic relocation.

Differential Revision: http://reviews.llvm.org/D18948

llvm-svn: 266921
2016-04-20 21:40:33 +00:00
Rui Ueyama 07320e4030 ELF: Template LinkerScript class.
Originally, linker scripts were basically an alternative way to specify
options to the command line options. But as we add more features to hanlde
symbols and sections, many member functions needed to be templated.
Now most the members are templated. It is probably time to template the
entire class.

Previously, LinkerScript is an executor of the linker script as well as
a storage of linker script configurations. This is not suitable to template
the class because when we are reading linker script files, we don't know
the ELF type yet, so we can't instantiate ELF-templated classes.

In this patch, I defined a new class, ScriptConfiguration, to store
linker script configurations. ScriptParser writes parse results to it,
and LinkerScript uses them.

Differential Revision: http://reviews.llvm.org/D19302

llvm-svn: 266908
2016-04-20 20:13:41 +00:00
Rafael Espindola c6b17bdc29 Delete refersToGotEntry.
It can be computed from the expression.

llvm-svn: 266890
2016-04-20 17:30:22 +00:00
Rafael Espindola 475dbf42e4 Simplify mips gp0 handling.
In all currently supported cases this is a nop.

llvm-svn: 266888
2016-04-20 17:20:49 +00:00
Rafael Espindola 2081dbcc7a Inline canRelaxTls.
It was always called in a position where the relocation type was already
known.

llvm-svn: 266880
2016-04-20 15:01:42 +00:00
Rafael Espindola f54413c18e Simplify canRelaxTls.
Check isTls in the called and pass a SymbolBody&.

llvm-svn: 266879
2016-04-20 14:52:18 +00:00
Rafael Espindola cc36a63f0b Move canRelaxTls to Writer.cpp. NFC.
llvm-svn: 266878
2016-04-20 14:41:55 +00:00
Rafael Espindola 6eda85ac1f Delete needsDynRelative.
It is now redundant. Writer.cpp can reason that 2 dynamic relocations
are needed: one to find the final got entry address and one to fill the
got entry.

llvm-svn: 266876
2016-04-20 14:36:24 +00:00
Rafael Espindola 58cd5db4ef Simplify mips got handling.
This avoids computing the address of a position in the got just to then
subtract got->getva().

llvm-svn: 266831
2016-04-19 22:46:03 +00:00
Rafael Espindola 5bf59728e2 Remove isGotRelative.
It is now redundant with the expression. While at it, handle both "X -
Got" and "Got - PC".

llvm-svn: 266607
2016-04-18 12:31:37 +00:00
Rafael Espindola 3f5d634c73 Have getRelExpr handle all cases on x86.
This requires adding a few more expression types, but is already a small
simplification. Having Writer.cpp know the exact expression will also
allow further simplifications.

llvm-svn: 266604
2016-04-18 12:07:13 +00:00
Rafael Espindola 99c224787b Delete the now redundant pointsToLocalDynamicGotEntry.
llvm-svn: 266584
2016-04-18 01:34:20 +00:00
Rafael Espindola df17277d72 Have getRelExpr return the final values for tls gd.
llvm-svn: 266583
2016-04-18 01:29:15 +00:00
Rafael Espindola c4d56970dc Change getRelExpr to return the final value for TLSLD. NFC.
llvm-svn: 266580
2016-04-18 00:28:57 +00:00
George Rimar 652852c5c0 Recommitted 266457 with fix:
* Do script driven layout only if SECTIONS section exist.

Initial commit message:

[ELF] - Implemented basic location counter support.

This patch implements location counter support. 
It also separates assign addresses for sections to assignAddressesScript() if it scipt exists.

Main testcase is test/ELF/linkerscript-locationcounter.s, It contains some work with location counter. It is basic now.
Implemented location counter assignment and '+' operations.

Patch by myself with LOTS of comments and design suggestions from Rui Ueyama.

Differential revision: http://reviews.llvm.org/D18499

llvm-svn: 266526
2016-04-16 10:10:32 +00:00
Rui Ueyama faac567e68 Revert r266457: "[ELF] - Implemented basic location counter support."
This reverts commit r266457 as it breaks "hello world" both on
Linux and FreeBSD.

llvm-svn: 266485
2016-04-15 22:39:27 +00:00
Rafael Espindola 5628ee7631 Simplify got handling.
Each getRelExpr is now expected to return the correct got expression
instead of having Writer patch it up with needsGot.

llvm-svn: 266466
2016-04-15 19:14:18 +00:00