Commit Graph

3720 Commits

Author SHA1 Message Date
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
Zachary Turner 3a57fbd6db [Support] Move Parallel algorithms from LLD to LLVM.
Differential Revision: https://reviews.llvm.org/D33024

llvm-svn: 302748
2017-05-11 00:03:52 +00:00
Rui Ueyama 42ec5b9728 Remove unused #include.
llvm-svn: 302719
2017-05-10 20:02:41 +00:00
Rui Ueyama 33d903d1b0 Rename parallelFor -> parallelForEachN.
So that it is clear that the function is a wrapper for for_each_n.

llvm-svn: 302718
2017-05-10 20:02:19 +00:00
Rafael Espindola d7dc225888 Use a DenseMap in LinkerScript::getCmd.
This improves many-sections.s with a linker script from 22s to 0.9s.

llvm-svn: 302708
2017-05-10 19:13:38 +00:00
Rafael Espindola fa948c724a Refactor OutputSection to OutputSectionCommand mapping.
We now always use getCmd. I will optimize it in a followup commit.

llvm-svn: 302706
2017-05-10 19:00:23 +00:00
Rui Ueyama 896cbc40ad [ELF] Improve error message for incompatible section types
Previously we were not printing out the type of the incompatible section
which made it difficult to determine what the problem was.

The error message format has been change to the following:

  error: section type mismatch for .shstrtab
  >>> <internal>:(.shstrtab): SHT_STRTAB
  >>> output section .shstrtab: Unknown

Patch by Alexander Richardson.

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

llvm-svn: 302694
2017-05-10 16:57:50 +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 c2dd0bdf17 Mark LinkerScript as final.
We used to inherit from it, but don't need it anymore.

llvm-svn: 302675
2017-05-10 14:45:15 +00:00
Rafael Espindola 3f38e818ac Remove one more use of section names.
llvm-svn: 302672
2017-05-10 14:35:20 +00:00
Rafael Espindola 2c923c2c37 Remove another use of section names. NFC.
llvm-svn: 302671
2017-05-10 14:28:31 +00:00
George Rimar 608cf67084 [ELF] - Don't segfault when assigning non-calculatable absolute symbol value.
This is PR32664.

Issue was revealed by linux kernel script which was:

SECTIONS {
 . = (0xffffffff80000000 + ALIGN(0x1000000, 0x200000));
 phys_startup_64 = ABSOLUTE(startup_64 - 0xffffffff80000000);

 .text : AT(ADDR(.text) - 0xffffffff80000000) {
.....
  *(.head.text)
Where startup_64 is in .head.text.

At the place of assignment to phys_startup_64 we can not calculate absolute value for startup_64
because .text section has no VA assigned. Two patches were prepared earlier to address this: D32173 and D32174.

And in comments for D32173 was suggested not try to support this case, but error out.

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

llvm-svn: 302668
2017-05-10 14:23:33 +00:00
George Rimar 4388b071bf [ELF] - Use LLVM_FALLTHROUGH in code.
When compiling LLD using GCC 7 it reports warnings like:
"warning: this statement may fall through [-Wimplicit-fallthrough=]"

LLVM has LLVM_FALLTHROUGH macro which can be used to avoid such warnings.
Together with D33036 this patch fixes them.

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

llvm-svn: 302666
2017-05-10 14:19:59 +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 c5b612b8b4 Don't use section names in getFiller. NFC.
This is just faster and avoids using names.

llvm-svn: 302661
2017-05-10 14:01:13 +00:00
Zachary Turner 092c767745 [Core] Make parallel algorithms match C++ Parallelism TS.
Differential Revision: https://reviews.llvm.org/D33016

llvm-svn: 302613
2017-05-10 01:16:22 +00:00
Rui Ueyama 91b95b61f8 Add memory ORIGIN and LENGTH expression support
Adds support for the ORIGIN and LENGTH linker script built in functions.

  ORIGIN(memory) Return the origin of the memory region
  LENGTH(memory) Return the length of the memory region

Redo of D29775 for refactored linker script parsing.

Patch by Robert Clarke

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

llvm-svn: 302564
2017-05-09 18:24:38 +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
George Rimar 1564122b05 [ELF] - Set DF_STATIC_TLS flag for i386 target.
This is PR32437.

DF_STATIC_TLS
If set in a shared object or executable, this flag instructs the 
dynamic linker to reject attempts to load this file dynamically. 
It indicates that the shared object or executable contains code 
using a static thread-local storage scheme. Implementations need 
not support any form of thread-local storage.

Patch checks if IE/LE relocations were used to check if code uses
static model. If so it sets the DF_STATIC_TLS flag.

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

llvm-svn: 302414
2017-05-08 10:24:38 +00:00
George Rimar d86a4e505b [ELF] - Linkerscript: support combination of linkerscript and --compress-debug-sections.
Previously it was impossible to use linkerscript with --compress-debug-sections 
because of assert failture:
Assertion failed: isFinalized(), file C:\llvm\lib\MC\StringTableBuilder.cpp, line 64

Patch fixes the issue

llvm-svn: 302413
2017-05-08 10:18:12 +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 81273c721c Remove isTlsLocalDynamicRel and isTlsInitialExecRel.
This feels a bit hackish, but I think it is still an improvement.

The way a tls address is computed in the various architectures is not
that different. For example, for local dynamic we need the base of the
tls (R_TLSLD or R_TLSLD_PC), and the offset of that particular symbol
(R_ABS).

Given the similarity, we can just use the expressions instead of
having two additional target hooks.

llvm-svn: 302279
2017-05-05 20:25:54 +00:00
Rui Ueyama 21ebb216ea Remove redundant `explicit`.
llvm-svn: 302273
2017-05-05 19:24:58 +00:00
Rafael Espindola 0f6cc65fe9 Remember OffsetInArchive in LazyObjectFile.
LazyObjectFile might turn out to be a BitcodeFile, so we need
OffsetInArchive.

llvm-svn: 302242
2017-05-05 15:17:07 +00:00
Rafael Espindola 0b1413a881 Use the archive offset with --whole-archive.
The test ELF/lto/thin-archivecollision.ll was not testing what it
wanted to test. It needs two archive members with the same name, but
different offsets.

Without this we could remove all references of OffsetInArchive and all
tests would still pass.

Fixing the test showed that the --whole-archive case was broken, which
this patch fixes.

llvm-svn: 302241
2017-05-05 15:08:06 +00:00
Rafael Espindola 80ae8ae186 Remember archive name when creating LazyObjectFile.
It is needed for creating an unique identifier for ThinLTO.

This fixes pr32931.

llvm-svn: 302235
2017-05-05 13:55:51 +00:00
George Rimar bb451903f5 [ELF] - Accept --defsym foo=value form.
Previously we accepted --defsym=foo=value only.

Reported by Sean Silva.

llvm-svn: 302227
2017-05-05 11:59:15 +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
Rafael Espindola 808f2d3c62 Reduce code duplication. NFC.
llvm-svn: 302155
2017-05-04 14:54:48 +00:00
Rafael Espindola 7c4eafa3ee Fix accounting of tbss.
We were correctly computing the size contribution of a .tbss input
section (it is none), but we were incorrectly considering the
alignment of the output section: it was advancing Dot instead of
ThreadBssOffset.

As far as I can tell this was always wrong in our linkerscript
implementation, but that became more visible now that the code is
shared with the non linker script case.

llvm-svn: 302107
2017-05-04 03:00:27 +00:00
Rui Ueyama b201a20eab Remove a comment that is no longer true.
llvm-svn: 302090
2017-05-03 23:10:33 +00:00
Rui Ueyama fd7deda57a Accept archive files with no symbol table instad of warning on them.
It seems virtually everyone who tries to do LTO build with Clang and
LLD was hit by a mistake to forget using llvm-ar command to create
archive files. I wasn't an exception. Since this is an annoying common
issue, it is probably better to handle that gracefully rather than
reporting an error and tell the user to redo build with different
configuration.

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

llvm-svn: 302083
2017-05-03 21:03:08 +00:00
Peter Collingbourne 1c697e99b6 Revert r301897, "ELF: Set symbol binding to STB_GLOBAL when undefining symbols during LTO."
It doesn't matter what binding we store in a non-UsedInRegularObj undefined
symbol because we should reset it when we see a real undefined symbol in
a combined LTO object. The fact that we weren't doing so before is a bug
(PR32899) which is now fixed.

llvm-svn: 302067
2017-05-03 19:23:30 +00:00
Rafael Espindola 5e20c75e3a Handle mixed strong and weak undefined symbols.
We were ignoring strong undefined symbols if they followed weak ones.

Fixes pr32899.

llvm-svn: 302065
2017-05-03 18:40:27 +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
Rui Ueyama 9decbfee32 Remove a dead function declaration.
llvm-svn: 301982
2017-05-02 22:42:24 +00:00
Joel Jones 93340741b8 Remove _NC suffix from ELF relocations TLSDESC_{LD64,ADD}_LO12
llvm-svn: 301979
2017-05-02 22:01:30 +00:00
Rui Ueyama c344313803 Fix typo.
llvm-svn: 301975
2017-05-02 21:16:06 +00:00
Rafael Espindola a0f30da62e Revert "Fix misnamed #include. Remove _NC suffix from ELF relocations TLSDESC_{LD64,ADD}_LO12"
This reverts commit r301964. It broke the build.

llvm-svn: 301969
2017-05-02 20:19:42 +00:00
Joel Jones f387eb62b9 Fix misnamed #include. Remove _NC suffix from ELF relocations TLSDESC_{LD64,ADD}_LO12
llvm-svn: 301964
2017-05-02 19:31:40 +00:00
Rafael Espindola a8a1a4fc30 Avoid empty .eh_frame sections.
Strip on OpenBSD does not correctly handle an empty .eh_frame section
and produces broken binaries in that case. Currently lld creates such
an empty .eh_frame section, despite the fact that the OpenBSD crtend.o
explicitly inserts a terminator. The Linux LSB "standard":

https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/ehframechpt.html#EHFRAME

explicitly says that

    The .eh_frame section shall contain 1 or more Call Frame Information (CFI) records.

This diff includes a test that specifically tests the issue I'm seeing
on OpenBSD.

Patch by Mark Kettenis!

llvm-svn: 301931
2017-05-02 15:45:31 +00:00
Peter Collingbourne 99c8fa3bef ELF: Set symbol binding to STB_GLOBAL when undefining symbols during LTO.
If there is a bug in the LTO implementation that causes it to fail to provide
an expected symbol definition, the linker should report an undefined symbol
error. Unfortunately, we were failing to do so if the symbol definition
was weak, as the undefine() function was turning the definition into a weak
undefined symbol, which resolves to zero if the symbol remains undefined. This
patch causes us to set the binding to STB_GLOBAL when we undefine a symbol.

I can't see a good way to test this. The behaviour should only be observable
if there is a bug in the LTO implementation.

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

llvm-svn: 301897
2017-05-02 05:07:41 +00:00
Rui Ueyama dfb1e2a1a1 Update commetns.
llvm-svn: 301896
2017-05-02 02:58:04 +00:00
Rui Ueyama f13a6904b3 Make getArchiveMembers function a non-member function.
It didn't have to be a member function of Driver. This patch makes
that function a file-scoped non-member function.

llvm-svn: 301895
2017-05-02 02:57:45 +00:00
Rui Ueyama 92a8d798b8 Add comments about how we handle mergeable sections with relocations.
Also factored out code.

llvm-svn: 301833
2017-05-01 20:49:09 +00:00
Rafael Espindola 4aa2ef5b0e Fix pr32816.
When using linkerscripts we were trying to sort SHF_LINK_ORDER
sections too early. Instead of always doing two runs of
assignAddresses, record the section order in processCommands.

llvm-svn: 301830
2017-05-01 20:32:39 +00:00
Rui Ueyama 3781137909 Fix comments.
llvm-svn: 301778
2017-04-30 20:58:20 +00:00