Commit Graph

1180 Commits

Author SHA1 Message Date
Rafael Espindola 2d9a3be2ab Keep a list of all OutputSectionCommands.
Now that we are trying to use the linker script representation as the
canonycal one, there are a few loops looking for just OutputSectionCommands.

Create a vector with just the OutputSectionCommands once that is
stable to simplify the rest of the code.

llvm-svn: 304181
2017-05-30 01:30:14 +00:00
Rafael Espindola 43e76cd489 Avoid a couple uses of OutputSections.
After fabricateDefaultCommands we can look at the script commands.

llvm-svn: 304014
2017-05-26 17:48:27 +00:00
Rafael Espindola 881cc1643a Avoid using EhFrameHdr->Sections.
This is a necessary step for moving clearOutputSections earlier.

llvm-svn: 304009
2017-05-26 17:28:17 +00:00
Rafael Espindola d23e9267a6 Order writable executable sections before writable ones.
On SPARC, .plt is both writeable and executable. The current way
sections are sorted means that lld puts it after .data/.bss. but it
really needs to be close to .test to make sure branches into .plt
don't overflow. I'd argue that because .bss is supposed to come last
on all architectures, we should change the default sort order such
that writable and executable sections come before sections that are
just writeable. read-only executable sections should still come after
sections that are just read-only of course. This diff makes this
change.

llvm-svn: 304008
2017-05-26 17:23:25 +00:00
Rui Ueyama e962e37792 Rearrange code for the sake of readability. NFC.
llvm-svn: 303961
2017-05-26 02:27:19 +00:00
Rui Ueyama 9e6f268054 Inline a trivial constructor.
llvm-svn: 303958
2017-05-26 02:17:13 +00:00
Rui Ueyama 2f106b4690 When uncompressing sections, remove SHF_COMPRESSED bits. NFC.
In this way, the content and the flag is always consistent, which I
think better than removing the bit when input sections reaches the Writer.

llvm-svn: 303926
2017-05-25 22:00:36 +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 27dd659be1 Move clearOutputSections earlier. NFC.
llvm-svn: 303781
2017-05-24 17:54:28 +00:00
Rafael Espindola aeb4b7d217 Clear OutSec->Sections.
Once the dummy linker script is created, we want it to be used for
everything to avoid having two redundant representations that can get
out of sync.

We were already clearing OutputSections. With this patch we clear the
Sections vector of every OutputSection.

llvm-svn: 303703
2017-05-23 22:54:06 +00:00
Rafael Espindola a46f688e8f Use linker script commands in writeMapFile.
This converts the last (chronologically) user of OutputSections to use
the linker script commands instead.

The idea is to convert all uses after fabricateDefaultCommands, so
that we have a single representation.

llvm-svn: 303384
2017-05-18 21:30:14 +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
Rafael Espindola 246c1c47ea Fix flag to start with 1 << 0. NFC.
Thanks to Andrew Ng for noticing it.

llvm-svn: 303354
2017-05-18 16:20:12 +00:00
George Rimar ec84ffc529 [ELF] - Detemplate Thunk creation.
Nothing special here, just detemplates code that became possible 
to detemplate after recent commits in a straghtforward way.

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

llvm-svn: 303237
2017-05-17 07:10:59 +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
George Rimar ab94768cc1 [ELF] - Use llvm::to_integer() instead of StringRef::getAsInteger().
Switch to llvm::to_integer() everywhere in LLD instead of 
StringRef::getAsInteger() because API of latter is confusing. 
It returns true on error and false otherwise what makes reading 
the code incomfortable.

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

llvm-svn: 303149
2017-05-16 08:19:25 +00:00
George Rimar 09328b3ef8 [ELF] - Apply clang-format. NFC.
llvm-svn: 302921
2017-05-12 17:00:07 +00:00
Rafael Espindola 5210141b07 Optimize orphan placement in a general way.
We used to place orphans by just using compareSectionsNonScript.

Then we noticed that since linker scripts can use another order, we
should first try match the section to a given PT_LOAD. But there is
nothing special about PT_LOAD. The same issue can show up for
PT_GNU_RELRO for example.

In general, we have to search for the most similar section and put the
orphan next to it. Most similar being defined as how long they follow
the same code path in compareSecitonsNonScript.

That is what this patch does. We now compute a rank for each output
section, with a bit for each branch in what was
compareSectionsNonScript.

With this findOrphanPos is now fully general and orphan placement can
be optimized by placing every section with the same rank at once.

The included testcase is a variation of many-sections.s that uses
allocatable sections to avoid the fast path in the existing
code. Without threads it goes form 46 seconds to 0.9 seconds.

llvm-svn: 302903
2017-05-12 14:52:22 +00:00
Rafael Espindola 8ff5c41192 Detemplate compareSections. NFC.
llvm-svn: 302849
2017-05-11 23:37:55 +00:00
Rafael Espindola 24a5a9058e Detemplate compareSectionsNonScript. NFC.
llvm-svn: 302848
2017-05-11 23:33:19 +00:00
Rafael Espindola 9e889eb48c Detemplate isRelroSection. NFC.
llvm-svn: 302847
2017-05-11 23:31:06 +00:00
Rafael Espindola 88ab9fb163 Detemplate the got.
This is a bit hackish, but allows for a lot of followup cleanups.

llvm-svn: 302845
2017-05-11 23:26:03 +00:00
Rafael Espindola 5ab1989584 Reduce templating. NFC.
llvm-svn: 302843
2017-05-11 23:16:43 +00:00
Rafael Espindola 895aea6d15 Reduce template usage. NFC.
llvm-svn: 302832
2017-05-11 22:02:41 +00:00
Rafael Espindola b3aa2c9b9e Reduce template usage. NFC.
llvm-svn: 302828
2017-05-11 21:33:30 +00:00
Rafael Espindola 4b1c3696e3 Reduce template usage. NFC.
llvm-svn: 302826
2017-05-11 21:23:38 +00:00
Petr Hosek 6b936bf6c7 [ELF] Define __ehdr_start unconditionally even when using linker script
This behavior differs from the semantics implemented by GNU linkers
which only define this symbol iff ELF headers are in the memory
mapped segment.

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

llvm-svn: 302687
2017-05-10 16:20:33 +00:00
Rafael Espindola dc1ed12015 Remove another use of section names. NFC.
llvm-svn: 302662
2017-05-10 14:12:02 +00:00
Rafael Espindola 0ca3712796 Use a simpler heuristic for placing orphans.
This is a bit easier to read and a lot faster in some cases. A version
of many-sections.s with linker scripts goes from 0m41.232s to
0m19.575s.

llvm-svn: 302528
2017-05-09 13:58:46 +00:00
Rafael Espindola b5de5b9354 Simplify orphan section positioning.
The code following this one already considers every possible insertion
point for orphan sections, there is no point in sorting them before.

llvm-svn: 302441
2017-05-08 16:49:20 +00:00
Rafael Espindola 660c9ab929 Delete LinkerScript::getSectionIndex.
We can set SectionIndex tentatively as we process the linker script
instead of looking it repeatedly.

In general we should try to have as few name lookups as possible.

llvm-svn: 302299
2017-05-05 21:34:26 +00:00
Rafael Espindola 02ed7575e7 Simplify the header allocation.
In the non linker script case we would try very early to find out if
we could allocate the headers. Failing to do that would add extra
alignment to the first ro section, since we would set PageAlign
thinking it was the first section in the PT_LOAD.

In the linker script case the header allocation must be done in the
end, causing some duplication.

We now tentatively add the headers to the first PT_LOAD and if it
turns out they don't fit, remove them. With this we only need to
allocate the headers in one place in the code.

llvm-svn: 302186
2017-05-04 19:34:17 +00:00
Peter Smith c60b4510ea [ELF] Fix problems with fabricateDefaultCommands() and --section-start
The --section-start <name>=<address> needs to be translated into equivalent
linker script commands. There are a couple of problems with the existing
implementation:
- The --section-start with the lowest address is assumed to be at the start
of the map. This assumption is incorrect, we have to iterate through the
SectionStartMap to find the lowest address.
- The addresses in --section-start were being over-aligned when the
sections were marked as PageAlign. This is inconsistent with the use of
SectionStartMap in fixHeaders(), and can cause problems when the PageAlign
causes an "unable to move location counter backward" error when the
--section-start with PageAlign is aligned to an address higher than the next
--section-start. The ld.bfd and ld.gold seem to be more consistent with this
approach but this is not a well specified area.
    
This change fixes the problems above and also corrects a typo in which
fabricateDefaultCommands() is called with the wrong parameter, it should be
called with AllocateHeader not Config->MaxPageSize.

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

llvm-svn: 302007
2017-05-03 08:44:50 +00:00
Rafael Espindola de8d9897d9 Bring back r301678.
This version uses a set to speed up the synchronize method.

Original message:

    Remove LinkerScript::flush.

    This patch replaces flush with a last ditch attempt at synchronizing
    the section list with the linker script "AST".

    The synchronization is a bit of a hack and should in time be avoided
    by creating the AST earlier so that modifications can be made directly
    to it instead of modifying the section list and synchronizing it back.

    This is the main step for fixing
    https://bugs.llvm.org/show_bug.cgi?id=32816. With this in place I
    think the only missing thing would be to have processCommands assign
    section indexes as dummy offsets so that the sort in
    OutputSection::finalize works.

    With this LinkerScript::assignAddresses becomes much simpler, which
    should help with the thunk work.

llvm-svn: 301745
2017-04-29 15:44:03 +00:00
Rui Ueyama 216aa11cc5 Revert r301678: Remove LinkerScript::flush.
This reverts commit r301678 since that change significantly slowed
down the linker. Before this patch, LLD could link clang in 8 seconds,
but with this patch it took 40 seconds.

llvm-svn: 301709
2017-04-28 22:40:58 +00:00
Rafael Espindola b3bc1ed0d4 Remove LinkerScript::flush.
This patch replaces flush with a last ditch attempt at synchronizing
the section list with the linker script "AST".

The synchronization is a bit of a hack and should in time be avoided
by creating the AST earlier so that modifications can be made directly
to it instead of modifying the section list and synchronizing it back.

This is the main step for fixing
https://bugs.llvm.org/show_bug.cgi?id=32816. With this in place I
think the only missing thing would be to have processCommands assign
section indexes as dummy offsets so that the sort in
OutputSection::finalize works.

With this LinkerScript::assignAddresses becomes much simpler, which
should help with the thunk work.

llvm-svn: 301678
2017-04-28 20:22:47 +00:00
Rui Ueyama 63d48e5956 Remove needless type conversions.
llvm-svn: 301513
2017-04-27 04:01:14 +00:00
Rui Ueyama a2a46a9532 Define __tls_get_addr as a hidden symbol even for ARM or MIPS.
addIgnored defines a given symbol even if there is no existing
symbol with the same name. So, even if libc provides __tls_get_addr,
we should still be able to call addIgnored.

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

llvm-svn: 301290
2017-04-25 04:44:54 +00:00
Peter Smith cbfe9e946f [ELF] Always use Script::assignAddresses()
This change fabricates linker script commands for the case where there is
no linker script SECTIONS to control address assignment. This permits us
to have a single Script->assignAddresses() function.
    
There is a small change in user-visible-behavior with respect to the
handling of .tbss SHT_NOBITS, SHF_TLS as the Script->assignAddresses()
requires setDot() to be called with monotically increasing addresses.
The tls-offset.s test has been updated so that the script and non-script
results match.

This change should make the non-script behavior of lld closer to an
equivalent linker script.

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

llvm-svn: 300687
2017-04-19 12:46:32 +00:00
Rui Ueyama 29181007df Update comment.
llvm-svn: 300676
2017-04-19 11:32:27 +00:00
George Rimar dbf9339715 [ELF] - Implemented --compress-debug-sections option.
Patch implements --compress-debug-sections=zlib.

In compare with D20211 (a year old patch, abandoned), it implementation
uses streaming and fully reimplemented, does not support zlib-gnu for
simplification.

This is PR32308.

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

llvm-svn: 300444
2017-04-17 08:58:12 +00:00
Rui Ueyama 3e1fc3f6fe Add "1" suffix if there's varaible ends with "2".
If we knew that we'd add End2, Edata2 and Etext2, we'd name their
original symbols with "1". This patch does it.

llvm-svn: 300263
2017-04-13 21:37:56 +00:00
Rui Ueyama 1505ba826c Replace a clever lambda helper with a simpler one.
llvm-svn: 300259
2017-04-13 21:23:03 +00:00
Rui Ueyama 9d773f3cb2 Add comments for the RELRO segment.
RELRO is a feature to make segments read-only after dynamic relocations
are applied. It is different from read-only segments because RELRO is
initially writable. And of course RELRO is different from writable
segments.

RELRO is not a very well known feature. We have a series of checks to
make a decision whether a section should be in a RELRO segment or not,
but we didn't describe why. This patch adds comments to explain how
that decision is made.

llvm-svn: 300176
2017-04-13 05:40:07 +00:00
James Henderson 9d9a663731 [ELF] Recommit r299635 to pad x86 executable sections with 0xcc
This follows r299748 which fixed a latent bug the original commit exposed.

llvm-svn: 299755
2017-04-07 10:36:42 +00:00
James Henderson d983180778 Revert r299635 because it exposed a latent bug.
llvm-svn: 299655
2017-04-06 15:22:58 +00:00
James Henderson 7ee227561e [ELF] Remove unnecessary cast and fix comments. NFC.
llvm-svn: 299636
2017-04-06 09:40:03 +00:00
James Henderson 8dd4c06a77 [ELF] Pad x86 executable sections with 0xcc int3 instructions
Executable sections should not be padded with zero by default. On some
architectures, 0x00 is the start of a valid instruction sequence, so can confuse
disassembly between InputSections (and indeed the start of the next InputSection
in some situations). Further, in the case of misjumps into padding, padding may
start to be executed silently.

On x86, the "0xcc" byte represents the int3 trap instruction. It is a single
byte long so can serve well as padding. This change switches x86 (and x86_64) to
use this value for padding in executable sections, if no linker script directive
overrides it. It also puts the behaviour into place making it easy to change the
behaviour of other targets when desired. I do not know the relevant instruction
sequences for trap instructions on other targets however, so somebody should add
this separately.

Because the old behaviour simply wrote padding in the whole section before
overwriting most of it, this change also modifies the padding algorithm to write
padding only where needed. This in turn has caused a small behaviour change with
regards to what values are written via Fill commands in linker scripts, bringing
it into line with ld.bfd. The fill value is now written starting from the end of
the previous block, which means that it always starts from the first byte of the
fill, whereas the old behaviour meant that the padding sometimes started mid-way
through the fill value. See the test changes for more details.

Reviewed by: ruiu

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

Bugzilla: http://bugs.llvm.org/show_bug.cgi?id=32227
llvm-svn: 299635
2017-04-06 09:29:08 +00:00
Rui Ueyama 0ce388bebb Remove unused typedefs.
llvm-svn: 299594
2017-04-05 21:46:06 +00:00
Rui Ueyama 9f125857ae Inline a small function. NFC.
llvm-svn: 299593
2017-04-05 21:45:47 +00:00
Rui Ueyama 6bd3822007 Use uint64_t to keep file size even on 32-bit machines.
If an output file is too large for 32-bit, we should report an error.

llvm-svn: 299592
2017-04-05 21:37:09 +00:00
Rui Ueyama f2dc4362c0 Inline a small function. NFC.
llvm-svn: 299590
2017-04-05 21:08:47 +00:00
Peter Smith 56abf209c2 [ELF] Make createThunks a class [NFC]
For range extension thunks we will need to repeatedly call createThunks()
until no more thunks are created. We will need to retain the state of
Thunks that we have created so far to avoid recreating them on later
passes. This change does not change the functionality of createThunks().

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

llvm-svn: 299530
2017-04-05 10:30:09 +00:00
George Rimar e6c5d3862d [ELF] - Define __bss_start symbol.
GNU linkers define __bss_start symbol.
Patch teaches LLD to do that. This is PR32051.

Below is part of standart ld.bfd script:

.data1          : { *(.data1) }
  _edata = .; PROVIDE (edata = .);
  . = .;
  __bss_start = .;
  .bss            :
  {
Currently LLD can emit up to 3 .bss* sections as one of testcase shows.
Implementation inserts this symbol before first .bss* output section.

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

llvm-svn: 299528
2017-04-05 10:03:25 +00:00
Rui Ueyama 81cb710784 Update comments.
llvm-svn: 298669
2017-03-24 00:15:57 +00:00
Rui Ueyama 9b55e92a7f Move a few functions to a new file Filesystem.{cpp,h}.
llvm-svn: 298667
2017-03-24 00:15:16 +00:00
Rui Ueyama a34da93847 Make elf::ScriptConfig a LinkerScript class member variable.
LinkerScript used to be a template class, so we couldn't instantiate
that class in elf::link. We instantiated ScriptConfig class earlier
instead so that the linker script parser can store configurations to
the object.

Now that LinkerScript is not a template, it doesn't make sense to
separate ScriptConfig from LinkerScript. This patch merges them.

llvm-svn: 298457
2017-03-21 23:03:09 +00:00
George Rimar 90a528ba7a [ELF] - Detemplate ARMExidxSentinelSection. NFC.
llvm-svn: 298350
2017-03-21 09:01:39 +00:00
George Rimar 35e846e14d [ELF] - Detemplate GdbIndexSection.
Patch moves Sections array to
InputFile (root class for input files).

That allows to detemplate GdbIndexSection.

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

llvm-svn: 298345
2017-03-21 08:19:34 +00:00
Simon Atanasyan d34a3631b2 [ELF][MIPS] Calculate relocations agains _gp_disp / __gnu_local_gp using dedicated 'expressions'
The patch introduces two new relocations expressions R_MIPS_GOT_GP and
R_MIPS_GOT_GP_PC. The first one represents a current value of `_gp`
pointer and used to calculate relocations against the `__gnu_local_gp`
symbol. The second one represents the offset between the beginning of
the function and the `_gp` pointer's value.

There are two motivations for introducing new expressions:
- It's better to keep all non-trivial relocation calculations in the
  single place - `getRelocTargetVA` function.
- Relocations against both `_gp_disp` and `__gnu_local_gp` symbols
  depend on the `_gp` value. It's a magical value points to the "middle"
  of GOT. Now all relocations use a common `_gp` value. But in fact,
  under some conditions each input file might require its own `_gp`
  value. I'm going to implement it in the future patches. So it's
  better to make `MipsGotSection` responsible for calculation of
  the `_gp` value.

llvm-svn: 298306
2017-03-20 21:03:43 +00:00
George Rimar 14534eb8a2 [ELF] - Detemplate MipsGotSection<ELFT>
This continues detemplation process.

Detemplating MipsGotSection<ELFT> is helpfull because can
help to detemplate getRelocTargetVA. (one more change is required)
It opens road to detemplation of GotSection<ELFT> and probably
something else after that.

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

llvm-svn: 298272
2017-03-20 16:44:28 +00:00
George Rimar 6c2949da39 [ELF] - Detemplate BuildIdSection section.
Does not introduce anything new,
just performs detemplate, using methods we
already have.

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

llvm-svn: 298269
2017-03-20 16:40:21 +00:00
George Rimar a8dba48762 [ELF] - Combine LinkerScriptBase and LinkerScript<ELFT>
Patch removes templated linkerscript class.

Unfortunately that required 2 additional static methods
findSymbol() and addRegularSymbol() because code
depends on Symtab<ELFT>::X

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

llvm-svn: 298241
2017-03-20 10:09:58 +00:00
Rui Ueyama d57e74b7d3 Compute Config member function return values only once.
We had a few Config member functions that returns configuration values.
For example, we had is64() which returns true if the target is 64-bit.
The return values of these functions are constant and never change.

This patch is to compute them only once to make it clear that they'll
never change.

llvm-svn: 298168
2017-03-17 23:29:01 +00:00
George Rimar 176d606020 [ELF] - Recommit r298078 "[ELF] - Simplify logic of creating "COMMON" section."
With fix of next warning:
Writer.cpp:361:3: warning: suggest parentheses around assignment used as truth value [-Wparentheses]

Original commit message:

Patch reuses BssSection section to simplify creation of 
COMMON section.

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

llvm-svn: 298086
2017-03-17 13:31:07 +00:00
George Rimar 4ddd9c9bd6 [ELF] - Revert r298078 and 298082
It segfaults.

llvm-svn: 298084
2017-03-17 13:21:22 +00:00
George Rimar 69739e6d1d [ELF] - Fix warning.
Writer.cpp:361:3: warning: suggest parentheses around assignment used as truth value [-Wparentheses]

llvm-svn: 298082
2017-03-17 13:15:35 +00:00
George Rimar f6c300e86d [ELF] - Simplify logic of creating "COMMON" section.
Patch reuses BssSection section to simplify creation of 
COMMON section.

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

llvm-svn: 298078
2017-03-17 13:04:06 +00:00
George Rimar f64618a621 [ELF] - Detemplate SymbolBody::getVA and SymbolBody::getPltVA. NFC.
llvm-svn: 298071
2017-03-17 11:56:54 +00:00
George Rimar dfc020e9f9 [ELF] - Detemplate PltSection. NFC.
Alternative approach can be remove templated method
either, like D31028 do.

llvm-svn: 298065
2017-03-17 11:01:57 +00:00
George Rimar 1ab9cf49d0 [ELF] - Recommit "[ELF] - Make Bss and BssRelRo sections to be synthetic (#3)."
Was fixed, details on review page.

Original commit message:

That removes CopyRelSection class completely, making
Bss/BssRelRo to be just regular synthetics.

This is splitted from D30541 and polished.
Difference from D30541 that all logic of SharedSymbol
converting to DefinedRegular was removed for now and
probably will be posted as separate patch.

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

llvm-svn: 298062
2017-03-17 10:14:53 +00:00
George Rimar 7702bc237e [ELF] - Removed unused templates #4. NFC.
llvm-svn: 297944
2017-03-16 11:20:02 +00:00
George Rimar 49a47f2a6d [ELF] - Removed unused template #1. NFC
llvm-svn: 297938
2017-03-16 10:29:44 +00:00
George Rimar f98c5c126c [ELF] - Detemplate OutputSection::assignOffsets. NFC.
llvm-svn: 297937
2017-03-16 10:24:54 +00:00
George Rimar 47bed8c9f7 Revert r297813 "[ELF] - Make Bss and BssRelRo sections to be synthetic (#3)."
I suppose it is the reason of BB fail:
http://lab.llvm.org:8011/builders/clang-cmake-aarch64-lld/builds/921

https://bugs.llvm.org/show_bug.cgi?id=32167

llvm-svn: 297933
2017-03-16 08:44:53 +00:00
Rafael Espindola a156555b5e simplify. NFC
llvm-svn: 297829
2017-03-15 12:31:54 +00:00
George Rimar 42886c4b47 [ELF] - Detemplate MipsRldMapSection. NFC.
After introducing Config->is64Bit() and 
recent changes in LinkerScriptBase, some
sections can be detemplated trivially. This 
is one of such cases.

llvm-svn: 297825
2017-03-15 12:02:31 +00:00
George Rimar 49648004ed [ELF] - Detemplate StringTableSection.
StringTableSection was <ELFT> templated previously,

It disallow to de-template code that uses it,
for example LinkerScript<ELFT>::discard uses it as:
if (S == In<ELFT>::ShStrTab)
  error("discarding .shstrtab section is not allowed");

It seems we can try to detemplate some of synthetic sections
and somehow make them available for non-templated calls.
(move out of In<ELFT> struct probably).

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

llvm-svn: 297815
2017-03-15 09:32:36 +00:00
George Rimar 22e3e7d165 [ELF] - Make Bss and BssRelRo sections to be synthetic (#3).
That removes CopyRelSection class completely, making
Bss/BssRelRo to be just regular synthetics.

This is splitted from D30541 and polished.
Difference from D30541 that all logic of SharedSymbol
converting to DefinedRegular was removed for now and
probably will be posted as separate patch.

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

llvm-svn: 297814
2017-03-15 09:21:29 +00:00
George Rimar 10f74fc10b [ELF] - Detemplate GotPltSection and IgotPltSection sections.
Patch introduces Config->is64Bit() and with help of that detemplates
GotPltSection and IgotPltSection sections

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

llvm-svn: 297813
2017-03-15 09:12:56 +00:00
Petr Hosek 02ad516b2e Support ABSOLUTE on the right hand side in linker scripts
This also requires postponing the assignment the assignment of
symbols defined in input linker scripts since those can refer to
output sections and in case we don't have a SECTIONS command, we
need to wait until all output sections have been created and
assigned addresses.

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

llvm-svn: 297802
2017-03-15 03:33:23 +00:00
George Rimar e21c3af7e9 [ELF] - Remove unnecessary template #4. NFC.
OutputSectionFactory has no ELFT templates anymore.

llvm-svn: 297720
2017-03-14 09:30:25 +00:00
George Rimar 2d2621090d [ELF] - Step to combine LinkerScript and LinkerScriptBase
We can move all not templated functionality to LinkerScriptBase.
Patch do that for hasPhdrsCommands() and shows how it helps to detemplate
things in other places.

Probably we should be able to merge these 2 classes into single one after such steps.
Even if not, it still looks as reasonable cleanup for me.

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

llvm-svn: 297714
2017-03-14 09:03:53 +00:00
Eugene Leviant 30c1b436ad [ELF] Fix crash when .eh_frame(_hdr) is discarded
lld crashes when .eh_frame or .eh_frame_hdr section is discarded
in linker script and there is no PHDRS directive.

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

llvm-svn: 297712
2017-03-14 08:49:09 +00:00
Peter Collingbourne f8435a9bda ELF: Resolve _end symbols correctly.
Fix a bug introduced in r297313 which caused them to resolve to the end
of the ELF header in PIEs and DSOs.

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

llvm-svn: 297638
2017-03-13 16:40:20 +00:00
George Rimar 78aa270041 [ELF] - Remove unnecessary template. NFC.
llvm-svn: 297622
2017-03-13 14:40:58 +00:00
Petr Hosek 7b79321e88 [ELF] Propely handle .eh_frame in linker scripts
Using .eh_frame input section pattern in linker script currently
causes a crash; this is because .eh_frame input sections require
special handling since they're all combined into a synthetic
section rather than regular output section.

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

llvm-svn: 297501
2017-03-10 20:00:42 +00:00
George Rimar 1c74c2f2a8 [ELF] - Do not try to create .eh_frame_hdr for relocatable output.
.eh_frame_hdr is a header constructed for .eh_frame sections.
We do not proccess .eh_frame when doing relocatable output,
so should not try to create .eh_frame_hdr too.
Previous behavior without this patch is segfault.

Fixes PR32118.

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

llvm-svn: 297365
2017-03-09 08:45:25 +00:00
Rafael Espindola 5616adf655 Remove DefinedSynthetic.
With this we have a single section hierarchy. It is a bit less code,
but the main advantage will be in a future patch being able to handle

foo = symbol_in_obj;

in a linker script. Currently that fails since we try to find the
output section of symbol_in_obj.  With this we should be able to just
return an InputSection from the expression.

llvm-svn: 297313
2017-03-08 22:36:28 +00:00
Rafael Espindola fcd208fdb3 Use uint32_t for alignment in more places, NFC.
llvm-svn: 297305
2017-03-08 19:35:29 +00:00
Rui Ueyama 007c002cb6 Revert r297008: [ELF] - Make Bss and BssRelRo sections to be synthetic (#2).
This reverts commit r297008 because it's reported that that
change broke AArch64 bots.

llvm-svn: 297297
2017-03-08 17:24:24 +00:00
Rafael Espindola c86b2cddc8 Convert a few more uses of uintX_t to uint64_t.
llvm-svn: 297286
2017-03-08 15:34:04 +00:00
Rafael Espindola 9371bab55a Convert a few uses of uintX_t to uint64_t.
llvm-svn: 297282
2017-03-08 15:21:32 +00:00
Peter Smith 1ec42d9a76 Finalize content of synthetic sections prior to Thunk Creation
This change moves the calls to finalizeContent() for each synthetic section
before createThunks(). This will allow us to assign addresses prior to
calling createThunks(). As addition of thunks may add to the static
symbol table and may affect the size of the mips got section we introduce a
couple of additional member functions to update these values.
    
Differential revision: https://reviews.llvm.org/D29983

llvm-svn: 297277
2017-03-08 14:06:24 +00:00
Rafael Espindola 3770763cda Rename Addralign to Alignment.
It now matches the name used in InputSectionBase.

llvm-svn: 297144
2017-03-07 14:55:52 +00:00
Rui Ueyama af6198d96d Remove Config->Rela and define Config->isRela() instead.
llvm-svn: 297108
2017-03-07 00:43:53 +00:00
Rafael Espindola 5c02b741eb Detemplate EhInputSection. NFC.
llvm-svn: 297077
2017-03-06 21:17:18 +00:00
Rafael Espindola 6119b865ec Detemplate merge (input and synthetic) sections. NFC.
llvm-svn: 297061
2017-03-06 20:23:56 +00:00
George Rimar c215a2ac40 [ELF] - Make Bss and BssRelRo sections to be synthetic (#2).
In compare with D30458, this makes Bss/BssRelRo to be pure
synthetic sections.

That removes CopyRelSection class completely, making
Bss/BssRelRo to be just regular synthetics.

SharedSymbols involved in creating copy relocations are
converted to DefinedRegular, what also simplifies things.

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

llvm-svn: 297008
2017-03-06 14:37:45 +00:00
George Rimar efc31dd9bb [ELF] - Reset output section size when assigning offsets.
In many places we reset Size to 0 before calling assignOffsets()
manually. Sometimes we don't do that. 
It looks we can just always do that inside.

Previous code had:
template <class ELFT> void OutputSection::assignOffsets() {
  uint64_t Off = Size;

And tests feels fine with Off = 0. 
I think Off = Size make no sence.

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

llvm-svn: 296609
2017-03-01 11:10:53 +00:00
Rui Ueyama 73d29ab3a7 Minor refactoring. NFC.
llvm-svn: 296511
2017-02-28 19:43:54 +00:00
Rui Ueyama 175e81cf3a Use make<> instead of new (BAlloc). NFC.
We converted them before, but there were a few remaining occurrences.

llvm-svn: 296510
2017-02-28 19:36:30 +00:00
Rui Ueyama 80474a26b9 De-template DefinedRegular.
Differential Revision: https://reviews.llvm.org/D30348

llvm-svn: 296508
2017-02-28 19:29:55 +00:00
George Rimar 6159f1290e [ELF] - Remove ElfSym::EhdrStart member. NFC.
We do not use it later, so don't have to store.

llvm-svn: 296466
2017-02-28 10:34:56 +00:00
Rui Ueyama b8dcdb5900 Merge SymbolTableSection::add{Global,Local} into one function.
Previously, these two functions put their symbols in different queues.
Now that the queues have been merged. So there's no point to keep two
separate functions.

llvm-svn: 296435
2017-02-28 04:20:16 +00:00
Rui Ueyama 945055aabf Rename SyntheticSection::finalize -> finalizeContents.
In LLD source code, too many functions are called "finalize", although
what they do are different. This patch gives it a better name.

llvm-svn: 296314
2017-02-27 03:07:41 +00:00
Rui Ueyama 9320cb0719 De-template SyntheticSection.
This class didn't use ELFT.

llvm-svn: 296313
2017-02-27 02:56:02 +00:00
Rui Ueyama 3255a52200 De-template InterpSection because it doesn't use ELFT.
llvm-svn: 296311
2017-02-27 02:32:49 +00:00
Rui Ueyama 536a26706f Move SymbolTable<ELFT>::Sections out of the class.
The list of all input sections was defined in SymbolTable class for a
historical reason. The list itself is not a template. However, because
SymbolTable class is a template, we needed to pass around ELFT to access
the list. This patch moves the list out of the class so that it doesn't
need ELFT.

llvm-svn: 296309
2017-02-27 02:32:08 +00:00
Rui Ueyama 02a036f2e6 De-template OutputSectionFactory.
Since OutputSection is no longer a template, it doesn't make much
sense to tempalte its factory class.

llvm-svn: 296308
2017-02-27 02:31:48 +00:00
Rui Ueyama 9d1bacb1b4 Remove useless template so that Out<ELFT> becomes just Out.
llvm-svn: 296307
2017-02-27 02:31:26 +00:00
Rui Ueyama 4076fa1e21 De-template SharedSymbol.
Differential Revision: https://reviews.llvm.org/D30351

llvm-svn: 296303
2017-02-26 23:35:34 +00:00
Rui Ueyama a37ace8d89 Rename OMagic -> Omagic for consistency.
llvm-svn: 296225
2017-02-25 01:52:03 +00:00
Rafael Espindola 24e6f363c5 Merge OutputSectionBase and OutputSection. NFC.
Now that all special sections are SyntheticSections, we only need one
OutputSection class.

llvm-svn: 296127
2017-02-24 15:07:30 +00:00
Rafael Espindola 40849419e2 Delete trivial getter.
llvm-svn: 296123
2017-02-24 14:28:00 +00:00
Petr Hosek f087e312b6 [ELF] Make __ehdr_start point to ELF file headers
__ehdr_start should be pointing to ELF file headers, not program
headers.

This is a reland of D30319.

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

llvm-svn: 296085
2017-02-24 04:11:02 +00:00
Petr Hosek 9a2bba7251 Revert "[ELF] Make __ehdr_start point to ELF file headers"
This reverts commit r296079.

llvm-svn: 296083
2017-02-24 03:18:59 +00:00
Petr Hosek 701ad3fbf9 [ELF] Make __ehdr_start point to ELF file headers
__ehdr_start should be pointing to ELF file headers, not program
headers.

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

llvm-svn: 296079
2017-02-24 03:00:52 +00:00
Rafael Espindola 66b4e21534 Convert EhOutputSection to be a synthetic section.
With this we complete the transition out of special output sections,
and with the previous patches it should be possible to merge
OutputSectionBase and OuputSection.

llvm-svn: 296023
2017-02-23 22:06:28 +00:00
Rafael Espindola 774ea7d0a9 Make InputSection a class. NFC.
With the current design an InputSection is basically anything that
goes directly in a OutputSection. That includes plain input section
but also synthetic sections, so this should probably not be a
template.

llvm-svn: 295993
2017-02-23 16:49:07 +00:00
Rui Ueyama a7e87252ce Always add PT_GNU_STACK.
If -z stack-size is given, we need to add PT_GNU_STACK even if
-z execstack is not given.

llvm-svn: 295945
2017-02-23 08:09:51 +00:00
Rafael Espindola c404d50d7c Merge InputSectionData and InputSectionBase.
Now that InputSectionBase is not a template there is no reason to have
the two.

llvm-svn: 295924
2017-02-23 02:32:18 +00:00
Rafael Espindola b4c9b81aad Convert InputSectionBase to a class.
Removing this template is not a big win by itself, but opens the way
for removing more templates.

llvm-svn: 295923
2017-02-23 02:28:28 +00:00
Rafael Espindola a55b86c0e5 Reduce templating a bit. NFC.
llvm-svn: 295909
2017-02-23 00:02:03 +00:00
Peter Smith 55865432b4 [ELF] Allow local symbols to be added after global symbols
This change moves the SymbolBodies with isLocal() == true before the global
symbols then calculating NumLocals rather than assuming all locals are
added before globals and the first NumLocals have isLocal() == true. This
permits Thunks to be moved after the pass that adds global symbols from
synthetics to the symbol table.

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

llvm-svn: 295650
2017-02-20 11:12:33 +00:00
Rafael Espindola ecbfd871f9 Don't print DISCARD sections as gced.
This is a small difference I noticed to gold and bfd. When given
--print-gc-sections, we print sections a linkerscript marks
DISCARD. The other linkers don't.

llvm-svn: 295467
2017-02-17 17:35:07 +00:00
Rafael Espindola 1a5c152b9c Add static. NFC.
llvm-svn: 295448
2017-02-17 14:32:15 +00:00
Rui Ueyama 5acac350e7 Add a comment.
llvm-svn: 295388
2017-02-17 00:40:44 +00:00
Rafael Espindola ee61d3589f Merge reloc sections in -emit-reloc mode.
Without this we would produce two relocation sections pointing to the
same section, which gnu tools reject.

This fixes pr31986.

The implementation of -r/--emit-reloc is getting fairly
complicated. But lets get the test passing before trying to refactor
it.

llvm-svn: 295385
2017-02-17 00:28:17 +00:00
Rafael Espindola 8290274c13 Share more output section creation code.
We can do this now that the linker script and the writer agree on
which sections should be combined.

llvm-svn: 295341
2017-02-16 17:32:26 +00:00
Rui Ueyama 26ad057099 Add comments.
llvm-svn: 295283
2017-02-16 04:51:46 +00:00
Rui Ueyama dec4ab0d0d Add comments.
llvm-svn: 295280
2017-02-16 04:19:03 +00:00
Rui Ueyama da5cc84661 Add CopyRelSection instances to BSS in the regular way.
Previously, space in a BSS section for copy relocations are reserved
in a special way. We directly manipulated size of the BSS section.
r294577 changed the way of doing it. Now, we create an instance of
CopyRelSection (which is a synthetic input section) for each copy
relocation.

This patch removes the remains of the old way and add CopyRelSections
to BSS sections using `addSections` function, which is the usual
way to add an input section to an output section.

llvm-svn: 295278
2017-02-16 04:12:19 +00:00
Ed Schouten 3bf713043a Make --export-dynamic work on non-PIC/PIE targets.
For CloudABI I'm only interested in generating non-PIC/PIE executables
on armv6 and i686, as PIE introduces larger overhead than on aarch64 and
x86_64. Still, I want to be able to instruct the linker to generate a
dynamic symbol table if requested. One example use for this is that
dynamic symbol tables can be used by programs to print nicely formatted
stacktraces, including symbol names.

Right now there seems to be some logic in LLD that it only wants to emit
dynamic symbol tables when either linking against libraries or when
building PIC. Let's extend this to also take --export-dynamic into
account.

Reviewed by:	ruiu
Differential Revision:	https://reviews.llvm.org/D29982

llvm-svn: 295240
2017-02-15 21:51:25 +00:00
Rui Ueyama 35723f09bb Explicitly return a new value instead of implicitly mutating a reference.
I think this is more readable than before.

llvm-svn: 295121
2017-02-14 23:35:42 +00:00
Rui Ueyama 104e2357de Do not store a computable attributes to Config.
llvm-svn: 295031
2017-02-14 05:45:47 +00:00
Rafael Espindola 08d6a3f133 Create only one section symbol per section.
Unfortunately some consumers of our .o files produced with -r expect
only one section symbol per section. That is true of at least of go's
own linker.

Combining them is a somewhat convoluted process. We have to create a
symbol for every section since we don't know which ones will be
needed. The relocation sections also have to be written first to
handle the Elf_Rel addend.

I did consider a completely different approach:

We could remove the -r special case of relocation sections when
reading. We would instead have a copyRelocs function that is used
instead of scanRelocs. It would create a DynamicReloc for each
relocation and a RelocationSection for each input relocation section.

A complication of such change is that DynamicReloc would have to take
a section index and a input section instead of a symbol since with
-emit-relocs some DynamicReloc would hold relocations referring to the
dynamic symbol table and other to the static symbol table.

That would be a pretty big change, and if we do it it is probably
better to do it as a refactoring.

llvm-svn: 294816
2017-02-11 01:40:49 +00:00
Peter Smith f09245a689 [ELF] Refactor PltSection and IPltSection into PltSection [NFC]
Much of the code in PltSection and IPltSection is similar, we identify
the IPlt by a HeaderSize of 0 and alter our behaviour in the member
functions appropriately:
-Iplt does not have a header
-Iplt always follows after the Plt
    
Differential Revision: https://reviews.llvm.org/D29664

llvm-svn: 294579
2017-02-09 10:56:15 +00:00
George Rimar 82bd8be6d8 Recommit r294464 "[ELF] - Added partial support for --emit-relocs (no --gc-section case, no /DISCARD/ support) #3"
with temporarily file name fix in testcase.

Original commit message:

-q, --emit-relocs - Generate relocations in output

Simplest implementation: 
* no GC case, 
* no "/DISCARD/" linkerscript command support.

This patch is extracted from D28612 / D29636,

Relative to PR31579.

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

llvm-svn: 294469
2017-02-08 16:18:10 +00:00
George Rimar 0b2cc8190d Reverted r294464 "[ELF] - Added partial support for --emit-relocs (no --gc-section case, no /DISCARD/ support) #3"
Broked build bot:
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/5835/steps/test/logs/stdio

llvm-svn: 294466
2017-02-08 16:10:14 +00:00
George Rimar d6ae624552 [ELF] - Added partial support for --emit-relocs (no --gc-section case, no /DISCARD/ support) #3
-q, --emit-relocs - Generate relocations in output

Simplest implementation: 
* no GC case, 
* no "/DISCARD/" linkerscript command support.

This patch is extracted from D28612 / D29636,

Relative to PR31579.

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

llvm-svn: 294464
2017-02-08 15:53:33 +00:00
Rui Ueyama 7ddd7a8b76 Use a utility function to reduce repetition. NFC.
llvm-svn: 294117
2017-02-05 05:18:58 +00:00
Rafael Espindola 9e9754b520 Replace MergeOutputSection with a synthetic section.
With a synthetic merge section we can have, for example, a single
.rodata section with stings, fixed sized constants and non merge
constants.

I can be simplified further by not setting Entsize, but that is
probably better done is a followup patch.

This should allow some cleanup in the linker script code now that
every output section command maps to just one output section.

llvm-svn: 294005
2017-02-03 13:06:18 +00:00
Rui Ueyama 9255b91a2b Make `-z stack-size` compatible with ld.bfd.
ld.bfd doesn't handle `-z stack-size=0` as a special case.
We shouldn't do that too.

llvm-svn: 293849
2017-02-02 01:12:45 +00:00
Rui Ueyama db00b61860 Simplify createPhdrs. NFC.
Instead of creating multiple PHDRs in a single loop, this patch
runs one for loop for each PHDR type. I think this improves code
readability.

llvm-svn: 293832
2017-02-01 22:42:17 +00:00
Petr Hosek 4d65ef3be1 [ELF] Handle multiple discontiguous .note sections
There could be multiple discontiguous output .note sections in which
case we need to put these into separate PT_NOTE segments rather then
placing them into a single segment. Where possible, we could reorder
the input sections to make sure that all .note are layed out next to
each other to avoid creation multiple PT_NOTE segments, but even in
that case, it's still possible to construct a discontiguous case e.g.
by using a linker script.

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

llvm-svn: 293811
2017-02-01 20:58:41 +00:00
Peter Smith 3a52eb0054 [ELF] Use SyntheticSections for Thunks
Thunks are now implemented by redirecting the relocation to the
symbol S, to a symbol TS in a Thunk. The Thunk will transfer control
to S. This has the following implications:
- All the side-effects of Thunks happen within createThunks()
- Thunks are no longer stored in InputSections and Symbols no longer
  need to hold a pointer to a Thunk
- The synthetic Thunk sections need to be merged into OutputSections
    
This implementation is almost a direct conversion of the existing
Thunks with the following exceptions:
- Mips LA25 Thunks are placed before the InputSection that defines
  the symbol that needs a Thunk.
- All ARM Thunks are placed at the end of the OutputSection of the
  first caller to the Thunk.
    
Range extension Thunks are not supported yet so it is optimistically
assumed that all Thunks can be reused.

This is a recommit of r293283 with a fixed comparison predicate as
std::merge requires a strict weak ordering.

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

llvm-svn: 293757
2017-02-01 10:26:03 +00:00
Peter Collingbourne 4a72c38702 ELF: Align RELRO to the target page size rather than the max page size.
If no bss sections appear after the relro segment, the loader will round
the r/w segment size to the target's page size. Align the relro size in the
same way to ensure that it does not extend past the end of the program's
own memory region.

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

llvm-svn: 293519
2017-01-30 18:20:07 +00:00
Rafael Espindola 64e5556e9f Fix -Werror build.
llvm-svn: 293390
2017-01-28 19:07:33 +00:00