Commit Graph

5984 Commits

Author SHA1 Message Date
Rui Ueyama 8b972d221e Simplify. NFC.
llvm-svn: 271133
2016-05-28 18:40:38 +00:00
Rafael Espindola 3b1ecb563f Make test more realistic.
It doesn't make mach sense to fetch less than 64 bits from a got
entry.

llvm-svn: 271116
2016-05-28 15:38:13 +00:00
Simon Atanasyan 9a9a3169e3 [ELF][MIPS] Always resolve MIPS GP-relative relocations to 'local' definitions
In case of MIPS, GP-relative relocations always resolve to a definition
in a regular input file, ignoring the one-definition rule. Such
relocations are used to setup GP relative offsets in a function's
prologue. So we, for example, should not attempt to create a dynamic
relocation even if the target symbol is preemptible.

Fixes bug 27880.

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

llvm-svn: 271100
2016-05-28 04:49:57 +00:00
Rui Ueyama 406b469de4 Avoid doing binary search.
MergedInputSection::getOffset is the busiest function in LLD if string
merging is enabled and input files have lots of mergeable sections.
It is usually the case when creating executable with debug info,
so it is pretty common.

The reason why it is slow is because it has to do faily complex
computations. For non-mergeable sections, section contents are
contiguous in output, so in order to compute an output offset,
we only have to add the output section's base address to an input
offset. But for mergeable strings, section contents are split for
merging, so they are not contigous. We've got to do some lookups.

We used to do binary search on the list of section pieces.
It is slow because I think it's hostile to branch prediction.

This patch replaces it with hash table lookup. Seems it's working
pretty well. Below is "perf stat -r10" output when linking clang
with debug info. In this case this patch speeds up about 4%.

Before:

       6584.153205 task-clock (msec)         #    1.001 CPUs utilized            ( +-  0.09% )
               238 context-switches          #    0.036 K/sec                    ( +-  6.59% )
                 0 cpu-migrations            #    0.000 K/sec                    ( +- 50.92% )
         1,067,675 page-faults               #    0.162 M/sec                    ( +-  0.15% )
    18,369,931,470 cycles                    #    2.790 GHz                      ( +-  0.09% )
     9,640,680,143 stalled-cycles-frontend   #   52.48% frontend cycles idle     ( +-  0.18% )
   <not supported> stalled-cycles-backend
    21,206,747,787 instructions              #    1.15  insns per cycle
                                             #    0.45  stalled cycles per insn  ( +-  0.04% )
     3,817,398,032 branches                  #  579.786 M/sec                    ( +-  0.04% )
       132,787,249 branch-misses             #    3.48% of all branches          ( +-  0.02% )

       6.579106511 seconds time elapsed                                          ( +-  0.09% )

After:

       6312.317533 task-clock (msec)         #    1.001 CPUs utilized            ( +-  0.19% )
               221 context-switches          #    0.035 K/sec                    ( +-  4.11% )
                 1 cpu-migrations            #    0.000 K/sec                    ( +- 45.21% )
         1,280,775 page-faults               #    0.203 M/sec                    ( +-  0.37% )
    17,611,539,150 cycles                    #    2.790 GHz                      ( +-  0.19% )
    10,285,148,569 stalled-cycles-frontend   #   58.40% frontend cycles idle     ( +-  0.30% )
   <not supported> stalled-cycles-backend
    18,794,779,900 instructions              #    1.07  insns per cycle
                                             #    0.55  stalled cycles per insn  ( +-  0.03% )
     3,287,450,865 branches                  #  520.799 M/sec                    ( +-  0.03% )
        72,259,605 branch-misses             #    2.20% of all branches          ( +-  0.01% )

       6.307411828 seconds time elapsed                                          ( +-  0.19% )

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

llvm-svn: 270999
2016-05-27 14:39:13 +00:00
Rafael Espindola 6af546188f Avoid having to check in a binary.
llvm-svn: 270986
2016-05-27 12:27:21 +00:00
Peter Collingbourne 5079f3b727 Update LLD for D20550.
Differential Revision: http://reviews.llvm.org/D20704

llvm-svn: 270968
2016-05-27 05:21:45 +00:00
Sean Silva 8ef190c7b0 Make -L description a bit more precise.
llvm-svn: 270966
2016-05-27 04:48:26 +00:00
Sean Silva 3b536d0916 Explain a bit better what --start-lib and --end-lib do.
llvm-svn: 270965
2016-05-27 04:48:24 +00:00
Sean Silva 688fade4dd Add a help description for --threads to avoid confusion.
llvm-svn: 270964
2016-05-27 04:48:21 +00:00
Sean Silva 2c1a9da83f --threads is a flag, not a number
We would previously accept `--threads=4`, but this option just turns on
threading and does not specify a number of threads.

I ran into this by accident because I was passing `--threads=<n>` but
the number didn't seem to affect anything.

llvm-svn: 270963
2016-05-27 04:30:27 +00:00
Simon Atanasyan 84bb355c3a [ELF][MIPS] Handle section symbol points to the .MIPS.options / .reginfo section
MIPS .reginfo and .MIPS.options sections are consumed by the linker, and
the linker produces a single output section. But it is possible that
input files contain section symbol points to the corresponding input
section. In case of generation a relocatable output we need to write
such symbols to the output file.

Fixes bug 27878.

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

llvm-svn: 270910
2016-05-26 20:46:01 +00:00
Rafael Espindola a5cefffc33 Update for llvm change.
llvm-svn: 270907
2016-05-26 20:31:06 +00:00
George Rimar a8f9cf18ad Removed redundant argument. NFC.
llvm-svn: 270847
2016-05-26 13:37:12 +00:00
George Rimar 95433df129 [ELF] - Added support for jmp/call relaxations when R_X86_64_GOTPCRELX/R_X86_64_REX_GOTPCRELX are used.
D15779 introduced basic approach to support new relaxations.
This patch implements relaxations for jmp and call instructions,
described in System V Application Binary Interface AMD64 Architecture Processor 
Supplement Draft Version 0.99.8 (https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-r249.pdf, 
B.2 "B.2 Optimize GOTPCRELX Relocations")

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

llvm-svn: 270721
2016-05-25 16:51:08 +00:00
Rui Ueyama d884927463 Make SectionPiece 8 bytes smaller on LP64.
This patch makes SectionPiece class 8 bytes smaller on platforms
on which pointer size is 8 bytes. Sean suggested in a post commit
review for r270340 that this could make a differentce, and it
actually is. Time to link clang (with debug info) improved from
6.725 seconds to 6.589 seconds or by about 2%.

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

llvm-svn: 270717
2016-05-25 16:37:01 +00:00
Rui Ueyama 1795f782e9 Do not ignore --no_ctors_in_init_array flag.
That flag is probably too dangerous to ignore silently.

llvm-svn: 270711
2016-05-25 15:30:11 +00:00
Ed Maste 2e04361a21 ELF: improve CIE no-augmentation test
Add another possible error that may be reported for the same case. The
original reproduction case that prompted r270706 produced the error
"corrupted CIE" instead of "corrupted or unsupported CIE information".
The specific error depends on arbitrary data later in the file so
check that neither is emitted in case the input is ever changed.

Document the process used to create the input .o and rename the test
file to .s, as requested by Rafael.

llvm-svn: 270709
2016-05-25 15:14:08 +00:00
Ed Maste 594e06b879 ELF: Handle empty CIE augmentation string
"A zero length string indicates that no augmentation data is present."

The FreeBSD/mips toolchain (GCC 4.2.1) generates .debug_frame sections
containing CIE records that have an empty augmentation string.

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

llvm-svn: 270706
2016-05-25 14:45:28 +00:00
George Rimar 5c33b91bbe [ELF] - Implemented optimization for R_X86_64_GOTPCREL relocation.
System V Application Binary Interface AMD64 Architecture Processor Supplement Draft Version 0.99.8 
(https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-r249.pdf, B.2 "B.2 Optimize GOTPCRELX Relocations")
introduces possible relaxations for R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX.

That patch implements the next relaxation: 
mov foo@GOTPCREL(%rip), %reg => lea foo(%rip), %reg
and also opens door for implementing all other ones.

Implementation was suggested by Rafael Ávila de Espíndola with few additions and testcases by myself.

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

llvm-svn: 270705
2016-05-25 14:31:37 +00:00
Rui Ueyama c789b631f3 Really define --export-dynamic-symbol= as an alias to --export-dynamic-symbol.
Thanks to Sean for pointing it out.

llvm-svn: 270660
2016-05-25 04:29:55 +00:00
Rui Ueyama 02fcf11a9c Fix comment.
llvm-svn: 270659
2016-05-25 04:29:53 +00:00
Rui Ueyama e66f45c6eb Reduce code duplication.
llvm-svn: 270657
2016-05-25 04:10:14 +00:00
Rui Ueyama 2487f19258 Add `static` to a file-scope function.
llvm-svn: 270652
2016-05-25 03:40:02 +00:00
Rui Ueyama dadda2fe08 Add a few options for compatibility with GNU.
llvm-svn: 270651
2016-05-25 03:38:16 +00:00
Rui Ueyama 0fcdc730ad Create Relocations.cpp and move scanRelocs there.
scanReloc and the functions on which scanReloc depends is in total
more than 600 lines of code. Since scanReloc does not depend on Writer,
it is better to move it into a separate file.

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

llvm-svn: 270606
2016-05-24 20:24:43 +00:00
Rafael Espindola 5ee9e7fd80 Use range loop.
Thanks to Rui for the suggestion.

llvm-svn: 270601
2016-05-24 19:14:09 +00:00
Rafael Espindola 1f5696f9c1 Fix a wrong assumption.
llvm-svn: 270573
2016-05-24 16:03:27 +00:00
Rui Ueyama 19ccffe4bc Do not start over relocation search from beginning.
This patch addresses a post-commit review for r270325. r270325
introduced getReloc function that searches a relocation for a
given range. It always started searching from beginning of relocation
vector, so it was slower than before. Previously, we used to use
the fact that the relocations are sorted. This patch restore it.

llvm-svn: 270572
2016-05-24 15:40:46 +00:00
Rafael Espindola 820f4bb972 Handle terminator .eh_frame when creating the index.
llvm-svn: 270568
2016-05-24 15:17:47 +00:00
Rafael Espindola bfffa94ea7 Fix crash in .eh_frame marker section.
llvm-svn: 270563
2016-05-24 14:51:50 +00:00
Rafael Espindola 29da3e3577 Simplify. Thanks to Rui for the suggestion.
llvm-svn: 270555
2016-05-24 12:17:11 +00:00
Rafael Espindola fe3a2f1b81 Revert "Simplify. Thanks to Rui for the suggestion."
This reverts commit r270551.

Sorry, I commited the wrong branch :-(

llvm-svn: 270554
2016-05-24 12:12:06 +00:00
Rafael Espindola dba64b8ea4 Simplify. Thanks to Rui for the suggestion.
llvm-svn: 270551
2016-05-24 11:53:15 +00:00
Rafael Espindola 97434957ef Update for llvm change.
llvm-svn: 270550
2016-05-24 11:16:14 +00:00
Rui Ueyama 70595aae64 Inline SymbolBody::init. NFC.
I think this function was too short to be an independent function.

llvm-svn: 270534
2016-05-24 04:51:49 +00:00
Rui Ueyama ace4f90cf3 Do not pass the symbol table. NFC.
Since the symbol table is a singleton class and globally accessible,
we don't need to pass it around.

llvm-svn: 270533
2016-05-24 04:25:47 +00:00
Rui Ueyama 0b9a90364b Rename EHInputSection -> EhInputSection.
llvm-svn: 270532
2016-05-24 04:19:20 +00:00
Rui Ueyama 151ff30783 Simplify. NFC.
llvm-svn: 270531
2016-05-24 04:12:52 +00:00
Rui Ueyama 022d8e8a86 Make scanReloc and related functions non-member functions.
scanReloc does not depend on Writer, so it doesn't have to be
in the class.

llvm-svn: 270530
2016-05-24 03:36:07 +00:00
Rui Ueyama afa35a2a37 Remove Writer::ensureBss().
Previously, we created a .bss section when needed. We had a function
ensureBss() for that purpose. Turned out that was error-prone
because it was easy to forget to call that function before accessing
the .bss section.

This patch always make the BSS section. The section is added to the
output when it's not empty.

llvm-svn: 270527
2016-05-24 03:16:51 +00:00
Rui Ueyama f5febef249 Create a new file EhFrame.cpp and move code to read .eh_frame there.
llvm-svn: 270526
2016-05-24 02:55:45 +00:00
Rui Ueyama 98843087cb Reject zero-sized symbols when creating copy relocations.
Copy relocations are relocations to copy data from DSOs to
executable's .bss segment at runtime. It doesn't make sense to
create such relocations for zero-sized symbols.

GNU linkers don't agree with each other. ld rejects such
relocation/symbol pair. gold don't reject that but do not create
copy relocations as well.  I took the former approach because
I don't think the latter is what user wants.

llvm-svn: 270525
2016-05-24 02:37:40 +00:00
Rui Ueyama b7eda28aaa Use range-based for.
llvm-svn: 270523
2016-05-24 02:10:28 +00:00
Rui Ueyama 6de2e6829d Make getFdeEncoding a non-member function.
This function does not depend on EhOutputSection class.

llvm-svn: 270522
2016-05-24 02:08:38 +00:00
Rui Ueyama fa2f307c54 Remove dead code.
The dead declarations made MSVC to warn on explicit template
instantiations of the classes.

llvm-svn: 270471
2016-05-23 18:08:27 +00:00
Rui Ueyama b91bf1a9a0 Do not split mergeable sections if they are gc'ed.
Previously, mergeable section's constructors did more than just
setting member variables; it split section contents into small
pieces. It is not always computationally cheap task because if
the section is a mergeable string section, it needs to scan the
entire section to split them by NUL characters.

If a section would be thrown away by GC, that cost ended up
being a waste of time. It is going to be larger problem if the
section is compressed -- the whole time to uncompress it and
split it up is going to be a waste.

Luckily, we can defer section splitting after GC. We just have
to remember which offsets are in use during GC and apply that later.
This patch implements it.

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

llvm-svn: 270455
2016-05-23 16:55:43 +00:00
Rui Ueyama 2ab3d20819 Fix typos.
llvm-svn: 270451
2016-05-23 16:36:47 +00:00
Rui Ueyama de9777af1b Remove EhFrameHeader<ELFT>::reserveFde. NFC.
llvm-svn: 270448
2016-05-23 16:30:41 +00:00
Rui Ueyama 8a6ef4e6b2 Remove dead code.
Since now we always set SHT_PROGBITS to .eh_frame sections,
this code path is not executed at runtime.

llvm-svn: 270446
2016-05-23 16:24:22 +00:00
Rui Ueyama 3b31e6711b Make .eh_frame a singleton output object.
.eh_frame_hdr assumes that there is only one .eh_frame and
ensures it by assertions. This patch makes .eh_frame a real
singleton object to simplify.

llvm-svn: 270445
2016-05-23 16:24:16 +00:00