WebAssembly / WebAssembly/tool-conventions

Revisit the default of `-fvisibility=hidden`

Open
#176 13 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
WebAssembly
Stars
372
Forks
75
PR merge metrics
No merged PRs in 30d

Description

;TLDR; visibility is currently only used by emscripten and emscripten uses a default of -fvisibility=default.

A long while ago we choose to make -fvisibility=hidden the default for the WebAssembly backend in llvm. IIRC the rational was that we would want to avoid exporting a lot of C/C++ symbols by default.

However, the only time the wasm-ld linker actually exports things based on their visibility is when -shared is used (or in the static linking case when --export-dynamic is passed). These flags are not currently used outside of emscripten. For example, with wasi-sdk users are currently things via on of 3 different methods:

  1. Explicit --export on the command line (e.g. --export=foo)
  2. --export-all on the command line. This is even worse that exporting non-hidden symbols since it exports everything (do we even what to support this going forward?)
  3. export_name attribute in the source code.

In emscripten, the visibility attribute is honored when -shared/-pie is used, and we recently switch from using --export-all to --export-dynamic + -fvisibility=default which results in fewer exports (for example --export-all exports all libc-internal symbols , even those marked as hidden, whereas --export-dynamic + -fvisibility=default does not). See https://github.com/emscripten-core/emscripten/pull/15413.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the wasm-ld linker behavior described here, then compare how emscripten and wasi-sdk use -fvisibility=hidden/default, -shared/-pie, --export-dynamic, --export-all, and export_name. Review the linked emscripten change for context. Done requires an agreed convention for the default and its supported export mechanisms, followed by coordinated implementation and validation.

Written by the indexing model from the issue text.

Assessment

Tech stack
wasm
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.