Skip to content

Remove guesswork from getStackPointerGlobal. NFC#8679

Open
sbc100 wants to merge 1 commit intomainfrom
stack_pointer_name
Open

Remove guesswork from getStackPointerGlobal. NFC#8679
sbc100 wants to merge 1 commit intomainfrom
stack_pointer_name

Conversation

@sbc100
Copy link
Copy Markdown
Member

@sbc100 sbc100 commented May 6, 2026

We were just assuming that if no __stack_pointer was imported then the first global must be the __stack_pointer.

Instead we can just require that the global be names correctly in the name section. This will require an emscripten-side change to ensure names are generated when running this pass.

Needed for fixing emscripten-core/emscripten#24964.

@sbc100 sbc100 requested a review from a team as a code owner May 6, 2026 22:07
@sbc100 sbc100 requested review from kripken and removed request for a team May 6, 2026 22:07
Copy link
Copy Markdown
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean emscripten will need wasm-ld to always emit modules with the name section? I guess we'll need to strip it in optimized builds?

Comment thread src/wasm/wasm-emscripten.cpp Outdated
@sbc100
Copy link
Copy Markdown
Member Author

sbc100 commented May 6, 2026

wasm-emscripten-finalize, just like all the binaryen tools, will strip the name section unless we explictly pass -g

@sbc100 sbc100 force-pushed the stack_pointer_name branch 2 times, most recently from 0bd8f34 to c13f503 Compare May 6, 2026 23:53
@dschuff
Copy link
Copy Markdown
Member

dschuff commented May 7, 2026

Requiring a name section seems brittle? It could be stripped, or not updated after a transform?
Exporting the stack pointer with a name also seems maybe less than ideal since it would be an unnecessary export, but at least it can be independent of the name section.

@sbc100
Copy link
Copy Markdown
Member Author

sbc100 commented May 7, 2026

From the emscipten side this is not brittle. wasm-emscripten-finalize is always the first thing we do after linking and this pass only ever runs as part of wasm-emscripten-finalize.

I don't know that there are any other users of this pass other than emscripten?

@sbc100
Copy link
Copy Markdown
Member Author

sbc100 commented May 7, 2026

It could be stripped, or not updated after a transform?

Do you mean during the same run of binaryen that uses the name? The name section is only depended on here when the module is read in. If we strip the name section I don't think that changes the global->name properties that were initially set by the name section when the module was loaded.

@sbc100
Copy link
Copy Markdown
Member Author

sbc100 commented May 7, 2026

if it turns out there are other users, and they don't want to use the name section we can perhaps introduce a flag to specify which global represents the stack pointer?

We were just assuming that if no `__stack_pointer` was imported then the
first global must be the `__stack_pointer`.

Instead we can just require that the global be names correctly in the
name section.  This will require an emscripten-side change to ensure
names are generated when running this pass.

Needed for fixing emscripten-core/emscripten#24964.
@sbc100 sbc100 force-pushed the stack_pointer_name branch from 8e2c2be to 18f0cbd Compare May 7, 2026 00:22
sbc100 added a commit that referenced this pull request May 7, 2026
Without this the github CI often shows the errors in confusing locations
interspersed with the test names.

I confirmed in #8679 that this addresses the issue. Maybe there is a
better place to do this but this is good improvement for now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants