Commit Graph

635 Commits

Author SHA1 Message Date
Simon Atanasyan 1a728fdf5c [ELF][MIPS] Simplify `if` condition. NFC
In case of MIPS ABI relocation has R_GOTREL expression's type iif the
relocation type is either R_MIPS_GPREL16 or R_MIPS_GPREL32. So it is
enough to check expression's type only.

llvm-svn: 268741
2016-05-06 15:02:45 +00:00
Rafael Espindola d39dadeb64 Don't produce a relocation to read only memory.
This is hopefully last case where we would produce a relocation to a
read only section.

llvm-svn: 268688
2016-05-05 21:19:38 +00:00
Rafael Espindola 66434562e7 Fix copy relocations in pie.
We were creating the copy relocations just fine, but then thinking that
the .bss position could be preempted and creating a dynamic relocation
to it, which would crash at runtime since that memory is read only.

llvm-svn: 268668
2016-05-05 19:41:49 +00:00
Peter Collingbourne 3ad1c1e242 ELF: Undefine all symbols, not just those that we expect to be defined.
This allows the combined LTO object to provide a definition with the same
name as a symbol that was internalized without causing a duplicate symbol
error. This normally happens during parallel codegen which externalizes
originally-internal symbols, for example.

In order to make this work, I needed to relax the undefined symbol error to
only report an error for symbols that are used in regular objects.

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

llvm-svn: 268649
2016-05-05 17:13:49 +00:00
Rafael Espindola 474eb019b4 Move static function to avoid forward declaration. NFC.
llvm-svn: 268646
2016-05-05 16:40:28 +00:00
Rafael Espindola 462220de47 Reuse logic for deciding whether to keep a local symbol or not.
llvm-svn: 268644
2016-05-05 16:38:46 +00:00
Peter Collingbourne e29e142a10 ELF: Do not use -1 to mark pieces of merge sections as being tail merged.
We were previously using an output offset of -1 for both GC'd and tail
merged pieces. We need to distinguish these two cases in order to filter
GC'd symbols from the symbol table -- we were previously asserting when we
asked for the VA of a symbol pointing into a dead piece, which would end
up asking the tail merging string table for an offset even though we hadn't
initialized it properly.

This patch fixes the bug by using an offset of -1 to exclusively mean GC'd
pieces, using 0 for tail merges, and distinguishing the tail merge case from
an offset of 0 by asking the output section whether it is tail merge.

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

llvm-svn: 268604
2016-05-05 04:10:12 +00:00
Rafael Espindola de17d28a32 Don't produce relative relocs to ro segments.
We were already checking for non relative relocations.

If we ever decide to add support for rw text segments this means we will
have a single spot to add the flag.

llvm-svn: 268558
2016-05-04 21:40:07 +00:00
Rafael Espindola 3fa5bbd91b Rename isRelRelative.
What it is computing is if we need a dynamic relocation or not.

llvm-svn: 268556
2016-05-04 21:28:56 +00:00
Rafael Espindola 946ca27b61 Use early return. NFC.
llvm-svn: 268554
2016-05-04 21:09:24 +00:00
Rafael Espindola 38bd217d0c Delete getTlsGotRel.
It was an old hack to avoid duplicating expression computation, but that
is not needed with getExprRel.

llvm-svn: 268515
2016-05-04 15:51:23 +00:00
Rafael Espindola ebb04b9eb6 Simplify handling of hint relocations.
llvm-svn: 268501
2016-05-04 14:44:22 +00:00
Simon Atanasyan add74f37f2 [ELF][MIPS] Read/write .MIPS.options section
MIPS N64 ABI introduces .MIPS.options section which specifies miscellaneous
options to be applied to an object/shared/executable file. LLVM as well as
modern versions of GNU tools read and write the only type of the options -
ODK_REGINFO. It is exact copy of .reginfo section used by O32 ABI.

llvm-svn: 268485
2016-05-04 10:07:38 +00:00
Peter Collingbourne 6f535b744f Check return value of addOptionalSynthetic before calling a member function on it.
Found with UBSan.

llvm-svn: 268410
2016-05-03 18:03:45 +00:00
Peter Collingbourne c357278a38 ELF: Remove the function SymbolTable<ELFT>::findFile.
We already have the function SymbolBody::getSourceFile which does the same thing.

llvm-svn: 268353
2016-05-03 01:48:25 +00:00
Peter Collingbourne 6a4225962d ELF: Forbid all relative relocations to absolute symbols in PIC, except for weak undefined.
Weak undefined symbols resolve to the image base. This is a little strange,
but it allows us to link function calls to such symbols. Normally such a
call will be guarded with a comparison, which will load a zero from the GOT.

There's one example of such a function call in crti.o in Linux's CRT.

As part of this change, I also needed to make the synthetic start and end
symbols image base relative in the case where their sections were empty,
so that PC-relative references to those symbols would continue to work.

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

llvm-svn: 268350
2016-05-03 01:21:08 +00:00
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