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

Open
#666 0 comments 0 reactions 0 assignees View on GitHub

@jeremy-code is already working on this.

Since Nov 13, 2026.

  • #912 by @jeremy-code — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
54/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c, wasm
Domain
tooling

Research direction

Start by compiling the provided C reproduction with the shown WASI SDK command, then inspect the resulting .wasm imports or its .wat output. Trace why formatting calls retain __stdio_close, __stdio_write, and __stdio_seek; done means the output no longer imports the corresponding WASI calls when the program does not use standard streams.

Written by the indexing model from the issue text.

Description

sprintf, snprintf (and probably also vsprintf and vsnprintf, but that's more difficult to provide a minimal reproduction) will pull in fd_close, fd_seek, fd_write despite no stdin/stdout/stderr usage.

#include <stdio.h>

__attribute__((export_name("foo")))
void foo() {
  char buffer[26];
  sprintf(buffer, "An error occurred: %d", 1);
  snprintf(buffer, sizeof buffer, "An error occurred: %d", 1);
}
clang \
  -Os \
  -flto \
  --sysroot=/opt/wasi-sdk/share/wasi-sysroot \
  --target=wasm32-wasip1 \
  -Wl,--lto-O3 \
  -Wl,--no-entry \
  -nostartfiles \
  -o $OUTPUT_DIR/main.wasm \
  main.c

This was compiled with the Docker container ghcr.io/webassembly/wasi-sdk:wasi-sdk-34.

Here is the corresponding text format .wat: https://gist.github.com/jeremy-code/259c873e9b25f170ad909a5da8079d14. __stdio_close, __stdio_write, __stdio_seek are pulled in despite not being used (both directly and indirectly).

(module
 (import "wasi_snapshot_preview1" "fd_close" (func $__imported_wasi_snapshot_preview1_fd_close (param i32) (result i32)))
 (import "wasi_snapshot_preview1" "fd_seek" (func $__imported_wasi_snapshot_preview1_fd_seek (param i32 i64 i32 i32) (result i32)))
 (import "wasi_snapshot_preview1" "fd_write" (func $__imported_wasi_snapshot_preview1_fd_write (param i32 i32 i32 i32) (result i32)))
 ;; ...
)

Possibly related issues:

  1. https://github.com/WebAssembly/wasi-sdk/issues/190
  2. https://github.com/WebAssembly/wasi-sdk/issues/401
Dominant language
CMake
Stars
1.7k
Forks
242
Avg merge
7h 43m
Merged PRs (30d)
2

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

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.

More from WebAssembly/wasi-sdk

All issues in WebAssembly/wasi-sdk

Similar issues

More DevTools issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.