Commit Graph

25 Commits

Author SHA1 Message Date
Sam Clegg 5a9b25e15b [lld][WebAssembly] Refactor input chunk class hierarchy. NFC
The main motivation for this refactor is to remove the subclass
relationship between the InputSegment and MergeInputSegment and
SyntenticMergedInputSegment so that we can use the merging classes for
debug sections which are not data segments.

In the process of refactoring I also remove all the virtual functions
from the class hierarchy and try to reuse techniques used in the ELF
linker (see `lld/ELF/InputSections.h`).

Differential Revision: https://reviews.llvm.org/D102546
2021-05-17 21:01:17 -07:00
Sam Clegg 3b8d2be527 Reland: "[lld][WebAssembly] Initial support merging string data"
This change was originally landed in: 5000a1b4b9
It was reverted in: 061e071d8c

This change adds support for a new WASM_SEG_FLAG_STRINGS flag in
the object format which works in a similar fashion to SHF_STRINGS
in the ELF world.

Unlike the ELF linker this support is currently limited:
- No support for SHF_MERGE (non-string merging)
- Always do full tail merging ("lo" can be merged with "hello")
- Only support single byte strings (p2align 0)

Like the ELF linker merging is only performed at `-O1` and above.

This fixes part of https://bugs.llvm.org/show_bug.cgi?id=48828,
although crucially it doesn't not currently support debug sections
because they are not represented by data segments (they are custom
sections)

Differential Revision: https://reviews.llvm.org/D97657
2021-05-10 16:03:38 -07:00
Nico Weber 061e071d8c Revert "[lld][WebAssembly] Initial support merging string data"
This reverts commit 5000a1b4b9.
Breaks tests, see https://reviews.llvm.org/D97657#2749151

Easily repros locally with `ninja check-llvm-mc-webassembly`.
2021-05-10 18:28:28 -04:00
Sam Clegg 5000a1b4b9 [lld][WebAssembly] Initial support merging string data
This change adds support for a new WASM_SEG_FLAG_STRINGS flag in
the object format which works in a similar fashion to SHF_STRINGS
in the ELF world.

Unlike the ELF linker this support is currently limited:
- No support for SHF_MERGE (non-string merging)
- Always do full tail merging ("lo" can be merged with "hello")
- Only support single byte strings (p2align 0)

Like the ELF linker merging is only performed at `-O1` and above.

This fixes part of https://bugs.llvm.org/show_bug.cgi?id=48828,
although crucially it doesn't not currently support debug sections
because they are not represented by data segments (they are custom
sections)

Differential Revision: https://reviews.llvm.org/D97657
2021-05-10 13:15:12 -07:00
Sam Clegg bda8b84884 [lld][WebAssembly] Disallow exporting of TLS symbols
Cross module TLS is currently not supported by our ABI.  This
change makes explicitly exporting a TLS symbol into an error
and prevents implicit exporting (via --export-all).

See https://github.com/emscripten-core/emscripten/issues/14120

Differential Revision: https://reviews.llvm.org/D102044
2021-05-10 09:58:44 -07:00
Sam Clegg 7d09e1d7cf [lld][WebAssembly] Minor refactor in preparation for SHF_STRINGS supports. NFC.
A couple of small changes to match the ELF linker in preparation
for adding support string mergings.

Differential Revision: https://reviews.llvm.org/D97654
2021-03-01 16:15:29 -08:00
Sam Clegg 70f3c6e9e6 [lld][WebAssembly] Delay the merging of data section when dynamic linking
With dynamic linking we have the current limitation that there can be
only a single active data segment (since we use __memory_base as the
load address and we can't do arithmetic in constant expresions).

This change delays the merging of active segments until a little later
in the linking process which means that the grouping of data by section,
and the magic __start/__end symbols work as expected under dynamic
linking.

Differential Revision: https://reviews.llvm.org/D96453
2021-02-11 10:54:15 -08:00
Wouter van Oortmerssen 582fd474dd [WebAssembly] wasm64: fix memory.init operand types
I had assumed they would all become in i64, but this is not necessary as long as data segments stay 32-bit, see:
https://github.com/WebAssembly/memory64/blob/master/proposals/memory64/Overview.md

Differential Revision: https://reviews.llvm.org/D85552
2020-08-10 10:15:20 -07:00
Thomas Lively 190dacc3cc [WebAssembly] Elide data segments for .bss sections
Summary:
WebAssembly memories are zero-initialized, so when module does not
import its memory initializing .bss sections is guaranteed to be a
no-op. To reduce binary size and initialization time, .bss sections
are simply not emitted into the final binary unless the memory is
imported.

Reviewers: sbc100

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

Tags: #llvm

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

llvm-svn: 374940
2019-10-15 19:05:11 +00:00
Thomas Lively 21143b93a6 [WebAssembly] Sort output data sections to place .bss last
Summary:
This was always the intended behavior, but had not been
implemented. This ordering is important for Emscripten when generating
.mem files while compiling to JS, since only zeros at the end of
initialized memory can be dropped.

Fixes https://github.com/emscripten-core/emscripten/issues/8999

Reviewers: sbc100

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

Tags: #llvm

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

llvm-svn: 372284
2019-09-19 01:14:59 +00:00
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
Thomas Lively 6004d9a13d [WebAssembly] Add option to emit passive segments
Summary:
Adds `--passive-segments` and `--active-segments` flags to control
what kind of segments are emitted. For now the default is always
to emit active segments so this is not a breaking change, but in
the future the default will be changed to passive segments when
shared memory is requested and active segments otherwise. When
passive segments are emitted, corresponding memory.init and
data.drop instructions are emitted in a `__wasm_init_memory`
function that is automatically called at the beginning of
`__wasm_call_ctors`.

Reviewers: sbc100, aheejin, dschuff

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

Tags: #llvm

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

llvm-svn: 365088
2019-07-03 22:04:54 +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
Sam Clegg 622ad04625 [WebAssembly] Fix windows compiler warning by using explicit 64bit shift. NFC.
Differential Revision: https://reviews.llvm.org/D56874

llvm-svn: 351488
2019-01-17 22:09:09 +00:00
Sam Clegg 6320efb4ed [WebAssembly] Store section alignment as a power of 2
This change bumps for version number of the wasm object file
metadata.

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

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

llvm-svn: 351287
2019-01-16 01:43:21 +00:00
Rui Ueyama ac95bb1d52 [WebAssembly] Remove another trivial accessor.
Differential Revision: https://reviews.llvm.org/D43725

llvm-svn: 329336
2018-04-05 19:37:31 +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 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
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 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
Sam Clegg a43c16157d [WebAssembly] Remove extra semicolon. NFC.
llvm-svn: 320777
2017-12-15 00:34:32 +00:00
David Blaikie c004ffcd42 wasm/OutputSegment.h: Include missing header
llvm-svn: 318879
2017-11-22 21:10: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