Commit Graph

216 Commits

Author SHA1 Message Date
Sam Clegg c729c1b47d [WebAssembly] Initial support for LTO
Differential Revision: https://reviews.llvm.org/D47162

llvm-svn: 333570
2018-05-30 18:07:52 +00:00
Sam Clegg e9ce661e32 [WebAssembly] Add support for response file parsing
Differential Revision: https://reviews.llvm.org/D47500

llvm-svn: 333499
2018-05-30 03:51:56 +00:00
Sam Clegg fb983cda8a [WebAssembly] Add option to remove LEB padding at relocate sites
This change adds the ability for lld to remove LEB padding from
code section. This effectively shrinks the size of the resulting
binary in proportion to the number of code relocations.

Since there will be a performance cost this is currently only active for
-O1 and above. Some toolchains may instead want to perform this
compression as a post linker step (for example running a binary through
binaryen will automatically compress these values).

I imagine we might want to make this the default in the future.

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

llvm-svn: 332783
2018-05-18 23:28:05 +00:00
Benjamin Kramer 5455038d98 [lld] Make helpers static. NFC.
llvm-svn: 332408
2018-05-15 22:01:54 +00:00
Sam Clegg 65d6380cd6 [WebAssembly] Allow signautre of entry function to be flexible
Since we a no longer using this function for the wasm start
section we don't actually care what its signature is.

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

llvm-svn: 332308
2018-05-14 23:01:16 +00:00
Sam Clegg 668447677a [WebAssembly] Add a flag to control merging data segments
Merging data segments produces smaller code sizes because each segment
has some boilerplate. Therefore, merging data segments is generally the
right approach, especially with wasm where binaries are typically
delivered over the network.

However, when analyzing wasm binaries, it can be helpful to get a
conservative picture of which functions are using which data
segments[0]. Perhaps there is a large data segment that you didn't
expect to be included in the wasm, introduced by some library you're
using, and you'd like to know which library it was. In this scenario,
merging data segments only makes the analysis worse.

Alternatively, perhaps you will remove some dead functions by-hand[1]
that can't be statically proven dead by the compiler or lld, and
removing these functions might make some data garbage collect-able, and
you'd like to run `--gc-sections` again so that this now-unused data can
be collected. If the segments were originally merged, then a single use
of the merged data segment will entrench all of the data.

[0] https://github.com/rustwasm/twiggy
[1] https://github.com/fitzgen/wasm-snip

Patch by Nick Fitzgerald!

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

llvm-svn: 332013
2018-05-10 18:23:51 +00:00
Nico Weber cac2b3349e lld-link: Add --color-diagnostics(={always,never,auto})?, --no-color-diagnostics flags.
This is most useful when using lld-link on a non-Win host (but it might become
useful on Windows too if lld also grows a fansi-escape-codes flag).

Also make the help for --color-diagnostic mention the valid values in ELF and
wasm, and print the flag name with two dashes in diags, since the one-dash form
is seen as a list of many one-letter flags in some contexts.

https://reviews.llvm.org/D46693

llvm-svn: 332012
2018-05-10 18:19:02 +00:00
Sam Clegg 752494bfe3 [WebAssembly] Check function signatures by default
But only produce a warning (for now) unless --fatal-warnings
is passed.

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

llvm-svn: 331574
2018-05-05 01:23:07 +00:00
Sam Clegg a0f095ebd7 [WebAssembly] Add --stack-first option which places the shadow stack at start of linear memory
Fixes https://bugs.llvm.org/show_bug.cgi?id=37181

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

llvm-svn: 331467
2018-05-03 17:21:53 +00:00
Nicholas Wilson 358af38d37 [WebAssembly] Implement -print-gc-sections, to better test GC of globals
Differential Revision: https://reviews.llvm.org/D44311

llvm-svn: 330456
2018-04-20 17:28:12 +00:00
Nicholas Wilson 6c7fe30a1c [WebAssembly] Implement --print-gc-sections for synthetic functions
Enables cleaning up confusion between which name variables are mangled
and which are unmangled, and --print-gc-sections then excersises and
tests that.

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

llvm-svn: 330449
2018-04-20 17:09:18 +00:00
Rui Ueyama 96ba8befa9 [WebAssembly] Remove StackPointerGlobal member variable from the driver.
Since InputGlobal makes a copy of a given object, we can use a temporary
object allocated on the stack here.

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

llvm-svn: 329337
2018-04-05 19:37:48 +00:00
Rui Ueyama 0961218c10 [WebAssembly] Error if both --export-table and --import-table are specified.
Differential Revision: https://reviews.llvm.org/D45001

llvm-svn: 328873
2018-03-30 16:06:14 +00:00
Nicholas Wilson fc90b30dc2 [WebAssembly] Name Config members after commandline argument. NFC
This addresses a late review comment from D44427/rLLD328643

llvm-svn: 328700
2018-03-28 12:53:29 +00:00
Nicholas Wilson 874eedd779 [WebAssembly] Add export/import for function pointer table
This enables callback-style programming where the JavaScript environment
can call back into the Wasm environment using a function pointer
received from the module.

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

llvm-svn: 328643
2018-03-27 17:38:51 +00:00
Nicholas Wilson 531769b9f9 [WebAssembly] Demangle symbol names for use by the browser debugger
Differential Revision: https://reviews.llvm.org/D44316

llvm-svn: 327392
2018-03-13 13:30:04 +00:00
Nicholas Wilson 08cff61572 [WebAssembly] Add missing --demangle arg
Previously, Config->Demangle was uninitialised (not hooked up to
commandline handling)

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

llvm-svn: 327390
2018-03-13 13:12:03 +00:00
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
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
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
Nicholas Wilson dbd90bf8d1 [WebAssembly] Run clang-format. NFC
llvm-svn: 326896
2018-03-07 13:28:16 +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 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 c9f0b65f54 [WebAssebmly] Minor simplification. NFC.
llvm-svn: 326013
2018-02-24 01:58:38 +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
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 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 78f766a9aa [WebAssembly] Remove unused header
llvm-svn: 325624
2018-02-20 21:08:28 +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
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
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
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
Sam Clegg 0362633fd2 [WebAssembly] Add support for --gc-sections
In this initial version we only GC symbols with `hidden` visibility since
other symbols we export to the embedder.

We could potentially modify this the future and only use symbols
explicitly passed via `--export` as GC roots.

This version of the code only does GC of data and code. GC for the
types section is coming soon.

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

llvm-svn: 323842
2018-01-31 01:45:47 +00:00
Sam Clegg ff2b12216b [WebAssembly] Remove --emit-relocs
This was added to mimic ELF, but maintaining it has cost
and we currently don't have any use for it outside of the
test code.

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

llvm-svn: 323154
2018-01-22 21:55:43 +00:00
Sam Clegg 0f0a428738 [WebAssembly] Remove special handling of entry point export.
Its much easier to export it via setHidden(false), now that
that is a thing.

As a side effect the start function is not longer always exports first
(becuase its being exported just like all the other function).

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

llvm-svn: 323025
2018-01-20 01:44:45 +00:00
Sam Clegg 096aa50ba4 [WebAssembly] Remove redundant function: addSyntheticUndefinedFunction. NFC.
Differential Revision: https://reviews.llvm.org/D42327

llvm-svn: 323024
2018-01-20 01:40:17 +00:00
Sam Clegg 77ee17d191 [WebAssembly] Remove custom handling for undefined entry
This code was needed back when we were not able to write
out the synthetic symbol for main.

Add tests to make sure we can handle this now.

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

llvm-svn: 323020
2018-01-20 00:52:51 +00:00
Sam Clegg 51bcdc2d49 [WebAssembly] Define __heap_base global
This is an immutable exported global representing
the start of the heap area.  It is a page aligned.

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

llvm-svn: 322609
2018-01-17 01:34:31 +00:00
Sam Clegg 5a11dd9690 [WebAssembly] Create synthetic __dso_handle symbol
This is used by __cxa_ataxit to determine the currently
executing DLL.  Once we fully support DLLs this will need
to be set to some address within the DLL.

The ELF linker added support for this symbol here:
https://reviews.llvm.org/D33856

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

llvm-svn: 322606
2018-01-17 01:10:28 +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 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 6074e6b094 Remove redundant local variables.
llvm-svn: 320436
2017-12-11 23:19:11 +00:00
Rui Ueyama 9d8ce23c9c Reduce indentation.
llvm-svn: 320433
2017-12-11 23:09:03 +00:00
Rui Ueyama 8cbb3b56b9 Sort.
llvm-svn: 320394
2017-12-11 17:52:43 +00:00
Rui Ueyama 909d123893 Change function type more LLVM-ish.
Also fix variable naming style.

llvm-svn: 320393
2017-12-11 17:52:28 +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
Sam Clegg c5872e864a [WebAssembly] Add check to ensure symbol VA is only set once. NFC.
Also remove resulting unneeded function.

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

llvm-svn: 320118
2017-12-08 00:13:14 +00:00
Sam Clegg 80cfdd6b56 [WebAssembly] Remove used variable
llvm-svn: 320007
2017-12-07 03:51:37 +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
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
Sam Clegg 4eedcfc946 [WebAssembly] Improve support linker synthetic symbols
This is part of larger change to add synthetic symbols
for section start/end points and init/fini_array:
  https://reviews.llvm.org/D40760

Allows synthetic global symbols to have an explicitly set
virtual address.

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

llvm-svn: 319813
2017-12-05 19:05:45 +00:00
Sam Clegg 3b4a475c37 [WebAssembly] Remove used --sysroot option
Differential Revision: https://reviews.llvm.org/D40771

llvm-svn: 319805
2017-12-05 18:13:45 +00:00
Sam Clegg 22cfe52398 [WebAssembly] Simplify check for emitting relocations
This is a small change I split of from a larger one
that simplifies the condition that need to be checked
when decided if we need to emit relocation and all the
things they depend on (symbols, etc).

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

llvm-svn: 319789
2017-12-05 16:53:25 +00:00
Rui Ueyama 69989bdbf2 clang-format.
llvm-svn: 319512
2017-12-01 02:11:29 +00:00
Sam Clegg 49ed926287 [WebAssembly] Fix typos
Patch by Nicholas Wilson

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

llvm-svn: 319506
2017-12-01 00:53:21 +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
Rui Ueyama ceb15e8a51 Fix spelling. NFC.
llvm-svn: 319238
2017-11-28 22:17:39 +00:00
Rui Ueyama 2445b0ccac Remove unused `using`.
llvm-svn: 319236
2017-11-28 22:14:13 +00:00
Rui Ueyama 2017d52b54 Move Memory.{h,cpp} to Common.
Differential Revision: https://reviews.llvm.org/D40571

llvm-svn: 319221
2017-11-28 20:39:17 +00:00
Rui Ueyama 3e03944f02 Factor out more code to Common/Args.cpp.
Differential Revision: https://reviews.llvm.org/D40540

llvm-svn: 319211
2017-11-28 19:58:45 +00:00
Sam Clegg c94d393ad5 [WebAssembly] Initial wasm linker implementation
This linker backend is still a work in progress but is
enough to link simple programs including linking against
library archives.

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

llvm-svn: 318539
2017-11-17 18:14:09 +00:00