Commit Graph

44 Commits

Author SHA1 Message Date
Sam Clegg 52b2456a95 [WebAssembly] Fix --export of LTO symbols
Differential Revision: https://reviews.llvm.org/D48697

llvm-svn: 335881
2018-06-28 17:21:46 +00:00
Sam Clegg ce004bfe35 [WebAssembly] Add support for bitcode archive members
This change effects the behavior of --export-all. Previously
--export-all would only effect symbols that survived GC. Now
--export-all will prevent any non-local symbols from being GCed.

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

llvm-svn: 335878
2018-06-28 17:04:58 +00:00
Nicola Zaghen e7245b429b [lld] Update uses of DEBUG macro to LLVM_DEBUG.
The DEBUG() macro is very generic so it might clash with other projects.
The renaming was done as follows:
- git grep -l 'DEBUG' | xargs sed -i 's/\bDEBUG\s\?(/LLVM_DEBUG(/g'
- git diff -U0 master | ../clang/tools/clang-format/clang-format-diff.py -i -p1 -style LLVM

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

llvm-svn: 332351
2018-05-15 13:36:20 +00:00
Sam Clegg 3876d89a1b [WebAssembly] Update to match llvm changes
Subscribers: dschuff, jgravelle-google, aheejin, sunfish, llvm-commits

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

llvm-svn: 332306
2018-05-14 22:42:33 +00:00
Sam Clegg d177ab2a5f [WebAssembly] Add support for debug (DWARF) sections
Specifically add support for custom sections that contain
relocations, and for the two new relocation types needed
by DWARF sections.

See: https://reviews.llvm.org/D44184

Patch by Yury Delendik!

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

llvm-svn: 331566
2018-05-04 23:14:42 +00:00
Roman Lebedev d338222a8c [LLD][WASM] Handle WASM_SYMBOL_TYPE_SECTION in toString().
Fixes build. If this is not the desired solution, please revert.
WasmSymbolType was changed in rL330982 / D44184

llvm-svn: 330984
2018-04-26 20:00:11 +00:00
Nicholas Wilson a1e299f58b [WebAssembly] Implement GC for imports
Differential Revision: https://reviews.llvm.org/D44313

llvm-svn: 330454
2018-04-20 17:18:06 +00:00
Sam Clegg e3f3ccf886 [WebAssembly] Refactor to avoid conflating global and fucntion index space. NFC
Differential Revision: https://reviews.llvm.org/D44358

llvm-svn: 327326
2018-03-12 19:56:23 +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
Rui Ueyama b961abc886 [WebAssembly] Reduce code repetition. NFC.
Differential Revision: https://reviews.llvm.org/D43910

llvm-svn: 326379
2018-02-28 22:51:51 +00:00
Rui Ueyama 5420dd098b [WebAssembly] Simplify Symbol::getWasmType. NFC.
Differential Revision: https://reviews.llvm.org/D43717

llvm-svn: 326293
2018-02-28 01:10:50 +00:00
Rui Ueyama b911f12211 [WebAssembly] Inline translateVA as it's trivial.
The problem I want to address now is that chunks have too many data
members for "offsets", and their origins are not well defined.
For example, InputSegment has OutputSegmentOffset, but it's base class
also has OutputOffset. That's very confusing.

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

llvm-svn: 326291
2018-02-28 01:01:34 +00:00
Rui Ueyama 28f3b20db5 [WebAssembly] Remove trivial accessors.
{set,get}OutputSegment don't hide anything, so remove them.

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

llvm-svn: 326276
2018-02-28 00:20:29 +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 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
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 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 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
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
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 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 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 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 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 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 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 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 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 a681a1167e [WebAssembly] Remove wasm/Strings.cpp+h
This file contained only a single function that was only
really needed in one place, so just inline it.

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

llvm-svn: 319876
2017-12-06 03:10:39 +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 7e7566323d toString function take a const refs where possible
Differential Revision: https://reviews.llvm.org/D40824

llvm-svn: 319787
2017-12-05 16:50:46 +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 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
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