Commit Graph

83 Commits

Author SHA1 Message Date
Rui Ueyama 136d27ab4d [Coding style change][lld] Rename variables for non-ELF ports
This patch does the same thing as r365595 to other subdirectories,
which completes the naming style change for the entire lld directory.

With this, the naming style conversion is complete for lld.

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

llvm-svn: 365730
2019-07-11 05:40:30 +00:00
Rui Ueyama 7e296adec7 Make functions and member variables distinguishable even after the name style change. NFC.
llvm-svn: 365605
2019-07-10 09:10:01 +00:00
Sam Clegg 9abe8c4805 [lld][WebAssembly] Report undefined symbols during scanRelocations
This puts handling of undefined symbols in a single location.  Its
also more in line with the ELF backend which only reports undefined
symbols based on relocations.

One side effect is that we no longer report undefined symbols that are
only referenced in GC'd sections.

This also fixes a crash reported in the emscripten toolchain:
https://github.com/emscripten-core/emscripten/issues/8930.

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

llvm-svn: 365553
2019-07-09 20:45:20 +00:00
Sam Clegg 15006469bf [lld][WebAssembly] Fix __start/__stop symbols when combining input segments
We should be generating one __start/__stop pair per output segment
not per input segment.  The test wasn't catching this because it was
only linking a single object file.

Fixes PR41565

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

llvm-svn: 365308
2019-07-08 10:35:08 +00:00
Sam Clegg a282a61ba3 [WebAssembly] Handle object parsing more like the ELF backend
Differential Revision: https://reviews.llvm.org/D62886

llvm-svn: 362626
2019-06-05 17:50:45 +00:00
Sam Clegg 8e8ddaa38f [WebAssembly] Add comment as follow-up to rL362276. NFC.
Subscribers: dschuff, jgravelle-google, aheejin, sunfish, llvm-commits

Tags: #llvm

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

llvm-svn: 362522
2019-06-04 16:35:23 +00:00
Sam Clegg 7d4ec5af6c [WebAssembly] Don't export __data_end and __heap_base by default.
These can still be exported via --export if needed.

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

llvm-svn: 362276
2019-05-31 22:51:59 +00:00
Sam Clegg d506b0a484 [WebAssembly] Fix signatures of undefined function in LTO object which are not called directly.
We recently added special handling for function that are not called
directly but failed to add testing for the LTO case.

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

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

llvm-svn: 361975
2019-05-29 15:36:42 +00:00
Sam Clegg 59f959ff33 [WebAssembly] Relax signature checking for undefined functions that are not called directly
When function signatures don't match and the undefined function is not
called directly (i.e. only has its address taken) we don't issue a
warning or create a runtime thunk for the undefined function.

Instead in this case we simply use the defined version of the function.
This is possible since checking signatures of dynamic calls happens
at runtime so any invalid usage will still result in a runtime error.

This is needed to allow C++ programs to link without generating
warnings.  Its not uncommon in C++ for vtables to be populated by
function address whee the signature of the function is not known in the
compilation unit.  In this case clang declares the method as void(void)
and relies on the vtable caller casting the data back to the correct
signature.

Fixes: https://bugs.llvm.org/show_bug.cgi?id=40412

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

llvm-svn: 361678
2019-05-24 22:45:08 +00:00
Sam Clegg a5ca34e6b3 [WebAssebmly] Add support for --wrap
The code for implementing this features is taken almost verbatim
from the ELF backend.

Fixes: https://bugs.llvm.org/show_bug.cgi?id=41681

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

llvm-svn: 361639
2019-05-24 14:14:25 +00:00
Sam Clegg 7991b68284 [lld] Trace all references with lld --trace-symbol
Previously undefined symbol references were only traced if they were
seen before that definition.

Fixes https://bugs.llvm.org/show_bug.cgi?id=41878

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

llvm-svn: 361636
2019-05-24 13:29:17 +00:00
Sam Clegg 4bce63a0e7 Reland: [WebAssembly] Add __start_/_stop_ symbols for data sections
This is a reland of rL361235.

Fixes https://bugs.llvm.org/show_bug.cgi?id=41565

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

llvm-svn: 361476
2019-05-23 10:06:03 +00:00
Sam Clegg c0a4f45bcb Revert "[WebAssembly] Add __start_/_stop_ symbols for data sections"
This reverts commit 7804dbddcc.

This change broke a bunch of tests of the WebAssembly waterfall.
Will hopefully reland with increased test coverage.

llvm-svn: 361273
2019-05-21 17:16:33 +00:00
Sam Clegg 7804dbddcc [WebAssembly] Add __start_/_stop_ symbols for data sections
Fixes https://bugs.llvm.org/show_bug.cgi?id=41565

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

llvm-svn: 361236
2019-05-21 10:07:30 +00:00
Sam Clegg 697f2149f1 [WebAssembly] LTO: Honor comdat groups when loading bitcode files
But don't apply comdat groups when loading the LTO object files.
This is basically the same logic used by the ELF linker.

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

llvm-svn: 360782
2019-05-15 16:03:28 +00:00
Fangrui Song 196a440411 [wasm] Simplify. NFC
llvm-svn: 358663
2019-04-18 13:33:29 +00:00
Sam Clegg 0cfaa2470f [WebAssembly] Ensure ArchiveName is set even in the presence of --whole-archive.
Differential Revision: https://reviews.llvm.org/D60431

llvm-svn: 357966
2019-04-09 05:41:52 +00:00
Benjamin Kramer ba2ea93ad1 Make helper functions static. NFC.
llvm-svn: 357187
2019-03-28 17:18:42 +00:00
Sam Clegg a688a42cdd [WebAssembly] Improve support for "needed" list in dylink section
This change adds basic support for shared library dependencies
via the dylink section.

See https://github.com/WebAssembly/tool-conventions/pull/77

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

llvm-svn: 356102
2019-03-13 21:29:20 +00:00
Sam Clegg d15a4154a8 [WebAssembly] Don't mark lazy symbols as `IsUsedInRegularObj`
This matches the ELF does.  Update the comment in ELF/Symbols.h and
duplicate it in wasm/Symbols.h

This a followup on rL355580 and rL355577.

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

llvm-svn: 355737
2019-03-08 21:10:48 +00:00
Sam Clegg f8d736f1dc [WebAssembly] Remove redundant code added in rL354538. NFC.
The code for encoding the symbols signature into its name
was not actually being used in the final version of this change.

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

llvm-svn: 354539
2019-02-21 01:33:26 +00:00
Richard Trieu 14bab09e11 Fix unused variable warning.
llvm-svn: 354535
2019-02-21 00:36:14 +00:00
Sam Clegg 6540e57002 [WebAssembly] Don't generate invalid modules when function signatures mismatch
Previously we could emit a warning and generate a potentially invalid
wasm module (due to call sites and functions having conflicting
signatures). Now, rather than create invalid binaries we handle such
cases by creating stub functions containing unreachable, effectively
turning these into runtime errors rather than validation failures.

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

llvm-svn: 354528
2019-02-20 23:19:31 +00:00
Sam Clegg 230dc11d24 [WebAssembly] Refactor handling of weak undefined functions. NFC.
Also add to the docs.

This is refactor in preparation for https://reviews.llvm.org/D57909

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

llvm-svn: 353478
2019-02-07 22:42:16 +00:00
Dan Gohman 9b84eeaa3e [WebAssembly] Fix imported function symbol names that differ from their import names in the .o format
Add a flag to allow symbols to have a wasm import name which differs from the
linker symbol name, allowing the linker to link code using the import_module
attribute.

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

llvm-svn: 353473
2019-02-07 22:00:48 +00:00
Sam Clegg 1f3f774f10 [WebAssembly] Implement --trace and --trace-symbol
Differential Revision: https://reviews.llvm.org/D57725

llvm-svn: 353264
2019-02-06 02:35:18 +00:00
Sam Clegg 7cc0753118 [WebAssembly] Support imports from custom module names
Fixes: https://bugs.llvm.org/show_bug.cgi?id=37168

This is only a first pass at supporting these custom import
modules.  In the long run we most likely want to treat these
kinds of symbols very differently.  For example, it should not
be possible to resolve such as symbol at static link type.

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

llvm-svn: 352828
2019-02-01 02:29:57 +00:00
Sam Clegg 37b4ee523b [WebAssembly] Don't load weak undefined symbols from archive files
Summary: Fixes PR40494

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

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

llvm-svn: 352554
2019-01-29 22:26:31 +00:00
Chandler Carruth 2946cd7010 Update the file headers across all of the LLVM projects in the monorepo
to reflect the new license.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

llvm-svn: 351636
2019-01-19 08:50:56 +00:00
Heejin Ahn e915a71f18 [WebAssembly] Add support for the event section
Summary:
This adds support for the 'event section' specified in the exception
handling proposal.

Wasm exception handling binary model spec:
https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md#changes-to-the-binary-model

Reviewers: sbc100, ruiu

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

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

llvm-svn: 348703
2018-12-08 06:17:43 +00:00
Sam Clegg 45218f4af9 [WebAssembly] Remove `using` statements from header files. NFC.
Differential Revision: https://reviews.llvm.org/D54758

llvm-svn: 347621
2018-11-27 01:08:16 +00:00
Heejin Ahn 6f4286fb97 [WebAssembly] Fix inaccurate comments / assertion messages
Reviewers: sbc100

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

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

llvm-svn: 347273
2018-11-19 23:31:28 +00:00
Sam Clegg 8b0b48f343 [WebAssembly] Preserve function signatures during LTO
With LTO when and undefined function (with a known signature)
in replaced by a defined bitcode function we were loosing the
signature information (since bitcode functions don't have
signatures).

With this change we preserve the original signature from the
undefined function and verify that the post LTO compiled
function has the correct signature.

This change improves the error handling in the case where
there is a signature mismatch with a function defined in
a bitcode file.

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

llvm-svn: 343340
2018-09-28 16:50:14 +00:00
Sam Clegg 47e2b6b29e [WebAssembly] Don't error when --undefined symbols are not found
This matches the behavior of the ELF linker where -u/--undefined
means symbols will get pulled in from archives but won't result
in link error if they are missing.

Also, don't actually great symbol table entries for the undefined
symbols, again matching more closely the ELF linker.

This also results in simplification of the code.

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

llvm-svn: 338938
2018-08-04 00:04:06 +00:00
Sam Clegg 4c2cbfe68d Set IsUsedInRegularObj in a consistent manor between COFF, ELF and wasm. NFC
Differential Revision: https://reviews.llvm.org/D49147

llvm-svn: 338767
2018-08-02 20:39:19 +00:00
Sam Clegg f989a92dea [WebAssemlby] Set IsUsedInRegularObj correctly for undefined data symbols
Differential Revision: https://reviews.llvm.org/D49113

llvm-svn: 337314
2018-07-17 19:15:02 +00:00
Sam Clegg cefbf9aca1 [WebAssembly] LTO: Fix signatures of undefined functions in bitcode
Function symbols that come from bitcode have not signatures.
After LTO when the real symbols are read in we need to make
sure that we set the signature on the existing symbol.
the signature-less undefined functions.

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

llvm-svn: 335875
2018-06-28 16:53:53 +00:00
Sam Clegg ffd0aaf810 Revert "[WebAssembly] Error on mismatched function signature in final output"
This caused a lot of issues on the WebAssembly waterfall.
In particular, until with the signature of `main`.  We
probably want a better solution for main before we re-land.

Reverts rL335192

llvm-svn: 335355
2018-06-22 15:13:10 +00:00
Sam Clegg 1369dfa30b [WebAssembly] Error on mismatched function signature in final output
During symbol resolution, emit warnings for function signature
mismatches.  During GC, if any mismatched symbol is marked as live
then generate an error.

This means that we only error out if the mismatch is written to the
final output.  i.e. if we would generate an invalid wasm file.

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

llvm-svn: 335192
2018-06-21 00:12:25 +00:00
Sam Clegg ddaab86972 [WebAssembly] Update function signature mismatch error message. NFC.
We don't start our error messages with capital letters.

Split out from https://reviews.llvm.org/D48394

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

llvm-svn: 335186
2018-06-20 22:45:03 +00:00
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
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 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 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 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
Nicholas Wilson c4d9aa1b5f [WebAssembly] Avoid COMDAT hashmap lookup for each symbol. NFC
This reduces the number of lookups to one per COMDAT group, rather than
one per symbol in a COMDAT group.

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

llvm-svn: 327523
2018-03-14 15:45:11 +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
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
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