blob: 4485e50ccf51e6352260f5805104885eca4cfa2a [file] [log] [blame]
Sam Cleggc94d3932017-11-17 18:14:09 +00001WebAssembly lld port
2====================
3
Sam Cleggc94d3932017-11-17 18:14:09 +00004The WebAssembly version of lld takes WebAssembly binaries as inputs and produces
Sam Clegg77ab7c12018-09-27 00:22:24 +00005a WebAssembly binary as its output. For the most part it tries to mimic the
6behaviour of traditional ELF linkers and specifically the ELF lld port. Where
7possible that command line flags and the semantics should be the same.
Sam Cleggc94d3932017-11-17 18:14:09 +00008
9
10Object file format
11------------------
12
13The format the input object files that lld expects is specified as part of the
14the WebAssembly tool conventions
15https://github.com/WebAssembly/tool-conventions/blob/master/Linking.md.
16
17This is object format that the llvm will produce when run with the
Sam Clegg262e0902018-05-10 17:59:41 +000018``wasm32-unknown-unknown`` target. To build llvm with WebAssembly support
Sam Cleggc94d3932017-11-17 18:14:09 +000019currently requires enabling the experimental backed using
20``-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly``.
21
22
Sam Clegg77ab7c12018-09-27 00:22:24 +000023Usage
24-----
25
26The WebAssembly version of lld is installed as **wasm-ld**. It shared many
27common linker flags with **ld.lld** but also includes several
28WebAssembly-specific options:
29
30.. option:: --no-entry
31
32 Don't search for the entry point symbol (by default ``_start``).
33
34.. option:: --export-table
35
36 Export the function table to the environment.
37
38.. option:: --import-table
39
40 Import the function table from the environment.
41
42.. option:: --export-all
43
44 Export all symbols (normally combined with --no-gc-sections)
45
46.. option:: --[no-]export-default
47
48 Export symbols marked as 'default' visibility. Default: true
49
50.. option:: --global-base=<value>
51
52 Address at which to place global data
53
54.. option:: --[no-]merge-data-segments
55
56 Enable/Disble merging of data segments. Default: true
57
58.. option:: --stack-first
59
60 Place stack at start of linear memory rather than after data
61
62.. option:: --compress-relocations
63
64 Compress the relocation targets in the code section.
65
66.. option:: --allow-undefined
67
68 Allow undefined symbols in linked binary
69
70.. option:: --import-memory
71
72 Import memory from the environment
73
74.. option:: --initial-memory=<value>
75
76 Initial size of the linear memory. Default: static data size
77
78.. option:: --max-memory=<value>
79
80 Maximum size of the linear memory. Default: unlimited
81
82By default the function table is neither imported nor exported.
83
84Symbols are exported if they are marked as ``visibility=default`` at compile
85time or if they are included on the command line via ``--export``.
86
87Since WebAssembly is designed with size in mind the linker defaults to
88``--gc-sections`` which means that all un-used functions and data segments will
89be stripped from the binary.
90
91The symbols which are preserved by default are:
92
93- The entry point (by default ``_start``).
94- Any symbol which is to be exported.
95- Any symbol transitively referenced by the above.
96
97
Sam Cleggc94d3932017-11-17 18:14:09 +000098Missing features
99----------------
100
Sam Clegg77ab7c12018-09-27 00:22:24 +0000101- Merging of data section similiar to ``SHF_MERGE`` in the ELF world is not
102 supported.
103- No support for creating shared libaries. The spec for shared libraries in
104 WebAssembly is still in flux:
105 https://github.com/WebAssembly/tool-conventions/blob/master/DynamicLinking.md