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

Aperta
#666 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@jeremy-code ci sta già lavorando.

Dal 13/11/2026.

  • #912 di @jeremy-code — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
54/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
c, wasm
Ambito
tooling

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
CMake
Stelle
1.7k
Fork
242
Merge medio
7h 43m
PR unite (30g)
2

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di WebAssembly/wasi-sdk

Tutte le issue di WebAssembly/wasi-sdk

Issue simili

Altre issue su DevTools

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.