Commit Graph

5971 Commits

Author SHA1 Message Date
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
Rui Ueyama f86cb90a2d Do not propagate section name and attributes to .eh_frame.
.eh_frame is always ".eh_frame" and its attribute is fixed.
No need to copy from inputs to outputs. GNU gold also sets
SHT_PROGBITS.

llvm-svn: 270443
2016-05-23 15:12:41 +00:00
Rui Ueyama 1e479c23aa Rename EHOutputSection -> EhOutputSection for consistency.
llvm-svn: 270442
2016-05-23 15:07:59 +00:00
Rui Ueyama e75e933efc Refactor EhFrameHdr.
Previously, EhFrameHdr section computed addresses to which FDEs are
applied to. This is not an ideal design because EhFrameHdr does not
know much about FDEs unless EhFrame passes the information to EhFrameHdr.
It is what we did.

This patch simplifies the code by making EhFrame to compute the
values and pass the cooked information to EhFrameHdr. EhFrameHdr no
longer have to know about the details of FDEs such as FDE encodings.

llvm-svn: 270393
2016-05-23 03:00:33 +00:00
Rui Ueyama 95a232e5c9 Add comment.
llvm-svn: 270390
2016-05-23 01:45:05 +00:00
Rui Ueyama 1b2936fc82 Simplify. NFC.
llvm-svn: 270388
2016-05-23 01:31:10 +00:00
Rui Ueyama 744d47ea05 Make file-local function file-local. NFC.
llvm-svn: 270387
2016-05-23 00:45:54 +00:00
Rui Ueyama 518f1af04d Split MergeInputSection's ctor. NFC.
llvm-svn: 270386
2016-05-23 00:40:24 +00:00
Rui Ueyama 88abd9b300 Move splitInputSection from EHOutputSection to EHInputSection.
llvm-svn: 270385
2016-05-22 23:53:00 +00:00
Rui Ueyama e2060aa747 Attempt to unbreak buildbots.
My last commit made Clang to fail with an assertion failure.
https://llvm.org/bugs/show_bug.cgi?id=27835
This is a patch to avoid that.

llvm-svn: 270384
2016-05-22 23:52:56 +00:00
Rui Ueyama f8b285c037 Refactor EHOutputSection.
This patch refactors EHOutputSection using SectionPiece struct.
EHRegion class was removed since we can now directly use SectionPiece.

An incomplete support of large CIE/FDE record (> 2^32 bytes) was removed
because it silently created broken executable. There are several places
in the existing code that "size" field is always 4 bytes and at offset 4
in the record, which is not true for 64-bit size records. We will have to
support that in future, but it is better to error out instead of creating
malformed eh_frame sections.

llvm-svn: 270382
2016-05-22 23:16:14 +00:00
Rui Ueyama 34dc99e2c5 Store section contents to SectionPiece. NFC.
So that we don't need to cut a slice when we use a SectionPiece.

llvm-svn: 270348
2016-05-22 01:15:32 +00:00
Rui Ueyama c6ebb02fca Use StringPiece::Size instead of calculating it again. NFC.
llvm-svn: 270347
2016-05-22 01:03:41 +00:00
Rui Ueyama 90fa3722d2 Simplify SplitInputSection::getRangeAndSize.
This patch adds Size member to SectionPiece so that getRangeAndSize
can just return a SectionPiece instead of a std::pair<SectionPiece *, uint_t>.
Also renamed the function.

llvm-svn: 270346
2016-05-22 00:41:38 +00:00