Commit Graph

30 Commits

Author SHA1 Message Date
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
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 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 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 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 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 ab2ac29066 [WebAssembly] Improve toString(OutputSection). NFC.
llvm-svn: 321146
2017-12-20 05:14:48 +00:00
Sam Clegg d451da1bd1 [WebAssembly] Fix a couple of typos. NFC.
Also remove unneeded braces and old comment.

llvm-svn: 321103
2017-12-19 19:56:27 +00:00
Sam Clegg 0d0dd39159 [WebAssembly] Add support for writing out init functions in linking section
This change add support for init functions in the linking
section, but only in -r/--relocatable mode.

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

llvm-svn: 321088
2017-12-19 17:09:45 +00:00
Sam Clegg f61676a18a [WebAssembly] Move code for copying of data segment relocation. NFC.
This is a preparetory change for function gc which also
requires relocations to be copied in ranges like this.

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

llvm-svn: 320948
2017-12-17 17:52:01 +00:00
Sam Clegg c018115480 [WebAssembly] Don't include lazy symbols in import table
This bug was introduced in: https://reviews.llvm.org/D41304.
Add a test for this case.

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

llvm-svn: 320872
2017-12-15 22:17:15 +00:00
Sam Clegg 574d7ce954 [WebAssembly] Base imports on Symtab. NFC.
Since imports are undefined symbols we know we can
find all of them my looking at the symbol table alone.
(i.e. imports cannot be have local binding).

This will be strictly faster and also allows us
to to remove a method from Symbol class

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

llvm-svn: 320847
2017-12-15 19:23:49 +00:00
Sam Clegg fc1a912b9b [WebAssembly] De-dup indirect function table.
Create the indirect function table based on symbols rather
than just duplicating the input entries.  This has the
effect of de-duplicating the table.

This is a followup to the equivalent change made for globals:
  https://reviews.llvm.org/D40859

Partially based on a patch by Nicholas Wilson:
  https://reviews.llvm.org/D40845

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

llvm-svn: 320428
2017-12-11 22:00:56 +00:00
Sam Clegg 3f1fb88afb [WebAssembly] Preserve ordering of global symbols
This change restores the behavior that global indexes
are assigned in object file order.  This was accidentally
changed in https://reviews.llvm.org/D40859.

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

llvm-svn: 320426
2017-12-11 21:52:21 +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 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 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
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
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 e48f223ed6 Remove `else` or `break` after `fatal`. NFC.
fatal() does not return, so we don't need `else` or `break` after a call
of fatal.

llvm-svn: 319355
2017-11-29 20:45:58 +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
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