`sprintf`, `snprintf` pull in `fd_close`, `fd_seek`, `fd_write` despite no stdin/stdout/stderr usage
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 54/100
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:
- 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from WebAssembly/wasi-sdk
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
WebAssembly/wasi-sdk#657 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
WebAssembly/wasi-sdk#639 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
WebAssembly/wasi-sdk#638 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
WebAssembly/wasi-sdk#629 · 2 comments · 2 reactions ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
WebAssembly/wasi-sdk#588 · 1 comment ·
All issues in WebAssembly/wasi-sdk
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
zai-org/zcode-plugins#202 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
swc-project/swc-next-issues#497 ·
-
application-issue
Difficulty 1/5 Under an hour Newbie friendliness 82/100
Installomator/Installomator#3657 · 1 comment ·
Maintainers usually reply within 3 days
-
[Bug]: 只读平台工具的描述写 "Query: projectId",但 schema 要求包进 query 对象,首次调用必然失败Possibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Tencent/LoopForge#1084 · 2 comments ·
Maintainers usually reply within 1 day