Commit Graph

944 Commits

Author SHA1 Message Date
Jack Andersen 7078f833ae Merge with latest master 2017-01-27 09:28:48 -10:00
Jack Andersen 2fa85b9bd4 Merge branch 'master' into small-data 2017-01-27 08:22:12 -10:00
Peter Smith 1a0ca791ab [ELF][ARM] 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.

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



git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@293283 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-27 13:10:16 +00:00
Eugene Leviant 2b9698d609 [ELF] Bypass section type check
Differential revision: https://reviews.llvm.org/D28761


git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@293276 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-27 11:01:43 +00:00
Rafael Espindola 366d3b63de Change the --retain-symbols-file implementation.
It now uses the same infrastructure as symbol versions. This fixes us
creating a dynamic relocation without a corresponding dynamic symbol.

This also means that unlike gold and bfd we keep a STB_LOCAL in the
static symbol table. It seems an odd feature to offer precise control
over what is in a symbol table that is not used by the dynamic
linker. We can bring this back if needed, but it would probably be
better to just have --discard option that tells the linker to keep in
the static symbol table only what is in the dynamic one.

Should fix the eog build.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@293093 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-25 21:23:06 +00:00
Peter Smith 84c9934af6 [ELF] Add local mapping symbols to ARM PLT entries
Mapping symbols allow a mapping symbol aware disassembler to
correctly disassemble the PLT when the code immediately prior to the
PLT is Thumb.

To implement this we add a function to add symbols with local
binding to be defined in SyntheticSymbols.

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



git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@293044 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-25 10:31:16 +00:00
George Rimar af811a7e32 [ELF] - Stop handling local symbols in a special way.
Previously we stored kept locals in a KeptLocalSyms arrays,
belonged to files.

Patch makes SymbolTableSection to store locals in Symbols member,
that already present and was used for globals.
SymbolTableSection already had NumLocals counter member, so change
itself is trivial.

That allows to simplify handling of -r,
Body::DynsymIndex is no more used as "symbol table index" for relocatable
output.

Change was suggested during review of D28773 and opens road for D28612.

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

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@292789 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-23 14:07:23 +00:00
Rafael Espindola 4cdd9dc779 Don't create a bogus PT_PHDR if we don't allocate the headers.
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@292644 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-20 20:46:15 +00:00
Rafael Espindola a0862ed9ec Reduce code duplication when allocating program headers.
This will simplify a bug fix.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@292642 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-20 20:41:18 +00:00
Rafael Espindola d5464274f6 Simplify. NFC.
addIgnored already creates the symbol only if there is a reference to
it.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@292628 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-20 18:20:37 +00:00
Rafael Espindola 5e2c3f06cc Also define 'end' if it is present in a .so.
I don't know of anything using it, but we should handle it like _end.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@292513 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-19 19:51:02 +00:00
Peter Smith c2fa8bee30 [ELF] Move createThunks() after scanRelocations()
A necessary first step towards range extension thunks is to delay
the creation of thunks until the layout of InputSections within
OutputSections has been done.
    
The change scans the relocations directly from InputSections rather
than looking in the ELF File the InputSection came from. This will
allow a future change to redirect the relocations to symbols defined
by Thunks rather than indirect when resolving relocations.
    
A side-effect of moving ThunkCreation is that the OutSecOff of
InputSections may change in an OutputSection that contains Thunks.
In well behaved programs thunks are not in OutputSections with
dynamic relocations.
    
Differential Revision: https://reviews.llvm.org/D28811



git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@292359 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-18 09:57:14 +00:00
Rui Ueyama e138eb29ab Return early if writeMapFile failed.
This patch adds a test for an invalid output path for -Map option,
though that test is not for verifying that we are using error()
instead of fatal() in writeMapFile.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@292336 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-18 03:34:38 +00:00
Rafael Espindola 3e23324851 Add a isInCurrentDSO helper. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@292228 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-17 16:08:06 +00:00
George Rimar 9dbdc45742 [ELF] - Do not create huge garbage files on section offset overflow.
Patch changes behavior to not try open the output 
file if we already know about error.

That is not just cleaner, but also fixes nasty behavior of linker that
could create huge temporarily files under certain conditions.

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

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@292219 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-17 13:50:34 +00:00
Simon Atanasyan 638ebb7b84 [ELF][MIPS] Exclude mips .got from PT_GNU_RELRO segment
On MIPS .got section cannot be included into the PT_GNU_RELRO segment.
Sometimes it might work, but in general it is unsupported. One of the
problem is that all sections marked by SHF_MIPS_GPREL should be grouped
together because data in these sections is addressable with a gp
relative address, but such sections might be writable.

This patch exclude mips .got from PT_GNU_RELRO segment and group
SHF_MIPS_GPREL sections.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@292161 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-16 21:17:23 +00:00
Rafael Espindola eea64b3d65 Implement -Map.
The format is not exactly the same as the one in bfd since bfd always
follows a linker script and prints it along.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@291958 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-13 21:05:46 +00:00
George Rimar 7f81d50d4c [ELF] - Move the addition of synthetics from addPredefinedSections()
These were 3 last synthetics that were added in addPredefinedSections() instead
of createSyntheticSections(). Now it is possible to move addition to correct common place.

Also patch fixes testcase which discards .shstrtab, by restricting doing that.

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

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@291908 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-13 16:18:15 +00:00
Rui Ueyama cc622a7000 Remove error(error_code, const Twine &).
Now we have the consistent interface for all log/warn/error/fatal functions.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@291847 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-12 22:18:04 +00:00
Peter Collingbourne db71377734 ELF: Reserve space for copy relocations of read-only symbols in relro.
When reserving copy relocation space for a shared symbol, scan the DSO's
program headers to see if the symbol is in a read-only segment. If so,
reserve space for that symbol in a new synthetic section named .bss.rel.ro
which will be covered by the relro program header.

This fixes the security issue disclosed on the binutils mailing list at:
https://sourceware.org/ml/libc-alpha/2016-12/msg00914.html

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

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@291524 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-10 01:21:50 +00:00
Peter Collingbourne 3824cad093 ELF: Place relro sections after non-relro sections in r/w segment.
This is in preparation for my next change, which will introduce a relro
nobits section. That requires that relro sections appear at the end of the
progbits part of the r/w segment so that the relro nobits section can appear
contiguously.

Because of the amount of churn required in the test suite, I'm making this
change separately.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@291523 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-10 01:21:30 +00:00
Rui Ueyama 394f978875 Support non-regular output files.
This patch enables something like "-o /dev/null".
Previouly, it failed because such files cannot be renamed.

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

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@291496 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-09 23:07:05 +00:00
Peter Collingbourne 3bab351cab ELF: Round p_memsz of the PT_GNU_RELRO program header up to the page size.
The glibc dynamic loader rounds the size down, so without this the loader
will fail to change the memory protection for the last page.

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

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@290986 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-04 18:56:15 +00:00
Peter Collingbourne 6f02c25d44 ELF: Simplify; addOptionalSynthetic() does not need to return a value. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@290932 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-04 02:43:01 +00:00
George Rimar d0d0b886e3 [ELF] - Fix mistype in comment. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@290510 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-25 06:49:17 +00:00