Commit Graph

198 Commits

Author SHA1 Message Date
Nicholas Wilson 0185281ad1 [WebAssembly] Add test for imported ctor and fix indexing bug found
This bug was found by accident while trying to expand out testcases
for imported symbols, and is covered by the additional test case.

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

llvm-svn: 327290
2018-03-12 16:04:04 +00:00
Nicholas Wilson 5639da89a9 [WebAssembly] Reorder synthetic functions to come first
This matches the existing ordering that's been there for globals
for a while (__stack_pointer coming first).

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

llvm-svn: 327286
2018-03-12 15:44:07 +00:00
Sam Clegg c1be8230ef [WebAssembly] Improve logging and comments around relocations. NFC.
Differential Revision: https://reviews.llvm.org/D44350

llvm-svn: 327232
2018-03-11 01:35:02 +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
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
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
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
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
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
Rui Ueyama dcf6234dad [WebAssembly] Simplify COMDAT handling.
Differential Revision: https://reviews.llvm.org/D43966

llvm-svn: 326509
2018-03-01 23:29:05 +00:00
Sam Clegg 8518e7ded5 [WebAssembly] Use uint8_t for single byte values to match the spec
Differential Revision: https://reviews.llvm.org/D43922

llvm-svn: 326455
2018-03-01 18:06:39 +00:00
Nicholas Wilson 4cdf5b8fa0 [WebAssembly] Reorder exports to match symbol table order
This fixes a TODO introduced in rLLD325861.

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

llvm-svn: 326424
2018-03-01 09:38:02 +00:00
Rui Ueyama 0931e957ff [WebAssembly] Remove unused forward declaration.
llvm-svn: 326411
2018-03-01 02:37:26 +00:00
Sam Clegg ea397f67e3 [WebAssembly] Use Twine rather than StringRef for logging messages
Also add missing tracing to writeU8.

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

llvm-svn: 326398
2018-03-01 00:42:57 +00:00
Rui Ueyama 67d6908f59 Use DenseMap::lookup() instead of find() and a hand-written null check.
llvm-svn: 326382
2018-02-28 23:03:06 +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 29abfe4a8f [WebAssembly] Use toArrayRef. NFC.
Differential Revision: https://reviews.llvm.org/D43855

llvm-svn: 326340
2018-02-28 17:43:15 +00:00
Rui Ueyama 22c8f33a9b [WebAssembly] Return a StringRef instead of std::string from getSectionName(). NFC.
Differential Revision: https://reviews.llvm.org/D43854

llvm-svn: 326337
2018-02-28 17:33:04 +00:00
Rui Ueyama ba16baccf1 [WebAssembly] Improve WasmSignatureDenseMapInfo.
Let X and Y be types. Previously, functions F(X, Y) and G(Y, X) had
the same hash value because their hash values are computed as follows:

  hash(F) = hash(X) + hash(Y)
  hash(G) = hash(Y) + hash(X)

This patch fixes the issue by using hash_combine.

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

llvm-svn: 326336
2018-02-28 17:32:50 +00:00
Rui Ueyama 26a84fc84f [WebAssembly] Fix variable name.
llvm-svn: 326301
2018-02-28 03:43:38 +00:00
Rui Ueyama 67769100ce [WebAssembly] Remove unnecessary namespace specifiers. NFC.
llvm-svn: 326300
2018-02-28 03:38:14 +00:00
Rui Ueyama 0a9583ce79 [WebAssembly] Simplify initializeSymbols and merge it with ObjFile::parse. NFC.
This patch simplifies initializeSymbols. Since that function is called
at the tail context of ObjFile::parse, and the function is called only
once from that function, that's effectively just a continuation of
ObjFile::parse. So this patch merge it with ObjFile::parse.

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

llvm-svn: 326296
2018-02-28 02:57:37 +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 4764b5748a [WebAssembly] Remove ELF-ness.
These output section names are ELF-specific. We shouldn't have this rule
for WebAssembly.

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

llvm-svn: 326289
2018-02-28 00:57:28 +00:00
Rui Ueyama 4a1b2bbc88 [WebAssembly] Do not use inheritance to define SubSection.
SubSection inherited from SyntheticSection, and SyntheticSection inherits
from OutputSection, so SubSection was an OutputSection. But that's wrong
because SubSection is not actually a WebAssembly output section.
It shares some functionalities with OutputSection, but overall it's very
different.

This patch removes that inheritance.

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

llvm-svn: 326286
2018-02-28 00:52:42 +00:00
Rui Ueyama 4b56adce20 [WebAssembly] Refactor ObjFile::initializeSymbols.
The main purpose of this change is to make initializeSymbols shorter.

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

llvm-svn: 326285
2018-02-28 00:50:54 +00:00
Rui Ueyama 19eedbf013 [WebAssembly] Do not use Subsection as a local variable name.
That variable hides the class of the same name.

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

llvm-svn: 326283
2018-02-28 00:39:30 +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 caa8e2335f [WebAssembly] Do not remove existing output file.
FileOutputBuffer automatically removes an existing file, so we don't
need to do that. Actually doing that is discouraged because when the
linker fails to create an output for some reason after instantiating
FileOutputBufffer, FileOutputBuffer removes a temporary file and don't
touch an existing file. That's an desired behavior from the user's
point of view.

(Internally, FileOutputBuffer writes its contents to a temporary file
and then rename it over to an existing file on commit()).

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

llvm-svn: 326281
2018-02-28 00:33:59 +00:00
Rui Ueyama 319eb8b3c3 [WebAssembly] Remove redundant local variables.
Differential Revision: https://reviews.llvm.org/D43709

llvm-svn: 326280
2018-02-28 00:31:16 +00:00
Rui Ueyama 8bfa2a629d [WebAssembly] Simplify createLikingSection.
Summary: [WebAssembly] Simplify createLikingSection.

Reviewers: sbc100

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

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

llvm-svn: 326279
2018-02-28 00:28:07 +00:00
Rui Ueyama d1063bb9f9 [WebAssembly] Inline accessor functions that are called only once.
Looks like these accessor functions are a bit overly defensive, and
due to the amount of code, that part isn't easy to read. We have
code to log translation results in writeTo and writeRelocations, so
I don't think we need to log it again in these functions.
I think the new function is much easier to understand.

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

llvm-svn: 326277
2018-02-28 00:26:26 +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
Rui Ueyama 7d696880fb [WebAssembly] Use more specific type and simplify code.
Instead of {Function,Global,Data}Symbol, use Defined{Function,Global,Data}
because undefined symbol should never reach this function.

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

llvm-svn: 326275
2018-02-28 00:18:34 +00:00
Rui Ueyama 4145d252c2 [WebAssembly] Remove LastDefinedKind for consistency with undefined kinds. NFC.
Differential Revision: https://reviews.llvm.org/D43711

llvm-svn: 326274
2018-02-28 00:16:11 +00:00
Rui Ueyama da69b711c9 [WebAssembly] Remove premature optimization.
I think calling reserve() for each object file is too many and isn't useful.
We can add reserve() later. By default, we shouldn't add reserve() to a lot
of places.

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

llvm-svn: 326273
2018-02-28 00:15:59 +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 37254065dd [WebAssembly] Use StringRef instead of `const char *`.
Differential Revision: https://reviews.llvm.org/D43721

llvm-svn: 326269
2018-02-28 00:01:31 +00:00
Sam Clegg 99eb42c0c5 [WebAssembly] Remove DataSize from linking metadata
This means we don't need to write the linking metadata section
at all for executable (non-relocatable) output.

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

llvm-svn: 326268
2018-02-27 23:58:03 +00:00
Rui Ueyama afb87d8336 [WebAssembly] Remove dead code.
llvm-svn: 326018
2018-02-24 02:43:31 +00:00
Rui Ueyama 1973cc5358 [WebAssembly] Remove dead code.
llvm-svn: 326017
2018-02-24 02:34:03 +00:00