Skip to content

Allow users to override or filter list of exported symbols passed to the WASM linker #104130

Open
@Manishearth

Description

@Manishearth

Currently, the way export visibility is handled in WASM is that rustc manually passes a list of all exported functions to the WASM linker:

for sym in symbols {
self.cmd.arg("--export").arg(&sym);
}

In almost every mode of compilation for Rust it doesn't matter too much if the exports list covers more than is needed, because there's a linker at the very end dealing with this. Rlibs and staticlibs may end up containing extra symbols, but the end binary will have dead code removed by the final linker. Dynamic libraries end up containing extra symbols which is a disk size issue (not a huge deal), but the dynamic linker's capable of only paging in the necessary bits.

The landscape is very different for WASM, however. In WASM, the final binary is a .wasm file that gets sent over the network, and its size matters. It's impractical to compile large libraries to a single .wasm file and recommend everyone use it since most users will not be using 99% of that wasm file.

There are tools for doing dead code elimination in JS, usually going by the name "tree shaking". Furthermore it's often practical for a WASM user to just list out the symbols they need.

With all of this, it would be useful to be able to customize which symbols get exported as a part of the linker process, rather than updating the code (as different library clients will need different things and it might not always be practical to pepper the library with a hundred client specific cfgs, nor is it an appropriate separation of concerns)

It would be nice if rust had a pair of codegen flags that would:

  • Allow explicitly allowlisting/listing symbols that get passed down to rust-lld --export
  • Allow explicitly denylisting symbols that get passed down to rust-lld --export, to "filter out" features

cc @sffc

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesO-wasmTarget: WASM (WebAssembly), http://webassembly.org/

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions