Commit Graph

198 Commits

Author SHA1 Message Date
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
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
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
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
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
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 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
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
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
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 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 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
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
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
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
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
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
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
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 8f6d2def2b [WebAssembly] Write minimal types section
Don't include type signatures that are not referenced by
some relocation.

We don't include this in the -gc-sections settings since
we are always building the type section from scratch,
just like we do the table elements.

In the future we might want to unify the relocation
processing which is currently done once for gc-sections
and then again for building the sympathetic type and
table sections.

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

llvm-svn: 323931
2018-01-31 23:48:14 +00:00
Sam Clegg 1a9b7b911d [WebAssembly] Update to match llvm change rL323901. NFC
See: https://reviews.llvm.org/rL323901

Patch by Nicholas Wilson!

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

llvm-svn: 323903
2018-01-31 19:54:34 +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 b839f1590e [WebAssembly] Sort options in `Options.td`. NFC.
Differential Revision: https://reviews.llvm.org/D42627

llvm-svn: 323624
2018-01-28 19:57:04 +00:00
Sam Clegg fadf51886a [WebAssembly] Add getName and getFileName methods to InputChunk base class. NFC.
Summary: These are useful to upcoming addition of --gc-sections support.

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

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

llvm-svn: 323623
2018-01-28 19:57:03 +00:00
Sam Clegg fc50c62311 clang format
llvm-svn: 323622
2018-01-28 19:57:02 +00:00
Sam Clegg 24b3dcd4bf [WebAssemly] Associate symbol with InputChunk in which they are defined. NFC.
Summary:
Rather than explicit Function or InputSegment points store a
pointer to the base class (InputChunk) and use llvm dynamic
casts when we need a subtype.

This change is useful for add the upcoming gc-section support
wants to deal with all input chunks.

Subscribers: aheejin, llvm-commits

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

llvm-svn: 323621
2018-01-28 19:57:01 +00:00
Sam Clegg b5885118f4 [WebAssembly] Remove unneeded include. NFC.
llvm-svn: 323620
2018-01-28 19:33:00 +00:00
Sam Clegg 67abf53961 [WebAssembly] Don't duplicate functions in table output
Previously, we were ensuring that the "output index" for
InputFunctions was unique across all symbols that referenced
a function body, but allowing the same function body to have
multiple table indexes.

Now, we use the same mechanism for table indexes as we already
do for output indexes, ensuring that each InputFunction is only
placed in the table once.

This makes the LLD output table denser and smaller, but should
not change the behaviour.

Note that we still need the `Symbol::TableIndex` member, to
store the table index for function Symbols that don't have an
InputFunction, i.e. for address-taken imports.

Patch by Nicholas Wilson!

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

llvm-svn: 323379
2018-01-24 21:45:25 +00:00
Sam Clegg 48bbd63fea [WebAssembly] Always start table index at 1, even for relocatable output
Previously llvm was using 0 as the first table index for wasm object
files but now that has switched to 1 we can have the output of lld
do the same and simplify the code.

Patch by Nicholas Wilson!

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

llvm-svn: 323378
2018-01-24 21:37:30 +00:00
Sam Clegg 7e8795fde4 [WebAssembly] Remove excess debugging. NFC.
llvm-svn: 323286
2018-01-24 00:15:53 +00:00
Sam Clegg ab604a9882 [WebAssembly] Update to match llvm changes to TABLE relocations
TABLE relocations now store the function that is being refered
to indirectly.

See rL323165.

Also extend the call-indirect.ll a little.

Based on a patch by Nicholas Wilson!

llvm-svn: 323168
2018-01-23 01:25:56 +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 04b76f4077 [WebAssembly] Include SYMBOL_INFO for imports as well as exports
Only effects --emit-relocs/--relocatable

Patch by Nicholas Wilson!

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

llvm-svn: 322994
2018-01-19 21:49:41 +00:00
Sam Clegg 729a864dfa [WebAssembly] Include weak imports when linking with --relocatable
We need these import since relocations are generated against them.

Patch by Nicholas Wilson!

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

llvm-svn: 322990
2018-01-19 20:56:20 +00:00
Sam Clegg 272c70179a [WebAssembly] Allow non-zero table offset in input object
Summary: This change enables D42284 to land without breaking lld

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

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

llvm-svn: 322976
2018-01-19 18:21:42 +00:00
Sam Clegg 811236c36b [WebAssembly] Fix variable whose name is also a type name
Some compilers don't like this and generate a warning.

llvm-svn: 322921
2018-01-19 03:31:07 +00:00
Sam Clegg 14ae6e7c5c [WebAssembly] Export the stack pointer when using --emit-relocs
This solves the problem that --emit-relocs needs the stack-pointer
to be exported, in order to write out any relocations that reference
the __stack_pointer symbol by its symbol index.

Patch by Nicholas Wilson!

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

llvm-svn: 322911
2018-01-18 23:57:55 +00:00
Sam Clegg d3052d5522 [WebAssembly] Add missing function exports and SYM_INFO to --relocatable output
When writing relocatable files we were exporting for all globals
(including file-local syms), but not for functions. Oops. To be
consistent with non-relocatable output, all symbols (file-local
and global) should be exported. Any symbol targetted by further
relocations needs to be exported. The lack of local function
exports was just an omission, I think.

Second bug: Local symbol names can collide, causing an illegal
Wasm file to be generated! Oops again. This only previously affected
producing relocatable output from two files, where each had a global
with the same name. We need to "budge" the symbol names for locals
that are exported on relocatable output.

Third bug: LLD's relocatable output wasn't writing out any symbol
flags! Thus the local globals weren't being marked as local, and
the hidden flag was also stripped...

Added tests to exercise colliding local names with/without
relocatable flag

Patch by Nicholas Wilson!

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

llvm-svn: 322908
2018-01-18 23:40:49 +00:00
Sam Clegg 1963d71cb8 [WebAssembly] Simplify generation of "names" section
Simplify generation of "names" section by simply iterating
over the DefinedFunctions array.

This even fixes some bugs, judging by the test changes required.
Some tests are asserting that functions are named multiple times,
other tests are asserting that the "names" section contains the
function's alias rather than its original name

Patch by Nicholas Wilson!

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

llvm-svn: 322751
2018-01-17 20:19:04 +00:00
Sam Clegg 48d030d5c7 [WebAssembly] Remove DEBUG_FUNCTION_NAME after llvm change
Patch by Nicholas Wilson!

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

llvm-svn: 322745
2018-01-17 19:35:16 +00:00
Sam Clegg bd2bd5a92e [WebAssembly] Remove non-existent method declaration. NFC.
Patch by Nicholas Wilson!

llvm-svn: 322732
2018-01-17 19:01:52 +00:00
Sam Clegg 4e07ecb5ab [WebAssembly] Remove unused member variable. NFC.
Patch by Nicholas Wilson!

llvm-svn: 322731
2018-01-17 18:58:50 +00:00
Sam Clegg 54c3891328 [WebAssembly] Fix typo in comment
Patch by Nicholas Wilson!

llvm-svn: 322727
2018-01-17 18:50:30 +00:00
Sam Clegg fc0723c73f [WebAssembly] Refactor InputChunk.getSize(). NFC
Also, remove trailing semicolons.

Patch by Nicholas Wilson!

llvm-svn: 322726
2018-01-17 18:49:11 +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 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
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
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
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
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 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
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 ab2ac29066 [WebAssembly] Improve toString(OutputSection). NFC.
llvm-svn: 321146
2017-12-20 05:14:48 +00:00
Sam Clegg 5e8cba9e39 [WebAssembly] Apply data relocations in parallel. NFC.
Store data relocations with their respective segment.
This allows relocations to be applied as each segment
is written (and therefore in parallel).

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

llvm-svn: 321105
2017-12-19 20:45:15 +00:00