Skip to content

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

Merged
alexcrichton merged 2 commits into
WebAssembly:mainfrom
jeremy-code:dev/stderr-no-stdio
Nov 24, 2026
Merged

alexcrichton merged 2 commits into
WebAssembly:mainfrom
jeremy-code:dev/stderr-no-stdio

Conversation

@jeremy-code

Copy link
Copy Markdown
Contributor

__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?

@jeremy-code

Copy link
Copy Markdown
Contributor Author

Got it, I updated the PR to instead return -1 and set errno to EINVAL whenever printf (or anything else that uses printscan) attempts to interpret a double/floating point when they are not supported.

@alexcrichton
alexcrichton merged commit 238d349 into WebAssembly:main Nov 24, 2026
37 checks passed
@jeremy-code
jeremy-code deleted the dev/stderr-no-stdio branch November 24, 2026 16:27
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