Commit Graph

1255 Commits

Author SHA1 Message Date
George Rimar 80355234f7 [ELF] - Allow applying SHF_MERGE optimization for relocatable output.
This fixes PR35223.

Here I enabled SHF_MERGE section content merging for -r like
we do for regular linking.

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

llvm-svn: 318516
2017-11-17 11:27:57 +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
George Rimar 661a2c1970 [ELF] - Don't emit broken relocations for SHF_MERGE sections when --emit-relocs is used.
Previously our relocations we rewrote were broken for that case.
We emited incorrect addend and broken relocation info field
because did not produce section symbol for mergeable synthetic sections.

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

llvm-svn: 318394
2017-11-16 12:33:36 +00:00
Rafael Espindola a4884cc38f Try harder to delete the temporary file.
It is really hard to cover restarts in a debugger, SIGKILL or power
failures. I will try to handle them in a followup patch, but it will
not support all the systems lld has to run on.

RemoveFileOnSignal takes care of crashes.

So what is left is making sure all regular exits delete the file. This
patch does that by moving the buffer to error handling. That is a bit
of a hack, but seemed better than to generalize it to take a callback on
construction.

I will implement this on COFF on the next patch.

llvm-svn: 318060
2017-11-13 18:06:43 +00:00
Rafael Espindola 5f903f3848 Update for llvm change.
llvm-svn: 317657
2017-11-08 01:50:34 +00:00
Rafael Espindola f7a57294d7 Update for llvm change.
llvm-svn: 317650
2017-11-08 01:05:52 +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
Rui Ueyama aa8523e4b6 Move OutputSectionFactory to LinkerScript.cpp. NFC.
That class is used only by LinkerScript.cpp, so we should move it to
that file. Also, it no longer has to be a "factory" class. It can just
be a non-member function.

llvm-svn: 317427
2017-11-04 23:54:25 +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
George Rimar 8c0cdca99e [ELF] - Removed unused variable. NFC.
llvm-svn: 317316
2017-11-03 11:51:58 +00:00
James Henderson 50baa593f1 [ELF] Remove unnecessary function call. NFC.
StringTableSection does not implement postThunkContents, so calling it on these 
sections is pointless (it calls an empty virtual function), and we can remove it.

Reviewers: ruiu

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

llvm-svn: 317014
2017-10-31 17:28:44 +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
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