Commit Graph

10330 Commits

Author SHA1 Message Date
Rui Ueyama 72a9a2321f [WebAssembly] Remove a second parameter from toString().
toString(T) is a stringize function for an object of type T. Each type
that has that function defined should know how to stringize itself, and
there should be one string representation of an object. Passing a
"supplemental" argument to toString() breaks that princple. We shouldn't
add a second parameter to that function.

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

llvm-svn: 327182
2018-03-09 22:59:34 +00:00
Fangrui Song 17208f1ef9 [ELF] Add elf64lppc emulation.
Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 327177
2018-03-09 22:11:46 +00:00
Fangrui Song 0c483024e4 [ELF] Convert {read,write}*be to endianness-aware read/write.
Subscribers: emaste, nemanjai, arichardson, kbarton, llvm-commits

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

llvm-svn: 327156
2018-03-09 18:03:22 +00:00
Peter Collingbourne 04ff122632 ELF: Do not create multiple thunks for the same virtual address.
This avoids creating multiple thunks for symbols with aliases or which
belong to ICF'd sections. This patch reduces the size of Chromium for
Android by 260KB (0.8% of .text).

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

llvm-svn: 327154
2018-03-09 17:54:43 +00:00
Nicholas Wilson 2e55ee77e2 [WebAssembly] Handle weak undefined functions with a synthetic stub
This error case is described in Linking.md. The operand for call requires
generation of a synthetic stub.

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

llvm-svn: 327151
2018-03-09 17:06:38 +00:00
Nicholas Wilson ebda41f812 [WebAssembly] Refactor order of creation for SyntheticFunction
Previously we created __wasm_call_ctors with null InputFunction, and
added the InputFunction later. Now we create the SyntheticFunction with
null body, and set the body later.

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

llvm-svn: 327149
2018-03-09 16:43:05 +00:00
David Zarzycki 3e77b20dba [CMake] Properly conditionalize installation of lld libraries
In what appears to be a copy-and-paste error, lld currently only
installs libraries if the lld tools are configured to build.

Instead, lld should allow the libraries to be installed even if the lld
tools are not being built. Additionally, if users want to only install
the tools and not the libraries, the LLVM way of doing that is by
checking for LLVM_INSTALL_TOOLCHAIN_ONLY.

This fixes PR35960.

llvm-svn: 327126
2018-03-09 13:09:36 +00:00
Nico Weber 0771c604c9 [lld-link] Add support for /ignore:4037.
Fixes PR36657.
https://reviews.llvm.org/D44286

llvm-svn: 327124
2018-03-09 12:41:04 +00:00
Zachary Turner b575f46b6d Resubmit "Write a hash of the executable into the PE timestamp fields."
This fixes the broken tests that were causing failures.  The tests
before were verifying that the time stamp was 0, but now that we
are actually writing a timestamp, I just removed the match against
the timestamp value.

llvm-svn: 327049
2018-03-08 19:33:47 +00:00
George Rimar 1136ec64e8 [ELF] - Fix crash relative to SHF_LINK_ORDER sections.
Our code assumes all input sections in an output SHF_LINK_ORDER
section has SHF_LINK_ORDER flag. We do not check that and that can cause a crash.

That happens because we call 
std::stable_sort(Sections.begin(), Sections.end(), compareByFilePosition);, 
where compareByFilePosition predicate does not expect to see
null when calls getLinkOrderDep. 

The same might happen when sections refer to non-regular sections. 
Test cases demonstrate the issues, patch fixes them.

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

llvm-svn: 327006
2018-03-08 15:06:58 +00:00
George Rimar 9e2c8a9db1 [ELF] - Support "INSERT AFTER" statement.
This implements INSERT AFTER in a following way:

During reading scripts it collects all insert statements.
After we done and read all files it inserts statements into script commands list.

With that:
* Rest of code does know nothing about INSERT.
* Approach is straightforward and have no visible limitations.
* It is also easy to support INSERT BEFORE (was seen in clang code once).
* Should work for PR35877 and similar cases.

Cons:
* It assumes we have "main" scripts that describes sections.

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

llvm-svn: 327003
2018-03-08 14:54:38 +00:00
Hans Wennborg aee5881a85 [COFF] Make the DOS stub a real DOS program
It only adds a few bytes and is nice for backward compatibility.

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

llvm-svn: 327001
2018-03-08 14:27:28 +00:00
Heejin Ahn 2dce27d852 [WebAssembly] Add except_ref as a first-class type
Summary:
Add except_ref as a first-class type, according to the [[https://github.com/WebAssembly/exception-handling/blob/master/proposals/Level-1.md | Level 1 exception handling proposal ]].
Companion to D43706.

Reviewers: sbc100

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

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

llvm-svn: 326986
2018-03-08 04:06:57 +00:00
Rui Ueyama e66d7a798f Return early. NFC.
We don't need to handle an object file having more than one symbol table,
so as soon as we find the first one, we can process it and then return
from the function.

llvm-svn: 326977
2018-03-08 01:22:30 +00:00
Sam Clegg 7f81418183 [WebAssembly] Honor --allow-undefined even for explicit exports
When a symbol is exported via --export=foo but --allow-undefined
is also specified, the symbol is now allowed to be undefined.
Previously we were special casing such symbols.

This combinations of behavior is exactly what emescripten
requires. Although we are trying hard not to allow emscripten
specific features in lld, this one makes sense.

Enforce this behavior by added this case to test/wasm/undefined.ll.

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

llvm-svn: 326976
2018-03-08 01:16:05 +00:00
Rui Ueyama c13d858b6d Simplify LazyobjFile and readElfSymbols.
addElfSymbols and readJustSymbolsFile still has duplicate code, but
I didn't come up with a good idea to eliminate them. Since this patch
is an improvement, I'm sending this for review.

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

llvm-svn: 326972
2018-03-08 01:05:58 +00:00
Fangrui Song d8139348fb [ELF] Update test/ELF/eh-frame-hdr-augmentation.s
llvm-svn: 326944
2018-03-07 21:25:58 +00:00
Zachary Turner 0b4af0434b Revert "Write a hash of the executable into the PE timestamp fields."
This is breaking a couple of tests, so I'm reverting temporarily
until I can get everything resolved properly.

llvm-svn: 326943
2018-03-07 21:22:10 +00:00
Rui Ueyama 301305fd3d Use exact uint32_t for uint32_t ELF field. NFC.
llvm-svn: 326934
2018-03-07 19:25:36 +00:00
Rui Ueyama 5aa2db1e12 Initialize a member in C++11 style. NFC.
llvm-svn: 326933
2018-03-07 19:25:27 +00:00
Matt Morehouse 915b4dbf8a [lld] Attempt to appease buildbot.
r326903 broke the conflict-debug-variable.s test.

llvm-svn: 326931
2018-03-07 19:18:14 +00:00
Zachary Turner 69f3347b56 Write a hash of the executable into the PE timestamp fields.
Windows tools treats the timestamp fields as sort of a build id,
using it to archive executables on a symbol server, as well as
for matching executables to PDBs.  We were writing 0 for these
fields, which would cause symbol servers to break as they are
indexed in the symbol server based on this value.

Although the field is called timestamp, it can really be any
value that is unique per build, so to support reproducible builds
we use a hash of the executable here.

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

llvm-svn: 326920
2018-03-07 18:13:41 +00:00
George Rimar bf3c384673 [ELF] - Adjust rangeToString to report ranges in a different format.
It was raised during the review of D43819.

LLD usually use [X, Y] for reporting ranges, like below:
"relocation R_386_16 out of range: 65536 is not in [0, 65535]"

Patch changes rangeToString() to do the same.

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

llvm-svn: 326918
2018-03-07 17:54:25 +00:00
Rui Ueyama b0084a0eee Revert r326911: Improve --warn-symbol-ordering.
This reverts commit r326911 because it was committed by accident.

llvm-svn: 326914
2018-03-07 17:24:46 +00:00
Rui Ueyama e1847da924 Rename Indent{1,2} -> Indent{8,16}.
llvm-svn: 326912
2018-03-07 17:15:15 +00:00
Rui Ueyama ebfab927d9 Improve --warn-symbol-ordering.
Summary:
I originally tried to simplify code and then noticed that lld doesn't
do what it tells to the user by warn(). It says "unable to order
discarded symbol" but it actually can for sections eliminated by ICF.
With this patch, lld doesn't sort such sections.

Reviewers: jhenderson, rafael

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 326911
2018-03-07 17:15:06 +00:00
James Henderson cb4c19f315 [ELF] Prevent crash when reporting errors if debug line cannot be parsed
LLD uses the debug info and debug line sections to determine the location of
e.g. references to undefined symbols, when producing error messages. In the
event that debug info was present, but debug line parsing failed for some
reason, then a nullptr would end up being dereferenced by the location-lookup
code.

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

Reviewers: grimar
llvm-svn: 326899
2018-03-07 15:22:58 +00:00
Nicholas Wilson dbd90bf8d1 [WebAssembly] Run clang-format. NFC
llvm-svn: 326896
2018-03-07 13:28:16 +00:00
George Rimar 527bfd7a48 [ELF] - Recommit r326892,r326893 "[ELF] - Report LMA region overflows."
With fix: add missing "RUN:" prefix to test case.

Original commit message:
We do not report LMA region overflows currently.
Both GNU linkers do that. The patch implements it.

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

llvm-svn: 326895
2018-03-07 12:44:18 +00:00
George Rimar 06846c2251 [ELF] - Revert r326892, r326893.
Bots are still unhappy:
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/26259

llvm-svn: 326894
2018-03-07 12:33:00 +00:00
George Rimar 64b2ba1f81 [ELF] - Fix build bot after r326892 "[ELF] - Report LMA region overflows."
Removed excessive line from testcase.

llvm-svn: 326893
2018-03-07 12:16:26 +00:00
George Rimar 97e054e00d [ELF] - Report LMA region overflows.
We do not report LMA region overflows currently.
Both GNU linkers do that. The patch implements it.

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

llvm-svn: 326892
2018-03-07 11:54:30 +00:00
George Rimar 54baa5f45f [ELF] - Allow discarding .hash and .gnu.hash from linker script.
Currently, LLD segfaults when linker script attempts to discard
one of the hash sections. This patch fixes that.

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

llvm-svn: 326891
2018-03-07 11:47:15 +00:00
Nicholas Wilson 06e0d17cf5 [WebAssembly] Remove duplicated line of code and unreachable check. NFC
Differential Revision: https://reviews.llvm.org/D44146

llvm-svn: 326888
2018-03-07 11:15:47 +00:00
Nicholas Wilson 8269f37ce6 [WebAssembly] Use StringSaver to retain ownership of ctor function body. NFC
Differential Revision: https://reviews.llvm.org/D44149

llvm-svn: 326885
2018-03-07 10:37:50 +00:00
Rui Ueyama 9f0c36e7a9 Split long lines in a test file.
llvm-svn: 326850
2018-03-07 00:07:26 +00:00
Rui Ueyama 9e0171fbb6 Do not create temporary strings just to print out spaces. NFC.
llvm-svn: 326841
2018-03-06 22:48:46 +00:00
Rui Ueyama 09fcd4c34c Implement --just-symbols.
Differential Revision: https://reviews.llvm.org/D39348

llvm-svn: 326835
2018-03-06 21:25:37 +00:00
Rafael Espindola ddb33c0961 Improve duplicated version handling.
It looks like the problem that caused us to originally warn instead of
error was that of a symbol being assigned to the same version twice.

Now we don't warn if a symbol is assigned to the same version twice,
but error if it is assigned to multiple.

This fixes pr28342.

llvm-svn: 326813
2018-03-06 17:05:12 +00:00
Rui Ueyama 067617f9ba Remove redundant casts.
llvm-svn: 326753
2018-03-05 23:50:45 +00:00
Nicholas Wilson 94d3b16101 [WebAssembly] Reorder reloc sections to come after symtab
This matches LLVM change D43940.

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

llvm-svn: 326693
2018-03-05 12:33:58 +00:00
George Rimar 162d436c8e [ELF] - Support moving location counter when MEMORY is used.
We do not expand memory region correctly for following scripts:

.foo.1 : 
 {
   *(.foo.1)
   . += 0x1000;
 } > ram
Patch generalizes expanding of output sections and memory
regions in one place and fixes the issue.

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

llvm-svn: 326688
2018-03-05 10:54:03 +00:00
George Rimar 7b91e2133e [ELF] - Report location for div/mod by zero.
"division by zero" or "modulo by zero" are not
very informative errors and even probably confusing
as does not let to know that error is coming from linker script.
Patch adds location reporting.

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

llvm-svn: 326686
2018-03-05 10:02:44 +00:00
Rafael Espindola e3a6062844 Simplify. NFC.
Since r321982 we don't set VersionId in scanShlibUndefined, which
makes InVersionScript redundant.

llvm-svn: 326641
2018-03-03 02:13:50 +00:00
Rui Ueyama e89b0ef0a0 [WebAssembly] Simplify createDefined. NFC.
Differential Revision: https://reviews.llvm.org/D43849

llvm-svn: 326615
2018-03-02 21:19:55 +00:00
Nicholas Wilson 36f14f41e6 [WebAssembly] Rename global types to match the notation in the spec
llvm-svn: 326583
2018-03-02 14:54:34 +00:00
Nicholas Wilson f2f6d5e03b [WebAssembly] Export non-hidden defined data symbols via wasm globals
This fixes a TODO introduced in rLLD325861.

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

llvm-svn: 326581
2018-03-02 14:51:36 +00:00
Nicholas Wilson f6dbc2edee [WebAssembly] Pass ownership of body to SyntheticFunction. NFC
This avoids the Writer unnecessarily having a member to retain ownership
of the function body.

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

llvm-svn: 326580
2018-03-02 14:48:50 +00:00
Nicholas Wilson cb81a0c9d9 [WebAssembly] Add validation for init function signature
Differential Revision: https://reviews.llvm.org/D43947

llvm-svn: 326579
2018-03-02 14:46:54 +00:00
George Rimar 97785af464 [ELF] - Report error when memory region is overflowed by data commands.
LLD can not catch a memory area overflow when using a data command.
If we have the script below:

.foo : 
{
  *(.foo)
  BYTE(0x1)
} > ram

where BYTE overflows the ram region, we do not report it currently.
Patch fixes that.

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

llvm-svn: 326545
2018-03-02 08:11:58 +00:00