Skip to content

Prevent stderr being linked when in-memory stdio is used - #912

Open
jeremy-code wants to merge 1 commit into
WebAssembly:mainfrom
jeremy-code:dev/stderr-no-stdio
Open

jeremy-code wants to merge 1 commit into
WebAssembly:mainfrom
jeremy-code:dev/stderr-no-stdio

Conversation

@jeremy-code

Copy link
Copy Markdown

__stderr_FILE references the addresses of __stdio_write, __stdio_seek, __stdio_close; hence, linking stderr will include those imports.

floating_point_not_supported and long_double_not_supported now only output to stderr if it has already been linked instead of referencing stderr directly. Otherwise, it traps silently.

Add __stdio_write_needs_stderr function that references __stderr_FILE.

Closes wasi-sdk#666.

@jeremy-code
jeremy-code force-pushed the dev/stderr-no-stdio branch 3 times, most recently from 5810ee8 to 3213b8f Compare November 13, 2026 05:26
__stderr_FILE references the addresses of __stdio_write, __stdio_seek, __stdio_close; hence, linking stderr will include those imports.

floating_point_not_supported and long_double_not_supported now only outputs to stderr if it has already been linked instead of referencing stderr directly. Otherwise, it traps silently.

Add __stdio_write_needs_stderr function to reference __stderr_FILE.

@alexcrichton alexcrichton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the PR here, but I can't help but think that this is a bit of a roundabout way to solve a problem that's self-inflicted by wasi-libc. Thinking about this I'm wondering if it might be better to just return an error on unsupported format identifiers instead of trying to print anything to the screen.

For example this PR has pretty surprising behavior IMO where the rough intention is to print an error, but such an error only happens to show up should you use some other functions. That sort of behavior feels like spooky-action-at-a-distance to me and best avoided. If an error is unconditionally returned it's still surprising but at least it's deterministic.

Would you be interested to try to sketch out a solution like that?

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.

sprintf, snprintf pull in fd_close, fd_seek, fd_write despite no stdin/stdout/stderr usage

2 participants