Sam Clegg | c94d393 | 2017-11-17 18:14:09 +0000 | [diff] [blame] | 1 | WebAssembly lld port |
| 2 | ==================== |
| 3 | |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 +0000 | [diff] [blame] | 4 | The WebAssembly version of lld takes WebAssembly binaries as inputs and produces |
Sam Clegg | 77ab7c1 | 2018-09-27 00:22:24 +0000 | [diff] [blame^] | 5 | a WebAssembly binary as its output. For the most part it tries to mimic the |
| 6 | behaviour of traditional ELF linkers and specifically the ELF lld port. Where |
| 7 | possible that command line flags and the semantics should be the same. |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 +0000 | [diff] [blame] | 8 | |
| 9 | |
| 10 | Object file format |
| 11 | ------------------ |
| 12 | |
| 13 | The format the input object files that lld expects is specified as part of the |
| 14 | the WebAssembly tool conventions |
| 15 | https://github.com/WebAssembly/tool-conventions/blob/master/Linking.md. |
| 16 | |
| 17 | This is object format that the llvm will produce when run with the |
Sam Clegg | 262e090 | 2018-05-10 17:59:41 +0000 | [diff] [blame] | 18 | ``wasm32-unknown-unknown`` target. To build llvm with WebAssembly support |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 +0000 | [diff] [blame] | 19 | currently requires enabling the experimental backed using |
| 20 | ``-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly``. |
| 21 | |
| 22 | |
Sam Clegg | 77ab7c1 | 2018-09-27 00:22:24 +0000 | [diff] [blame^] | 23 | Usage |
| 24 | ----- |
| 25 | |
| 26 | The WebAssembly version of lld is installed as **wasm-ld**. It shared many |
| 27 | common linker flags with **ld.lld** but also includes several |
| 28 | WebAssembly-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 | |
| 82 | By default the function table is neither imported nor exported. |
| 83 | |
| 84 | Symbols are exported if they are marked as ``visibility=default`` at compile |
| 85 | time or if they are included on the command line via ``--export``. |
| 86 | |
| 87 | Since 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 |
| 89 | be stripped from the binary. |
| 90 | |
| 91 | The 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 Clegg | c94d393 | 2017-11-17 18:14:09 +0000 | [diff] [blame] | 98 | Missing features |
| 99 | ---------------- |
| 100 | |
Sam Clegg | 77ab7c1 | 2018-09-27 00:22:24 +0000 | [diff] [blame^] | 101 | - 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 |