| 1866 | |
| 1867 | @ToolchainProfiler.profile_block('link') |
| 1868 | def phase_link(linker_args, linker_inputs, wasm_target, js_syms): |
| 1869 | logger.debug(f'linking: {linker_args}') |
| 1870 | |
| 1871 | # Make a final pass over settings.EXPORTED_FUNCTIONS to remove any |
| 1872 | # duplication between functions added by the driver/libraries and function |
| 1873 | # specified by the user |
| 1874 | settings.EXPORTED_FUNCTIONS = dedup_list(settings.EXPORTED_FUNCTIONS) |
| 1875 | settings.REQUIRED_EXPORTS = dedup_list(settings.REQUIRED_EXPORTS) |
| 1876 | settings.EXPORT_IF_DEFINED = dedup_list(settings.EXPORT_IF_DEFINED) |
| 1877 | |
| 1878 | rtn = None |
| 1879 | if settings.LINKABLE and not settings.EXPORT_ALL: |
| 1880 | # In LINKABLE mode we pass `--export-dynamic` along with `--whole-archive`. This results |
| 1881 | # in over 7000 exports, which cannot be distinguished from the few symbols we explicitly |
| 1882 | # export via EMSCRIPTEN_KEEPALIVE or EXPORTED_FUNCTIONS. |
| 1883 | # In order to avoid unnecessary exported symbols on the `Module` object we run the linker |
| 1884 | # twice in this mode: |
| 1885 | # 1. Without `--export-dynamic` to get the base exports |
| 1886 | # 2. With `--export-dynamic` to get the actual linkable Wasm binary |
| 1887 | # TODO(sbc): Remove this double execution of wasm-ld if we ever find a way to |
| 1888 | # distinguish EMSCRIPTEN_KEEPALIVE exports from `--export-dynamic` exports. |
| 1889 | settings.LINKABLE = False |
| 1890 | building.link_lld(linker_args, wasm_target, external_symbols=js_syms, |
| 1891 | linker_inputs=linker_inputs) |
| 1892 | settings.LINKABLE = True |
| 1893 | rtn = extract_metadata.extract_metadata(wasm_target) |
| 1894 | |
| 1895 | building.link_lld(linker_args, wasm_target, external_symbols=js_syms, linker_inputs=linker_inputs) |
| 1896 | return rtn |
| 1897 | |
| 1898 | |
| 1899 | @ToolchainProfiler.profile_block('post link') |