Master the fundamental concepts of webassembly internals through this focused micro-challenge.
WebAssembly is a portable binary ISA. LLVM's \`clang --target=wasm32\` plus \`wasm-ld\` turns C into a \`.wasm\` module browsers and standalone runtimes can load.
Pipeline:
C symbols are hidden by default. Export with \`attribute((visibility("default")))\` or a linker \`--export\` flag so JavaScript or WASI can call \`add\`.
For example:
\`\`\`c attribute((export_name("add"))) int add(int a, int b) { return a + b; } \`\`\`
compiles to \`i32.add\` on two parameters in the Wasm stack machine.
Binary starts with magic \`\\0asm\` and version bytes, then type, function, export, and code sections.
Inspect both WAT and the raw binary hex for the same module. Seeing `00 61 73 6D` at offset zero confirms you are looking at Wasm, not a mislabeled object file from a wrong target triple.
This exercise asks you to document the clang/wasm-ld pipeline for a simple \`add\` function. You will show C source, linker commands, and the resulting WAT so you can read what the compiler produced.
You will use the same mental model here when reading production interpreter source later in the track. Sketch one concrete input on paper, predict the outcome, then confirm with code. That discipline catches logic errors early and makes debugging far faster when you extend the implementation in follow-on tasks.
Write a C program that documents the Wasm compilation workflow for a simple add function.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github