Commit Graph

1292 Commits

Author SHA1 Message Date
George Rimar f9b04fd91f [ELF] - Simplify output section creation.
When there is no SECTION commands given, all sections are
technically orphans, but now we handle script orphans sections
and regular "orphans" sections for non-scripted case differently,
though we can handle them at one place.

Patch do that change.

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

llvm-svn: 316984
2017-10-31 10:31:58 +00:00
George Rimar a6b1fbece1 [ELF] - Stop sorting input sections in createSections().
It does not seem that createSections() is a good place for
applying sorting. Patch changes code to do that inside
sortSections(), which looks more appropriate place.

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

llvm-svn: 316893
2017-10-30 10:12:49 +00:00
Peter Collingbourne e662436114 ELF: Correctly set edata if there are no .bss sections.
edata needs to be set to the end of the last mapped initialized
section. We were previously mishandling the case where there were no
non-mapped sections by setting it to the end of the last section in
the output file.

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

llvm-svn: 316877
2017-10-29 22:31:48 +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
George Rimar 3396bf07a2 [ELF] - Stop naming relocation sections with first input section name.
It was reported (https://reviews.llvm.org/D38724#902841) that when we use 
-ffunction-sections --emit-relocs build, REL[A] output section receives the name of first
input section, like .rela.text.first_function_in_text rather than .rela.text.

It is probably not really an issue as sh_info still points to correct target section, but
it does not look clean in output and allows internal section name to leak there,
what at least looks confusing and is not consistent with ld.bfd.

Patch changes this behavior so that target output section name is used as a base.

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

llvm-svn: 316760
2017-10-27 11:38:31 +00:00
George Rimar 96b1157814 [ELF] - Simplify reporting of garbage collected sections.
This moves reporting of garbage collected sections right after
we do GC. That simplifies things.

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

llvm-svn: 316759
2017-10-27 11:32:22 +00:00
Peter Smith 6c9df3fce5 [ELF] Add support for multiple passes to createThunks()
This change allows Thunks to be added on multiple passes. To do this we must
merge only the thunks added in each pass, and deal with thunks that have
drifted out of range of their callers.

A thunk may end out of range of its caller if enough thunks are added in
between the caller and the thunk. To handle this we create another thunk.

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

llvm-svn: 316754
2017-10-27 09:07:10 +00:00
Peter Smith 75030b6d56 [ELF] Introduce range extension thunks for ARM
This change adds initial support for range extension thunks. All thunks must
be created within the first pass so some corner cases are not supported. A
follow up patch will add support for multiple passes.

With this change the existing tests arm-branch-error.s and
arm-thumb-branch-error.s now no longer fail with an out of range branch.
These have been renamed and tests added for the range extension thunk.

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

llvm-svn: 316752
2017-10-27 09:04:11 +00:00
Rui Ueyama 0f46e45b03 Simplify logic to find the last executable segment. NFC.
llvm-svn: 316742
2017-10-27 05:08:39 +00:00
Rui Ueyama df15559c80 Fix typo.
llvm-svn: 316741
2017-10-27 04:59:33 +00:00
Rui Ueyama 02551abdca De-template EhFrameHdr. NFC.
llvm-svn: 316734
2017-10-27 03:14:24 +00:00
Rui Ueyama 572247f22e De-template EhFrameSection. NFC.
llvm-svn: 316731
2017-10-27 03:13:39 +00:00
Bob Haarman b8a59c8aa5 [lld] unified COFF and ELF error handling on new Common/ErrorHandler
Summary:
The COFF linker and the ELF linker have long had similar but separate
Error.h and Error.cpp files to implement error handling. This change
introduces new error handling code in Common/ErrorHandler.h, changes the
COFF and ELF linkers to use it, and removes the old, separate
implementations.

Reviewers: ruiu

Reviewed By: ruiu

Subscribers: smeenai, jyknight, emaste, sdardis, nemanjai, nhaehnle, mgorny, javed.absar, kbarton, fedor.sergeev, llvm-commits

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

llvm-svn: 316624
2017-10-25 22:28:38 +00:00
Rui Ueyama 7b4eddf0ea Improve comment.
llvm-svn: 316489
2017-10-24 19:53:51 +00:00
Konstantin Zhuravlyov e7f1734f1a LLD/ELF: Allow targets to set e_flags
Differential Revision: https://reviews.llvm.org/D39139

llvm-svn: 316460
2017-10-24 17:01:40 +00:00
Petr Hosek 2fd533db9f [ELF] When placing orphans, handle case when last section is dead
r315292 introduced a change that's supposed to consistently ignore
"dead" output sections when placing orphans. Unfortunately, that
change doesn't handle the special case when the orphan section is
second to last section and the last section is dead (e.g. because
it's being discarded) introducing a regression in some cases.

This change handles this case by using the same predicate when
checking the last section.

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

llvm-svn: 316307
2017-10-23 00:51:08 +00:00
Rafael Espindola 3558e24ae8 Remove unused argument.
llvm-svn: 316248
2017-10-20 23:28:19 +00:00
George Rimar 1c09dfe2bc [ELF] - Simplify. NFC.
llvm-svn: 316163
2017-10-19 15:03:59 +00:00
George Rimar a4ca931336 [ELF] - Remove excessive helper. NFC.
Removes addRegular() helper that looks excessive from Writer.cpp.

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

llvm-svn: 316068
2017-10-18 08:36:47 +00:00
George Rimar d30bd1321f [ELF] - Simplify. NFC.
llvm-svn: 316002
2017-10-17 14:31:29 +00:00
Bob Haarman 4f5c8c29ac [lld] Move Threads to Common
Summary:
This will allow using the functionality from other linkers. It is also
a prerequisite for sharing the error logging code.

Reviewers: ruiu

Reviewed By: ruiu

Subscribers: emaste, mgorny, llvm-commits

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

llvm-svn: 315725
2017-10-13 18:22:55 +00:00
Rui Ueyama 662bb00028 Hide SymbolBody::IsLocal.
IsLocal member is initialized by the constructor and will never change.
So we don't want to make it directly accessible.

llvm-svn: 315667
2017-10-13 03:37:26 +00:00
Rui Ueyama 5908c2f877 Rename processCommands -> processSectionCommands.
llvm-svn: 315415
2017-10-11 02:28:28 +00:00
Rui Ueyama 6b394caaf1 Rename Commands -> SectionCommands.
"Commands" was ambiguous because in the linker script, everything is
a command. We used to handle only SECTIONS commands, and at the time,
it might make sense to call them the commands, but it is no longer
the case. We handle not only SECTIONS but also MEMORY, PHDRS, VERSION,
etc., and they are all commands.

llvm-svn: 315409
2017-10-11 01:50:56 +00:00
Rui Ueyama a323e2a722 Rename HasSections -> HasSectionsComand.
HasSections is true if there is at least one SECTIONS linker
script command, and it is not directly related to whether we have
section objects or not. So I think the new name is better.

llvm-svn: 315405
2017-10-11 01:34:51 +00:00
Rui Ueyama ac27de9dc7 Remove ScriptConfiguration class and move the members to LinkerScript class.
ScriptConfiguration was a class to contain parsed results of
linker scripts. LinkerScript is a class to interpret it.

That ditinction was needed because we haven't instantiated
LinkerScript early (because, IIRC, LinkerScript class was a
ELFT template function). So, when we parse linker scripts,
we couldn't directly store the result to a LinkerScript instance.

Now, that limitation is gone. We instantiate LinkerScript
at the very beginning of our main function. We can directly
store parse results to a LinkerScript instance.

llvm-svn: 315403
2017-10-11 01:19:33 +00:00
Rafael Espindola 97c57b9e7b Don't create a dummy __tls_get_addr.
We just don't need one with the current setup.

We only error on undefined references that are used by some
relocation.

If we managed to relax all uses of __tls_get_addr, no relocation uses
it and we don't produce an error.

This is less code and fixes the case were we fail to relax. Before we
would produce a broken output, but now we produce an error.

llvm-svn: 315334
2017-10-10 17:27:34 +00:00
Andrew Ng 4d54a4b4f7 [LLD] Fix findOrphanPos to consistently ignore "dead" OutputSection's
When findOrphanPos does the reverse search to find the OutputSection
preceding the orphan's insertion point, look for a live OutputSection
and ignore "dead" OutputSection's. This matches the behaviour of the
forward search performed earlier in this function.

Added test which without the above fix fails as a result of an orphan
executable section being incorrectly placed in a non-executable segment.

Differential Review: https://reviews.llvm.org/D38690

llvm-svn: 315292
2017-10-10 10:05:52 +00:00
Rui Ueyama e03ba02348 Rename ignoreInterpSection -> needsInterpSection.
This should improve consistency. Also added comment.

llvm-svn: 315169
2017-10-08 03:52:15 +00:00
Rafael Espindola 8bd0c45c7a Inline small function. NFC.
llvm-svn: 315141
2017-10-07 01:08:28 +00:00
Rui Ueyama 8befefb2ea Remove OutputSection::updateAlignment.
I feel it is easier to understand without this function.

llvm-svn: 315140
2017-10-07 00:58:34 +00:00
Rui Ueyama c54d5b16d5 Do not mutate Script->Opt.Commands from a leaf helper function.
Factory::addInputSec added an output section to Script->Opt.Commands,
but that is too subtle. This patch makes it explicit so that it is easy
to see when a new element is added to Script->Opt.Commands.

llvm-svn: 315129
2017-10-06 23:34:43 +00:00
Rui Ueyama edafba200f Split addSection into two small functions. NFCI.
addSection function was hard to read because it behaves differently
depending on its arguments but what exactly it does is not clear.
Now it should be better. Still, it is not clear (not what but) why
it does what it does, but I'll take a look at it later.

llvm-svn: 315124
2017-10-06 23:06:40 +00:00
Rui Ueyama 8ad23dcd8b Revert r314616: Run writeTo() concurrently.
This reverts commit r314616 because nested parallel-for loops can hang.
Our ThreadPoolExecutor is not necessarily able to handle nested calls.

llvm-svn: 315098
2017-10-06 20:12:43 +00:00
Rui Ueyama 7d1f5fd840 Call exitLld() from elf::link.
We used to call exitLld() from a leaf function, Writer::run(), because
we had objects on the stack whose dtors are expensive. Now we no longer
have such objects on the stack, so there's no reason to exist from the
leaf function.

llvm-svn: 314869
2017-10-04 00:50:11 +00:00
Rui Ueyama 732f4e2778 Remove BssSection::reserveSpace().
We no longer call reserveSpace more than once, so it can be merged with
its constructor.

llvm-svn: 314867
2017-10-04 00:21:17 +00:00
Rui Ueyama 6aeea183ef Rewrite a comment.
llvm-svn: 314707
2017-10-02 18:54:59 +00:00
Simon Atanasyan 649e4d328f [MIPS] Fix PLT entries generation in case of linking regular and microMIPS code
Currently LLD calls the `isMicroMips` routine to determine type of PLT entries
needs to be generated: regular or microMIPS. This routine checks ELF
header flags in the `FirstObj` to retrieve type of linked object files.
So if the first file does not contain microMIPS code, LLD will generate
PLT entries with regular (non-microMIPS) code only.

Ideally, if a PLT entry is referenced by microMIPS code only this entry
should contain microMIPS code, if a PLT entry is referenced by regular
code this entry should contain regular code. In a "mixed" case the PLT
entry can be either microMIPS or regular, but each "cross-mode-call" has
additional cost.

It's rather difficult to implement this ideal solution. But we can
assume that if there is an input object file with microMIPS code, the
most part of the code is microMIPS too. So we need to deduce type of PLT
entries based on finally calculated ELF header flags and do not check
only the first input object file.

This change implements this.
  - The `getMipsEFlags` renamed to the `calcMipsEFlags`. The function
    called from the `LinkerDriver::link`. Result is stored in
    the Configuration::MipsEFlags field.
  - The `isMicroMips` and `isMipsR6` routines access the `MipsEFlags`
    field to get and check calculated ELF flags.
  - New types of PLT records created when necessary.

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

llvm-svn: 314675
2017-10-02 14:56:41 +00:00
George Rimar ba45584c4b [ELF] - Stop removing sections in removeUnusedSyntheticSections().
That makes code a bit more consistent. Instead of removing sections there
we can just mark them as dead. So that removeEmptyCommands() will
handle the rest.

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

llvm-svn: 314654
2017-10-02 09:11:13 +00:00
Rui Ueyama cb222035c2 Run writeTo() concurrently.
I don't know why we didn't use parallelForEach to call writeTo,
but there should be no reason to not do that, as most writeTo
functions are safe to run concurrently.

llvm-svn: 314616
2017-10-01 02:25:34 +00:00
Ben Dunbobbin 73eabf23a4 [ELF] Simpler scheme for handling common symbols
Convert all common symbols to regular symbols after scan.
This means that the downstream code does not to handle common symbols as a special case.

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

llvm-svn: 314495
2017-09-29 09:08:26 +00:00
George Rimar aaf5471429 [ELF] - Detemplate of HashTableSection<ELFT>
Detemplation of one more synthetic section.

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

llvm-svn: 314283
2017-09-27 09:14:59 +00:00
George Rimar 19d6ce9d8e [ELF] - Simplify removeUnusedSyntheticSections a bit.
Previously`InX::Got` and InX::MipsGot synthetic sections
were not removed if ElfSym::GlobalOffsetTable was defined.
ElfSym::GlobalOffsetTable is a symbol for _GLOBAL_OFFSET_TABLE_.

Patch moves ElfSym::GlobalOffsetTable check out from removeUnusedSyntheticSections.
Also note that there was no point to check ElfSym::GlobalOffsetTable for MIPS case
because InX::MipsGot::empty() always returns false for non-relocatable case, and in case
of relocatable output we do not create special symbols anyways.

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

llvm-svn: 314099
2017-09-25 09:46:33 +00:00
Rafael Espindola 9be24cf516 Fix assigning to _gp in linker scripts.
The previous logic was to try to detect if a linker script defined _gp
by checking !ElfSym::MipsGp->Value. That doesn't work in all cases as
the assigned value can be 0.

We now just always defined it Writer.cpp and always overwrite it
afterwards if needed.

llvm-svn: 313788
2017-09-20 18:30:57 +00:00
Rafael Espindola aad64e0a1c Tweak orphan section placement.
Given a linker script that ends in

.some_sec { ...} ;
__stack_start = .;
. = . + 0x2000;
__stack_end = .;

lld would put orphan sections like .comment before __stack_end,
corrupting the intended meaning.

The reason we don't normally move orphans past assignments to . is to
avoid breaking

rx_sec : { *(rx_sec) }
. = ALIGN(0x1000);
/* The RW PT_LOAD starts here*/

but in this case, there is nothing after and it seems safer to put the
orphan section last. This seems to match bfd's behavior and is
convenient for writing linker scripts that care about the layout of
SHF_ALLOC sections, but not of any non SHF_ALLOC sections.

llvm-svn: 313646
2017-09-19 17:29:58 +00:00
George Rimar 696a7f9ac6 [ELF] - Introduce std::vector<InputFile *> global arrays.
This patch removes lot of static Instances arrays from different input file 
classes and introduces global arrays for access instead. Similar to arrays we
have for InputSections/OutputSectionCommands.

It allows to iterate over input files in a non-templated code.

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

llvm-svn: 313619
2017-09-19 09:20:54 +00:00
Davide Italiano 763febc44d [ELF] Remove default argument for lambda.
This is not really OK in C++11, and GCc triggers a warning.
We can switch back to default arguments when C++14 will be the
minimum version of the standard supported, see:
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#974

Ack'ed by Rafael.

llvm-svn: 313550
2017-09-18 18:31:49 +00:00
Rafael Espindola e05e2f8b34 Keep some relocations with undefined weak symbols.
This fixes pr34301.

As the bug points out, we want to keep some relocations with undefined
weak symbols. This means that we cannot always claim that these
symbols are not preemptible as we do now.

Unfortunately, we cannot also just always claim that they are
preemptible. Doing so would, for example, cause us to try to create a
plt entry when we don't even have a dynamic symbol table.

What almost works is to say that weak undefined symbols are
preemptible if and only if we have a dynamic symbol table. Almost
because we don't want to fail the build trying to create a copy
relocation to a weak undefined.

llvm-svn: 313372
2017-09-15 18:05:02 +00:00
Rafael Espindola 056190c348 Don't make _gp absolute.
_gp points to a position in the file, so it is not really absolute. It
is also simpler to not force it to be absolute, so if there is no
strong ABI requirement we should not do it.

llvm-svn: 313333
2017-09-15 01:49:01 +00:00
George Rimar cb888a620d [ELF] - Refactor of Writer<ELFT>::forEachRelSec.
There is no need to scan over all input sections for relocatable output.
As we do not process or scan relocations anyways.
Patch moves check for Config->Relocatable out to avoid that and also removes
excessive check for isa<EhInputSection> from first for loop. 
It is excessive because we handle all of them in a second for loop below.
That all allowed to simplify code.

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

llvm-svn: 313127
2017-09-13 07:54:47 +00:00
Rafael Espindola 30ea5cf543 Update comment. NFC.
llvm-svn: 313051
2017-09-12 17:18:03 +00:00
Rafael Espindola 4d5601608d Simplify handling of predefined symbols.
Given our representation of symbols as section + offset, we can
finalize symbols like _end as soon as the section is known.

llvm-svn: 313048
2017-09-12 16:38:01 +00:00
Rui Ueyama 9011320921 Remove a redundant local variable.
llvm-svn: 312823
2017-09-08 19:41:35 +00:00
Rafael Espindola 8016bdfd93 Handle empty dynamic lists.
llvm-svn: 312820
2017-09-08 18:53:43 +00:00
Rafael Espindola ee6a352a8d Handle lazy symbols is computeIsPreemptible.
llvm-svn: 312812
2017-09-08 18:41:49 +00:00
Rafael Espindola 716c57bfb5 Simplify. NFC.
We handled all undefined symbols before this.

llvm-svn: 312808
2017-09-08 18:23:25 +00:00
Rafael Espindola bb468da200 Simplify as this runs before copy relocations are created.
llvm-svn: 312807
2017-09-08 18:21:14 +00:00
Rafael Espindola d72d97b3be If --dynamic-list is given, only those symbols are preemptible.
This allows combining --dynamic-list and version scripts too. The
version script controls which symbols are visible, and
--dynamic-list controls which of those are preemptible.

Unlike previous versions, undefined symbols are still considered
preemptible, which was the issue breaking the cfi tests.

This fixes pr34053.

llvm-svn: 312806
2017-09-08 18:16:59 +00:00
Dmitry Mikulin 1e30f07ce7 Currently lld creates a single section to collect all commons. There is no way
to separate commons based on file name patterns. The following linker script
construct does not work because commons are allocated before section placement
is done and the only synthesized BssSection that holds all commons has no file
associated with it:
SECTIONS { .common_0 : { *file0.o(COMMON) }}

This patch changes the allocation of commons to create a section per common
symbol and let the section logic do the layout.

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

llvm-svn: 312796
2017-09-08 16:22:43 +00:00
George Rimar 9a2da39837 [ELF] - Simplify #2. NFC.
llvm-svn: 312789
2017-09-08 13:40:07 +00:00
George Rimar 7ac3825afb [ELF] - Simplify. NFC.
llvm-svn: 312787
2017-09-08 13:26:45 +00:00
Rafael Espindola 0ff545c018 Revert "Revert "Revert r311468: If --dynamic-list is given, only those symbols are preemptible""
This reverts commit r312757.

Evgenii Stepanov reports that it broke some tests.

llvm-svn: 312771
2017-09-08 01:09:52 +00:00
Rafael Espindola b7d0be5896 Revert "Revert r311468: If --dynamic-list is given, only those symbols are preemptible"
If --dynamic-list is given, only those symbols are preemptible.

This allows combining --dynamic-list and version scripts too. The
version script controls which symbols are visible, and --dynamic-list
controls which of those are preemptible.

This fixes pr34053.

llvm-svn: 312757
2017-09-07 23:19:09 +00:00
George Rimar 6823c5f0c0 [ELF] - Rename PhdrEntry::First/Last to FirstSec/LastSec. NFC.
As was suggested in D34956 thread.

llvm-svn: 312712
2017-09-07 11:01:10 +00:00
George Rimar 582ede8922 [ELF] - Store pointer to PT_LOAD instead of pointer to first section in OutputSection
It is a bit more convinent and helps to simplify logic 
of program headers allocation a little.

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

llvm-svn: 312711
2017-09-07 10:53:07 +00:00
Davide Italiano a0186dd986 [ELF/Writer] Fix english in a comment. NFCI.
llvm-svn: 312669
2017-09-06 21:16:51 +00:00
Peter Smith 3ef89b0fc7 [ELF] Move fixSectionAlignments() before first call to assignAddresses()
The fixSectionAlignments() function may alter the alignment of some
OutputSections, this is likely to alter the addresses calculated earlier
in assignAddresses(). By moving the call to fixSectionAlignments() we
make sure that assignAddresses() is consistent with the early calculation
used for RangeThunks and the final call just before writing the image.

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

llvm-svn: 312636
2017-09-06 14:02:14 +00:00
Rui Ueyama 888da8c232 Do not use invalid iterators to fix Windows build.
std::vector::insert invalidates all iterators, so it was not safe to do

  Script->Opt.Commands.insert(++I, Make(ElfSym::End1));
  Script->Opt.Commands.insert(++I, Make(ElfSym::End2));

because after the first line, `I` is no longer valid.

This patch rewrites fixes the issue. I belive the new code without
higher-order functions is a bit more readable than before.

llvm-svn: 312570
2017-09-05 20:17:37 +00:00
Petr Hosek 7ab9f7be0c [ELF] Set p_memsz to p_filesz when aligning the last segment to page boundary
Having p_filesz different from p_memsz is confusing some tools.

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

llvm-svn: 312384
2017-09-01 21:48:20 +00:00
Petr Hosek 18821b60b0 [ELF] Generate symbol assignments for predefined symbols
The problem with symbol assignments in implicit linker scripts is that
they can refer synthetic symbols such as _end, _etext or _edata. The
value of these symbols is currently fixed only after all linker script
commands are processed, so these assignments will be using non-final and
hence invalid value.

Rather than fixing the symbol values after all command processing have
finished, we instead change the logic to generate symbol assignment
commands that set the value of these symbols while processing the
commands, this ensures that the value is going to be correct by the time
any reference to these symbol is processed and is equivalent to defining
these symbols explicitly in linker script as BFD ld does.

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

llvm-svn: 312305
2017-09-01 02:23:31 +00:00
George Rimar 60608a8ae5 [ELF] - Simplify (use llvm::erase_if). NFC.
llvm-svn: 311878
2017-08-28 09:28:15 +00:00
Sam Clegg 7dbd1fd73b Update comments: parallel_for_each -> parallelForEach
Also remove unused include of raw_ostream.h

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

llvm-svn: 311587
2017-08-23 19:03:20 +00:00
Rui Ueyama e158f7c329 Revert r311468: If --dynamic-list is given, only those symbols are preemptible
This reverts commit r311468 because it broke some CFI bots.

llvm-svn: 311497
2017-08-22 21:54:58 +00:00
Rui Ueyama 9cbbacb910 If --dynamic-list is given, only those symbols are preemptible
Patch by Rafael Espíndola.

This is PR34053.

The implementation is a bit of a hack, given the precise location where
IsPreemtible is set, it cannot be used from
SymbolTable::handleAnonymousVersion.

I could add another method to SymbolTable if you think that would be
better.

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

llvm-svn: 311468
2017-08-22 16:31:47 +00:00
George Rimar f7ef2a13f6 [ELF] - Recommit "[ELF] - Do not forget to fill last bytes of PT_LOADs with trap instructions."
With fix: explicitly specify ouput format for hexdump tool call.

Original commit message:

[ELF] - Do not forget to fill last bytes of PT_LOADs with trap instructions.

Previously last 4 bytes of executable loads
were not filled with trap instructions,
patch fixes this bug.

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

llvm-svn: 311315
2017-08-21 08:31:14 +00:00
George Rimar 09a6945b48 [ELF] - Revert r311310 "[ELF] - Do not forget to fill last bytes of PT_LOADs with trap instructions."
It broke BB:
http://lab.llvm.org:8011/builders/lld-x86_64-darwin13/builds/11792/steps/test_lld/logs/stdio

llvm-svn: 311314
2017-08-21 08:13:45 +00:00
George Rimar c7392cbe9a [ELF] - Do not forget to fill last bytes of PT_LOADs with trap instructions.
Previously last 4 bytes of executable loads
were not filled with trap instructions,
patch fixes this bug.

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

llvm-svn: 311310
2017-08-21 07:51:21 +00:00
Ben Dunbobbin 95637558fa Test commit.
Removed extraneous comment markers

llvm-svn: 311169
2017-08-18 16:15:36 +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 6238ed2457 Update comments as the function does not write to the first page anymore.
Also refactored the code a bit.

llvm-svn: 310886
2017-08-14 21:18:12 +00:00
Rafael Espindola 0158e2a50a Delete what looks like dead code.
The start of a segment should not have a gap that needs trap
instructions.

llvm-svn: 310696
2017-08-11 06:07:02 +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 35c908f20c Compute isPreemtible only once.
This is probably a small optimization, but the main motivation is
having a way of fixing pr34053 that doesn't require a hash lookup in
isPreempitible.

llvm-svn: 310602
2017-08-10 15:05:37 +00:00
Shoaib Meenai 335fad1c24 [lld] Allow rel iplt symbols with dynamic symbol table
Emit these symbols as long as we're building in a static configuration,
even if we're emitting a dynamic symbol table. This is consistent with
both bfd and gold.

Ordinarily, the combination of -static and -export-dynamic wouldn't make
much sense. Unfortunately, cmake versions prior to 3.4 forcefully
injected -rdynamic [1], so it seems worthwhile to support.

[1] https://cmake.org/cmake/help/v3.4/policy/CMP0065.html

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

llvm-svn: 310168
2017-08-05 05:01:07 +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
George Rimar d6bcde389a [ELF] - Fix "--symbol-ordering-file doesn't work with linker scripts"
This is PR33889,

Patch adds support of combination of linkerscript and
-symbol-ordering-file option.

If no sorting commands are present in script inside section declaration
and no --sort-section option specified, code uses sorting from ordering 
file if any exist.

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

llvm-svn: 310045
2017-08-04 10:25:29 +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
Petr Hosek edd6c3587c [ELF] When the code segment is the last, align it to the page boundary
When the data segment is the last segment, it is correct to leave
it unaligned. However, when the code segment is the last segment,
it should be aligned to the page boundary to avoid loading the
non-segment parts of the ELF file at the end of the file.

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

llvm-svn: 309829
2017-08-02 16:35:00 +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
George Rimar aa3541875e [ELF] - Store PhdrEntry values by pointers instead of storing by value.
That is slightly more convinent as allows to store pointer on
program header entry in a more safe way.
 
Change was used in 2 patches currently on review.

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

llvm-svn: 309253
2017-07-27 07:46:50 +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 aaa8e433ad Try to fix the windows build.
llvm-svn: 309162
2017-07-26 19:57:40 +00:00
Rafael Espindola bf991405de Try to fix the windows build.
llvm-svn: 309160
2017-07-26 19:37:58 +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
Rafael Espindola dc49af9d32 Make a function static. NFC.
llvm-svn: 308939
2017-07-24 23:55:33 +00:00
Dmitry Mikulin 97d6a80895 If user requested section alignment is greater than MaxPageSize, propagate it to segment headers correctly.
Differential Revision: https://reviews.llvm.org/D35813

llvm-svn: 308930
2017-07-24 21:27:02 +00:00
Rafael Espindola fae04ae44c Handle a section being more aligned than a page size.
llvm-svn: 308812
2017-07-22 00:17:57 +00:00
Rafael Espindola afbb7be6d5 Fix a crash.
This is PR33821.

What we really want to check in here is if the output section was
created, not if the command was empty.

llvm-svn: 308382
2017-07-18 21:46:27 +00:00