WebAssembly.rst (81ad626541db97eb356e2c1d4a20eb2a26a766ab) | WebAssembly.rst (2efbaac7a07fff163640a67873b3ac250794ec3f) |
---|---|
1WebAssembly lld port 2==================== 3 4The WebAssembly version of lld takes WebAssembly binaries as inputs and produces 5a 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 the command line flags and the semantics should be the same. 8 --- 61 unchanged lines hidden (view full) --- 70 compatible with outputting debug information. 71 72.. option:: --allow-undefined 73 74 Allow undefined symbols in linked binary. This is the legacy 75 flag which corresponds to ``--unresolve-symbols=ignore`` + 76 ``--import-undefined``. 77 | 1WebAssembly lld port 2==================== 3 4The WebAssembly version of lld takes WebAssembly binaries as inputs and produces 5a 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 the command line flags and the semantics should be the same. 8 --- 61 unchanged lines hidden (view full) --- 70 compatible with outputting debug information. 71 72.. option:: --allow-undefined 73 74 Allow undefined symbols in linked binary. This is the legacy 75 flag which corresponds to ``--unresolve-symbols=ignore`` + 76 ``--import-undefined``. 77 |
78.. option:: --allow-undefined-file=<filename> 79 80 Like ``--allow-undefined``, but the filename specified a flat list of 81 symbols, one per line, which are allowed to be undefined. 82 |
|
78.. option:: --unresolved-symbols=<method> 79 80 This is a more full featured version of ``--allow-undefined``. 81 The semanatics of the different methods are as follows: 82 83 report-all: 84 85 Report all unresolved symbols. This is the default. Normally the linker --- 91 unchanged lines hidden (view full) --- 177``visibility=default``. 178 179Imports 180~~~~~~~ 181 182By default no undefined symbols are allowed in the final binary. The flag 183``--allow-undefined`` results in a WebAssembly import being defined for each 184undefined symbol. It is then up to the runtime to provide such symbols. | 83.. option:: --unresolved-symbols=<method> 84 85 This is a more full featured version of ``--allow-undefined``. 86 The semanatics of the different methods are as follows: 87 88 report-all: 89 90 Report all unresolved symbols. This is the default. Normally the linker --- 91 unchanged lines hidden (view full) --- 182``visibility=default``. 183 184Imports 185~~~~~~~ 186 187By default no undefined symbols are allowed in the final binary. The flag 188``--allow-undefined`` results in a WebAssembly import being defined for each 189undefined symbol. It is then up to the runtime to provide such symbols. |
190``--allow-undefined-file`` is the same but allows a list of symbols to be 191specified. |
|
185 186Alternatively symbols can be marked in the source code as with the 187``import_name`` and/or ``import_module`` clang attributes which signals that 188they are expected to be undefined at static link time. 189 | 192 193Alternatively symbols can be marked in the source code as with the 194``import_name`` and/or ``import_module`` clang attributes which signals that 195they are expected to be undefined at static link time. 196 |
197Stub Libraries 198~~~~~~~~~~~~~~ 199 200Another way to specify imports and exports is via a "stub library". This 201feature is inspired by the ELF stub objects which are supported by the Solaris 202linker. Stub libraries are text files that can be passed as normal linker 203inputs, similar to how linker scripts can be passed to the ELF linker. The stub 204library is a stand-in for a set of symbols that will be available at runtime, 205but doesn't contain any actual code or data. Instead it contains just a list of 206symbols, one per line. Each symbol can specify zero or more dependencies. 207These dependencies are symbols that must be defined, and exported, by the output 208module if the symbol is question is imported/required by the output module. 209 210For example, imagine the runtime provides an external symbol ``foo`` that 211depends on the ``malloc`` and ``free``. This can be expressed simply as:: 212 213 #STUB 214 foo: malloc,free 215 216Here we are saying that ``foo`` is allowed to be imported (undefined) but that 217if it is imported, then the output module must also export ``malloc`` and 218``free`` to the runtime. If ``foo`` is imported (undefined), but the output 219module does not define ``malloc`` and ``free`` then the link will fail. 220 221Stub libraries must begin with ``#STUB`` on a line by itself. 222 |
|
190Garbage Collection 191~~~~~~~~~~~~~~~~~~ 192 193Since WebAssembly is designed with size in mind the linker defaults to 194``--gc-sections`` which means that all unused functions and data segments will 195be stripped from the binary. 196 197The symbols which are preserved by default are: --- 28 unchanged lines hidden --- | 223Garbage Collection 224~~~~~~~~~~~~~~~~~~ 225 226Since WebAssembly is designed with size in mind the linker defaults to 227``--gc-sections`` which means that all unused functions and data segments will 228be stripped from the binary. 229 230The symbols which are preserved by default are: --- 28 unchanged lines hidden --- |