Commit Graph

377 Commits

Author SHA1 Message Date
Rafael Espindola 13dbf944d8 Simplify. NFC.
If a section has been replaced (Sec != Sec->Repl) it is not Live.

llvm-svn: 320597
2017-12-13 17:36:53 +00:00
Rafael Espindola 8f619ab826 Compact symbols from 96 to 88 bytes.
By using an index instead of a pointer for verdef we can put the index
next to the alignment field. This uses the otherwise wasted area and
reduces the shared symbol size.

By itself the performance change of this is in the noise, but I have a
followup patch to remove another 8 bytes that improves performance
when combined with this.

llvm-svn: 320449
2017-12-12 01:45:49 +00:00
Rafael Espindola 87e0deaea7 Move RelaPlt and RelaIplt to InX. NFC.
llvm-svn: 320327
2017-12-10 20:07:03 +00:00
Rafael Espindola 58946cdb08 Move RelaDyn to InX. NFC.
llvm-svn: 320324
2017-12-10 19:44:42 +00:00
Rafael Espindola 6d907105c5 Remove this->. NFC.
llvm-svn: 320323
2017-12-10 19:28:32 +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
Rui Ueyama 04c821c7e3 Use lambda to simplify code.
Differential Revision: https://reviews.llvm.org/D40994

llvm-svn: 320130
2017-12-08 02:20:50 +00:00
Rafael Espindola d182aaa69d Further simplify .gnu.hash writing. NFC.
llvm-svn: 320072
2017-12-07 18:59:29 +00:00
Rafael Espindola f9f2abe7bd Simplify .gnu.hash writing. NFC.
llvm-svn: 320070
2017-12-07 18:51:19 +00:00
Rafael Espindola 50ca10bb58 Avoid using a temporary std::vector.
With this memory usage when linking clang goes from 174.62MB to
172.77MB.

llvm-svn: 320069
2017-12-07 18:46:03 +00:00
Rui Ueyama c4e50bfc55 Fix broken .gnu.hash section if -no-rosegment is given.
We fill executable sections with trap instructions (0xcc or equivalent).
If a .gnu.hash section was put into an executable segment, we created
corrupted .gnu.hash section. This patch fixes the issue.

llvm-svn: 319863
2017-12-06 00:49:48 +00:00
Rui Ueyama 2278826c60 Cache modulo values for the .gnu.hash section.
This change actually makes the linker slightly faster. My observation
is that, with this patch, link time of clang without debug is about 1%
faster.

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

llvm-svn: 319600
2017-12-02 00:37:13 +00:00
George Rimar 78e27e830d [ELF] - Produce relocation section name consistent with output section name when --emit-reloc used with linker script.
This is for "Bug 35474 - --emit-relocs produces wrongly-named reloc sections".

LLD currently for scripts like:

.text.boot : { *(.text.boot) }
emits relocation section with name .rela.text because does not take
redefined name of output section into account and builds section name
using rules for non-scripted case. Patch fixes this oddness.

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

llvm-svn: 319526
2017-12-01 09:04:52 +00:00
Rui Ueyama 1cf7f9cc80 Make .gnu.hash section smaller.
Our on-disk hash table was unnecessarily large. The cost of collision is
not high in the .gnu.hash table because each symbol in the .gnu.hash
table has a hash value with it. So, for each collided symbol, the
dynamic linker just compares an integer, which is pretty cheap.

This patch increases the load factor by about 8. Here's a comparison.

  $ readelf --histogram libclangSema.so.6.0.0svn-new-lld
  Histogram for `.gnu.hash' bucket list length (total of 582 buckets):
   Length  Number     % of total  Coverage
        0  11         (  1.9%)
        1  35         (  6.0%)      1.5%
        2  93         ( 16.0%)      9.5%
        3  108        ( 18.6%)     23.4%
        4  121        ( 20.8%)     44.1%
        5  86         ( 14.8%)     62.6%
        6  63         ( 10.8%)     78.8%
        7  38         (  6.5%)     90.2%
        8  18         (  3.1%)     96.4%
        9  6          (  1.0%)     98.7%
       10  3          (  0.5%)    100.0%

  $ readelf --histogram libclangSema.so.6.0.0svn-old-lld
  Histogram for `.gnu.hash' bucket list length (total of 4093 buckets):
   Length  Number     % of total  Coverage
        0  1498       ( 36.6%)
        1  1545       ( 37.7%)     37.7%
        2  712        ( 17.4%)     72.5%
        3  251        (  6.1%)     90.9%
        4  66         (  1.6%)     97.3%
        5  16         (  0.4%)     99.3%
        6  5          (  0.1%)    100.0%

  $ readelf --histogram libclangSema.so.6.0.0svn-bfd
  Histogram for `.gnu.hash' bucket list length (total of 1004 buckets):
   Length  Number     % of total  Coverage
      0  92         (  9.2%)
        1  227        ( 22.6%)      9.8%
        2  266        ( 26.5%)     32.6%
        3  222        ( 22.1%)     61.2%
        4  115        ( 11.5%)     81.0%
        5  55         (  5.5%)     92.8%
        6  21         (  2.1%)     98.2%
        7  6          (  0.6%)    100.0%

  $ readelf --histogram libclangSema.so.6.0.0svn-gold
  Histogram for `.gnu.hash' bucket list length (total of 2053 buckets):
   Length  Number     % of total  Coverage
        0  671        ( 32.7%)
        1  709        ( 34.5%)     30.4%
        2  470        ( 22.9%)     70.7%
        3  141        (  6.9%)     88.9%
        4  54         (  2.6%)     98.2%
        5  5          (  0.2%)     99.2%
        6  3          (  0.1%)    100.0%

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

llvm-svn: 319503
2017-11-30 23:59:40 +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
Rui Ueyama 2017d52b54 Move Memory.{h,cpp} to Common.
Differential Revision: https://reviews.llvm.org/D40571

llvm-svn: 319221
2017-11-28 20:39:17 +00:00
Rui Ueyama 15475e92c6 Use lambdas to store lazy-evaluated .dynamic entries.
Differential Revision: https://reviews.llvm.org/D40338

llvm-svn: 318938
2017-11-24 02:15:51 +00:00
Rafael Espindola de56343cf0 Simplify as-needed handling.
This is a reduction of a patch by Rui Ueyama.

llvm-svn: 318852
2017-11-22 17:50:42 +00:00
James Henderson f70c5beb22 [ELF] Fix DT_MIPS_LOCAL_GOTNO value for thunks and linker scripts
The MIPS GOT section has a number of local entries based on the number of pages
needed for output sections referenced by GOT page relocations. The number is
recorded in the DT_MIPS_LOCAL_GOTNO dynamic section tag. However, the dynamic tag
is added before assignAddresses has been called, meaning that any section size used
to calculate the value will not include size modifications caused by, for example,
linker scripts and thunks.

This change moves the calculation of DT_MIPS_LOCAL_GOTNO until writeTo, by which
time the output section sizes have been finalized.

Reviewers: ruiu, rafael

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

llvm-svn: 318828
2017-11-22 12:04:21 +00:00
Rafael Espindola bec3765bea Remove IsLocal.
Since we always have Binding in the current symbol design IsLocal is
redundant.

llvm-svn: 318497
2017-11-17 01:37:50 +00:00
Rafael Espindola a5d43d004a Propagate sh_entsize out.
No difference in practice other than having sh_entsize in the output.

This should simplify the patch for handling SHF_MERGE in -r.

Based on a patch by George Rimar.

llvm-svn: 318306
2017-11-15 16:56:20 +00:00
Simon Atanasyan cfa8aa7edb [MIPS] Set STO_MIPS_MICROMIPS flag and less-significant bit for microMIPS symbols
microMIPS symbols including microMIPS PLT records created for regular
symbols needs to be marked by STO_MIPS_MICROMIPS flag in a symbol table.
Additionally microMIPS entries in a dynamic symbol table should have
configured less-significant bit. That allows to escape teaching a
dynamic linker about microMIPS symbols.

llvm-svn: 318097
2017-11-13 22:40:36 +00:00
Simon Atanasyan 5a4e21364c [MIPS] Setup less-significant bit in the .got and .got.plt entries in case of microMIPS code
The less-significant bit signals about microMIPS code for jump/branch
instructions.

llvm-svn: 317741
2017-11-08 23:34:34 +00:00
Rui Ueyama 7957b08e87 Move MIPS-specific code from Symbols.cpp to MIPS.cpp.
We have a lot of "if (MIPS)" conditions in lld because the MIPS' ABI
is different at various places than other arch's ABIs at where it
don't have to be different, but we at least want to reduce MIPS-ness
from the regular classes.

llvm-svn: 317525
2017-11-07 00:04:22 +00:00
Peter Collingbourne b472aa0268 ELF: Remove function Symbol::isInCurrentOutput().
This function is now equivalent to isDefined().

llvm-svn: 317449
2017-11-06 04:39:07 +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
Peter Collingbourne 6c55a70838 ELF: Remove DefinedCommon.
Common symbols are now represented with a DefinedRegular that points
to a BssSection, even during symbol resolution.

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

llvm-svn: 317447
2017-11-06 04:33:58 +00:00
Rui Ueyama 48882249dd Rename Body -> Sym.
This patch is mechanically created by

  sed -i -e s/Body/Sym/g lld/ELF/*.{cpp,h}

and clang-format-diff.

llvm-svn: 317392
2017-11-04 00:31:04 +00:00
Rui Ueyama f483da0038 Rename replaceBody -> replaceSymbol.
llvm-svn: 317383
2017-11-03 22:48:47 +00:00
Zachary Turner a104d558d0 Fix variable name.
A mechanical rename caused an illegal name conflict between
a variable and a type, which was picked up by GCC.

llvm-svn: 317380
2017-11-03 22:33:49 +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 f1f00841d9 Merge SymbolBody and Symbol into one class, SymbolBody.
SymbolBody and Symbol were separated classes due to a historical reason.
Symbol used to be a pointer to a SymbolBody, and the relationship
between Symbol and SymbolBody was n:1.

r2681780 changed that. Since that patch, SymbolBody and Symbol are
allocated next to each other to improve memory locality, and they have
1:1 relationship now. So, the separation of Symbol and SymbolBody no
longer makes sense.

This patch merges them into one class. In order to avoid updating too
many places, I chose SymbolBody as a unified name. I'll rename it Symbol
in a follow-up patch.

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

llvm-svn: 317006
2017-10-31 16:07:41 +00:00
Jake Ehrlich 1128dc5e30 Give .note.gnu.build-id section alignment 4
All SHT_NOTE sections should have minimum alignment 4.

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

llvm-svn: 316961
2017-10-30 22:08:11 +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
Rui Ueyama bda337a8d8 Rename isInCurrentDSO -> isInCurrentOutput.
DSO is short for dynamic shared object, so the function name was a
little confusing because it sounded like it didn't work when we were
a creating statically-linked executable or something.

What we mean by "DSO" here is the current output file that we are
creating. Thus the new name. Alternatively, we could call it the current
ELF module, but "module" is a overloaded word, so I avoided that.

llvm-svn: 316809
2017-10-27 22:54:16 +00:00
Peter Collingbourne 5c54f15c55 ELF: Add support for emitting dynamic relocations in the Android relocation packing format.
The Android relocation packing format is a more compact
format for dynamic relocations in executables and DSOs
that is based on delta encoding and SLEBs. An overview
of the format can be found in the Android source code:
https://android.googlesource.com/platform/bionic/+/refs/heads/master/tools/relocation_packer/src/delta_encoder.h

This patch implements relocation packing using that format.

This implementation uses a more intelligent algorithm for compressing
relative relocations than Android's own relocation packer. As a
result it can generally create smaller relocation sections than
that packer. If I link Chromium for Android targeting ARM32 I get a
.rel.dyn of size 174693 bytes, as compared to 371832 bytes with gold
and the Android packer.

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

llvm-svn: 316775
2017-10-27 17:49:40 +00:00
Peter Smith f0c70f8d34 [ELF] Pre-create ThunkSections at Target specific intervals
When an OutputSection is larger than the branch range for a Target we
need to place thunks such that they are always in range of their caller,
and sufficiently spaced to maximise the number of callers that can use
the thunk. We use the simple heuristic of placing the
ThunkSection at intervals corresponding to a target specific branch range.
If the OutputSection is small we put the thunks at the end of the executable
sections.

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

llvm-svn: 316751
2017-10-27 08:58:28 +00:00
Rui Ueyama f9c66e4b80 Remove a boolean flag `Create`. NFC.
llvm-svn: 316738
2017-10-27 04:15:28 +00:00
Rui Ueyama 79048e4c5c Define a file-local write32 as a wrapper for endian::write32.
llvm-svn: 316736
2017-10-27 03:59:34 +00:00
Rui Ueyama 25f30880f5 Do not use InputSection::getFile<ELFT>() if InputSection::File suffices. NFC.
llvm-svn: 316735
2017-10-27 03:25:04 +00:00
Rui Ueyama 02551abdca De-template EhFrameHdr. NFC.
llvm-svn: 316734
2017-10-27 03:14:24 +00:00
Rui Ueyama 8629752c04 De-template EhReader. NFC.
llvm-svn: 316733
2017-10-27 03:14:09 +00:00
Rui Ueyama 572247f22e De-template EhFrameSection. NFC.
llvm-svn: 316731
2017-10-27 03:13:39 +00:00
Rui Ueyama c055225c6b Make EhFrameHdr pull data from EhFrameSection. NFC.
Previously, EhFrameSection pushes data to EhFrameHdr by calling addFde
function. By making EhFrameHdr pull data from EhFrameSection, we can
eliminate a member from EhFrameHdr.

llvm-svn: 316730
2017-10-27 03:13:24 +00:00
Rui Ueyama 076e2bb10e De-template a few functions. NFC.
llvm-svn: 316729
2017-10-27 03:13:09 +00:00
Rui Ueyama 88f0568ce5 Include an error code when getRandomBytes failed.
In a rare situation, the function can fail (e.g. it fails if it cannot
open /dev/urandom.)

llvm-svn: 316726
2017-10-27 01:25:29 +00:00
Rui Ueyama ed55e6c64f Remove an unnecessary inheritance.
llvm-svn: 316716
2017-10-26 23:54:00 +00:00
Rui Ueyama bfa84325ee Simplify.
Because of the same reason as r316600, I don't think we need a guard
against empty relocations.

llvm-svn: 316710
2017-10-26 22:30:25 +00:00
Rui Ueyama 6e5fda9db8 Move bit operations to a new file, ELF/Bits.h.
llvm-svn: 316707
2017-10-26 21:37:17 +00:00
George Rimar d605f414db [ELF] - Dedupliсate FDEs when sections are ICFed.
When LLD do ICF for 2 identical sections it leaves 2 duplicate entries in .eh_frame
pointing to the same address. After that it fixes .eh_frame_header's header,
so that it says it contains single FDE, though section itself contains 2 
(it contains garbage data at tail).

As a result excessive entries in .eh_frame and excessive dummy data in .eh_frame_header
emited to output. Patch fixes that. This is PR34518.

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

llvm-svn: 316648
2017-10-26 09:13:19 +00:00