Commit Graph

3898 Commits

Author SHA1 Message Date
Sam Clegg 2e25e896fb [WebAssembly] Improve wasm test cases
Add test for weakly defined symbols with the same name

Improve test for call-indirect to include the same call in two
different objects. This lays the ground work to improve the
output via de-duplicating the indirect call table:
   https://reviews.llvm.org/D40989

Also make all tests consistently pass -mtriple rather than
declaring in the sources.

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

llvm-svn: 320172
2017-12-08 18:37:44 +00:00
Sam Clegg 2c096bacc6 [WebAssembly] Add --no-entry argument
This adds a `--no-entry` argument to wasm LLD used to
suppress the default `_start` entry point.

Patch by Nicholas Wilson!

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

llvm-svn: 320167
2017-12-08 17:58:25 +00:00
Alexander Richardson f5ef4e5616 Print the bad value and required alignment for unaligned relocations
Reviewers: ruiu, grimar

Reviewed By: ruiu

Subscribers: emaste, javed.absar, llvm-commits

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

llvm-svn: 320147
2017-12-08 14:53:14 +00:00
Rui Ueyama 2569edd9b8 Fix a test that didn't actually test anything.
llvm-svn: 320117
2017-12-08 00:00:37 +00:00
Alexander Richardson 0ce9effaa1 Fix the test from r320056 on Windows
llvm-svn: 320058
2017-12-07 16:41:43 +00:00
Alexander Richardson 280252c6d1 [ELF][mips] Print the full file path for files with incompatible ISA
Summary:
I also changed the message to print both the ISA and the the architecture
name for incompatible files. Previously it would be quite hard to find the
actual path of the incompatible object files in projects that have many
object files with the same name in different directories.

Reviewers: atanasyan, ruiu

Reviewed By: atanasyan

Subscribers: emaste, sdardis, llvm-commits

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

llvm-svn: 320056
2017-12-07 16:08:59 +00:00
Igor Kudrin 892b14658e [ELF] Handle multiple "--version-script" options.
Both ld.bfd and ld.gold can handle this case.

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

llvm-svn: 320006
2017-12-07 03:25:39 +00:00
Sam Clegg 31de2f0ccf [WebAssembly] Add -u/--undefined argument handling
Adds a new argument to wasm-lld, `--undefined`, with
similar semantics to the ELF linker. It pulls in symbols
from files contained within a `.a` archive, forcing them
to be included even if the translation unit would not
otherwise be pulled in.

Patch by Nicholas Wilson

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

llvm-svn: 320004
2017-12-07 03:19:53 +00:00
Sam Clegg 74fe0ba105 [WebAssembly] Fix symbol exports under -r/--relocatable
This change cleans up the way wasm exports and globals
are generated, particualrly for -r/--relocatable where
globals need to be created and exported in order for
output relocations which reference them.

Remove the need for a per file GlobalIndexOffset and
instead set the output index for each symbol directly.
This simplifies the code in several places.

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

llvm-svn: 320001
2017-12-07 01:51:24 +00:00
Shoaib Meenai 9a5161e056 [COFF] Stop lowercasing paths in messages
It's pretty annoying to have LLD lowercase paths in error messages when
cross-compiling from a case-sensitive filesystem, since e.g. if I want
to examine the problematic object file, I have to perform some manual
case correction instead of just being able to copy the path from the
error message.

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

llvm-svn: 319996
2017-12-07 01:21:27 +00:00
George Rimar ba7afd7043 [ELF] - Show .plt symbols in -Map output.
As mentioned in PR35471, shared functions for which
.plt entry address is used shows up in bfd's map files. 
Patch teaches LLD to do the same.

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

llvm-svn: 319879
2017-12-06 08:36:21 +00:00
Rafael Espindola 3a02234e0d Make this test a bit less confusing.
Before this patch foo and bar have the same address as .text is empty.

llvm-svn: 319877
2017-12-06 03:35:40 +00:00
Rafael Espindola a834b529c3 Fix a crash.
This is a constructed testcase I noticed while working on another
patch.

llvm-svn: 319874
2017-12-06 02:53:43 +00:00
Rui Ueyama c4e50bfc55 Fix broken .gnu.hash section if -no-rosegment is given.
We fill executable sections with trap instructions (0xcc or equivalent).
If a .gnu.hash section was put into an executable segment, we created
corrupted .gnu.hash section. This patch fixes the issue.

llvm-svn: 319863
2017-12-06 00:49:48 +00:00
Evgeniy Stepanov 9ac3154d10 [lld] Fix handling of wildcards in dynamic lists.
Reviewers: pcc, ruiu

Subscribers: llvm-commits, emaste

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

llvm-svn: 319860
2017-12-06 00:14:04 +00:00
Sam Clegg b3974ffda0 [WebAssembly] Fix stack pointer relocations
This line was mistakenly deleted in rL319813

Add a test for stackpointer relocations.

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

llvm-svn: 319828
2017-12-05 20:38:22 +00:00
Peter Smith 732cd8cbef [ELF] Implement scanner for Cortex-A53 Erratum 843419
Add a new file AArch64ErrataFix.cpp that implements the logic to scan for
the Cortex-A53 Erratum 843419. This involves finding all the executable
code, disassembling the instructions that might trigger the erratum and
reporting a message if the sequence is detected.

At this stage we do not attempt to fix the erratum, this functionality
will be added in a later patch. See D36749 for proposal.

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

llvm-svn: 319780
2017-12-05 15:59:05 +00:00
Simon Atanasyan cf333b8a56 [ELF][MIPS] Make some tests tolerant of exact sections addresses. NFC.
llvm-svn: 319776
2017-12-05 15:33:14 +00:00
George Rimar 31cd5da582 Recommit r319747 "[ELF] - Show copy relocated symbols in a --Map file output."
With fix:
Specify -soname for input dso to fix up the .dynstr section
size in different environments.

Original commit message:

As mentioned in PR35471, copied symbols did not show
in --Map output. Patch fixes that.

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

llvm-svn: 319769
2017-12-05 14:23:18 +00:00
Peter Smith 7c40f93f38 [ELF] InX::BssRelRo should check section contents before marking relro
When a linker script is used with a pattern like { *(.bss .bss.*) } the
InX::BssRelRo section will match against .bss.*. By matching on the name
only, in the same way that .data.rel.ro works we prevent this
from happening, but permit scripts that want to explicitly provide
a .bss.rel.ro OutputSection.
    
Differential Revision: https://reviews.llvm.org/D40735

llvm-svn: 319755
2017-12-05 11:15:58 +00:00
George Rimar fe52e0064b [ELF] - Revert r319747 "[ELF] - Show copy relocated symbols in a --Map file output.".
It broke bots:
http://lab.llvm.org:8011/builders/lld-x86_64-darwin13/builds/15570/steps/test_lld/logs/stdio
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/10930/steps/check-lld%20asan/logs/stdio
http://lab.llvm.org:8011/builders/lld-x86_64-win7/builds/16336/steps/test%20lld/logs/stdio

According to outputs,
.dynstr section has different sizes for some reason.

llvm-svn: 319749
2017-12-05 09:38:05 +00:00
George Rimar d9ae97cdb6 [ELF] - Show copy relocated symbols in a --Map file output.
As mentioned in PR35471, copied symbols did not show
in --Map output. Patch fixes that.

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

llvm-svn: 319747
2017-12-05 09:13:45 +00:00
Rui Ueyama be61cc90c4 Make the behavior of the -v option more closer to GNU linkers.
Previously, lld exited with an error status if the only option given to
the command was -v. GNU linkers gracefully exit in that case. This patch
makes lld behave like GNU.

Note that even with this patch, lld's -v and --version options behave
slightly differently than GNU linkers' counterparts. For example,
if you run `ld.bfd -v -v`, the version string is printed out twice.
But that is an edge case that I don't think we need to take care of.

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

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

llvm-svn: 319717
2017-12-05 00:03:41 +00:00
Peter Smith 014be8ac35 [ELF] Add BYTE expression to test case for non-contiguous relro [NFC]
As well as location counter expressions. The data generating expressions
such as BYTE can generate a non-zero sized OutputSection that will report
0 until assignAddresses() is called. Add an example to the existing test
case relro-non-contiguous-script-data.s.

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

llvm-svn: 319648
2017-12-04 10:34:15 +00:00
Sam Clegg 4b27c0554c Reland "[WebAssembly] Add support for visibility flag""
Subscribers: jfb, dschuff, jgravelle-google, aheejin, sunfish

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

llvm-svn: 319627
2017-12-03 02:38:04 +00:00
Heejin Ahn 675147b54d [WebAssembly] Revert r319592 "Add support for visibility flag"
r319488 reportedly broke one of LLVM bots (ubuntu-gcc7.1-werror), and this patch
depends on that patch.
See http://lab.llvm.org:8011/builders/ubuntu-gcc7.1-werror/builds/3369 for
details.

llvm-svn: 319603
2017-12-02 02:05:50 +00:00
Sam Clegg e7487e4c92 [WebAssembly] Add support for visibility flag
Patch by Nicholas Wilson

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

llvm-svn: 319592
2017-12-01 22:37:25 +00:00
Rafael Espindola ba8016d697 Add test for pr35478.
This would have found the regression in r318924.

Thanks to James Henderson for finding the issue!

llvm-svn: 319565
2017-12-01 18:28:12 +00:00
Rafael Espindola b70824c1b8 Revert r318924 Skip over empty sections when checking for contiguous relro
PR35478 https://bugs.llvm.org/show_bug.cgi?id=35478 points out a flaw
in the implementation of r318924 from D40364. The implementation
depends on the Size field being set or the SyntheticSection::empty()
being accurate. These functions are not reliable as some linker script
commands that have yet to be processed may affect the results, causing
some non-zero size sections to be reported as zero size.

I think the first step is to revert r318924 and come up with a better
solution for the underlying problem rather than trying to layer more
heuristics onto the zero sized output section.

Chances are I'll be out of office by the time anyone sees this so feel
free to commit the revert if you agree with me.

Fixes PR35478

Current thoughts on the underlying problem:

Revisiting the motivation for adding the zero size check in the first
place; it was to prevent 0 sized SyntheticSections that a user does
not have full control over from needlessly breaking the PT_GNU_RELRO,
rather than trying to accommodate arbitrarily complex linker
scripts. Looking at the code, it looks like
removeUnusedSyntheticSections() should remove zero sized synthetic
sections. It does, but it doesn't set the Parent to nullptr, this has
the side effect that Sec == InX::BssRelRo->getParent() will make the
parent OutputSection of InX::BssRelRo RelRo even if there is no
InX::BssRelRo.

I tried a quick experiment with setting the Parent to nullptr and this
flushed out a few interesting test failures, it feels like playing
Jenga with every change:

    In the isRelroSection() we have to consider the case where there
    is no .plt and .plt.got but there is a ifunc plt with accompanying
    (ifunc .got or .plt.got)

    The PPC64 has PltHeaderSize == 0. Unfortunately HeaderSize == 0 is
    used to choose between the ifunc plt or normal plt. We seem to get
    away with this at the moment, but tests start to fail when Parent
    is set to nullptr for the .got.plt.

    The InX::BssRelRo and InX::Bss never get their sizes set and they
    are always removed by removeUnusedSyntheticSections(), their
    purpose seems to be as some kind of proxy for add .bss or
    .bss.relro InputSections into their parent OutputSections, they
    therefore don't behave like other SyntheticSections anyway.

My thinking is that some work is needed to make sure that the Sec ==
SyntheticSection->getParent() does a bit more checking before
returning true, particularly for InX::BssRelRo as that has special
behaviour. I'll hope to post something for review as soon as possible.

Patch by Peter Smith!

llvm-svn: 319563
2017-12-01 18:14:14 +00:00
George Rimar 78e27e830d [ELF] - Produce relocation section name consistent with output section name when --emit-reloc used with linker script.
This is for "Bug 35474 - --emit-relocs produces wrongly-named reloc sections".

LLD currently for scripts like:

.text.boot : { *(.text.boot) }
emits relocation section with name .rela.text because does not take
redefined name of output section into account and builds section name
using rules for non-scripted case. Patch fixes this oddness.

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

llvm-svn: 319526
2017-12-01 09:04:52 +00:00
Rui Ueyama cfd32bfad4 Add an additional test for r319503.
llvm-svn: 319518
2017-12-01 04:46:56 +00:00
Reid Kleckner 3e89b08303 Revert "Merge .xdata into .rdata by default"
This reverts commit r318699, it is breaking 32-bit SEH handlers in
Chromium.

llvm-svn: 319508
2017-12-01 01:04:31 +00:00
Rui Ueyama 1cf7f9cc80 Make .gnu.hash section smaller.
Our on-disk hash table was unnecessarily large. The cost of collision is
not high in the .gnu.hash table because each symbol in the .gnu.hash
table has a hash value with it. So, for each collided symbol, the
dynamic linker just compares an integer, which is pretty cheap.

This patch increases the load factor by about 8. Here's a comparison.

  $ readelf --histogram libclangSema.so.6.0.0svn-new-lld
  Histogram for `.gnu.hash' bucket list length (total of 582 buckets):
   Length  Number     % of total  Coverage
        0  11         (  1.9%)
        1  35         (  6.0%)      1.5%
        2  93         ( 16.0%)      9.5%
        3  108        ( 18.6%)     23.4%
        4  121        ( 20.8%)     44.1%
        5  86         ( 14.8%)     62.6%
        6  63         ( 10.8%)     78.8%
        7  38         (  6.5%)     90.2%
        8  18         (  3.1%)     96.4%
        9  6          (  1.0%)     98.7%
       10  3          (  0.5%)    100.0%

  $ readelf --histogram libclangSema.so.6.0.0svn-old-lld
  Histogram for `.gnu.hash' bucket list length (total of 4093 buckets):
   Length  Number     % of total  Coverage
        0  1498       ( 36.6%)
        1  1545       ( 37.7%)     37.7%
        2  712        ( 17.4%)     72.5%
        3  251        (  6.1%)     90.9%
        4  66         (  1.6%)     97.3%
        5  16         (  0.4%)     99.3%
        6  5          (  0.1%)    100.0%

  $ readelf --histogram libclangSema.so.6.0.0svn-bfd
  Histogram for `.gnu.hash' bucket list length (total of 1004 buckets):
   Length  Number     % of total  Coverage
      0  92         (  9.2%)
        1  227        ( 22.6%)      9.8%
        2  266        ( 26.5%)     32.6%
        3  222        ( 22.1%)     61.2%
        4  115        ( 11.5%)     81.0%
        5  55         (  5.5%)     92.8%
        6  21         (  2.1%)     98.2%
        7  6          (  0.6%)    100.0%

  $ readelf --histogram libclangSema.so.6.0.0svn-gold
  Histogram for `.gnu.hash' bucket list length (total of 2053 buckets):
   Length  Number     % of total  Coverage
        0  671        ( 32.7%)
        1  709        ( 34.5%)     30.4%
        2  470        ( 22.9%)     70.7%
        3  141        (  6.9%)     88.9%
        4  54         (  2.6%)     98.2%
        5  5          (  0.2%)     99.2%
        6  3          (  0.1%)    100.0%

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

llvm-svn: 319503
2017-11-30 23:59:40 +00:00
Rafael Espindola 279e5fa715 Add missing test. NFC.
We had no tests for what PROVIDE should do if there is a shared symbol
with the same name.

In both bfd and our existing implementation PROVIDE wins. Add a test
for that.

llvm-svn: 319486
2017-11-30 22:29:14 +00:00
Rafael Espindola 477ff12411 Error on -no-define-common if the output is not relocatable.
The ELF spec says

Symbols with section index SHN_COMMON may appear only in relocatable
objects.

Currently lld can produce file that break that requirement.

llvm-svn: 319473
2017-11-30 20:46:33 +00:00
Rafael Espindola de38b3d22f Handle copy relocations in symbol assignments.
When a linker script has "foo = bar" and bar is the result of a copy
relocation foo should point to the same location in .bss.

This is part of a growing evidence that copy relocations should be
implemented by using replaceSymbol to replace the SharedSymbol with a
Defined.

llvm-svn: 319449
2017-11-30 17:51:10 +00:00
Rafael Espindola 568ee2c089 Don't crash on invalid.
llvm-svn: 319404
2017-11-30 06:18:31 +00:00
Rafael Espindola 8ce6db0c4b Error instead of ignoring broken debug info.
Thanks to Davide for noticing.

llvm-svn: 319401
2017-11-30 05:37:35 +00:00
Sam Clegg b862159683 [WebAssembly] Allow function signature checking at link time
This change allows checking of function signatures but
does not yes enable it by default.  In this mode, linking
two objects that were compiled with a different signatures
for the same function will produce a link error.

New options for enabling and disabling this feature have been
added: (--check-signatures/--no-check-signatures).

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

llvm-svn: 319396
2017-11-30 01:40:08 +00:00
Rafael Espindola e10568364e Fix reloc section alignment in test.
This should fix the ubsan bot.

We still have to fix lld to produce a clean error on unaligned reloc
sections.

llvm-svn: 319385
2017-11-29 23:39:12 +00:00
Rafael Espindola f893396d1b Don't crash on broken debug info.
llvm-svn: 319367
2017-11-29 22:09:16 +00:00
Rui Ueyama 215286f2a4 [LLD] [COFF] Support ENTRY and SUBSYSTEM in .drectve sections
Adds support for "/ENTRY" and "/SUBSYSTEM" linker options in .drectve
sections. Some Mozilla binaries were using these directives and MSVC
link.exe appears to allow them. No attempt is made to reconcile these
with the options on the command line.

Patch by David Major!

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

llvm-svn: 319356
2017-11-29 20:46:13 +00:00
Peter Smith 31dddc97ae [ELF][AArch64] Add support for AArch64 range thunks.
The AArch64 unconditional branch and branch and link instructions have a
maximum range of 128 Mib. This is usually enough for most programs but
there are cases when it isn't enough. This change adds support for range
extension thunks to AArch64. For pc-relative thunks we follow the small
code model and use ADRP, ADD, BR. This has a limit of 4 gigabytes.

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

llvm-svn: 319307
2017-11-29 11:15:12 +00:00
Martin Storsjo 0010707e1c [COFF] Don't export symbols that have corresponding __imp_ symbols
GNU ld has got an exception for such symbols, and mingw-w64
occasionally uses that exception to avoid exporting symbols in cases
where they otherwise aren't caught by the other exclusion mechanisms.

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

llvm-svn: 319291
2017-11-29 05:50:49 +00:00
Douglas Yung ac8a9a005e Change Requires to REQUIRES so that it works properly.
llvm-svn: 319251
2017-11-28 23:15:20 +00:00
Rafael Espindola 97d05f95b9 Copy the visibility in copyFrom.
This is simpler and matches bfd's behavior on the changed test.

llvm-svn: 319248
2017-11-28 23:06:09 +00:00
Rafael Espindola 33e023070f Expand test a bit.
Also make it more reliable by not depending on the order of the
symbols.

This makes the next patch easier to read.

llvm-svn: 319246
2017-11-28 23:03:14 +00:00
Peter Collingbourne bcf7f290ff COFF: Do not add symbols in discarded sections to SEH handler list.
Differential Revision: https://reviews.llvm.org/D40576

llvm-svn: 319229
2017-11-28 21:30:05 +00:00
Rafael Espindola f70502d3a6 Bring r319051 back.
It had been reverted because it depended on r319008 which has been
recommitted.

Original message:

Add a missing test.

We were not testing that we correctly handled a .o with a weak symbol
after a .so.

llvm-svn: 319217
2017-11-28 20:21:44 +00:00
Rafael Espindola 1d4b3023dc Bring back r319008.
This includes a fix to mark copy reloc aliases as used.

Original message:

[ELF] Do not keep symbols if they referenced only from discarded sections.

This patch also ensures that in case of "--as-needed" is used,
DT_NEEDED entries are not created if they are required only by
these eliminated symbols.

llvm-svn: 319215
2017-11-28 20:17:58 +00:00