Commit Graph

9985 Commits

Author SHA1 Message Date
Rui Ueyama fe148c88da Remove dead code.
parseInt assumed that it could take a negative number literal (e.g.
"-123"). However, such number is in reality already handled as a
unary operator '-' followed by a number literal, so the number
literal is always non-negative. Thus, this code is dead.

llvm-svn: 322453
2018-01-14 04:44:21 +00:00
Sam Clegg a697df52cf [WebAssembly] Fix build failures due to warning
Oops, the waterfall tests with `-Werror -Wunused-variable`.

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

llvm-svn: 322442
2018-01-13 15:59:53 +00:00
Sam Clegg f98bccf06f Revert "[WebAssembly] Move checking of InputSegment comdat group earlier"
This reverts commit 7421eab7ccf2e14518f4526a084a5afc76ac9c6a.

llvm-svn: 322441
2018-01-13 15:57:48 +00:00
Sam Clegg 7c11dbf5b0 [WebAssembly] Move checking of InputSegment comdat group earlier
This should also fixe an unused varaible warning in the realeae
build.

llvm-svn: 322440
2018-01-13 15:44:54 +00:00
Eric Christopher 9ea500b417 Remove extraneous semicolon.
llvm-svn: 322426
2018-01-13 00:44:45 +00:00
Sam Clegg 4a379c3dd8 [WebAssembly] Use ArrayRef over raw pointers
Differential Revision: https://reviews.llvm.org/D42013

llvm-svn: 322423
2018-01-13 00:22:00 +00:00
Rafael Espindola 75702389bd Fix incorrect physical address on self-referencing AT command.
When a section placement (AT) command references the section itself,
the physical address of the section in the ELF header was calculated
incorrectly due to alignment happening right after the location
pointer's value was captured.

The problem was diagnosed and the first version of the patch written
by Erick Reyes.

llvm-svn: 322421
2018-01-12 23:26:25 +00:00
Rui Ueyama e2dfdbf0aa Do not pass an argument that can be easily inferred from other argument.
llvm-svn: 322416
2018-01-12 22:29:29 +00:00
Sam Clegg e0f6fcd0d9 [WebAssembly] Add COMDAT support
See https://bugs.llvm.org/show_bug.cgi?id=35533, and D40844

Things covered:
* Removing duplicate data segments (as determined by COMDATs emitted
  by the frontend)
* Removing duplicate globals and functions in COMDATs
* Checking that each time a COMDAT is seen it has the same symbols
  as at other times (ie it's a stronger check than simply giving all
  the symbols in the COMDAT weak linkage)

Patch by Nicholas Wilson!

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

llvm-svn: 322415
2018-01-12 22:25:17 +00:00
Sam Clegg f61910d8f6 [WebAssembly] Fix typo in file header
llvm-svn: 322412
2018-01-12 22:18:22 +00:00
Sam Clegg 2a06afae16 [WebAssembly] Add --export flag to force a symbol to be exported
This is useful for emscripten or other tools that want to
selectively exports symbols without necessarily changing the
source code.

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

llvm-svn: 322408
2018-01-12 22:10:35 +00:00
Sam Clegg 5068685678 [WebAssembly] Create synthetic __wasm_call_ctors function
This change create a new synthetic function in the final
output binary which calls the static constructors in sequence.

See: https://github.com/WebAssembly/tool-conventions/issues/25

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

llvm-svn: 322388
2018-01-12 18:35:13 +00:00
Sam Clegg 408064ef1e [WebAssembly] Don't allow functions to be named more than once
Even though a function can have multiple names in the
linking standards (i.e. due to aliases), there can only
be one name for a given function in the NAME section.

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

llvm-svn: 322383
2018-01-12 17:56:15 +00:00
Pavel Labath a006baa620 Attempt to fix FreeBSD build broken by the previous commit
The compiler could not find the conversion from
unique_ptr<WritableMemoryBuffer> to unique_ptr<MemoryBuffer>. This will
hopefully help it along.

llvm-svn: 322365
2018-01-12 10:09:10 +00:00
Pavel Labath 1c1e24ad96 [lld/COFF] Use WritableMemoryBuffer for creating the manifest
This avoids the need for const_casting the memory buffer contents in
order to write to it.

NFCI.

llvm-svn: 322363
2018-01-12 09:48:41 +00:00
George Rimar 9fc2c64b35 [ELF] - Do not use HeaderSize for conditions in PltSection.
Previously we checked (HeaderSize == 0) to find out if
PltSection section is IPLT or PLT. Some targets does not set
HeaderSize though. For example PPC64 has no lazy binding implemented
and does not set PltHeaderSize constant.

Because of that using of both IPLT and PLT relocations worked
incorrectly there (testcase is provided).

Patch fixes the issue.

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

llvm-svn: 322362
2018-01-12 09:35:57 +00:00
George Rimar 5d01a8be96 [ELF] - Fix for ld.lld does not accept "AT" syntax for declaring LMA region
AT> lma_region expression allows to specify the memory region
for section load address.

Should fix PR35684.

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

llvm-svn: 322359
2018-01-12 09:07:35 +00:00
Sam Clegg 7ed293e448 [WebAssembly] Reduce output of --verbose
llvm-svn: 322337
2018-01-12 00:34:04 +00:00
Sam Clegg 31efdcd78e [WebAssembly] When loading libraries look for companion `.imports` file
This allows libraries to supply a list of symbols which are
allowed to be undefined at link time (i.e. result in imports).

This method replaces the existing mechanism (-allow-undefined-file)
used by the clang driver to allow undefined symbols in libc.

For more on motivation for this see:
 https://github.com/WebAssembly/tool-conventions/issues/35

In the long run we hope to remove this features and instead
include this information in the object format itself.

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

llvm-svn: 322320
2018-01-11 22:31:35 +00:00
Rui Ueyama c43b7e61a2 Improve an error message.
Before:
$ ld.lld --plugin-opt=Os
ld.lld: error: --plugin-opt: number expected, but got 's'

After:
$ ld.lld --plugin-opt=Os
ld.lld: error: --plugin-opt=Os: number expected, but got 's'

llvm-svn: 322315
2018-01-11 22:11:25 +00:00
Dimitry Andric 656714a311 Fix thread race between SectionPiece's OutputOff and Live members
Summary:
As reported in bug 35788, rL316280 reintroduces a race between two
members of SectionPiece, which share the same 64 bit memory location.

To fix the race, check the hash before checking the Live member, as
suggested by Rafael.

Reviewers: ruiu, rafael

Reviewed By: ruiu

Subscribers: smeenai, emaste, llvm-commits

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

llvm-svn: 322264
2018-01-11 08:03:22 +00:00
Rui Ueyama 45fcbf0991 Remove redundnat Args.filter() argument.
OPT_plugin_opt_eq is an alias to OPT_plugin_opt, so we don't need
to give that twice.

llvm-svn: 322263
2018-01-11 07:55:01 +00:00
Shoaib Meenai d79bbf4474 [ELF] Fix SysV hash tables with --no-rosegment
When setting up the chain, we copy over the bucket's previous symbol
index, assuming that this index will be 0 (STN_UNDEF) for an unused
bucket (marking the end of the chain). When linking with --no-rosegment,
however, unused buckets will in fact contain the padding value, and so
the hash table will end up containing invalid chains. Zero out the hash
table section explicitly to avoid this, similar to what's already done
for GNU hash sections.

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

llvm-svn: 322259
2018-01-11 06:57:01 +00:00
Sam Clegg 8d027d6758 [WebAssembly] Optimize Writer::lookupType
Followup on https://reviews.llvm.org/D41894

llvm-svn: 322219
2018-01-10 20:12:26 +00:00
Sam Clegg d96d93576b [WebAssembly] Move relocation handling InputChunks.cpp
Teach each input chunk how to write itself and apply its
own relocations.

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

llvm-svn: 322212
2018-01-10 19:22:42 +00:00
Sam Clegg c375e4e433 [WebAssembly] Add seperate Writer::lookupType and Writer::registerType. NFC
Differential Revision: https://reviews.llvm.org/D41894

llvm-svn: 322211
2018-01-10 19:18:22 +00:00
Ed Maste 6ed7f00e49 Correct typo in help text
Information is a mass noun and doesn't take a plural "s".

llvm-svn: 322180
2018-01-10 12:55:14 +00:00
Rafael Espindola b5506e6baf Rename --icf-data and add a corresponding flag for functions.
When we have --icf=safe we should be able to define --icf=all as a
shorthand for --icf=safe --ignore-function-address-equality.

For now --ignore-function-address-equality is used only to control
access to non preemptable symbols in shared libraries.

llvm-svn: 322152
2018-01-10 01:37:36 +00:00
Sam Clegg 5fa274bea4 [WebAssembly] Add InputChunk as common base class for InputSegment and InputFunction. NFC.
Differential Revision: https://reviews.llvm.org/D41419

llvm-svn: 322148
2018-01-10 01:13:34 +00:00
Sam Clegg 20db381b90 [WebAssembly] Refactor symbol and symbol table to remove WasmSymbol references
This WasmSymbol types comes directly from the input objects
but we want to be able to represent synthetic symbols too.

This is more in line with how the ELF linker represents symbols.

This change also removes the logic from Symbol::getVirtualAddress
for finding the global address and instead has the InputFile
provide this.

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

llvm-svn: 322145
2018-01-10 00:52:20 +00:00
Sam Clegg 8d146bbc0c [WebAssembly] Output functions individually
The code section is now written out one function
at a time rather than all the functions in a given
objects being serialized at once.

This change lays the groundwork for supporting
--gc-sections.

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

llvm-svn: 322138
2018-01-09 23:56:44 +00:00
Sam Clegg f50534b127 [WebAssembly] Update YAML in tests to match LLVM change
Differential Revision: https://reviews.llvm.org/D41878

llvm-svn: 322122
2018-01-09 21:47:36 +00:00
Rui Ueyama 5fa0d6e4a2 [COFF] Process /EXPORT option in fastpath
Patch by Takuto Ikuta.

This patch reduces lld link time of chromium's blink_core.dll in
component build.

Total size of input argument in .directives become nearly 300MB in the
build and almost all its content are /EXPORT.

To reduce time of parsing too many /EXPORT option in the build, I
introduce fastpath for /EXPORT in ArgParser::parseDirectives.

On my desktop machine, 4 times stats of the link time are like below.
Improved around 20%.

This patch
TotalSeconds : 8.6217627
TotalSeconds : 8.5402175
TotalSeconds : 8.6855853
TotalSeconds : 8.3624441
Ave : 8.5525024

master
TotalSeconds : 10.9975031
TotalSeconds : 11.3409428
TotalSeconds : 10.6332897
TotalSeconds : 10.7650687
Ave : 10.934201075

llvm-svn: 322117
2018-01-09 20:36:42 +00:00
Igor Kudrin 5e9da2d06b [ELF] Add a comment for ARMExidxSentinelSection::Highest; Use "= nullptr" instead of "= 0". NFC.
Differential Revision: https://reviews.llvm.org/D41234

llvm-svn: 322066
2018-01-09 09:44:27 +00:00
Easwaran Raman bfa48a14ab [ELF] Explicit template instantiations for addFile
Summary:
All other templated methods have explicit instantiations but this one is
missing. Discovered while building with a clang with inliner
modifications.

Reviewers: espindola

Subscribers: emaste, llvm-commits, davidxl

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

llvm-svn: 322057
2018-01-09 05:35:29 +00:00
Rafael Espindola 4b6833332b Rewrite our relocation processing.
This splits relocation processing in two steps.

First, analyze what needs to be done at the relocation spot. This can
be a constant (non preemptible symbol, relative got reference, etc) or
require a dynamic relocation. At this step we also consider creating
copy relocations.

Once that is done we decide if we need a got or a plt entry.

The code is simpler IMHO. For example:

- There is a single call to isPicRel since the logic is not split
  among adjustExpr and the caller.
- R_MIPS_GOTREL is simple to handle now.
- The tracking of what is preemptible or not is much simpler now.

This also fixes a regression with symbols being both in a got and copy
relocated. They had regressed in r268668 and r268149.

The other test changes are because of error messages changes or the
order of two relocations in the output.

llvm-svn: 322047
2018-01-09 00:13:54 +00:00
Sam Clegg 87e61923a4 [WebAssembly] Write out undefined symbol addresses as zero
The addresses of undefined symbols that make it into the final
executable (i.e. weak references to non-existent symbols) should
resolve to zero.

Also, make sure to not include function in the indirect function
table if they are not included in the output.

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

llvm-svn: 322045
2018-01-08 23:39:11 +00:00
Shoaib Meenai c1ca8065b5 [ELF] Small grammar fix. NFC
The whole consists of the parts, not the other way around.

llvm-svn: 322042
2018-01-08 23:18:16 +00:00
Rui Ueyama 0657e5c3f2 Do not use parallelForEach to call maybeCompress().
Currently LLVM's paralellForEach has a problem with reentracy.
That caused https://bugs.llvm.org/show_bug.cgi?id=35788 (lld somtimes
hangs while linking Ruby 2.4) because maybeCompress calls writeTo which
uses paralellForEach.

This patch is to avoid using paralellForEach to call maybeCompress
to workaround the issue.

llvm-svn: 322041
2018-01-08 23:12:42 +00:00
Zachary Turner dc0ba5daff Fix newly failing tests.
These tests started failing because we now properly convert
DefRange records to and from Yaml, but there were some old yaml
files that had incorrect record definitions generated by the
old buggy obj2yaml.  Rather than try to re-generate the yaml files,
it's easier to just remove the records, and they weren't necessary
for the proper execution of the test anyway.

llvm-svn: 322040
2018-01-08 23:07:39 +00:00
Rafael Espindola d1bd95cf73 Move scanReloc to an auxiliary function.
The body of the in scanRelocs is fairly big. This moves it to its own
function.

It is not a big readability win by itself, but should help further
refactoring.

llvm-svn: 322035
2018-01-08 22:20:44 +00:00
Zachary Turner 59468f5a1e Fix uninitialized read error reported by MSAN.
The problem was that our Obj -> Yaml dumper had not been taught
to handle certain types of records.  This meant that when I
generated the test input files, the records were still there but
none of its fields were filled out.  So when it did the
Yaml -> Obj conversion as part of the test, it generated records
with garbage in them.

The patch here fixes the Obj <-> Yaml converter, and additionally
updates the test file with fresh Yaml generated by the fixed
converter.

llvm-svn: 322029
2018-01-08 21:38:50 +00:00
Shoaib Meenai 7e3e28f968 [COFF] Delete CanExitEarly
It was being set but never used, and its value is only ever needed
locally in lld::coff::link.

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

llvm-svn: 322026
2018-01-08 21:14:51 +00:00
Simon Atanasyan b9efca3257 Check test conditions more precisely. NFC
llvm-svn: 322014
2018-01-08 18:17:25 +00:00
James Henderson e1689689d8 [ELF] Compress debug sections after assignAddresses and support custom layout
Previously, in r320472, I moved the calculation of section offsets and sizes
for compressed debug sections into maybeCompress, which happens before
assignAddresses, so that the compression had the required information. However,
I failed to take account of relocations that patch such sections. This had two
effects:

1. A race condition existed when a debug section referred to a different debug
section (see PR35788).
2. References to symbols in non-debug sections would be patched incorrectly.
This is because the addresses of such symbols are not calculated until after
assignAddresses (this was a partial regression caused by r320472, but they
could still have been broken before, in the event that a custom layout was used
in a linker script).

assignAddresses does not need to know about the output section size of
non-allocatable sections, because they do not affect the value of Dot. This
means that there is no longer a reason not to support custom layout of
compressed debug sections, as far as I'm aware. These two points allow for
delaying when maybeCompress can be called, removing the need for the loop I
previously added to calculate the section size, and therefore the race
condition. Furthermore, by delaying, we fix the issues of relocations getting
incorrect symbol values, because they have now all been finalized.

llvm-svn: 321986
2018-01-08 10:17:03 +00:00
Shoaib Meenai fd3e4b0ea1 [COFF] Initalize ErrorHandler with CanExitEarly value
Previously, the COFF driver would call exit(1) from the
ErrorHandler in the case of a link error, even if
CanExitEarly=false was specified. Now it initializes
the ErrorHandler in the same way that the ELF driver does.

Patch by Andrew Kelley.

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

llvm-svn: 321983
2018-01-08 05:58:36 +00:00
Shoaib Meenai 3a15fb591e [ELF] Drop unnecessary VersionId setting in scanShlibUndefined
LLD previously used to handle dynamic lists and version scripts in the
exact same way, even though they have very different semantics for
shared libraries and subtly different semantics for executables. r315114
untangled their semantics for executables (building on previous work to
correct their semantics for shared libraries). With that change, dynamic
lists won't set the default version to VER_NDX_LOCAL, and so resetting
the version to VER_NDX_GLOBAL in scanShlibUndefined is unnecessary.

This was causing an issue because version scripts containing `local: *`
work by setting the default version to VER_NDX_LOCAL, but scanShlibUndefined
would override this default, and therefore symbols which should have
been local would end up in the dynamic symbol table, which differs from
both bfd and gold's behavior. gold silently keeps the symbol hidden in
such a scenario, whereas bfd issues an error. I prefer bfd's behavior
and plan to implement that in LLD in a follow-up (and the test case
added here will be updated accordingly).

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

llvm-svn: 321982
2018-01-08 05:53:11 +00:00
Rafael Espindola 8d13b213d4 Simplify handling of size relocations.
This is possible now that getSize is not a template.

llvm-svn: 321900
2018-01-05 21:41:17 +00:00
Rafael Espindola 73584cb587 Centralize Config->IsRela handling.
This merges the two places were we check Config->IsRela to decide how
to write a relocation addend.

llvm-svn: 321889
2018-01-05 20:08:38 +00:00
Zachary Turner 9e52e50ac0 Fix unhandled switch values.
llvm-svn: 321885
2018-01-05 19:28:39 +00:00
Zachary Turner 6047858270 [PDB] Correctly link S_FILESTATIC records.
This is not a record type that clang currently generates,
but it is a record that is encountered in object files generated
by cl.  This record is unusual in that it refers directly to
the string table instead of indirectly to the string table via
the FileChecksums table.  Because of this, it was previously
overlooked and we weren't remapping the string indices at all.
This would lead to crashes in MSVC when trying to display a
variable whose debug info involved an S_FILESTATIC.

Original bug report by Alexander Ganea

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

llvm-svn: 321883
2018-01-05 19:12:40 +00:00
Martin Storsjo 398425ef7f [COFF] Add a testcase for dllexported symbols via embedded directives
This is in preparation for fixing PR35733.

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

llvm-svn: 321790
2018-01-04 08:06:34 +00:00
Rafael Espindola a3ce1fdaba Inline a function that is only called once. NFC.
llvm-svn: 321780
2018-01-04 01:33:41 +00:00
Rafael Espindola bba410668a Use references for a few arguments that are never null.
llvm-svn: 321772
2018-01-03 23:26:20 +00:00
Rafael Espindola 9cded98ad6 Mention symbol name in error message.
llvm-svn: 321769
2018-01-03 22:55:46 +00:00
Rafael Espindola 7c99c14722 Use getLocation to improve error message.
llvm-svn: 321768
2018-01-03 22:44:58 +00:00
Rafael Espindola 7137b8c298 Update code as this also handles GOT relocations.
llvm-svn: 321738
2018-01-03 16:54:18 +00:00
Rafael Espindola 49422f341a Use a switch. NFC.
llvm-svn: 321737
2018-01-03 16:52:15 +00:00
Rafael Espindola cc333d7400 Refactor duplicated expression.
llvm-svn: 321736
2018-01-03 16:38:46 +00:00
Rafael Espindola 6e102b2fc6 Use a swtich. NFC.
llvm-svn: 321734
2018-01-03 16:29:43 +00:00
Rafael Espindola 28aa6e2bc5 Simplify mips gprel handling.
We normally add checks on the architecture independent Expr instead of
on the architecture dependent relocation type.

llvm-svn: 321733
2018-01-03 16:16:05 +00:00
Hans Wennborg b7f377a863 Docs, release notes: update version to 7.0.0
llvm-svn: 321729
2018-01-03 15:51:31 +00:00
Rafael Espindola b5153ef7e8 Don't assume that size relocations are always constant.
llvm-svn: 321688
2018-01-03 03:58:58 +00:00
Rafael Espindola 4b2350d79b Produce relocations with weak undef if the section is RW.
If a section is RW there is no reason to drop a relocation with a weak
undefined symbol.

llvm-svn: 321684
2018-01-03 01:24:58 +00:00
Rafael Espindola 2640a0a5e5 Align SHT_NOBITS sections is they are the first on a PT_LOAD.
We normally want to ignore SHT_NOBITS sections when computing
offsets. The sh_offset of section itself seems to be irrelevant and

- If the section is in the middle of a PT_LOAD, it will make no
  difference on the computed offset of the followup section.

- If it is in the end of a PT_LOAD, we want to avoid its alignment
  changing the offset of the followup sections.

The issue is if it is at the start of the PT_LOAD. In that case we do
have to align it so that the following sections have congruent address
and offset module the page size. We were not handling this case.

This should fix freebsd kernel link.

llvm-svn: 321657
2018-01-02 16:46:30 +00:00
George Rimar edb61167e5 [ELF] - Add missing dynamic tags when producing output with IRelative relocations only.
This is "Bug 35751 - .dynamic relocation entries omitted if output
contains only IFUNC relocations"

We have InX::RelaPlt and InX::RelaIPlt synthetic sections for PLT relocations.
They are usually live in rela.plt section. Problem appears when InX::RelaPlt
section is empty. In that case we did not produce normal set of dynamic tags
required, because logic was written in the way assuming we always have
non-IRelative relocations in rela.plt.

Patch fixes the issue.

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

llvm-svn: 321600
2017-12-31 07:42:54 +00:00
George Rimar 3208588e7a [ELF] - Remove excessive checks. NFC.
This was raised in comments for D41592.
With current code we always assign parent
section for Rel[a] sections like
InX::RelaPlt or InX::RelaDyn, so checking
their parent for null is excessive.

llvm-svn: 321581
2017-12-30 08:40:45 +00:00
Shoaib Meenai 0c958fba14 [ELF] Only scan executables for shlib undefined symbols
If using a version script with a `local: *` in it, symbols in shared
libraries will still get default visibility if another shared library on
the link line has an undefined reference to the symbol. This is quite
surprising. Neither bfd nor gold have this behavior when linking a
shared library, and none of LLD's tests fail without this behavior, so
it seems safe to limit scanShlibUndefined to executables.

As far as executables are concerned, gold doesn't do any automatic
default visibility marking, and bfd issues a link error about a shared
library having a reference to a hidden symbol rather than silently
giving that symbol default visibility. I think bfd's behavior here is
preferable to LLD's, but that's something to be considered in a
follow-up.

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

llvm-svn: 321578
2017-12-30 08:00:44 +00:00
Benjamin Kramer 61085ca999 Update lld tests after r321526.
llvm-svn: 321529
2017-12-28 17:20:41 +00:00
Rui Ueyama a63eed0f80 Do not parse the same /export string more than once.
Differential Revision: https://reviews.llvm.org/D41607

llvm-svn: 321513
2017-12-28 07:41:19 +00:00
Bob Haarman e90ac016e7 [COFF] support /ignore:4217
Summary:
lld-link accepts link.exe's /ignore option, but used to ignore
it. This can lead to semantic differences when warnings are treated as
fatal errors. One such case is when we resolve an __imp_ symbol to a
local definition. We emit a warning in that case, which /wx turns into
a fatal. This change makes lld-link accept /ignore:4217 to suppress
that warning, so that code that links with link.exe /wx /ignore:4217
links with lld-link, too.

Fixes PR35762.

Reviewers: rnk, ruiu

Reviewed By: ruiu

Subscribers: llvm-commits

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

llvm-svn: 321512
2017-12-28 07:02:13 +00:00
Rafael Espindola 465e7c94ed Allow copy relocation with -z notext.
This makes adjustExpr a bit simpler too IMHO.

It seems that some of the complication around relocation processing
is that we are trying to create copy relocations too early. It seems
we could handle a few simple cases first and continue.

llvm-svn: 321507
2017-12-28 00:23:49 +00:00
Rafael Espindola e2e070c6c4 Don't try to preempt protected symbols with -z notext.
I will send a followup patch removing the FIXME this patch adds.

llvm-svn: 321499
2017-12-27 20:53:13 +00:00
George Rimar a0ab8d7a58 [ELF] - Allow relocation to a weak undefined symbol when -z notext is given.
Previously we failed to resolve them when produced executables:
"relocation R_X86_64_32 cannot be used against shared object; recompile with -fPIC"

Patch fixes it so that we resolve them to 0 for executables. 
And for -shared case we still should produce the relocation.

This finishes fixing PR35720.

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

llvm-svn: 321473
2017-12-27 07:29:55 +00:00
Rui Ueyama 17a3077f59 Make it clear where is a placeholder for later binary patching.
This is an aesthetic change to represent a placeholder for later
binary patching as "0, 0, 0, 0" instead of "0x00, 0x00, 0x00, 0x00".
The former is how we represent it in COFF, and I found it easier to
read than the latter.

llvm-svn: 321471
2017-12-27 06:54:18 +00:00
Rui Ueyama 130eb04689 [COFF] Do not parse args twice if no rsp files exists
Patch by Takuto Ikuta.

This patch reduces link time of chromium's blink_core.dll in component
build. Total size of input argument in .directives become nearly 300MB
in the build and no rsp file is used. Speedup link by skipping duplicate
parsing.

On my desktop machine, 4 times stats are like below. Improved around 15%.

This patch
TotalSeconds : 18.408538
TotalSeconds : 17.2996744
TotalSeconds : 17.1053862
TotalSeconds : 17.809777
avg: 17.6558439

master
TotalSeconds : 20.9290504
TotalSeconds : 19.9158213
TotalSeconds : 21.0643515
TotalSeconds : 20.8775831
avg: 20.696701575

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

llvm-svn: 321470
2017-12-27 06:08:10 +00:00
Rafael Espindola 63a4a98e4c Add a comment about subtracting two non abs symbols. NFC.
llvm-svn: 321458
2017-12-26 18:11:14 +00:00
Rui Ueyama c67d6b2da0 Simplify script lexer.
Differential Revision: https://reviews.llvm.org/D41577

llvm-svn: 321453
2017-12-26 10:13:10 +00:00
Rafael Espindola a9c490b71d Allow relocations in rw sections to create plt entries.
If a relocation cannot be implemented by the dynamic linker and the
section is rw, allow creating a plt entry to use as the function
address as if the section was ro.

This matches bfd and gold. It also matches our behavior with -z
notext.

llvm-svn: 321430
2017-12-24 19:02:10 +00:00
Rafael Espindola 6a97f80755 Fix output section offset and contents when linker script uses memory region and data commands.
Advance the memory region offset when handling a linker script data
command such as BYTE or LONG.  Failure to advance the offset results
in corrupted output with overlapping sections.

Update tests to check for this combination of both a) memory regions
and b) data commands.

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

Patch by Owen Shaw!

llvm-svn: 321418
2017-12-24 03:46:35 +00:00
Rafael Espindola 9a84f6b954 Detemplate reportDuplicate.
We normally avoid "switch (Config->EKind)", but in this case I think
it is worth it.

It is only executed when there is an error and it allows detemplating
a lot of code.

llvm-svn: 321404
2017-12-23 17:21:39 +00:00
George Rimar d70da0e55f [ELF] - Fix mistype in comment. NFC.
llvm-svn: 321403
2017-12-23 16:34:58 +00:00
George Rimar 3bdf6baa25 [ELF] - Allow using PLT relocations when "-z notext" is given.
This is part of PR35720.

Currently LLD allows dynamic relocations against text when -z notext is given.
Though for non-PIC relocations like R_X86_64_PC32 that does not work,
we produce "relocation R_X86_64_PC32 cannot be used against shared object;"
error because they may overflow in runtime.

Solution implemented is to use PLT for them.

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

llvm-svn: 321400
2017-12-23 09:00:37 +00:00
Rafael Espindola 9f37543cf8 Detemplate isCompatible(). NFC.
llvm-svn: 321393
2017-12-23 00:04:34 +00:00
Rafael Espindola 9cbb6dd1fc Result of subtracting two symbols should be absolute.
When two linker script symbols are subtracted, the result should be absolute.

This is the behavior of binutils' ld.

Patch by Erick Reyes!

llvm-svn: 321390
2017-12-22 21:55:28 +00:00
Sam Clegg 5cfffbc875 [WebAssembly] Increase test coverage for weak aliases
LLVM-side is now fixed

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

llvm-svn: 321385
2017-12-22 20:35:19 +00:00
Rafael Espindola bb2f9081dc Note that the test .tar.xz has been updated.
The difference is the avoidance of a few absolute paths. Thanks to
Galina Kistanova for the patch.

llvm-svn: 321381
2017-12-22 19:37:32 +00:00
Rafael Espindola b9a18fd0a2 Define isUndefWeak inline.
This small function was showing up in the profile. Defining it inline
gives about 0.3% speedup.

llvm-svn: 321317
2017-12-21 22:26:44 +00:00
Rafael Espindola a973cc2282 Call isStaticLinkTimeConstant only once per relocation.
It is a pretty expensive function. Some of the speedups:

clang: 1.92%
chrome: 1.15%
linux-kernel: 1.40%
llvm-svn: 321311
2017-12-21 21:45:35 +00:00
Sam Clegg 86109f63c8 [WebAssembly] Add extra test for weak global symbols
Summary:
Currently the test only checks behaviour for weak function symbols.

Should be good to merge straight away?

Reviewers: sbc100

Reviewed By: sbc100

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

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

llvm-svn: 321308
2017-12-21 21:15:00 +00:00
Sam Clegg 1cf31bbca5 [WebAssmebly] Fix references to weak aliases
Corresponding LLVM change: https://reviews.llvm.org/D41472

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

llvm-svn: 321244
2017-12-21 02:43:39 +00:00
Sam Clegg c6e4d73f31 [WebAssembly] Improve weak alias tests cases
Based on: https://github.com/WebAssembly/tool-conventions/issues/34

Currently weak-alias-overide.ll exhibits incorrect
behaviour in that call_direct() calls the wrong function.

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

llvm-svn: 321241
2017-12-21 02:30:09 +00:00
Rafael Espindola ce3b52c186 Pass an InputFile to the InputSection constructor.
This simplifies toRegularSection and reduces the noise in a followup
patch.

llvm-svn: 321240
2017-12-21 02:11:51 +00:00
Rafael Espindola 604032729c Convert a few more InputFiles to references.
We use null files in sections to represent linker created sections,
so ObjFile<ELFT> is never null.

llvm-svn: 321238
2017-12-21 02:03:39 +00:00
Rafael Espindola 5c73c49c9f Detemplate createCommentSection.
It was only templated so it could create a dummy section header that
was immediately parsed back.

llvm-svn: 321235
2017-12-21 01:21:59 +00:00
Rafael Espindola bb3198949f Use dyn_cast instead of dyn_cast_or_null.
There should be no null sections in InputSections.

llvm-svn: 321219
2017-12-20 20:46:08 +00:00
Rafael Espindola 920d7d80e2 clang-format. NFC.
llvm-svn: 321216
2017-12-20 19:59:47 +00:00
Rafael Espindola efb483f63a Pass a InputFile reference to the Lazy constructor. NFC.
llvm-svn: 321199
2017-12-20 18:01:32 +00:00
Rafael Espindola 8276f1bda6 Use a reference to a file in the LazyArchive symbol.
It is never null.

llvm-svn: 321198
2017-12-20 17:59:43 +00:00
Rafael Espindola 2e5c71eadc LazyObject's file is never null, use a reference.
llvm-svn: 321196
2017-12-20 17:52:36 +00:00