Commit Graph

10392 Commits

Author SHA1 Message Date
Rui Ueyama 22c8f33a9b [WebAssembly] Return a StringRef instead of std::string from getSectionName(). NFC.
Differential Revision: https://reviews.llvm.org/D43854

llvm-svn: 326337
2018-02-28 17:33:04 +00:00
Rui Ueyama ba16baccf1 [WebAssembly] Improve WasmSignatureDenseMapInfo.
Let X and Y be types. Previously, functions F(X, Y) and G(Y, X) had
the same hash value because their hash values are computed as follows:

  hash(F) = hash(X) + hash(Y)
  hash(G) = hash(Y) + hash(X)

This patch fixes the issue by using hash_combine.

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

llvm-svn: 326336
2018-02-28 17:32:50 +00:00
Nicholas Wilson 280f872bb2 [WebAssembly] Reorder symbol table to match MC order
Update LLD test expectations for new symbol ordering introduced by
Differential D43685.

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

llvm-svn: 326335
2018-02-28 17:20:51 +00:00
Igor Kudrin c844524e46 [ELF] Process linker scripts deeper when declaring symbols.
We should process symbols inside output section declarations the same way as top-level ones.

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

llvm-svn: 326305
2018-02-28 05:55:56 +00:00
Rui Ueyama 26a84fc84f [WebAssembly] Fix variable name.
llvm-svn: 326301
2018-02-28 03:43:38 +00:00
Rui Ueyama 67769100ce [WebAssembly] Remove unnecessary namespace specifiers. NFC.
llvm-svn: 326300
2018-02-28 03:38:14 +00:00
Rui Ueyama 0a9583ce79 [WebAssembly] Simplify initializeSymbols and merge it with ObjFile::parse. NFC.
This patch simplifies initializeSymbols. Since that function is called
at the tail context of ObjFile::parse, and the function is called only
once from that function, that's effectively just a continuation of
ObjFile::parse. So this patch merge it with ObjFile::parse.

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

llvm-svn: 326296
2018-02-28 02:57:37 +00:00
Sam Clegg 42cf40b4c5 [WebAssembly] Add test for `--undefined` flag. NFC.
Specifically the case where the undefined symbol is not found
during the link.

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

llvm-svn: 326294
2018-02-28 01:42:16 +00:00
Rui Ueyama 5420dd098b [WebAssembly] Simplify Symbol::getWasmType. NFC.
Differential Revision: https://reviews.llvm.org/D43717

llvm-svn: 326293
2018-02-28 01:10:50 +00:00
Rui Ueyama b911f12211 [WebAssembly] Inline translateVA as it's trivial.
The problem I want to address now is that chunks have too many data
members for "offsets", and their origins are not well defined.
For example, InputSegment has OutputSegmentOffset, but it's base class
also has OutputOffset. That's very confusing.

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

llvm-svn: 326291
2018-02-28 01:01:34 +00:00
Rui Ueyama 4764b5748a [WebAssembly] Remove ELF-ness.
These output section names are ELF-specific. We shouldn't have this rule
for WebAssembly.

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

llvm-svn: 326289
2018-02-28 00:57:28 +00:00
Fangrui Song 2074eab509 [ELF] Rename test/ELF/note-loadaddr.c to .s NFC
llvm-svn: 326287
2018-02-28 00:53:51 +00:00
Rui Ueyama 4a1b2bbc88 [WebAssembly] Do not use inheritance to define SubSection.
SubSection inherited from SyntheticSection, and SyntheticSection inherits
from OutputSection, so SubSection was an OutputSection. But that's wrong
because SubSection is not actually a WebAssembly output section.
It shares some functionalities with OutputSection, but overall it's very
different.

This patch removes that inheritance.

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

llvm-svn: 326286
2018-02-28 00:52:42 +00:00
Rui Ueyama 4b56adce20 [WebAssembly] Refactor ObjFile::initializeSymbols.
The main purpose of this change is to make initializeSymbols shorter.

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

llvm-svn: 326285
2018-02-28 00:50:54 +00:00
Rui Ueyama 19eedbf013 [WebAssembly] Do not use Subsection as a local variable name.
That variable hides the class of the same name.

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

llvm-svn: 326283
2018-02-28 00:39:30 +00:00
Rui Ueyama c61b834f31 [WebAssembly] Do not use default arguments for SymbolTable.
Differential Revision: https://reviews.llvm.org/D43727

llvm-svn: 326282
2018-02-28 00:37:03 +00:00
Rui Ueyama caa8e2335f [WebAssembly] Do not remove existing output file.
FileOutputBuffer automatically removes an existing file, so we don't
need to do that. Actually doing that is discouraged because when the
linker fails to create an output for some reason after instantiating
FileOutputBufffer, FileOutputBuffer removes a temporary file and don't
touch an existing file. That's an desired behavior from the user's
point of view.

(Internally, FileOutputBuffer writes its contents to a temporary file
and then rename it over to an existing file on commit()).

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

llvm-svn: 326281
2018-02-28 00:33:59 +00:00
Rui Ueyama 319eb8b3c3 [WebAssembly] Remove redundant local variables.
Differential Revision: https://reviews.llvm.org/D43709

llvm-svn: 326280
2018-02-28 00:31:16 +00:00
Rui Ueyama 8bfa2a629d [WebAssembly] Simplify createLikingSection.
Summary: [WebAssembly] Simplify createLikingSection.

Reviewers: sbc100

Subscribers: jfb, dschuff, jgravelle-google, aheejin, sunfish, llvm-commits

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

llvm-svn: 326279
2018-02-28 00:28:07 +00:00
Rui Ueyama d1063bb9f9 [WebAssembly] Inline accessor functions that are called only once.
Looks like these accessor functions are a bit overly defensive, and
due to the amount of code, that part isn't easy to read. We have
code to log translation results in writeTo and writeRelocations, so
I don't think we need to log it again in these functions.
I think the new function is much easier to understand.

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

llvm-svn: 326277
2018-02-28 00:26:26 +00:00
Rui Ueyama 28f3b20db5 [WebAssembly] Remove trivial accessors.
{set,get}OutputSegment don't hide anything, so remove them.

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

llvm-svn: 326276
2018-02-28 00:20:29 +00:00
Rui Ueyama 7d696880fb [WebAssembly] Use more specific type and simplify code.
Instead of {Function,Global,Data}Symbol, use Defined{Function,Global,Data}
because undefined symbol should never reach this function.

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

llvm-svn: 326275
2018-02-28 00:18:34 +00:00
Rui Ueyama 4145d252c2 [WebAssembly] Remove LastDefinedKind for consistency with undefined kinds. NFC.
Differential Revision: https://reviews.llvm.org/D43711

llvm-svn: 326274
2018-02-28 00:16:11 +00:00
Rui Ueyama da69b711c9 [WebAssembly] Remove premature optimization.
I think calling reserve() for each object file is too many and isn't useful.
We can add reserve() later. By default, we shouldn't add reserve() to a lot
of places.

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

llvm-svn: 326273
2018-02-28 00:15:59 +00:00
Rui Ueyama e3498ec562 [WebAssembly] Separate addUndefined into addUndefined{Function,Data,Global}.
Previously, one function adds all types of undefined symbols. That
doesn't fit to the wasm's undefined symbol semantics well because
different types of undefined symbols are very different in wasm.
As a result, separate control flows merge in this addUndefined function
and then separate again for each type. That wasn't easy to read.

This patch separates the function into three functions. Now it is pretty
clear what we are doing for each undefined symbol type.

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

llvm-svn: 326271
2018-02-28 00:09:22 +00:00
Rui Ueyama 37254065dd [WebAssembly] Use StringRef instead of `const char *`.
Differential Revision: https://reviews.llvm.org/D43721

llvm-svn: 326269
2018-02-28 00:01:31 +00:00
Sam Clegg 99eb42c0c5 [WebAssembly] Remove DataSize from linking metadata
This means we don't need to write the linking metadata section
at all for executable (non-relocatable) output.

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

llvm-svn: 326268
2018-02-27 23:58:03 +00:00
Alexander Richardson 8edd70b7c6 [ELF] Add llvm-readelf to the lit tool substitutions
Summary:
Some of the tests invoke llvm-readelf. This currently appears to work
probably because the LLVM binary directory is included in $PATH. However,
this is quite fragile so let's just make lit expand the full path.

Reviewers: ruiu, espindola

Reviewed By: ruiu

Subscribers: llvm-commits

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

llvm-svn: 326257
2018-02-27 22:01:02 +00:00
Rui Ueyama f0884e474c Add `--dynamic-linker=foo` as an alias for `--dynamic-linker foo`.
This patch fixes a minor compatibility issue with ld.gold and ld.bfd.

llvm-svn: 326243
2018-02-27 20:37:18 +00:00
Rafael Espindola 3f4c673d38 Put undefined symbols from shared libraries in the symbol table.
With the recent fixes these symbols have more in common than not with
regular undefined symbols.

llvm-svn: 326242
2018-02-27 20:31:22 +00:00
Rafael Espindola 893c13e58e Add missing REQUIRES.
llvm-svn: 326210
2018-02-27 17:13:23 +00:00
Rafael Espindola b851121130 Fix gcc warning.
Should fix the build in some bots.

llvm-svn: 326209
2018-02-27 17:11:10 +00:00
Rafael Espindola 3bfa8f0120 Add support for SHF_ARM_PURECODE.
Now we don't mark a PT_LOAD as readable if all its sections are
SHF_ARM_PURECODE.

llvm-svn: 326207
2018-02-27 16:55:25 +00:00
George Rimar 46045364b2 [ELF] - Format, fix mistype. NFC.
llvm-svn: 326198
2018-02-27 14:06:47 +00:00
George Rimar a77b963c90 [ELF] - Fix case of using both --icf and --symbol-ordering-file together.
Imagine that we have sections A, B, C, where A == C and
symbol ordering file containing symbols: symC, symB, symA

Previously because of ICF it was possible that final order would be
B, A or B, C. That violates order specified in ordering file.
Patch changes that.

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

llvm-svn: 326179
2018-02-27 08:26:38 +00:00
Igor Kudrin 3345c9ac18 [ELF] Create and export symbols provided by a linker script if they referenced by DSOs.
It should be possible to resolve undefined symbols in dynamic libraries
using symbols defined in a linker script.

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

llvm-svn: 326176
2018-02-27 07:18:07 +00:00
Martin Storsjo 41ffd96445 [MinGW] Ignore the --start-group --end-group parameters
These are required for handling circular dependencies between
static libraries, which is something that lld-link always does without
any extra parameters.

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

llvm-svn: 326172
2018-02-27 06:26:35 +00:00
Rafael Espindola 79c23eec04 Keep flags from phantom synthetic sections.
This fixes pr36475.

I think this code can be simplified a bit, but I would like to check
in the more direct fix if we are in agreement on the direction and
then refactor.

This is not something that bfd does. The issue is not noticed in bfd
because it keeps fewer sections from the linkerscript in the output.

The reasons why it seems reasonable to do this:

- As George noticed, we would still keep the flags if the output
  section had both an empty synthetic section and a regular section
- We need an heuristic to find the flags of output sections. Using the
  flags of a synthetic section that would have been there seems a
  reasonable heuristic.

llvm-svn: 326137
2018-02-26 22:32:15 +00:00
Jonas Devlieghere 560ce2c70f Re-land: "[Support] Replace HashString with djbHash."
This patch removes the HashString function from StringExtraces and
replaces its uses with calls to djbHash from DJB.h.

This change is *almost* NFC. While the algorithm is identical, the
djbHash implementation in StringExtras used 0 as its default seed while
the implementation in DJB uses 5381. The latter has been shown to result
in less collisions and improved avalanching and is used by the DWARF
accelerator tables.

Because some test were implicitly relying on the hash order, I've
reverted to using zero as a seed for the following two files:

  lld/include/lld/Core/SymbolTable.h
  llvm/lib/Support/StringMap.cpp

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

llvm-svn: 326091
2018-02-26 15:16:42 +00:00
George Rimar 0c97f4eba4 [ELF] - Fix variable name and mistype in comment. NFC.
llvm-svn: 326090
2018-02-26 15:16:03 +00:00
Jonas Devlieghere 370bf3ef49 Revert "[Support] Replace HashString with djbHash."
It looks like some of our tests depend on the ordering of hashed values.
I'm reverting my changes while I try to reproduce and fix this locally.

Failing builds:

  lab.llvm.org:8011/builders/lld-x86_64-darwin13/builds/18388
  lab.llvm.org:8011/builders/clang-cmake-x86_64-sde-avx512-linux/builds/6743
  lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/15607

llvm-svn: 326082
2018-02-26 12:05:18 +00:00
Jonas Devlieghere b9ad175935 [Support] Replace HashString with djbHash.
This removes the HashString function from StringExtraces and replaces
its uses with calls to djbHash from DJB.h

This is *almost* NFC. While the algorithm is identical, the djbHash
implementation in StringExtras used 0 as its seed while the
implementation in DJB uses 5381. The latter has been shown to result in
less collisions and improved avalanching.

https://reviews.llvm.org/D43615
(cherry picked from commit 77f7f965bc9499a9ae768a296ca5a1f7347d1d2c)

llvm-svn: 326081
2018-02-26 11:30:13 +00:00
Rui Ueyama afb87d8336 [WebAssembly] Remove dead code.
llvm-svn: 326018
2018-02-24 02:43:31 +00:00
Rui Ueyama 1973cc5358 [WebAssembly] Remove dead code.
llvm-svn: 326017
2018-02-24 02:34:03 +00:00
Rui Ueyama c9f0b65f54 [WebAssebmly] Minor simplification. NFC.
llvm-svn: 326013
2018-02-24 01:58:38 +00:00
Rui Ueyama 20571c39a1 Do not use `auto` for type that is not obvious in a local context.
llvm-svn: 326012
2018-02-24 01:39:25 +00:00
Fangrui Song ffac3ed341 [ELF] Fix IsPreemptible comment and typo. NFC
llvm-svn: 325963
2018-02-23 21:57:49 +00:00
Rui Ueyama a6a0616508 Remove dead code.
llvm-svn: 325955
2018-02-23 20:33:43 +00:00
Rui Ueyama 97f66af615 Inline printHelp.
Differential Revision: https://reviews.llvm.org/D43526

llvm-svn: 325953
2018-02-23 20:24:40 +00:00
Rui Ueyama eecdaaac27 Handle --version before handling --mllvm.
Because it's a waste of time to handle --mllvm before --version.

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

llvm-svn: 325952
2018-02-23 20:24:28 +00:00
Rui Ueyama 39049c05a9 Inline a trivial ctor.
Differential Revision: https://reviews.llvm.org/D43525

llvm-svn: 325948
2018-02-23 20:13:38 +00:00
Simon Atanasyan a4cde9d2e2 [ELF][MIPS] Set EI_ABIVERSION flag accordingly to MIPS ABIs requirement
MIPS ABIs require that if an executable file uses non-PIC model, the
EI_ABIVERSION entry in the ELF header should be incremented from 0 to 1.
That allows obsoleted / limited dynamic linkers refuse to link them.

llvm-svn: 325890
2018-02-23 11:28:57 +00:00
George Rimar db1a062447 [ELF] - Do not remove empty output sections that are explicitly assigned to phdr in script.
This continues direction started in D43069.

We can keep sections that are explicitly assigned to segment in script.
It helps to simplify code.

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

llvm-svn: 325887
2018-02-23 10:53:04 +00:00
George Rimar 2d53967b48 Recommit "[ELF] - Do not crash with --emit-relocs and --icf=all together."
Latest patch version now.

Original commit message:

[ELF] - Do not crash with --emit-relocs and --icf=all together.

Previously we would crash because did not mark .rel[a] sections
as dead and they tried to access parent which was not live
after ICF and therefore was null.

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

llvm-svn: 325879
2018-02-23 10:37:33 +00:00
George Rimar aa359f87e8 [ELF] - Revert r325877 "[ELF] - Do not crash with --emit-relocs and --icf=all together."
Not latest version of patch was committed by mistake.

llvm-svn: 325878
2018-02-23 10:30:31 +00:00
George Rimar cde84d1cd0 [ELF] - Do not crash with --emit-relocs and --icf=all together.
Previously we would crash because did not mark .rel[a] sections
as dead and they tried to access parent which was not live
after ICF and therefore was null.

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

llvm-svn: 325877
2018-02-23 10:27:13 +00:00
George Rimar 3cdf0d969a [ELF] - Report error if removed empty output section declaration used undefined symbols.
This is for fixing PR36297.

Issue itself is that if we have SECTIONS { .bar (a+b) : { *(.stub) } };
script and no section .stub, when LLD will remove .bar, but
produce output with undefined symbols a and b.

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

llvm-svn: 325875
2018-02-23 10:15:54 +00:00
George Rimar 1fdb280bec [ELF] - Added testcase for testing visibility of weak_odr symbols.
This is relative to "Bug 36166 - tools/gold/X86/comdat.ll is failing only on Debian Unstable" (PR36166).
Something changed in newer versions of gold and now together with gold-plugin
there is an issue shown in PR, symbol may get wrong visibility.

LLD works fine, but we have no testcase for the same use case, patch adds it.

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

llvm-svn: 325874
2018-02-23 10:08:15 +00:00
George Rimar 4e6f52c9a4 [ELF] - Add testcase documenting flags assigned when empty synthetic section is removed.
This responds to PR36475,

r325763 led to unexprected layout change, though
new behavior seems to be more correct.

Previously we could have following script:

.foo : { *(.foo) } 
.bar : { *(.synthetic_empty) BYTE(0x11) }}
where synthetic_empty is a synthetic section which is empty and
hence removed by linker.

Before r325763 .bar would receive section flags from .synthetic_empty,
but after this revision it receives flags the same as .foo section has.

It is the same as if there would not be any synthetic_empty section in a script,
so looks reasonable and consistent behavior:
.foo : { *(.foo) } 
.bar : { BYTE(0x11) }}

Patch adds testcase to document it.

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

llvm-svn: 325873
2018-02-23 09:57:17 +00:00
Hans Wennborg ff52eb5927 ReleaseNotes: user lower-case for lld in the text
llvm-svn: 325869
2018-02-23 08:27:38 +00:00
Sam Clegg 9310297438 [WebAssembly] Add explicit symbol table
This change modified lld to in response the llvm change which
moved to a more explicit symbol table in the object format.

Based on patches by Nicholas Wilson:
 1. https://reviews.llvm.org/D41955
 2. https://reviews.llvm.org/D42585

The primary difference that we see in the test output is that
for relocatable (-r) output we now have symbol table which
replaces exports/imports and globals.

See: https://github.com/WebAssembly/tool-conventions/issues/38
Differential Revision: https://reviews.llvm.org/D43264

llvm-svn: 325861
2018-02-23 05:08:53 +00:00
Sam Clegg 6c4dbfeec1 [WebAssembly] Move lambda declaration output of loop. NFC.
Differential Revision: https://reviews.llvm.org/D43534

llvm-svn: 325857
2018-02-23 04:59:57 +00:00
Fangrui Song 9cd5df0e15 [ELF] Add comment for preemptible and fix typo. NFC
Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 325855
2018-02-23 02:05:48 +00:00
Rui Ueyama c30927411c Make undefined symbol in DSO to pull out object files from archive files.
We have an internal program that does't link without this patch. I don't
know of any open-source program that needs this, but there might be.
Since this patch improves compatibility with GNU linkers with a few lines
of code, I think it's worth to be committed.

The problem is about undefined symbols in DSOs. Some programs depend on
the GNU linkers' behavior that they pull out object files from archive
files to resolve undefined symbols in DSOs. We already allow that kind of
"reverse" dependency (from DSOs to the main executable) for regular
symbols, in particular, for "__progname" symbol (which is usually in
crt0.o), but that doesn't work if the symbol is in an archive file.
This patch is to make it work.

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

llvm-svn: 325849
2018-02-23 01:16:57 +00:00
Zachary Turner 401b2a463c Update lld documentation to mention PDB support.
Differential Revision: https://reviews.llvm.org/D43636

llvm-svn: 325821
2018-02-22 19:12:57 +00:00
George Rimar 925529b821 [ELF] - Rewrote outdated comment. NFC.
llvm-svn: 325809
2018-02-22 17:52:43 +00:00
George Rimar 563e4f2f58 [ELF] - Introduce getInputSections() helper.
We sometimes need to iterate over input sections for a given
output section. It is not very convinent because we have to iterate
over section descriptions.
Patch introduces getInputSections helper, it simplifies things.

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

llvm-svn: 325763
2018-02-22 09:55:28 +00:00
Rui Ueyama 9060b57e70 Revert r325679: [ELF] Add -nopie alias for -no-pie (PR36423)
This reverts commit r325679 that was committed without discussion.
Actually, in the discussion thread, most people opposed to have this
option in lld. Reverting that change doesn't mean that this is a
final decision, but that needs to be discussed first.

llvm-svn: 325714
2018-02-21 20:08:14 +00:00
Simon Dardis f5e0b40095 [mips][lld] Address post commit review nit.
Address @ruiu's post commit review comment about a value which is intended
to be a unsigned 32 bit integer as using uint32_t rather than unsigned.

llvm-svn: 325713
2018-02-21 20:01:43 +00:00
Sam Clegg 011dce2d14 [WebAssembly] Use make<> rather then make_unique<>. NFC.
lld uses an arena allocator to one of allocations
like these can just use make<>.

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

llvm-svn: 325706
2018-02-21 18:37:44 +00:00
Sam Clegg 9f93422651 [WebAssembly] Rename member DefinedFunctions -> InputFunctions. NFC.
This avoids confusion with the `DefinedFunction` symbol
type.

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

llvm-svn: 325705
2018-02-21 18:29:23 +00:00
George Rimar 5bd90e2db1 [ELF] - Simplify. NFC.
llvm-svn: 325681
2018-02-21 14:21:23 +00:00
Hans Wennborg 82fca76868 [ELF] Add -nopie alias for -no-pie (PR36423)
In r324043, --nopie was renamed to --no-pie to presumably fix a typo.

As it turns out, "nopie" wasn't a typo but the spelling used by
OpenBSD's binutils ld. Gold on the other hand spells the flag "no-pie".
(Vanilla binutils doesn't have a flag like this at all.)

Since they do the same thing, let's support both spellings.

llvm-svn: 325679
2018-02-21 13:54:26 +00:00
George Rimar db7c630b01 [ELF] - Simplify testcase. NFC.
This removes script input file and inlines script into
testcase body. That is consistent with othet LS tests
and makes testcase easier to read.

llvm-svn: 325673
2018-02-21 11:56:55 +00:00
Sam Clegg 29b8feb615 [WebAssembly] Use stable sort when sorting ctore functions
Patch by Nicholas Wilson!

llvm-svn: 325656
2018-02-21 00:34:34 +00:00
Aaron Smith 39bb8c5003 [lit] Fix a problem with spaces in the python path by adding quotes around it
Summary:
This fixes two failing tests on Windows with an installed version of python that has spaces in the path.

* elf/lto/cache.ll
* mach-o/dependency_info.yaml

Reviewers: zturner, llvm-commits, stella.stamenova

Subscribers: emaste, arichardson

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

llvm-svn: 325650
2018-02-21 00:03:41 +00:00
Simon Dardis cd8758233e [mips][lld] Spectre variant two mitigation for MIPSR2
This patch provides migitation for CVE-2017-5715, Spectre variant two,
which affects the P5600 and P6600. It implements the LLD part of
-z hazardplt. Like the Clang part of this patch, I have opted for that
specific option name in case alternative migitation methods are required
in the future.

The mitigation strategy suggested by MIPS for these processors is to use
hazard barrier instructions. 'jalr.hb' and 'jr.hb' are hazard
barrier variants of the 'jalr' and 'jr' instructions respectively.

These instructions impede the execution of instruction stream until
architecturally defined hazards (changes to the instruction stream,
privileged registers which may affect execution) are cleared. These
instructions in MIPS' designs are not speculated past.

These instructions are defined by the MIPS32R2 ISA, so this mitigation
method is not compatible with processors which implement an earlier
revision of the MIPS ISA.

For LLD, this changes PLT stubs to use 'jalr.hb' and 'jr.hb'.

Reviewers: atanasyan, ruiu

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

llvm-svn: 325647
2018-02-20 23:49:17 +00:00
Sam Clegg 00245539b6 [WebAssembly] Rename GlobalSymbol types. NFC.
Purely a rename in preparation for adding new global symbol type.

We want to use GlobalSymbol to represent real wasm globals and
DataSymbol for pointers to things in linear memory (what ELF would
call STT_OBJECT).

This reduces the size the patch to add the explicit symbol table
which is coming soon!

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

llvm-svn: 325645
2018-02-20 23:38:27 +00:00
Sam Clegg f187c4d2e5 Consistent use of header file for ICF and MarkLive
Previously wasm used a separate header to declare markLive
and ELF used to declare ICF.  This change makes each backend
consistently declare these in their own headers.

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

llvm-svn: 325631
2018-02-20 22:09:59 +00:00
Sam Clegg 3141ddc58d Consistent (non) use of empty lines in include blocks
The profailing style in lld seem to be to not include such empty lines.
Clang-tidy/clang-format seem to handle this just fine.

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

llvm-svn: 325629
2018-02-20 21:53:18 +00:00
Rui Ueyama c03c9040aa Use more early returns in SymbolTable.cpp.
I think if statements that end with return is easier to read than
cascaded if-else-if-else-if statements because it makes clear that
execution of a function terminates there. This patch also adds more
blank lines to separate code blocks to meaningful pieces.

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

llvm-svn: 325625
2018-02-20 21:08:47 +00:00
Sam Clegg 78f766a9aa [WebAssembly] Remove unused header
llvm-svn: 325624
2018-02-20 21:08:28 +00:00
Teresa Johnson 2c2ed3cf03 [lld/LTO] Remove unused Path parameter to AddBufferFn
Summary:
With D43396, no clients use the Path parameter anymore.
This is the lld side fix with D43400.

Depends on D43396 and D43400.

Reviewers: pcc

Subscribers: emaste, inglorion, arichardson, llvm-commits

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

llvm-svn: 325620
2018-02-20 20:21:59 +00:00
Sam Clegg f60b0d5c62 feedback
llvm-svn: 325614
2018-02-20 18:55:07 +00:00
Sam Clegg 93e559b138 [WebAssembly] Split addDefined into two different methods. NFC.
Subscribers: jfb, dschuff, jgravelle-google, aheejin, sunfish, llvm-commits

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

llvm-svn: 325613
2018-02-20 18:55:06 +00:00
Sam Clegg b92b6b532f [WebAssembly] Remove unused header
This header used to be needed here for the `OutRelocation` struct
but that no longer exists.

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

llvm-svn: 325608
2018-02-20 18:40:05 +00:00
Sam Clegg 4f61714fd6 [WebAssembly] Remove InputChunk from Symbol baseclass
Instead include InputFuction and InputSegment directly
in the subclasses that use them (DefinedFunction and
DefinedGlobal).

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

llvm-svn: 325603
2018-02-20 17:45:38 +00:00
Sam Clegg c7e885b52a [WebAssembly] Check signatures of weakly defined funtions too
Subscribers: jfb, dschuff, jgravelle-google, aheejin, sunfish, llvm-commits

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

llvm-svn: 325598
2018-02-20 17:20:44 +00:00
Rui Ueyama bf450d905d Do not create a temporary data structure for relocations.
This patch removes `OutRelocations` vector from the InputChunk and
directly consume `Relocations` vector instead. This should make the linker
faster because we don't create a temporary data structure, and it matches
the lld's design principle that we don't create temporary data structures
for object files but instead directly consume mmap'ed data whenever possible.

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

llvm-svn: 325549
2018-02-20 04:26:26 +00:00
Rui Ueyama c1e5c218e6 Merge two small functions and add comments.
Differential Revision: https://reviews.llvm.org/D43406

llvm-svn: 325538
2018-02-19 22:44:18 +00:00
Rui Ueyama c06d94aa31 Removed a variable that is used only once.
llvm-svn: 325537
2018-02-19 22:39:52 +00:00
Rui Ueyama 34133b23e4 [WebAssembly] Expand a lambda that is used only once.
Differential Revision: https://reviews.llvm.org/D43435

llvm-svn: 325536
2018-02-19 22:34:47 +00:00
Rui Ueyama 81bee04bf9 [WebAssembly] Define toString(wasm::InputChunk *) and use that in MarkLive.cpp.
Define toString(wasm::InputChunk *) and use that in MarkLive.cpp.

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

llvm-svn: 325535
2018-02-19 22:29:48 +00:00
Alexander Richardson 048e2508ad Rename DynamicReloc::getAddend() to computeAddend(). NFC
Summary:
Before the name of the function sounded like it was just a getter for the
private class member Addend. However, it actually calculates the final
value for the r_addend field in Elf_Rela that is used when writing the
.rela.dyn section. I also added a comment to the UseSymVA member to
explain how it interacts with computeAddend().

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

llvm-svn: 325485
2018-02-19 11:00:15 +00:00
Rui Ueyama c6c66225a3 Simplify.
llvm-svn: 325453
2018-02-17 23:37:26 +00:00
Rui Ueyama b3107476a4 Remove an unused accessor and simplify the logic a bit. NFC.
llvm-svn: 325445
2018-02-17 20:41:38 +00:00
Rui Ueyama 03c7f3a2d0 Factor out common code from applySecRel functions.
Differential Revision: https://reviews.llvm.org/D43412

llvm-svn: 325444
2018-02-17 20:28:15 +00:00
Sam Clegg caca8d5db3 [WebAssembly] Remove unneeded classifer methods from Symbol class. NFC.
We already have isa<> for this, and these methods were simply
duplicating those redundantly.

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

llvm-svn: 325418
2018-02-17 00:44:21 +00:00
Rui Ueyama ff59a899d6 Use toString to print out garbage-collected sections.
Currently, archive file name is missing in this message. In general,
we should avoid constructing strings in an ad-hoc manner and instead
use toString() to get consistent output strings.

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

llvm-svn: 325416
2018-02-17 00:09:49 +00:00
Sam Clegg 3f8db98807 [WebAssembly] Simplify FunctionSymbol::get/set/hasFunctionType. NFC.
Differential Revision: https://reviews.llvm.org/D43416

llvm-svn: 325415
2018-02-16 23:50:23 +00:00
Sam Clegg 6d83fb4c07 [WebAssembly] Remove unneeded Chunk::getFileName() method. NFC.
Differential Revision: https://reviews.llvm.org/D43405

llvm-svn: 325414
2018-02-16 23:46:51 +00:00
Rui Ueyama 7c9ad29304 Remove "--full-shutdown" and instead use an environment variable LLD_IN_TEST.
We are running lld tests with "--full-shutdown" option because we don't
want to call _exit() in lld if it is running tests. Regular shutdown
is needed for leak sanitizer.

This patch changes the way how we tell lld that it is running tests.
Now "--full-shutdown" is removed, and LLD_IN_TEST environment variable
is used instead.

This patch enables full shutdown on all ports, e.g. ELF, COFF and wasm.
Previously, we enabled it only for ELF.

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

llvm-svn: 325413
2018-02-16 23:41:48 +00:00
Rui Ueyama 4aab7b1d91 Do not print out "no input files" twice.
Differential Revision: https://reviews.llvm.org/D43408

llvm-svn: 325406
2018-02-16 22:58:19 +00:00
Rui Ueyama f05124e60c Use wasm-ld instead of "lld -flavor wasm".
Invoking lld as ld.lld, ld.ld64, lld-link or wasm-ld is preferred
than invoking lld as lld and pass an -flavor option. We have "lld"
file mostly for historical reasons.

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

llvm-svn: 325405
2018-02-16 22:58:02 +00:00
Konstantin Zhuravlyov 82a6199140 AMDGPU/LLD: Remove the use of binary file from one of the AMDGPU tests
Differential Revision: https://reviews.llvm.org/D43413

llvm-svn: 325404
2018-02-16 22:55:36 +00:00
Konstantin Zhuravlyov b3ec7396ed AMDGPU: Update elf flags in amdgpu-elf-flags.s
This is required after r325399:
  - EF_AMDGPU_ARCH_GCN got removed
  - In the test, EF_AMDGPU_ARCH_GCN is replaced with EF_AMDGPU_MACH_AMDGCN_GFX803

llvm-svn: 325400
2018-02-16 22:35:36 +00:00
Martin Storsjo ef4f78bbf2 [COFF] Add support for ARM64 secrel relocations for add/load instructions
Differential Revision: https://reviews.llvm.org/D43287

llvm-svn: 325396
2018-02-16 22:02:38 +00:00
Rui Ueyama 4f2b1189d5 Revert an accidental change to where "-flavor GNU" was used by intention.
llvm-svn: 325392
2018-02-16 21:24:01 +00:00
Rui Ueyama 5c33bbed58 Replace -flavor {gnu,darwin} with ld64.lld or ld.lld.
llvm-svn: 325390
2018-02-16 21:16:57 +00:00
Rui Ueyama 61dc84a4db Remove `else` after `break`.
llvm-svn: 325387
2018-02-16 20:53:53 +00:00
Rui Ueyama e351c3a438 Use write32le instead of write32<little>.
llvm-svn: 325384
2018-02-16 20:38:15 +00:00
Rui Ueyama 1184253891 Refactor wasm/WriterUtil.{cpp,h}.
Summary:
 - Makes code more in line with LLVM style (e.g. const char * -> StringRef)
 - Do not use formatv since we can construct message just by `+`
 - Replace some odd types such as `const StringRef` with more common type
 - Do not use default arguments if they are not necessary

Reviewers: sbc100

Subscribers: jfb, aheejin, llvm-commits, sunfish

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

llvm-svn: 325383
2018-02-16 20:38:00 +00:00
Sam Clegg b2f6e1c2f2 [WebAssebmly] Remove unneeded cast. NFC.
llvm-svn: 325382
2018-02-16 20:26:15 +00:00
Peter Collingbourne 09e04af42f ELF: Stop collecting a list of symbols in ArchiveFile.
There seems to be no reason to collect this list of symbols.

Also fix a bug where --exclude-libs would apply to all symbols that
appear in an archive's symbol table, even if the relevant archive
member was not added to the link.

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

llvm-svn: 325380
2018-02-16 20:23:54 +00:00
Rafael Espindola f931c179ca Don't depend on "call foo" producing a X86_64_PC32.
Newer versions of the gnu assembler produce a X86_64_PLT32 for
calls. There is a change under review in llvm to do the same, so update
the tests to not depend on it.

We can still produce a R_X86_64_PC32 with ".long foo - .".

llvm-svn: 325379
2018-02-16 20:05:58 +00:00
Rui Ueyama 7b9ed65666 Style fix. NFC.
llvm-svn: 325377
2018-02-16 19:53:29 +00:00
Sam Clegg fe78ccf1a1 [WebAssembly] Fix bug is function signature checking
This bug effected undefined symbols that were resolved by
existing defined symbols.  We were skipping the signature
check in this case.

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

llvm-svn: 325376
2018-02-16 19:45:41 +00:00
Sam Clegg 3d1f4b954d [WebAssembly] Fix typos in comment. NFC.
Patch by Nicholas Wilson!

llvm-svn: 325370
2018-02-16 18:37:32 +00:00
Rafael Espindola b960325989 Simplify RelocationBaseSection::addReloc.
Now that we have R_ADDEND, UseSymVA was redundant. We only want to
write the symbol virtual address when using an expression other than
R_ADDEND.

llvm-svn: 325360
2018-02-16 16:53:04 +00:00
James Henderson 149343c374 [ELF] Extend symbol-order-warnings test case for ICF
Reviewed by: rafael

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

There is some discussion as to the exact behaviour of combining ICF and
--symbol-ordering-file, but it seems beneficial to warn when attempting
to order the removed symbol regardless of the preferred approach.

llvm-svn: 325333
2018-02-16 10:49:57 +00:00
George Rimar 97f4d158bd [ELF] - Fix comment. NFC.
Addresses forgotten comment for D43071.

llvm-svn: 325332
2018-02-16 10:46:50 +00:00
George Rimar 1c08e9f5ce [ELF] - Support COPY, INFO, OVERLAY output sections attributes.
This is PR36298.

(COPY), (INFO), (OVERLAY) all have the same effect:
section should be marked as non-allocatable.

(https://www.eecs.umich.edu/courses/eecs373/readings/Linker.pdf, 
3.6.8.1 Output Section Type)

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

llvm-svn: 325331
2018-02-16 10:42:58 +00:00
Alexander Richardson cfb6093379 Ensure that Elf_Rel addends are always written for dynamic relocations
Summary:
This follows up on r321889 where writing of Elf_Rel addends was partially
moved to RelocationBaseSection. This patch ensures that the addends are
always written to the output section when a input section uses RELA but the
output is REL.

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

llvm-svn: 325328
2018-02-16 10:01:17 +00:00
Rui Ueyama 6de1e858a1 Fix an issue that weak bit is dropped when there's a lazy object symbol.
Previously, we accidentally dropped STB_WEAK bit from an undefined symbol
if there is a lazy object symbol with the same name. That caused a
compatibility issue with GNU gold.

llvm-svn: 325316
2018-02-16 04:27:46 +00:00
Igor Kudrin 943f62d9d7 [ELF] Fix use after free in case of using --whole-archive.
Differential Revision: https://reviews.llvm.org/D34554

llvm-svn: 325313
2018-02-16 03:26:53 +00:00
Rui Ueyama 65b620be8a Relax relocation type checking in a non-ALLOC section.
Even though it doesn't make sense, there seems to be multiple programs
in the wild that create PC-relative relocations in non-ALLOC sections.
I believe this is caused by the negligence of GNU linkers to not report
any errors for such relocations.

Currently, lld emits warnings against such relocations and exits.
So, you cannot link any program that contains wrong relocations until
you fix an issue in a program that generates wrong ELF files. It's often
impractical to fix a program because it's not always easy.

This patch relaxes the error checking and emit a warning instead.

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

llvm-svn: 325307
2018-02-16 01:10:51 +00:00
Igor Kudrin 25f917341e [ELF] Simplify handling of AT section attribute.
This also makes the behavior close to GNU ld's.

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

llvm-svn: 325213
2018-02-15 06:13:52 +00:00
Rui Ueyama 44a8471227 Fix an issue that lld drops symbol versions for -r.
When we are emitting a relocatable output, we should keep the original
symbol name including "@" part. Previously, we drop that part unconditionally
which resulted in dropping versions from symbols.

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

llvm-svn: 325204
2018-02-15 02:40:58 +00:00
Sam Clegg c484ee0a9c [WebAssebmly] Remove use of Optional to fix assertion in gcc
This was causing GCC builds with fail with:
Symbols.h:240:3: error: static assertion failed: Symbol types must be
trivially destructible
  static_assert(std::is_trivially_destructible<T>(

The reason this is a gcc-only failure is that OptionalStorage has
as specialization for POD types that isn't built under GCC.

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

llvm-svn: 325185
2018-02-14 22:55:38 +00:00
Rui Ueyama 38781a59f6 Revert r325158: Convert an assert to a static_assert. NFC.
This reverts commit r325158 because it broke GCC builds.

llvm-svn: 325183
2018-02-14 22:43:43 +00:00
Rui Ueyama de8140066a Remove a failing static_assert.
This static_assert is legitimate, but it is failing on some build environments.
I'm removing it until it's fixed to unbreak the bots.

llvm-svn: 325181
2018-02-14 22:26:23 +00:00
Sam Clegg ab31b7759d Convert an assert to a static_assert. NFC.
Differential Revision: https://reviews.llvm.org/D43305

llvm-svn: 325158
2018-02-14 19:28:46 +00:00
Rui Ueyama 5e52022af6 Make --export-dynamic-symbol to add undefined symbols even if --export-dynamic is given.
This patch addresses a minor compatibility issue with GNU linkers.
Previously, --export-dynamic-symbol is completely ignored if you
pass --export-dynamic together.

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

llvm-svn: 325152
2018-02-14 18:38:33 +00:00
Sam Clegg dfb0b2c78f [WebAssembly] Use a Symbol class heirarchy. NFC.
This brings wasm into line with ELF and COFF in terms of
symbol types are represented.

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

llvm-svn: 325150
2018-02-14 18:27:59 +00:00
James Henderson de300e66bb [ELF] Add warnings for various symbols that cannot be ordered
There are a number of different situations when symbols are requested
to be ordered in the --symbol-ordering-file that cannot be ordered for
some reason. To assist with identifying these symbols, and either
tidying up the order file, or the inputs, a number of warnings have
been added. As some users may find these warnings unhelpful, due to how
they use the symbol ordering file, a switch has also been added to
disable these warnings.

The cases where we now warn are:

 * Entries in the order file that don't correspond to any symbol in the input
 * Undefined symbols
 * Absolute symbols
 * Symbols imported from shared objects
 * Symbols that are discarded, due to e.g. --gc-sections or /DISCARD/ linker script sections
 * Multiple of the same entry in the order file

Reviewed by: rafael, ruiu

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

llvm-svn: 325125
2018-02-14 13:36:22 +00:00
Nicholas Wilson 9ce7033356 Add make targets for running all lld tests
Differential Revision: https://reviews.llvm.org/D42587

llvm-svn: 325124
2018-02-14 13:28:53 +00:00
Rafael Espindola 1d76120d9a Use a stricter return type in buildSectionOrder. NFC.
We sort inside output sections, so all the sections we see should be
InputSectionBase.

I noticed the patch adding callgraph based section ordering used this
type and changing this separately makes the merge easier.

llvm-svn: 325094
2018-02-14 01:42:26 +00:00
Rui Ueyama 2d9e7a8956 Use toString to stringize sections and files.
Differential Revision: https://reviews.llvm.org/D43251

llvm-svn: 325065
2018-02-13 22:56:49 +00:00
Rui Ueyama 7d67dd118a Use LLVM's SetVector insteead of unordered_set.
SetVector guarantees ordering, so with that we can get a deterministic
output for error messages.

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

llvm-svn: 325064
2018-02-13 22:30:52 +00:00
Reid Kleckner fd52096259 [LLD] Implement /guard:[no]longjmp
Summary:
This protects calls to longjmp from transferring control to arbitrary
program points. Instead, longjmp calls are limited to the set of
registered setjmp return addresses.

This also implements /guard:nolongjmp to allow users to link in object
files that call setjmp that weren't compiled with /guard:cf. In this
case, the linker will approximate the set of address taken functions,
but it will leave longjmp unprotected.

I used the following program to test, compiling it with different -guard
flags:
  $ cl -c t.c -guard:cf
  $ lld-link t.obj -guard:cf

  #include <setjmp.h>
  #include <stdio.h>
  jmp_buf buf;
  void g() {
    printf("before longjmp\n");
    fflush(stdout);
    longjmp(buf, 1);
  }
  void f() {
    if (setjmp(buf)) {
      printf("setjmp returned non-zero\n");
      return;
    }
    g();
  }
  int main() {
    f();
    printf("hello world\n");
  }

In particular, the program aborts when the code is compiled *without*
-guard:cf and linked with -guard:cf. That indicates that longjmps are
protected.

Reviewers: ruiu, inglorion, amccarth

Subscribers: llvm-commits

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

llvm-svn: 325047
2018-02-13 20:32:53 +00:00
Sam Clegg 447ae4044d [WebAssembly] Unify concepts of discarded and non-live input chunks. NFC.
It seems redundant to store this information twice.  None of the
locations where this bit is checked care about the distinction.

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

llvm-svn: 325046
2018-02-13 20:29:38 +00:00
Sam Clegg a189230bf5 [WebAssembly] Cleanup methods for add synthetic symbols to symbtab. NFC.
These were duplicating (incorrectly) some of the logic for
handling conflicts, but since they are only ever added right
at the start we can assume no existing symbols.

Also rename these methods for clarity.

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

llvm-svn: 325045
2018-02-13 20:14:26 +00:00
Rui Ueyama cfba0bed26 Fix coding style error.
llvm-svn: 325038
2018-02-13 18:40:52 +00:00
Rui Ueyama af7242a385 Use reinterpret_cast<> instead of C-style cast. NFC.
It is currently interpreted as reinterpret_cast<>. Make it explicit.

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

llvm-svn: 325033
2018-02-13 18:11:42 +00:00
Sam Clegg 38f52b2eb8 Check that Symbol types are trivially destructible
This adds an extra level of static safety to our use of placement
new to allocate Symbol types.  It prevents the accidental addition
on a non-trivially-destructible member that could allocate and
leak memory.

From the spec: Storage occupied by trivially destructible objects
may be reused without calling the destructor.

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

llvm-svn: 325025
2018-02-13 17:32:31 +00:00
Rafael Espindola d49866edba Use RelType in a few more places. NFC.
llvm-svn: 325017
2018-02-13 16:06:11 +00:00
Rafael Espindola 35cf8bbe36 Add a simpler version of addReloc. NFC.
Extracted from a patch by Alexander Richardson!

llvm-svn: 325016
2018-02-13 16:03:52 +00:00
Reid Kleckner 1941bb7887 Add REQUIRES: zlib to gdb-index.s test
llvm-svn: 324978
2018-02-13 01:19:56 +00:00
Rui Ueyama 005e7c3d75 Do not use Decompressor::isCompressedELFSection. NFC.
In order to identify a compressed section, we check if a section name
starts with ".zdebug" or the section has SHF_COMPRESSED flag. We already
use the knowledge in this function. So hiding that check in
isCompressedELFSection doesn't make sense.

llvm-svn: 324951
2018-02-12 22:32:57 +00:00
Rui Ueyama 3cd48fb124 Remove 'z' in .zdebug when decompressing a section.
When decompressing a compressed debug section, we drop SHF_COMPRESSED
flag but we didn't drop "z" in ".zdebug" section name. This patch does
that for consistency.

This change also fixes the issue that .zdebug_gnu_pubnames are not
dropped when we are creating a .gdb_index section.

llvm-svn: 324949
2018-02-12 22:25:45 +00:00
Rui Ueyama ac114d27ae s/uncompress/decompress/g.
In lld, we use both "uncompress" and "decompress" which is confusing.
Since LLVM uses "decompress", we should use the same term.

llvm-svn: 324944
2018-02-12 21:56:14 +00:00
Galina Kistanova c6cd1f0139 Fixed extra ‘;’ warning
llvm-svn: 324830
2018-02-11 02:32:21 +00:00
Alexander Richardson 59aaf1ae33 Use RelType instead of uint32_t in DynamicReloc. NFC
llvm-svn: 324821
2018-02-10 18:14:34 +00:00
Rui Ueyama 37a9889309 Make a lambda a static function to make the ICF main function shorter.
llvm-svn: 324756
2018-02-09 18:00:46 +00:00
Rui Ueyama 7b90efbece Do not print out removed ICF sections for -verbose.
GNU gold doesn't print out ICF sections for -verbose. It only shows
them for -print-icf-sections. We printed out them for -verbose because
we didn't have -print-icf-sections. Now that we have the option, there's
no reason to print out for -verbose.

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

llvm-svn: 324755
2018-02-09 17:55:09 +00:00
Rui Ueyama 90b395e93a Make --export-dynamic-symbol to pull out object files from archives.
This is for compatiblity with GNU gold. GNU gold tries to resolve
symbols specified by --export-dynamic-symbol. So, if a symbol specified
by --export-dynamic-symbol is in an archive file, lld's result is
currently different from gold's.

Interestingly, that behavior is different for --dynamic-list.
I added a new test to ensure that.

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

llvm-svn: 324752
2018-02-09 17:39:06 +00:00
Rafael Espindola ecfd73457c Refactor how we decide which sections to sort.
This is a bit more verbose, but it has a few advantages.

The logic on what to do with special sections like .init_array is not
duplicated. Before we would need keep isKnownNonreorderableSection in
sync.

I think with this the call graph based sorting can be implemented by
"just" returning a new order from buildSectionOrder.

llvm-svn: 324744
2018-02-09 16:09:22 +00:00
Ed Maste 1136f3f0fd Add IMPLEMENTATION NOTES describing lld's .a handling in the man page
This content is based on the description in NewLLD.rst.

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

llvm-svn: 324739
2018-02-09 15:36:13 +00:00
Sam Clegg 3dc44a66af [WebAssebmly] Remvoe trailing semicolon. NFC.
llvm-svn: 324716
2018-02-09 07:12:29 +00:00
Sam Clegg 77d4edcf05 [WebAssembly] Remove redundant check global output index
llvm-svn: 324715
2018-02-09 07:09:12 +00:00
Rui Ueyama 206dc227a6 Remove redundant semicolon.
llvm-svn: 324698
2018-02-09 01:43:59 +00:00
Rui Ueyama 892bb89bc9 Rename confusing variable names in a test.
"%tar" looks like a tar archive, but it's actually an .a archive.

llvm-svn: 324692
2018-02-09 01:03:22 +00:00
Rui Ueyama cd7a415938 Use log to print out a verbose message.
llvm-svn: 324688
2018-02-09 00:15:12 +00:00
Rui Ueyama d42b1c0534 Remove Config->Verbose because we have errorHandler().Verbose.
llvm-svn: 324684
2018-02-08 23:52:09 +00:00
Rui Ueyama 153b04f1be Fix --print-icf-sections output.
Previously, multiple chunks of --print-icf-sections messages were interleaved
and didn't make sense. This is because forEachClass is multi-threaded.

llvm-svn: 324683
2018-02-08 23:51:58 +00:00
Michael J. Spencer e43db0e89e [ELF] Don't sort non reorderable sections with --symbol-ordering-file
Differential Revision: https://reviews.llvm.org/D43038

llvm-svn: 324656
2018-02-08 22:03:23 +00:00
Dmitry Mikulin 8ddd922d73 Symbols defined in linker scripts should not have dso_local flag set in LTO resolutions.
Differential Revision: https://reviews.llvm.org/D43051

llvm-svn: 324559
2018-02-08 04:25:52 +00:00
Ed Maste 421fdaa121 Document --build-id=fast in ld.lld.1
Initial ld.lld.1 man page commit in r324512 crossed paths with r324502
which added --build-id=fast, allowing --build-id to be documented as a
synonym for --build-id=fast. Catch up with that change in the man page.

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

llvm-svn: 324528
2018-02-07 21:22:20 +00:00
Ed Maste 3a775a17ca Add ld.lld.1 man page, describing lld's ELF linker
One of the FreeBSD requirements for enabling lld as the system linker is
that it has a man page. Other FreeBSD developers and I created one using
lld's --help output as a starting point.  This is an expanded and
improved version of that.

This man page would benefit from additional content, but it provides
basic user-facing coverage of lld's options and serves as a good
starting point.

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

llvm-svn: 324512
2018-02-07 20:38:18 +00:00
Rui Ueyama fa9f699d30 Add --build-id=fast as a synonym for --build-id.
When you omit an argument, most options fall back to their defaults.
For example, --color-diagnostics is a synonym for --color-diagnostics=auto.
We don't have a way to specify the default choice for --build-id, so we
can't describe --build-id (without an argument) in that way.
This patch adds "fast" for the default build-id choice.

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

llvm-svn: 324502
2018-02-07 19:22:42 +00:00
Simon Atanasyan 7244159b82 [ELF][MIPS] Mark the test as required MIPS target support. NFC
llvm-svn: 324468
2018-02-07 10:14:22 +00:00
Simon Atanasyan 85815a3149 [ELF][MIPS] Ignore incorrect version definition index for _gp_disp symbol
MIPS BFD linker puts _gp_disp symbol into DSO files and assigns zero
version definition index to it. This value means 'unversioned local
symbol' while _gp_disp is a section global symbol. We have to handle
this bug in the LLD because BFD linker is used for building MIPS
toolchain libraries.

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

llvm-svn: 324467
2018-02-07 10:02:49 +00:00
George Rimar 308c92b25d [ELF] - Fix BB after r324463.
Test requires arm, but specified x86.

llvm-svn: 324464
2018-02-07 09:41:14 +00:00
George Rimar 3d5e86e5ee [ELF] - Remove unused synthetic sections correctly.
This is PR35740 which now crashes
because we remove unused synthetic sections incorrectly.

We can keep input section description and corresponding output
section live even if it must be empty and dead. 
This results in a crash because SHF_LINK_ORDER handling code
tries to access first section which is nullptr in this case.

Patch fixes the issue.

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

llvm-svn: 324463
2018-02-07 09:11:07 +00:00
George Rimar 27ae7ae774 [ELF] - Make defsym to work correctly with reserved symbols.
Previously --defsym=foo2=etext+2 would produce incorrect value
for foo2 because expressions did not work correctly with
reserved symbols, section offset was calculated wrong for them.

Fixes PR35744.

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

llvm-svn: 324461
2018-02-07 09:00:34 +00:00
George Rimar 9d9e9e1889 [ELF] - Allow set CPU string with -plugin-opt=mcpu=<xxx>
Previously we ignored -plugin-opt=mcpu=<xxx>
and the only way to set CPU string was to pass
-mllvm -mcpu=<xxx>
Though clang may pass it with use of plugin options:
-plugin-opt=mcpu=x86-64
Since we are trying to be compatible in command line
with gold plugin, seems we should support it too.

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

llvm-svn: 324459
2018-02-07 08:50:36 +00:00
George Rimar c9b6c5c67d [ELF] - Add testcase for -debugger-tune=<value>
In D42733 we supported different LTO command line
options, including -debugger-tune=<value>.

Initially debugger-tune support was needed to fix PR36035.
Patch adds testcase for this option to check we
don't simply ignore it.

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

llvm-svn: 324457
2018-02-07 08:43:19 +00:00
Sam Clegg 37a4a8a4b1 [WebAssembly] Add __data_end link-sythentic symbol.
This is similar to _end (See https://linux.die.net/man/3/edata for more)
but using our own unique name since our use cases will most likely be
different and we want to keep our options open WRT to memory layout.

This change will allow is to remove the DataSize from the linking
metadata section which is currently being used by emscripten to derive
the end of the data.

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

llvm-svn: 324443
2018-02-07 03:04:53 +00:00
Dmitry Mikulin c84e0ee0e2 Don't set dso_local flag in LTO resolutions for absolute symbols defined in ELF
objects, it confuses codegen into generating pc-rel relocations for those
symbols, which leads to linker errors.

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

llvm-svn: 324435
2018-02-07 00:49:51 +00:00
Rui Ueyama 532fa0e1ca Make sure that --no-check-sections doesn't print out warning messages.
Differential Revision: https://reviews.llvm.org/D42988

llvm-svn: 324434
2018-02-07 00:41:34 +00:00
Rafael Espindola 16a3716db4 Simplify libtool compatibility hack.
I tested that if I remove "elf" from the message, building a program
that uses libtool prints

checking whether to build shared libraries... no

but with this patch it still prints

checking whether to build shared libraries... yes

llvm-svn: 324428
2018-02-07 00:13:01 +00:00
Rafael Espindola 339dbb8af2 Convert a use of Config->Static.
In lld this was the only use of Config->Static where it meant anything
else other than "use .a instead of .so".

If a program turns out to not use any dynamic libraries, we should
produce the same result with and without -static.

llvm-svn: 324421
2018-02-06 22:59:24 +00:00
Rafael Espindola 64626b344b Store just argv[0] in Config.
Having the full argv there seems in conflict with the desire to parse
all command line options in the Driver.

llvm-svn: 324418
2018-02-06 22:37:05 +00:00
Rafael Espindola eed9725451 Hide the --full-shutdown option.
llvm-svn: 324365
2018-02-06 18:12:41 +00:00
Benjamin Kramer 6400a97418 [COFF] LTO does not require a disassembler.
llvm-svn: 324355
2018-02-06 15:42:41 +00:00
George Rimar 9dc740d0a9 [ELF] - Re-commit r324322 "Use InitTargetOptionsFromCodeGenFlags/ParseCommandLineOptions for parsing LTO options.".
With fix:
Keep logic that ignores -plugin-opt=mcpu=x86-64 -plugin-opt=thinlto,
add checks for those to testcases.

Original commit message:

[ELF] - Use InitTargetOptionsFromCodeGenFlags/ParseCommandLineOptions for parsing LTO options.

gold plugin uses InitTargetOptionsFromCodeGenFlags + 
ParseCommandLineOptions for parsing LTO options.
Patch do the same change for LLD.

Such change helps to avoid parsing/whitelisting LTO
plugin options again on linker side, what can help LLD
to automatically support new -plugin-opt=xxx options
passed.

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

llvm-svn: 324340
2018-02-06 12:20:05 +00:00
George Rimar bc08aa7d97 Revert r324322 "[ELF] - Use InitTargetOptionsFromCodeGenFlags/ParseCommandLineOptions for parsing LTO options."
It broke BB:
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/8162

llvm-svn: 324332
2018-02-06 10:31:01 +00:00
George Rimar 86372289a8 [ELF] - Use InitTargetOptionsFromCodeGenFlags/ParseCommandLineOptions for parsing LTO options.
gold plugin uses InitTargetOptionsFromCodeGenFlags + 
ParseCommandLineOptions for parsing LTO options.
Patch do the same change for LLD.

Such change helps to avoid parsing/whitelisting LTO
plugin options again on linker side, what can help LLD
to automatically support new -plugin-opt=xxx options
passed.

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

llvm-svn: 324322
2018-02-06 09:05:56 +00:00
Reid Kleckner af2f7da74c [COFF] Add minimal support for /guard:cf
Summary:
This patch adds some initial support for Windows control flow guard. At
the end of the day, the linker needs to synthesize a table of RVAs very
similar to the structured exception handler table (/safeseh).

Both /safeseh and /guard:cf take sections of symbol table indices
(.sxdata and .gfids$y) and turn them into RVA tables referenced by the
load config struct in the CRT through special symbols.

Reviewers: ruiu, amccarth

Subscribers: llvm-commits

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

llvm-svn: 324306
2018-02-06 01:58:26 +00:00
Rui Ueyama bb8d15e4d7 Add -no-allow-multiple-definition, -no-pic-executable and -no-warn-common.
GNU gold has these options.

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

llvm-svn: 324300
2018-02-06 00:45:15 +00:00
Reid Kleckner feda4f6a50 Fix LLD wasm error check on Windows, which prints "lld.EXE: error: ..."
llvm-svn: 324297
2018-02-06 00:06:45 +00:00
Rafael Espindola 7a7a81d9d1 Replace ApplyDynamicRelocs with WriteAddends.
The difference is that WriteAddends also takes IsRela into
consideration.

llvm-svn: 324271
2018-02-05 20:55:46 +00:00
Rafael Espindola 0e4df539fa Change the default of --apply-dynamic-relocs.
When using Elf_Rela every tool should use the addend in the
relocation.

We have --apply-dynamic-relocs to work around bugs in tools that don't
do that.

The default value of --apply-dynamic-relocs should be false to make
sure these bugs are more easily found in the future.

llvm-svn: 324264
2018-02-05 19:39:04 +00:00
Rui Ueyama e80ce52cee Allow both -no-omagic and --no-omagic.
Any multi-character option that doesn't start with "o" should be
allowed to start both with "-" and "--".

llvm-svn: 324262
2018-02-05 19:14:03 +00:00
Peter Smith 64f65b02d2 [ELF] Implement --[no-]apply-dynamic-relocs option.
When resolving dynamic RELA relocations the addend is taken from the
relocation and not the place being relocated. Accordingly lld does not
write the addend field to the place like it would for a REL relocation.
Unfortunately there is some system software, in particlar dynamic loaders
such as Bionic's linker64 that use the value of the place prior to
relocation to find the offset that they have been loaded at. Both gold
and bfd control this behavior with the --[no-]apply-dynamic-relocs option.
This change implements the option and defaults it to true for compatibility
with gold and bfd.

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

llvm-svn: 324221
2018-02-05 10:15:08 +00:00
George Rimar f9dc10cd89 [ELF] - Report valid binary filename when reporting error.
We did not report valid filename for duplicate symbol error when
symbol came from binary input file.
Patch fixes it.

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

llvm-svn: 324217
2018-02-05 09:47:24 +00:00
Sam Clegg f0d433d0c6 [WebAssembly] Refactor linker-generated symbols. NFC.
Group all synthetic symbols in the in single struct to match
the ELF linker.

This change is part of a larger change to add more linker
symbols such as `_end` and `_edata`.

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

llvm-svn: 324157
2018-02-02 22:59:56 +00:00
Rui Ueyama 7a64a3d59c Simplify.
llvm-svn: 324155
2018-02-02 22:48:09 +00:00
Rui Ueyama edd4ec54d6 Update Eq so that it uses NAME just like B does. NFC.
llvm-svn: 324154
2018-02-02 22:45:47 +00:00
Rui Ueyama 6a8e79b8e5 Add -{no,}-check-sections flags to enable/disable section overlchecking
GNU linkers have this option.

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

llvm-svn: 324150
2018-02-02 22:24:06 +00:00