Commit Graph

8600 Commits

Author SHA1 Message Date
Peter Smith 8f7565b6f2 [ELF] Refactor ThunkCreator to not key on OutputSection for Thunks
In preparation for inserting Thunks into InputSectionDescriptions this
simple change associates added Thunks with a vector of InputSections instead
of an OutputSection. As of now we are just using OutputSection::Sections.

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

llvm-svn: 304782
2017-06-06 09:42:44 +00:00
George Rimar 1124001c68 [ELF] - Early return from writeTo() if section is SHT_NOBITS. NFCi.
That addresses port commit comments for https://reviews.llvm.org/D33646

llvm-svn: 304777
2017-06-06 07:46:28 +00:00
George Rimar 8cde9a7e77 [ELF] - Allow multiple comdats when producing relocatable output.
Previously LLD would fail for case when there are multiple comdats and -r.

That happened because it merged all ".group" (SHT_GROUP) sections into single
output, producing broken result. Such sections may have similar name, alignment and flags
and other properties. We need to produce separate output section for each such input one.

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

llvm-svn: 304769
2017-06-06 06:38:32 +00:00
Rafael Espindola a6fef0e5db Move clearOutputSections earlier.
This moves clearOutputSections and OutputSectionCommands creation as
early as possible without changing other code.

llvm-svn: 304751
2017-06-05 23:43:49 +00:00
Konstantin Zhuravlyov 4c882d90aa AMDGPU/LLD: Remove deprecated and unused elf definitions from tests
Differential Revision: https://reviews.llvm.org/D33691

llvm-svn: 304734
2017-06-05 20:57:17 +00:00
Petr Hosek 7953e62f2e [ELF] Define __dso_handle symbol if needed
Traditionally, it has been defined in crtbegin.o, which is typically
provided by libgcc or as part of the C library on some systems. However,
but there's no principled reason for it to be there. We optionaly
define this symbol, which can be used on platforms that don't provide
__dso_handle in crtbegin.o or which don't use crtbegin.o at all.

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

llvm-svn: 304732
2017-06-05 20:42:34 +00:00
Dmitry Mikulin db3b87b2c0 Symbols re-defined with -wrap and -defsym need to be excluded from inter-
procedural optimizations to prevent dropping symbols and allow the linker
to process re-directs.

PR33145: --wrap doesn't work with lto.
Differential Revision: https://reviews.llvm.org/D33621

llvm-svn: 304719
2017-06-05 16:24:25 +00:00
George Rimar 60a0ea161e [ELF] - Make LLD remove gnu-lib compression prefix (".z") after decompression when using -r
This is PR33289.

Previously LLD leaved section naming as is and that lead to wrong result,
because we decompress sections when using -r,
and hence should remove ".z" prefix.

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

llvm-svn: 304711
2017-06-05 12:49:21 +00:00
Peter Smith 43e852fb79 [ELF] SHF_LINK_ORDER should sort based on InputSectionDescriptions
This change alters the sorting for OutputSections with the SHF_LINK_ORDER
flag in OutputSection::finalize() to use the InputSectionDescription
representation and not the OutputSection::Sections representation.

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

llvm-svn: 304700
2017-06-05 08:51:15 +00:00
Rafael Espindola c7c42f6ae0 Convert another OutputSections use.
This allows moving clearOutputSections a bit earlier.

llvm-svn: 304654
2017-06-03 06:51:22 +00:00
Reid Kleckner c2eaccb0af Revert "Merge IAT and ILT."
This reverts r303374. It breaks Chrome's IAT patching code:
http://crbug.com/729077

llvm-svn: 304584
2017-06-02 18:49:38 +00:00
Reid Kleckner 146eb7a65f Re-land "COFF: migrate def parser from LLD to LLVM"
This reverts commit r304561 and re-lands r303490 & co.

The fix was to use "SymbolName" when translating LLD's internal export
list to lib/Object's short export struct. The SymbolName reflects the
actual symbol name, which may include fastcall and stdcall mangling bits
not included in the /EXPORT or .def file EXPORTS name:

@@ -434,8 +434,7 @@ std::vector<COFFShortExport> createCOFFShortExportFromConfig() {
   std::vector<COFFShortExport> Exports;
   for (Export &E1 : Config->Exports) {
     COFFShortExport E2;
-    E2.Name = E1.Name;
+    // Use SymbolName, which will have any stdcall or fastcall qualifiers.
+    E2.Name = E1.SymbolName;
     E2.ExtName = E1.ExtName;
     E2.Ordinal = E1.Ordinal;
     E2.Noname = E1.Noname;

llvm-svn: 304573
2017-06-02 17:53:06 +00:00
Reid Kleckner 5a1ed789e1 Add test case for LLD/COFF for stdcall exports in .def files
The .def file parser changes I reverted broke this test case, and
exported "__imp__foo" instead of "__imp__foo@8". This was
http://crbug.com/728726.

llvm-svn: 304572
2017-06-02 17:48:06 +00:00
Reid Kleckner d249e4a188 Revert "COFF: migrate def parser from LLD to LLVM"
This reverts commits r303490, r303491, r303493, and r303494.

This caused http://crbug.com/728726. Essentially, exporting stdcall
functions doesn't appear to work after this change. Reduced test case
soon.

llvm-svn: 304561
2017-06-02 16:26:24 +00:00
George Rimar 6a0644b24b [ELF] - Following commit for r304531 to fix BB.
Not sure why I did not faced that locally earlier, 
llvm-readobj did not have -s flag for 2/3 tests.

llvm-svn: 304539
2017-06-02 10:38:45 +00:00
George Rimar ef84219d21 [ELF] - Assign SHF_INFO_LINK flag to REL[A] sections.
Spec says: (http://www.sco.com/developers/gabi/latest/ch4.sheader.html)

sh_info
This member holds extra information, whose interpretation depends on the section type.
If the sh_flags field for this section header includes the attribute SHF_INFO_LINK, 
then this member represents a section header table index.

SHF_INFO_LINK
The sh_info field of this section header holds a section header table index.

Since sh_info for SHT_REL[A] sections should contain the section header index of the
section to which the relocation applies, this is
consistent with spec to put this flag. Behavior matches both bfd and gold as well.

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

llvm-svn: 304531
2017-06-02 09:17:45 +00:00
Rafael Espindola 0f7dc0e2d0 Run fabricateDefaultCommands before fixSectionAlignments.
This allows us to remove the PageAlign field. It will also allow
moving fabricateDefaultCommands earlier.

llvm-svn: 304513
2017-06-02 01:37:58 +00:00
Rafael Espindola bb7bd3eefe Simplify. NFC.
llvm-svn: 304511
2017-06-02 01:24:37 +00:00
Zachary Turner ebd3ae8371 [CodeView] Properly align symbol records on read/write.
Object files have symbol records not aligned to any particular
boundary (e.g. 1-byte aligned), while PDB files have symbol
records padded to 4-byte aligned boundaries.  Since they share
the same reading / writing code, we have to provide an option to
specify the alignment and propagate it up to the producer or
consumer who knows what the alignment is supposed to be for the
given container type.

Added a test for this by modifying the existing PDB -> YAML -> PDB
round-tripping code to round trip symbol records as well as types.

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

llvm-svn: 304484
2017-06-01 21:52:41 +00:00
Rafael Espindola 6888072808 Move maybeCompress to OutputSectionCommand.
This removes a call to getCmd and allows us to move
clearOutputSections earlier.

llvm-svn: 304439
2017-06-01 16:57:48 +00:00
Rafael Espindola cca62ef861 Move synchronize earlier.
This is probably the correct location for it: next to
fabricateDefaultCommands. If we don't have a linker script, we
fabricate one. If we have one, we patch it.

llvm-svn: 304436
2017-06-01 16:42:16 +00:00
Rafael Espindola 3f235c71cc Move clearOutputSections earlier.
Now it is as early as it can go: just before synchronize. We now have
to move synchronize earlier too.

llvm-svn: 304434
2017-06-01 16:32:58 +00:00
Rafael Espindola 805f5152c5 Synchronize the linker script with -r.
I don't have a testcase in mind, but there is no reason to have the
linker script out of sync during a -r link.

llvm-svn: 304433
2017-06-01 16:30:12 +00:00
Rafael Espindola faf25a7216 Convert a few more uses of OutputSections. NFC.
Also needed to move clearOutputSections earlier.

llvm-svn: 304420
2017-06-01 16:26:28 +00:00
Rafael Espindola 8a0966ea03 Convert a few user of OutputSections NFC.
This is needed to move clearOutputSections earlier.

llvm-svn: 304419
2017-06-01 16:21:33 +00:00
George Rimar d602987271 [ELF] - Properly handle R_386_GOTPC relocation.
This is PR33243. R_GOTONLY_PC_FROM_END was not in a list of link time constant
expressions and that was a result of confusiing messages like PR shows:

/usr/bin/ld.lld: error: /usr/lib/go/src/runtime/alg.go:47: 
can't create dynamic relocation R_386_GOTPC against local symbol in readonly segment defined in /tmp/nice/go-link-597453838/go.o

Though in reality we just should not have try to create a dynamic relocation for this case at all.

Patch fixes the issue.

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

llvm-svn: 304393
2017-06-01 07:53:58 +00:00
George Rimar b940f65cd2 [ELF] - Do not crash when proccessing absolute symbols during GC.
This is PR33239, previously we segfault on given testcase.

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

llvm-svn: 304392
2017-06-01 07:47:56 +00:00
Rafael Espindola 05c4f67cf3 Move name lookup to script parsing time.
We were looking up sections by name during expression evaluation. By
keeping track of forward declarations we can do the lookup during
script parsing.

Doing the lookup earlier will be more efficient when assignAddresses
is run twice and removes two uses of OutputSections.

llvm-svn: 304381
2017-06-01 01:16:50 +00:00
Rafael Espindola 47c9f84d50 Simplify. NFC.
The sections are ordered, so we can just use the first one when
looking for the lowest address.

llvm-svn: 304369
2017-05-31 22:49:50 +00:00
Rafael Espindola cccd2c604e Merge two nested ifs. NFC.
llvm-svn: 304368
2017-05-31 22:46:19 +00:00
Rafael Espindola 969c6512c2 Move clearOutputSections earlier.
Another step into merging the linker script and non linker script code
paths.

llvm-svn: 304339
2017-05-31 20:22:27 +00:00
Rafael Espindola db5e56f7b2 Store a single Parent pointer for InputSectionBase.
Before InputSectionBase had an OutputSection pointer, but that was not
always valid. For example, if it was a merge section one actually had
to look at MergeSec->OutSec.

This was brittle and caused bugs like the one fixed by r304260.

We now have a single Parent pointer that points to an OutputSection
for InputSection, but to a SyntheticSection for merge sections and
.eh_frame. This makes it impossible to accidentally access an invalid
OutSec.

llvm-svn: 304338
2017-05-31 20:17:44 +00:00
Rafael Espindola d54c566510 Simplify. NFC.
llvm-svn: 304334
2017-05-31 19:53:40 +00:00
Rafael Espindola 0dc2510762 Simplify. NFC.
llvm-svn: 304330
2017-05-31 19:26:37 +00:00
Rafael Espindola 23db636080 Simplify. NFC.
llvm-svn: 304328
2017-05-31 19:22:01 +00:00
Rafael Espindola b47c6e5cbd Fix a crash.
We would crash if a SHF_LINK_ORDER section pointed to a non
InputSection section. Since those sections are not merged in order,
SHF_LINK_ORDER is pretty meaningless and we can error on that case.

llvm-svn: 304327
2017-05-31 19:09:52 +00:00
Peter Smith ea79b215d6 [ELF] .ARM.exidx sentinel section should use InputSectionDescriptions.
This change converts the writing of the .ARM.exidx sentinel section to use
the InputSectionDescriptions instead of OutputSection::Sections this is in
preparation for the retirement of OutputSection::Sections.
    
Differential Revision: https://reviews.llvm.org/D33500

llvm-svn: 304289
2017-05-31 09:02:21 +00:00
Rafael Espindola 180de970c8 Fix crash when processing relocations in .eh_frame.
This happens when attempting to link shared libraries using exceptions on
MIPS. It requires -z notext because clang generates R_MIPS_64 relocations
inside .eh_frame.
The crash happened because for EhInputSection the OutSec member is null.

Patch by Alexander Richardson!

llvm-svn: 304260
2017-05-31 00:23:23 +00:00
Rafael Espindola e39709b20d Check Live instead of the section type.
By the time we get here all live sections should have been combined
into InputSections.

llvm-svn: 304243
2017-05-30 20:40:03 +00:00
Rafael Espindola a85e8dda54 Remove unnecessary cast.
llvm-svn: 304240
2017-05-30 20:24:52 +00:00
Peter Smith 626c997aff [ELF] Add .ARM.exidx sentinel section to an OutputSectionDescription
When there is a linker script with .ARM.exidx in the SECTIONS
command we must add the .ARM.exidx sentinel section to the
InputSectionDescriptions as well as to OutputSection::Sections.

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

llvm-svn: 304206
2017-05-30 11:51:02 +00:00
George Rimar fa71b2635c [ELF] - Fix comment. NFC.
llvm-svn: 304197
2017-05-30 07:51:25 +00:00
George Rimar d4096140e3 [ELF] - Do not crash when linkerscript applies fill to .bss.
I found that during visual inspection of code while wrote different patch.
Script in testcase probably have nothing common with real life, but
we segfault currently using it.

If output section is known NOBITS, there is no need to create
writers threads for doing nothing or proccess any filler logic that 
is useless here. We can just early return, that is what this patch do.

DIfferential revision: https://reviews.llvm.org/D33646

llvm-svn: 304192
2017-05-30 05:48:09 +00:00
Petr Hosek 08dfd53269 [ELF] Filter out non InputSection members from InputSections
InputSections may contain MergeInputSection members which trigger
a segmentation fault when trying to cast them to InputSection.

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

llvm-svn: 304189
2017-05-30 05:17:58 +00:00
Petr Hosek 3c6de1a66c [ELF] Use late evaluation for ALIGN in expression
While the following expression is handled fine:

  PROVIDE_HIDDEN(newsym = oldsym + address);

The following expression triggers an error because the expression
is evaluated as absolute:

  PROVIDE_HIDDEN(newsym = ALIGN(oldsym, CONSTANT(MAXPAGESIZE)) + address);

To avoid this error, we use late evaluation for ALIGN by making the
alignment an attribute of the expression itself.

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

llvm-svn: 304185
2017-05-30 03:18:28 +00:00
Rafael Espindola 1da971706e Replace a few more uses of OutputSections.
llvm-svn: 304182
2017-05-30 01:36:48 +00:00
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
George Rimar 3b189d1643 [ELF] - Do not allow -r to eat comdats.
This is PR33052, "Bug 33052 - -r eats comdats ".

To fix it I stop removing group section from out when -r is given
and fixing SHT_GROUP content when writing it just like we do some
other fixup, e.g. for Rel[a]. (it needs fix for section indices that
are in group).

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

llvm-svn: 304140
2017-05-29 08:37:50 +00:00
Petr Hosek ffa786f465 [lld][ELF]Add option to make .dynamic read only
The .dynamic section of an ELF almost doesn't need to be written to with
the exception of the DT_DEBUG entry. For several reasons having a read
only .dynamic section would be useful. This change adds the -z keyword
"rodynamic" which forces .dynamic to be read-only. In this case DT_DEBUG
will not be emited.

Patch by Jake Ehrlich

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

llvm-svn: 304024
2017-05-26 19:12:38 +00:00
George Rimar 1ef2e237bf [ELF] - Attemp to fix bot
http://lab.llvm.org:8011/builders/lld-x86_64-darwin13/builds/8549/steps/build_Lld/logs/stdio

llvm-svn: 304016
2017-05-26 18:07:25 +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
George Rimar 8684dbaa14 [ELF] - Follow up for r303975. NFCi.
Restore bitwise-or order and fix warning
(was changed by mistake during resolve of conflicts).

llvm-svn: 303976
2017-05-26 12:16:39 +00:00
George Rimar c1a0364cd6 [ELF] - Do not produce duplicate values in .gdb_index's constant pool area.
I found this when builded llc binary using gcc 5.4.1 + LLD.
gcc produces duplicate entries in .debug_gnu_pubtypes section, ex:

UnifyFunctionExitNodes.cpp.o has:
0x0000ac07 EXTERNAL TYPE "std::success_type<void*>"
0x0000ac07 EXTERNAL TYPE "std::success_type<void*>"

clang produces single entry here:
0x0000d291 EXTERNAL TYPE "std::__success_type<void *>"

If we link output from gcc with LLD, that would produce excessive duplicate
entries in .gdb_index constant pool area. That does not seem affect gdb work,
but makes .gdb_index larger than it can be.

I also checked that gold filters out such duplicates too. Patch fixes it.

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

llvm-svn: 303975
2017-05-26 12:09:26 +00:00
George Rimar 5f5905eea8 [ELF] - Simplify implementation of constant pool when building .gdb_index
https://sourceware.org/gdb/onlinedocs/gdb/Index-Section-Format.html says:
"A CU vector in the constant pool is a sequence of offset_type values. 
The first value is the number of CU indices in the vector. 
Each subsequent value is the index and symbol attributes of a CU in the CU list."

Previously we keeped 2 values until the end, what was useless. 
Initially was a part of D32647, though it is possible to split out. 
Patch do that.

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

llvm-svn: 303973
2017-05-26 12:01:40 +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 240b9515e2 Simplify. NFC.
llvm-svn: 303959
2017-05-26 02:17:30 +00:00
Rui Ueyama 9e6f268054 Inline a trivial constructor.
llvm-svn: 303958
2017-05-26 02:17:13 +00:00
Rafael Espindola f307d3ea4d Remove dummy cast. NFC.
llvm-svn: 303948
2017-05-26 00:37:39 +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 1c2baad6dd Revert "Simplify a variable type by using StringRef instead of CachedHashStringRef."
This reverts commit r303787.

It caused a slowdown in fast links. That is, links with no debug info
or optimizations.

llvm-svn: 303925
2017-05-25 21:53:02 +00:00
Zachary Turner 2897e0306e [lld] Fix a bug where we continually re-follow type servers.
Originally this was intended to be set up so that when linking
a PDB which refers to a type server, it would only visit the
PDB once, and on subsequent visitations it would just skip it
since all the records had already been added.

Due to some C++ scoping issues, this was not occurring and it
was revisiting the type server every time, which caused every
record to end up being thrown away on all subsequent visitations.

This doesn't affect the performance of linking clang-cl generated
object files because we don't use type servers, but when linking
object files and libraries generated with /Zi via MSVC, this means
only 1 object file has to be linked instead of N object files, so
the speedup is quite large.

llvm-svn: 303920
2017-05-25 21:16:03 +00:00
Rui Ueyama 5012858e26 Accept not only --reproduce <foo> but also --reproduce=<foo>.
llvm-svn: 303905
2017-05-25 19:49:54 +00:00
Rui Ueyama 236e781011 Use MD5::hash(). NFC.
llvm-svn: 303893
2017-05-25 18:17:43 +00:00
Rui Ueyama 69ae29b1d1 Do not allow delay-importing data symbols.
If you pass /delayload:<dllname> to the COFF linker, it creates thunks
so that DLLs are loaded when they are used for the first time instead of
load-time.

This mechanism do not work for data symbols as there's no way to trap
acccesses to data imported from DLLs. (Technically, I think if we do not
initially map dllimport tables in memory, we could actually trap accesses
and delay-load data symbols, but that's not what Windows do.)

This patch is to report an error when you try to delay-load data symbols.

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

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

llvm-svn: 303890
2017-05-25 18:03:34 +00:00
Rui Ueyama 0e8521c05a Reduce indentation. NFC.
llvm-svn: 303815
2017-05-24 22:36:11 +00:00
Rui Ueyama 9aa82f76ac Garbage collect dllimported symbols.
This is a different implementation than r303225 (which was reverted
in r303270, re-submitted in r303304 and then re-reverted in r303527).

In the previous patch, I tried to add Live bit to each dllimported
symbol. It turned out that it didn't work with "oldnames.lib" which
contains a lot of weak aliases to dllimported symbols.

The way we handle weak aliases is to check if undefined symbols
can be resolved using weak aliases, and if so, memcpy the Defined
symbols to weak Undefined symbols, so that any references to weak
aliases automatically see defined symbols instead of undefined ones.

This memcpy happens before MarkLive kicks in.

That means we may have multiple copies of dllimported symbols. So
turning on one instance's Live bit is not enough.

This patch moves the Live bit to dllimport file. Since multiple
copies of dllsymbols still point to the same file, we can use it as the
central repository to keep track of liveness.

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

llvm-svn: 303814
2017-05-24 22:30:06 +00:00
Rafael Espindola a28414d7ec Simplify MipsRldMapSection::writeTo.
It is not clear why a synthetic section wants to use padding defined
in the linker script. The padding is for the space between sections.

It was also missing a test.

llvm-svn: 303812
2017-05-24 22:04:32 +00:00
Rui Ueyama 96cbf8bca6 Fix the sanitizer-windows bot.
Looks like r303801 broke the sanitizer-windows bot. I don't fully
understand what is going on, so I'll partially revert that patch.

llvm-svn: 303805
2017-05-24 20:32:23 +00:00
Rui Ueyama 27abe98cfa Close the gap between ELF and COFF ICF implementations. NFC.
We originally wrote the ICF code for COFF and ported it to ELF.
They started diverging since then. This patch closes the gap.

llvm-svn: 303801
2017-05-24 19:56:29 +00:00
Rui Ueyama f04c04837c Improve parallelism of ICF.
This is the only place we use threads for ICF. The intention of this code
was to split an input vector into 256 shards and process them in parallel.
What the code was actually doing was to split an input into 257 shards,
process the first 256 shards in parallel, and the remaining one in serial.

That means this code takes ceil(256/n)+1 instead of ceil(256/n) where n
is the number of available CPU cores. The former converges to 2 while
the latter converges to 1.

This patches fixes the above issue.

llvm-svn: 303797
2017-05-24 19:22:34 +00:00
Kamil Rytarowski e739e49c0f Replace std::call_once with llvm:call_once
Summary:
This is required on some platforms, as GNU libstdc++ std::call_once is known to be buggy.

This fixes operation of LLD on at least NetBSD and perhaps OpenBSD and Linux PowerPC.

The same change has been introduced to LLVM and LLDB.

Reviewers: ruiu

Reviewed By: ruiu

Subscribers: emaste, #lld

Tags: #lld

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

llvm-svn: 303788
2017-05-24 18:31:48 +00:00
Rui Ueyama 466c82b74f Simplify a variable type by using StringRef instead of CachedHashStringRef.
A variable `ComdatGroup` is not supposed to contain a large number of
items. Even when linking clang, it ends up having only 300K strings.
It doesn't make sense to use CachedHashStringRef for this hash table.
This patch has neutral or slightly positive impact on performance while
reducing code complexity.

llvm-svn: 303787
2017-05-24 18:22:27 +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
Rui Ueyama 8df7fa782e Rewrite badly-formatted switch. NFC.
llvm-svn: 303777
2017-05-24 17:12:53 +00:00
Rui Ueyama 216d6834ba Make key-value types explicit. NFC.
llvm-svn: 303776
2017-05-24 17:12:32 +00:00
Rui Ueyama d6489635f4 Change the control flow so that the function is a bit more readable. NFC.
llvm-svn: 303775
2017-05-24 17:12:10 +00:00
Dmitry Mikulin fd0c844fbb Do not track section types of previous sections, always use PROGBITS for dummy sections.
Fix for PR33029.

llvm-svn: 303770
2017-05-24 16:48:31 +00:00
Zachary Turner bb64231d2d Don't do a full scan of the type stream before processing records.
LazyRandomTypeCollection is designed for random access, and in
order to provide this it lazily indexes ranges of types.  In the
case of types from an object file, there is no partial index
to build off of, so it has to index the full stream up front.
However, merging types only requires sequential access, and when
that is needed, this extra work is simply wasted.  Changing the
algorithm to work on sequential arrays of types rather than
random access type collections eliminates this up front scan.

llvm-svn: 303707
2017-05-24 00:26:27 +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 6a1aa8d9b4 Use more strict types. NFC.
By the time we get to linker scripts, all special InputSectionBase
should have been combined into synthetic sections, which are a type of
InputSection. The net result is that we can use InputSection in a few
places that were using InputSectionBase.

llvm-svn: 303702
2017-05-23 22:47:31 +00:00
Peter Collingbourne 968fe93803 ELF: The later of --build-id and --build-id= wins.
If the compiler driver passes --build-id and the user uses -Wl to
pass --build-id= then the user's flag should take precedence.

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

llvm-svn: 303689
2017-05-23 21:16:48 +00:00
Evgeniy Stepanov f12ac5b776 [lld] Infer relocation model from module flags in relocatable LTO link.
Fix for PR33096.

llvm-svn: 303579
2017-05-22 21:11:44 +00:00
Zachary Turner d4136e945e Implement various flavors of type merging.
Previous algotirhm assumed that types and ids are in a single
unified stream.  For inputs that come from object files, this
is the case.  But if the input is already a PDB, or is the result
of a previous merge, then the types and ids will already have
been split up, in which case we need an algorithm that can
accept operate on independent streams of types and ids that
refer across stream boundaries to each other.

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

llvm-svn: 303577
2017-05-22 21:07:43 +00:00
Rui Ueyama b6632d9cd1 Revert r303304: Re-submit r303225: Garbage collect dllimported symbols.
This reverts commit r303304 because it looks like the change
introduced a crash bug. At least after that change, LLD with thinlto
crashes when linking Chromium.

llvm-svn: 303527
2017-05-22 06:01:37 +00:00
Martell Malone 1e39e5e964 COFF: migrate def parser from LLD to LLVM [2/2]
This is split up into two commits.
This commit removes the DEF parser from LLD
See the previous commit for the creation in LLVM.

Reviewers: ruiu

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

llvm-svn: 303491
2017-05-20 19:56:44 +00:00
Zachary Turner 526f4f2aa8 Resubmit "[CodeView] Provide a common interface for type collections."
This was originally reverted because it was a breaking a bunch
of bots and the breakage was not surfacing on Windows.  After much
head-scratching this was ultimately traced back to a bug in the
lit test runner related to its pipe handling.  Now that the bug
in lit is fixed, Windows correctly reports these test failures,
and as such I have finally (hopefully) fixed all of them in this
patch.

llvm-svn: 303446
2017-05-19 19:26:58 +00:00
Zachary Turner 1dfcf8d92c Revert "[CodeView] Provide a common interface for type collections."
This is a squash of ~5 reverts of, well, pretty much everything
I did today.  Something is seriously broken with lit on Windows
right now, and as a result assertions that fire in tests are
triggering failures.  I've been breaking non-Windows bots all
day which has seriously confused me because all my tests have
been passing, and after running lit with -a to view the output
even on successful runs, I find out that the tool is crashing
and yet lit is still reporting it as a success!

At this point I don't even know where to start, so rather than
leave the tree broken for who knows how long, I will get this
back to green, and then once lit is fixed on Windows, hopefully
hopefully fix the remaining set of problems for real.

llvm-svn: 303409
2017-05-19 05:57:45 +00:00
Zachary Turner b32ec02b80 [CodeView] Raise the source to ID map out of the TypeStreamMerger.
This map will be needed to rewrite symbol streams after re-writing
the corresponding type streams.

llvm-svn: 303390
2017-05-18 23:04:08 +00:00
Zachary Turner 0c60f269fc [CodeView] Provide a common interface for type collections.
Right now we have multiple notions of things that represent collections of
types. Most commonly used are TypeDatabase, which is supposed to keep
mappings from TypeIndex to type name when reading a type stream, which
happens when reading PDBs. And also TypeTableBuilder, which is used to
build up a collection of types dynamically which we will later serialize
(i.e. when writing PDBs).

But often you just want to do some operation on a collection of types, and
you may want to do the same operation on any kind of collection. For
example, you might want to merge two TypeTableBuilders or you might want
to merge two type streams that you loaded from various files.

This dichotomy between reading and writing is responsible for a lot of the
existing code duplication and overlapping responsibilities in the existing
CodeView library classes. For example, after building up a
TypeTableBuilder with a bunch of type records, if we want to dump it we
have to re-invent a bunch of extra glue because our dumper takes a
TypeDatabase or a CVTypeArray, which are both incompatible with
TypeTableBuilder.

This patch introduces an abstract base class called TypeCollection which
is shared between the various type collection like things. Wherever we
previously stored a TypeDatabase& in some common class, we now store a
TypeCollection&.

The advantage of this is that all the details of how the collection are
implemented, such as lazy deserialization of partial type streams, is
completely transparent and you can just treat any collection of types the
same regardless of where it came from.

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

llvm-svn: 303388
2017-05-18 23:03: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
Rui Ueyama a674943211 Set IMAGE_DLL_CHARACTERISTICS_NO_BIND.
Our output is not compatible with the Binding feature, so make it
explicit that.

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

llvm-svn: 303378
2017-05-18 20:26:58 +00:00
Rui Ueyama 9fbfd76fe3 Merge IAT and ILT.
Previously, LLD-produced executables had IAT (Import Address Table) and
ILT (Import Lookup Table) as separate chunks of data, although their
contents are identical. My interpretation of the COFF spec when I wrote
the COFF linker is that they need to be separate tables even though they
are the same.

But Peter found that the Windows loader is fine with executables in
which IAT and ILT are merged. This is a patch to merge IAT and ILT.
I confirmed that an lld-link self-hosted with this patch works fine.

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

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

llvm-svn: 303374
2017-05-18 19:59:22 +00:00
Peter Collingbourne 03638d091a COFF: Replace DLLNames maps with vectors.
The import lists are already binned by DLL name, so there's no need to
deduplicate here.

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

llvm-svn: 303371
2017-05-18 18:53:39 +00:00
Rafael Espindola 1b41409079 Use a forward declaration. NFC.
llvm-svn: 303363
2017-05-18 17:26:00 +00:00
Rui Ueyama 01f93335a0 Use make<> everywhere in COFF to make it consistent with ELF.
We've been using make<> to allocate new objects in ELF. We have
the same function in COFF, but we didn't use it widely due to
negligence. This patch uses the function in COFF to close the gap
between ELF and COFF.

llvm-svn: 303357
2017-05-18 17:03:49 +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