Skip to content

Should we add function names to source maps generated by emscripten? #20715

@dschuff

Description

@dschuff

Currently emscripten can generate source maps that map wasm binary offsets to source locations. These can be used for symbolizing binaries in devtools, and various other tooling outside the browser. Currently if you use -gsource-map you get one of these, and you also get a name section in the binary. That means that if a user wants to have the mappings for a production binary, they need to strip the binary and save name information (or the whole unstripped binary) separately, in addition to the source maps.
However the source map format actually has a field to hold a list of such names (see https://github.com/tc39/source-map-spec/blob/main/source-map-rev3.md). Each segment in the mapping section can have a pointer to an index in this table. Currently we do not populate the names.
In principle we could, e.g. put the same information in the source maps names field as in the name section in the binary in a 1:1 way such that an index in the sourcemap field corresponds to an index in the name section.

Advantages: it would make the name section in the binary unnecessary, and all the information could be in one place. Aside from being conceptually simpler, it would be easier for external tools that wanted to do symbolization (especially if such tools already support names in source maps), and would be simpler for users who wanted to use sourcemaps with release binaries (since they wouldn't have to strip the release binary and keep the unstripped binary separately).

Disadvantages: Browsers understand the name section more directly than sourcemaps (e.g. in V8's case, it will include the names directly in stack traces even when not using devtools); there might also be other tools that understand wasm binaries but not sourcemaps. Swapping the name section for names in a source map might result in overall size bloat (because the sourcemap mapping section has 1 name index per segment, not per function).

As a related issue, IIRC there's no current way to explicitly control whether a binary has a name section. You always just get it along with either DWARF or source map. If we change the -gsource-map flag to only produce a source map (or even if we dont?) we might want some flag to control generating a name section that could be orthogonal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions