Commit Graph

290 Commits

Author SHA1 Message Date
Rafael Espindola 1a5411238e Revert "[ELF] Make InputSection<ELFT>::writeTo virtual"
This reverts commit r286100.

This saves 8 bytes of every InputSection.

llvm-svn: 286235
2016-11-08 14:47:16 +00:00
Eugene Leviant 0a8f1fe6f7 [ELF] Make InputSection<ELFT>::writeTo virtual
Differential revision: https://reviews.llvm.org/D26281

llvm-svn: 286100
2016-11-07 09:04:06 +00:00
Rui Ueyama e8a6102fa9 Rewrite CommonInputSection as a synthetic input section.
A CommonInputSection is a section containing all common symbols.
That was an input section but was abstracted in a different way
than the synthetic input sections because it was written before
the synthetic input section was invented.

This patch rewrites CommonInputSection as a synthetic input section
so that it behaves better with other sections.

llvm-svn: 286053
2016-11-05 23:05:47 +00:00
Rafael Espindola e19abab9a7 Now that the ELFFile constructor does nothing, create it when needed.
This avoids duplicating the buffer in InputFile.

llvm-svn: 285965
2016-11-03 20:44:50 +00:00
Rafael Espindola 454fe154a7 Update for llvm change.
llvm-svn: 285956
2016-11-03 19:07:44 +00:00
Rui Ueyama 6dc7fcbec4 Create SyntheticSections.cpp.
We are going to have many more classes for linker-synthesized
input sections, so it's worth to be added to a separate file
than to the file for regular input sections.

llvm-svn: 285740
2016-11-01 20:28:21 +00:00
Davide Italiano 1da3a52d11 [ELF/GC] Fix pending references to garbage collected sections.
The example reported in PR30793 shows a case where gc reclaims
a SHF_TLS section, but it doesn't reclaim the section containing
the debug info for it.
This is expected, as we do not reclaim non-alloc sections
during the garbage collection phase (and this is not going to
change anytime soon, at least this is what I gathered last I
talked with Rafael about it).
So, we end up with a pending reference, thinking that the input
was invalid (which is not true, as it's GC that removed the
SHT_TLS section, and therefore didn't create the PT_TLS *segment*
for it). In cases like this, just assign a VA of zero at relocation
time instead of error'ing out (this is what gold does as well, FWIW).

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

llvm-svn: 285735
2016-11-01 20:11:01 +00:00
Rafael Espindola 092d3b7f3b Don't store an OutputLoc in every InputSection.
It was only used by build-id and that can easily compute it.

llvm-svn: 285691
2016-11-01 13:57:19 +00:00
Eugene Leviant 282251a226 Convert BuildIdSection to input section
Differential revision: https://reviews.llvm.org/D25627

llvm-svn: 285682
2016-11-01 09:49:24 +00:00
Eugene Leviant c4681203e1 Allow fetching source line, when multiple "AX" sections present
Differential revision: https://reviews.llvm.org/D26070

llvm-svn: 285680
2016-11-01 09:17:50 +00:00
Rafael Espindola 093abab817 Don't create a dummy ELF to process a binary file.
Now that it is easy to create input section and symbols, this is
simple.

llvm-svn: 285322
2016-10-27 17:45:40 +00:00
Rafael Espindola 99558efed6 Pass a InputSectionData to classoff.
This allows a non template class to hold input sections.

llvm-svn: 285221
2016-10-26 18:44:57 +00:00
Rafael Espindola 1854a8ebb8 Delete trivial getters. NFC.
llvm-svn: 285190
2016-10-26 12:36:56 +00:00
Rafael Espindola 0e090522c8 Read section headers upfront.
Instead of storing a pointer, store the members we need.

The reason for doing this is that it makes it far easier to create
synthetic sections. It also avoids reading data from files multiple
times., which might help with cross endian linking and host
architectures with slow unaligned access.

There are obvious compacting opportunities, but this already has mixed
results even on native x86_64 linking.

There is also the possibility of better refactoring the code for
handling common symbols, but this already shows that a custom class is
not necessary.

llvm-svn: 285148
2016-10-26 00:54:03 +00:00
Rafael Espindola 397f0aa0d3 Be a bit more consistent about using getters. NFC.
llvm-svn: 285082
2016-10-25 16:42:46 +00:00
Rafael Espindola 58139d1758 Delete getSectionHdr.
We were fairly inconsistent as to what information should be accessed
with getSectionHdr and what information (like alignment) was stored
elsewhere.

Now all section info has a dedicated getter. The code is also a bit
more compact.

llvm-svn: 285079
2016-10-25 16:14:25 +00:00
Simon Atanasyan bed04bf1df [ELF][MIPS] Put local GOT entries accessed via a 16-bit index first
Some MIPS relocations used to access GOT entries are able to manipulate
16-bit index. The other ones like R_MIPS_CALL_HI16/LO16 can handle
32-bit indexes. 16-bit relocations are generated by default. The 32-bit
relocations are generated by -mxgot flag passed to compiler. Usually
these relocation are not mixed in the same code but files like crt*.o
contain 16-bit relocations so even if all "user's" code compiled with
-mxgot flag a few 16-bit relocations might come to the linking phase.

Now LLD does not differentiate local GOT entries accessed via a 16-bit
and 32-bit indexes. That might lead to relocation's overflow if 16-bit
entries are allocated to far from the beginning of the GOT.

The patch introduces new "part" of MIPS GOT dedicated to the local GOT
entries accessed by 32-bit relocations. That allows to put local GOT
entries accessed via a 16-bit index first and escape relocation's overflow.

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

llvm-svn: 284809
2016-10-21 07:22:30 +00:00
Rafael Espindola 113860b9ae Compact SectionPiece.
We allocate a lot of these when linking debug info. This speeds up the
link of debug programs by 1% to 2%.

llvm-svn: 284716
2016-10-20 10:55:58 +00:00
Peter Smith d648603415 [ELF] Allow relative exceptions relocations in shared libraries
The R_ARM_PREL31 and R_ARM_NONE relocations should not be faulted in
shared libraries. In the case of R_ARM_NONE, we have moved the TLS
relaxation hint instruction to R_TLSDESC_CALL so that R_HINT can be used
without side-effects. In the case of R_ARM_PREL31 we permit it to be used
against PLT entries as the personality routines are imported when used in
shared libraries.

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

llvm-svn: 284710
2016-10-20 09:59:26 +00:00
George Rimar a4c7e74d4b [ELF] - Applied clang format. NFC.
llvm-svn: 284705
2016-10-20 08:36:42 +00:00
Rafael Espindola 116d83fbe0 Don't call markLiveAt for non alloc sections.
We don't gc them anyway, so just use an early return in Enqueue.

llvm-svn: 284663
2016-10-19 23:13:40 +00:00
Rafael Espindola 2adccee13f Don't gc non-alloca non-string pieces.
We were already doing it for strings. This matches the behavior of
bfd and gold.

llvm-svn: 284598
2016-10-19 14:50:26 +00:00
Rafael Espindola 88eb6482ca Add a faster binary search.
Even with the hash table cache, binary search was still pretty
hot. This can be made even faster with prefetching.

Idea from http://cglab.ca/~morin/misc/arraylayout-v2/

I will suggest moving this to llvm.

llvm-svn: 284594
2016-10-19 14:17:36 +00:00
Rafael Espindola ad74c1cfdf Use reserve instead of grow.
The table was still being resized as grow doesn't account for the fact
that the table needs to remain 3/4 full.

llvm-svn: 284487
2016-10-18 15:31:23 +00:00
Justin Lebar ee34a7343d [ADT] Move CachedHashString to its own header in ADT, and rename to CachedHashStringRef.
Summary:
Reclaiming the name 'CachedHashString' will let us add a type with that
name that owns its value.

Reviewers: timshen

Subscribers: llvm-commits

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

llvm-svn: 284434
2016-10-17 22:24:36 +00:00
Rui Ueyama acb67bcb98 Move a utility function to Strings.cpp.
So that we can use the function from anywhere.

llvm-svn: 284092
2016-10-13 00:13:15 +00:00
Rui Ueyama 5665af836f Fix variable name. NFC.
llvm-svn: 284079
2016-10-12 23:22:59 +00:00
Rui Ueyama 05384080df Support GNU-style ZLIB-compressed input sections.
Previously, we supported only SHF_COMPRESSED sections because it's
new and it's the ELF standard. But there are object files compressed
in the GNU style out there, so we had to support it.

Sections compressed in the GNU style start with ".zdebug_" and
contain different headers than the ELF standard's one. In this
patch, getRawCompressedData is responsible to handle it.

A tricky thing about GNU-style compressed sections is that we have
to rename them when creating output sections. ".zdebug_" prefix
implies the section is compressed. We need to rename ".zdebug_"
".debug" because our output sections are not compressed.
We do that in this patch.

llvm-svn: 284068
2016-10-12 22:36:31 +00:00
Peter Smith 0a259f3b9c [ELF][ARM] Initial implentation of ARM exceptions support
The .ARM.exidx sections contain a table. Each entry has two fields:
- PREL31 offset to the function the table entry describes
- Action to take, either cantunwind, inline unwind, or PREL31 offset to
  .ARM.extab section

The table entries must be sorted in order of the virtual addresses the
first entry of the table describes. Traditionally this is implemented by
the SHF_LINK_ORDER dependency. Instead of implementing this directly we
sort the table entries post relocation. 

The .ARM.exidx OutputSection is described by the PT_ARM_EXIDX program
header

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

llvm-svn: 283730
2016-10-10 09:39:26 +00:00
Rui Ueyama 8c8ff00b28 Improve comments.
Also use uint64_t instead of uintX_t so that you don't have to
think about two different cases to verify that the code is correct.

llvm-svn: 283585
2016-10-07 19:54:57 +00:00
Rafael Espindola 88b9d66d4a Add () for clarity. NFC.
llvm-svn: 283556
2016-10-07 14:23:28 +00:00
George Rimar 7c213fd17e [ELF] - Check that section alignment is a power of 2.
I found that this check still may be useful in some cases.
At fact since we use uint32_t alignment, then maximum value
that is valid for us is 0x80000000. But some broken files,
for example file from testcase may have greater value.
Because of that offset calculation overflow and crash happens.

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

llvm-svn: 283544
2016-10-07 12:27:45 +00:00
Rafael Espindola 5fc2b1d2fe Store the hash in SectionPiece.
This spreads out computing the hash and using it in a hash table. The
speedups are:

firefox
  master 6.811232891
  patch  6.559280249 1.03841162939x faster
chromium
  master 4.369323666
  patch  4.33171853 1.00868134338x faster
chromium fast
  master 1.856679971
  patch  1.850617741 1.00327578725x faster
the gold plugin
  master 0.32917962
  patch  0.325711944 1.01064645023x faster
clang
  master 0.558015452
  patch  0.550284165 1.01404962652x faster
llvm-as
  master 0.032563515
  patch  0.032152077 1.01279662275x faster
the gold plugin fsds
  master 0.356221362
  patch  0.352772162 1.00977741549x faster
clang fsds
  master 0.635096494
  patch  0.627249229 1.01251060127x faster
llvm-as fsds
  master 0.030183188
  patch  0.029889544 1.00982430511x faster
scylla
  master 3.071448906
  patch  2.938484138 1.04524944215x faster

This seems to be because we don't stall as much. When linking firefox
stalled-cycles-frontend goes from 57.56% to 55.55%.

With -O2 the difference is even more significant since we avoid
recomputing the hash. For firefox we go from 9.990295265 to
 9.149627521 seconds (1.09x faster).

llvm-svn: 283367
2016-10-05 19:36:02 +00:00
Rafael Espindola 32aca87bf8 Compact SectionPiece.
It is pretty easy to get the data from the InputSection, so we don't
have to store it.

This opens the way for storing the hash instead.

llvm-svn: 283357
2016-10-05 18:40:00 +00:00
Rafael Espindola 939e9493bf Simplify setting the Live bit in SectionPiece. NFC.
llvm-svn: 283340
2016-10-05 17:02:09 +00:00
George Rimar 422e47a9f5 [ELF] - Do not hang if broken object has option descriptor in .MIPS.options with size of zero.
Previously lld would hang in infinite loop in this case,
patch fixes the issue. Object was found during AFL run.

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

llvm-svn: 283208
2016-10-04 10:23:07 +00:00
Simon Atanasyan 3a61cabbb2 [ELF][MIPS] Do not accept non-zero GP0 value for relocatable object only
Follow-up to r282716. Reject input files with non-zero GP0 value only in
case of relocatable object generation. In other case we can handle
arbitrary GP0 value so it does not have a sense to make the restriction
so wide.

llvm-svn: 283194
2016-10-04 08:24:25 +00:00
George Rimar 2c0a7f081a [ELF] - Do not crash on invalid section alignment.
Case was revealed by id_000010,sig_08,src_000000,op_havoc,rep_4 from PR30540.

Out implementation uses uint32 for storing section alignment value,
what seems reasonable, though if value exceeds 32 bits bounds we have
truncation and final value of 0.

Patch fixes the issue.

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

llvm-svn: 283097
2016-10-03 10:04:38 +00:00
George Rimar f50bafc708 [ELF] - Inlined template argument variable. NFC.
llvm-svn: 282851
2016-09-30 13:46:34 +00:00
Rafael Espindola 2629602f28 Fix another --gc-sections crash.
The missing case was when a merge section was only referenced from
non-alloca sections.

llvm-svn: 282847
2016-09-30 06:48:09 +00:00
Rafael Espindola c1eff79f61 Fix --gc-sections crash.
We would crash when a non-alloca section pointed to a gced part of a
merge section.

That can happen when a C/c++ constant in put in a merge section and
debug info is present.

llvm-svn: 282845
2016-09-30 06:37:29 +00:00
Simon Atanasyan 353fc1e947 [ELF][MIPS] Set GP0 value to zero in case of relocatable object generation
LLD does not update relocations addends when generate a relocatable
object. That is why we should not write a non-zero GP0 value into
the .reginfo and .MIPS.options sections. And we should not accept input
object files with non-zero GP0 value because we cannot handle them
properly.

llvm-svn: 282716
2016-09-29 12:58:48 +00:00
Eugene Leviant d2778848ef Don't GC non-alloc mergeable section pieces
Differential revision: https://reviews.llvm.org/D25033

llvm-svn: 282708
2016-09-29 10:27:10 +00:00
Davide Italiano 03f7005375 [ELF] Resolve weak undefined TLS symbols when no phdr is available.
If we pass --gc-sections to lld and .tbss is not referenced,
the section is reclaimed and lld doesn't create a TLS program header.
R_TLS tries to access the program header -> lld crashes.
Mimic what bfd/gold do in this case and resolve a weak undefined
TLS symbol to the base of the TLS block, i.e. give it a value of zero.

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

llvm-svn: 282279
2016-09-23 18:47:50 +00:00
Rui Ueyama 2d7fe598f2 Turn a no-op assignment into an assertion.
r279456 guarantees that this condition is always satisfied.

llvm-svn: 281426
2016-09-14 00:09:50 +00:00
Rafael Espindola c7e1e03498 Store an ArrayRef for Data in InputSectionData.
llvm-svn: 281210
2016-09-12 13:13:53 +00:00
Rafael Espindola 54f1614ec1 Revert "Revert "Compact InputSectionData from 64 to 48 bytes. NFC.""
This reverts commit r281096.

The previous link errors should be fixed by r281208.

llvm-svn: 281209
2016-09-12 13:06:10 +00:00
Rafael Espindola 78fe670994 Revert "Compact InputSectionData from 64 to 48 bytes. NFC."
This reverts commit r281084.

The link was failing on some bots. No idea why. I will try to
reproduce it on Monday.

llvm-svn: 281096
2016-09-09 21:20:30 +00:00
Rafael Espindola 82621dcb10 Compact InputSectionData from 64 to 48 bytes. NFC.
llvm-svn: 281084
2016-09-09 19:42:11 +00:00
Rafael Espindola 042a3f209b Compute section names only once.
This simplifies error handling as there is now only one place in the
code that needs to consider the possibility that the name is
corrupted. Before we would do it in every access.

llvm-svn: 280937
2016-09-08 14:06:08 +00:00