Commit Graph

269 Commits

Author SHA1 Message Date
Andrew Ng 6dee736c91 [LLD] Fix padding of .eh_frame when in executable segment
The default padding for an executable segment is the target trap
instruction which for x86_64 is 0xCC. However, the .eh_frame section
requires the padding to be zero. The code that writes the .eh_frame
section assumes that its segment is zero initialized and does not
explicitly write the zero padding. This does not work when the .eh_frame
section is in the executable segment (for example when using
-no-rosegment).

This patch changes the .eh_frame writing code to explicitly write the
zero padding.

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

llvm-svn: 312706
2017-09-07 08:43:56 +00:00
George Rimar e89c5bfbc2 [ELF] - Never call splitIntoPieces() twice. NFC.
Previously it was called twice for .comment synthetic section.
That created 2 pieces of data, which was deduplicated anyways,
but was not clean.

llvm-svn: 312327
2017-09-01 12:04:52 +00:00
Rui Ueyama 2b6631bb36 Remove GdbIndexSection::finalizeContents.
GdbIndexSection doesn't need lazy finalization because when an instance
of the class is created, we already know all debug info sections.
We can initialize the instnace in the ctor.

llvm-svn: 310931
2017-08-15 17:01:39 +00:00
Rui Ueyama e5d642cf5b Use ArrayRef instead of std::vector&.
llvm-svn: 310930
2017-08-15 17:01:28 +00:00
Rui Ueyama 2114cab93d Update a comment and rename a function.
llvm-svn: 310929
2017-08-15 17:01:17 +00:00
Rui Ueyama 43099e4409 Remove SymbolTable::findInCurrentDSO.
This function doesn't seem to add value to the symbol table as
it is easy to write code without it.

llvm-svn: 310925
2017-08-15 16:03:11 +00:00
Rui Ueyama 9c77d27004 Garbage-collect common symbols.
Liveness is usually a notion of input sections, but this patch adds
"liveness" bit to common symbols because they don't belong to any
input section.

This patch is based on https://reviews.llvm.org/D36520

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

llvm-svn: 310617
2017-08-10 15:54:27 +00:00
Rafael Espindola 6e93d0546a Move File from SymbolBody to Symbol.
With this Symbol has the same size as before, but DefinedRegular goes
from 72 to 64 bytes.

I also find this a bit easier to read. There are fewer places
initializing File for example.

This has a small but measurable speed improvement on all tests (1%
max).

llvm-svn: 310142
2017-08-04 22:31:42 +00:00
James Henderson a5bc09a86f [ELF] Explicitly write null bytes in string tables
Following r309829, if a string table appears in an executable segment, the strings
will not be null terminated. This is a problem, for example, for the .dynstr
section when using -no-rosegment. The strings end up being terminated with 0xcc
because prior to this patch, LLD did not explicitly write the null terminators.
This change fixes that by always writing the null terminators.

Reviewers: rafael

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

llvm-svn: 310042
2017-08-04 09:07:55 +00:00
George Rimar a9b071482d [ELF] - Replace parallelForEach with ranged form.
Makes code a bit more convinent to write/read.

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

llvm-svn: 310040
2017-08-04 08:30:16 +00:00
George Rimar 2d23da0033 [ELF] - Use multithreading for building .gdb_index.
Enables multithreaded .gdb_index building.

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

llvm-svn: 309688
2017-08-01 14:57:13 +00:00
Rafael Espindola 8c022ca783 Merge OutputSectionCommand and OutputSection.
This is a bit of a hack, but it is *so* convenient.

Now that we create synthetic linker scripts when none is provided, we
always have to handle paired OutputSection and OutputsectionCommand and
keep a mapping from one to the other.

This patch simplifies things by merging them and creating what used to
be OutputSectionCommands really early.

llvm-svn: 309311
2017-07-27 19:22:43 +00:00
Rui Ueyama 709fb2bb10 Rename ObjectFile -> ObjFile.
Rename it because it was too easy to conflict with llvm::object::ObjectFile
which broke buildbots several times.

llvm-svn: 309199
2017-07-26 22:13:32 +00:00
Rafael Espindola 244ef98161 Detemplate SymbolTable.
NFC, just makes it easier to access from non templated code.

llvm-svn: 309152
2017-07-26 18:42:48 +00:00
Rui Ueyama bc2c9e0278 Do not strip SHF_GROUP in elf::decompressAndMergeSections().
SHF_GROUP flag should have been removed when the control reaches here
because InputSectionBase turns the flag off. So this code should be
redundant.

llvm-svn: 308680
2017-07-20 21:42:30 +00:00
Rafael Espindola 8b1afd59c3 Speed up gdb index creation.
With that in place we can use lld's own infrastructure for the low
level detail of dwarf parsing.

With this we don't decompress sections twice, we don't scan all
realocations and even with this simplistic implementation linking
clang with gdb index goes from 34.09 seconds to 20.80 seconds.

llvm-svn: 308544
2017-07-19 22:27:35 +00:00
George Rimar b939d32f53 [ELF] - Fix member name: alignment -> Alignment. NFC.
llvm-svn: 308300
2017-07-18 11:59:19 +00:00
George Rimar 67c60727ce [ELF] - Apply clang-format. NFC.
llvm-svn: 308297
2017-07-18 11:55:35 +00:00
George Rimar f525c928cf [ELF] - Implement filter library support (-F / --filter)
This is PR33766.

-F name
--filter=name
When creating an ELF shared object, set the internal DT_FILTER field to the specified name. This tells the dynamic linker that the symbol table of the shared object which is being created should be used as a filter on the symbol table of the shared object name.

If you later link a program against this filter object, then, when you run the program, the dynamic linker will see the DT_FILTER field. The dynamic linker will resolve symbols according to the symbol table of the filter object as usual, but it will actually link to the definitions found in the shared object name. Thus the filter object can be used to select a subset of the symbols provided by the object name.
(https://linux.die.net/man/1/ld).

Shared Objects as Filters:
https://docs.oracle.com/cd/E19683-01/817-3677/chapter4-31738/index.html

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

llvm-svn: 308167
2017-07-17 09:43:18 +00:00
Igor Kudrin 202a9f6817 [ELF] Fix writing the content of the .got section in a wrong place.
In filling the .got sections, InputSection::OutSecOff was added twice
when finding the position to apply a relocation: first time in
InputSection::writeTo() and then in SectionBase::getOffset().

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

llvm-svn: 308003
2017-07-14 08:10:45 +00:00
Rafael Espindola 300b38678c Refactor gdb index creation.
I have a patch to let DwarfContext defer to lld for getting section
contents and relocations.

That is a pretty big performance improvement.

This is just a refactoring to make that easier to do.

This change makes the *creation* of gdb index a dedicated step and
makes that templated. That is so that we can uses Elf_Rel in the code.

llvm-svn: 307867
2017-07-12 23:56:53 +00:00
George Rimar 1b51b7fc7f [ELF] - Fail the link if something happens on DWARF parsing stage of -gdb-index building
This is relative to PR33173,

Previously if something wrong happened on DWARF parsers side during parsing
object for building gdb index (like was in PR: unsupported relocation) 
then LLD continued and finished the link. DWARF parsers sure showed error
message on their side, but that is all.

Patch changes behavior to fail the link in this case and show more
detailed message.

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

llvm-svn: 307370
2017-07-07 09:18:05 +00:00
Rafael Espindola 4cc0cd6556 Use Entry::SecSize in a couple of cases.
This avoids having to compute relocation section sizes early, removing
the last use of assignOffsets.

llvm-svn: 307219
2017-07-05 23:06:59 +00:00
Rui Ueyama 0cc1483562 Add basic 64-bit SPARC support
Add support for the most common SPARC relocations.
Make DT_PLTGOT point to the PLT on SPARC.
Mark the PLT as executable on SPARC.

This adds a basic test that creates a SPARV9 executable
that invokes the exit system call on OpenBSD.

Patch by Mark Kettenis.

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

llvm-svn: 306565
2017-06-28 17:05:39 +00:00
George Rimar dbe843d602 [ELF] - Do not set st_size field of SHT_UNDEF symbols.
This fixes PR33598.

Size field for undefined symbols is not significant.
Setting it to fixed value, like zero, may be useful though.

For example when we have 2 DSO's, like in this PR, if lower level DSO may
change slightly (in part of some symbol's st_size)  and higher-level DSO is
rebuilt, then tools that monitoring checksum of high level DSO file can notice
it and trigger cascade of some other unnecessary actions. 
If we set st_size to zero, that can be avoided.

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

llvm-svn: 306526
2017-06-28 09:51:33 +00:00
Peter Collingbourne dc7936eced ELF: Move section merging before ICF. NFCI.
Differential Revision: https://reviews.llvm.org/D34093

llvm-svn: 305176
2017-06-12 00:00:51 +00:00
George Rimar b4b7b74b5a [ELF] - Fix build bot.
SyntheticSections.cpp:1773:29: error: chosen constructor is explicit in copy-initialization
        CuVectors.push_back({});
                            ^~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/set:428:14: note: constructor declared here
    explicit set(const value_compare& __comp = value_compare())
             ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:702:59: note: passing argument to parameter '__x' here
    _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);

llvm-svn: 305054
2017-06-09 04:48:56 +00:00
George Rimar 8666562e89 [ELF] - Make implementation of .gdb index to be more natural for futher paralleling.
This patch reimplements .gdb_index in more natural way,
that makes proccess of switching to multithreaded index building to
be trivial. 

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

llvm-svn: 304927
2017-06-07 16:59:11 +00:00
Rafael Espindola 66d98495b0 Delete dead function.
llvm-svn: 304914
2017-06-07 14:24:32 +00:00
George Rimar 0641b8b4d3 [ELF] - Simplify readAddressArea() implementation.
Approach significantly simplifies LLD .gdb_index code and makes it much faster.
Also it should resolve issues, like D33176 tries to address once and forever in a clean way.

LLC binary linking without patch and without --gdb-index: 1,599241063
LLC binary linking without patch and with --gdb-index: 6,064316262
LLC binary linking with patch and with --gdb-index: 4,116792104

Time spent for building gdbindex changes from (6,064316262 - 1,599241063 == 4,465075199)
to (4,116792104- 1,599241063 == 2,517551041).
That is 2,517551041/4,465075199 = 0,564 or about 44% speedup.

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

llvm-svn: 304895
2017-06-07 10:52:02 +00:00
Zachary Turner 264b5d9e88 Move Object format code to lib/BinaryFormat.
This creates a new library called BinaryFormat that has all of
the headers from llvm/Support containing structure and layout
definitions for various types of binary formats like dwarf, coff,
elf, etc as well as the code for identifying a file from its
magic.

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

llvm-svn: 304864
2017-06-07 03:48:56 +00:00
Rafael Espindola db5e56f7b2 Store a single Parent pointer for InputSectionBase.
Before InputSectionBase had an OutputSection pointer, but that was not
always valid. For example, if it was a merge section one actually had
to look at MergeSec->OutSec.

This was brittle and caused bugs like the one fixed by r304260.

We now have a single Parent pointer that points to an OutputSection
for InputSection, but to a SyntheticSection for merge sections and
.eh_frame. This makes it impossible to accidentally access an invalid
OutSec.

llvm-svn: 304338
2017-05-31 20:17:44 +00:00
Rafael Espindola 0dc2510762 Simplify. NFC.
llvm-svn: 304330
2017-05-31 19:26:37 +00:00
Rafael Espindola 23db636080 Simplify. NFC.
llvm-svn: 304328
2017-05-31 19:22:01 +00:00
Rafael Espindola b47c6e5cbd Fix a crash.
We would crash if a SHF_LINK_ORDER section pointed to a non
InputSection section. Since those sections are not merged in order,
SHF_LINK_ORDER is pretty meaningless and we can error on that case.

llvm-svn: 304327
2017-05-31 19:09:52 +00:00
Peter Smith ea79b215d6 [ELF] .ARM.exidx sentinel section should use InputSectionDescriptions.
This change converts the writing of the .ARM.exidx sentinel section to use
the InputSectionDescriptions instead of OutputSection::Sections this is in
preparation for the retirement of OutputSection::Sections.
    
Differential Revision: https://reviews.llvm.org/D33500

llvm-svn: 304289
2017-05-31 09:02:21 +00:00
Rafael Espindola 180de970c8 Fix crash when processing relocations in .eh_frame.
This happens when attempting to link shared libraries using exceptions on
MIPS. It requires -z notext because clang generates R_MIPS_64 relocations
inside .eh_frame.
The crash happened because for EhInputSection the OutSec member is null.

Patch by Alexander Richardson!

llvm-svn: 304260
2017-05-31 00:23:23 +00:00
Petr Hosek ffa786f465 [lld][ELF]Add option to make .dynamic read only
The .dynamic section of an ELF almost doesn't need to be written to with
the exception of the DT_DEBUG entry. For several reasons having a read
only .dynamic section would be useful. This change adds the -z keyword
"rodynamic" which forces .dynamic to be read-only. In this case DT_DEBUG
will not be emited.

Patch by Jake Ehrlich

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

llvm-svn: 304024
2017-05-26 19:12:38 +00:00
George Rimar 1ef2e237bf [ELF] - Attemp to fix bot
http://lab.llvm.org:8011/builders/lld-x86_64-darwin13/builds/8549/steps/build_Lld/logs/stdio

llvm-svn: 304016
2017-05-26 18:07:25 +00:00
George Rimar 8684dbaa14 [ELF] - Follow up for r303975. NFCi.
Restore bitwise-or order and fix warning
(was changed by mistake during resolve of conflicts).

llvm-svn: 303976
2017-05-26 12:16:39 +00:00
George Rimar c1a0364cd6 [ELF] - Do not produce duplicate values in .gdb_index's constant pool area.
I found this when builded llc binary using gcc 5.4.1 + LLD.
gcc produces duplicate entries in .debug_gnu_pubtypes section, ex:

UnifyFunctionExitNodes.cpp.o has:
0x0000ac07 EXTERNAL TYPE "std::success_type<void*>"
0x0000ac07 EXTERNAL TYPE "std::success_type<void*>"

clang produces single entry here:
0x0000d291 EXTERNAL TYPE "std::__success_type<void *>"

If we link output from gcc with LLD, that would produce excessive duplicate
entries in .gdb_index constant pool area. That does not seem affect gdb work,
but makes .gdb_index larger than it can be.

I also checked that gold filters out such duplicates too. Patch fixes it.

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

llvm-svn: 303975
2017-05-26 12:09:26 +00:00
George Rimar 5f5905eea8 [ELF] - Simplify implementation of constant pool when building .gdb_index
https://sourceware.org/gdb/onlinedocs/gdb/Index-Section-Format.html says:
"A CU vector in the constant pool is a sequence of offset_type values. 
The first value is the number of CU indices in the vector. 
Each subsequent value is the index and symbol attributes of a CU in the CU list."

Previously we keeped 2 values until the end, what was useless. 
Initially was a part of D32647, though it is possible to split out. 
Patch do that.

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

llvm-svn: 303973
2017-05-26 12:01:40 +00:00
Rafael Espindola f307d3ea4d Remove dummy cast. NFC.
llvm-svn: 303948
2017-05-26 00:37:39 +00:00
Rafael Espindola a28414d7ec Simplify MipsRldMapSection::writeTo.
It is not clear why a synthetic section wants to use padding defined
in the linker script. The padding is for the space between sections.

It was also missing a test.

llvm-svn: 303812
2017-05-24 22:04:32 +00:00
Rafael Espindola 55b169bf5d Move writeTo to OutputSectionCommand.
This reduces how many times we have to map from OutputSection to
OutputSectionCommand. It is a required step to moving
clearOutputSections earlier.

In order to always use writeTo in OutputSectionCommand we have to call
fabricateDefaultCommands for -r links and move section compression
after it.

llvm-svn: 303784
2017-05-24 18:08:04 +00:00
Rafael Espindola a6465bbb72 Alternative way to detemplate GotSection.
GetSection is a template because write calls relocate.

relocate has two parts. The non alloc code really has to be a
template, as it is looking a raw input file data.

The alloc part is only a template because of getSize.

This patch folds the value of getSize early, detemplates
getRelocTargetVA and splits relocate into a templated non alloc case
and a regular function for the alloc case. This has the nice advantage
of making sure we collect all the information we need for relocations
before getting to InputSection::relocateNonAlloc.

Since we know got is alloc, it can just call the function directly and
avoid the template.

llvm-svn: 303355
2017-05-18 16:45:36 +00:00
George Rimar d8daafd0fb [ELF] - Update for LLVM's r303163 change. NFCi.
llvm-svn: 303164
2017-05-16 12:34:51 +00:00
George Rimar 390242d0e9 [ELF] - Detemplate elf::addSyntheticLocal(). NFC.
llvm-svn: 303155
2017-05-16 10:11:36 +00:00
George Rimar 69b17c35d9 [ELF] - Detemplate access to SymTab, DynSymTab, GnuHashTab. NFC.
Follow up for r303150.

llvm-svn: 303153
2017-05-16 10:04:42 +00:00
George Rimar f45f681609 [ELF] - Detemplate GnuHashTableSection and SymbolTableSection sections.
SymbolTableBaseSection was introduced.

Detemplation of SymbolTableSection should allow to detemplate more things.

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

llvm-svn: 303150
2017-05-16 08:53:30 +00:00