aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/WasmObjectFile.cpp
diff options
context:
space:
mode:
authorNick Fitzgerald <fitzgen@gmail.com>2025-03-04 09:39:30 -0800
committerGitHub <noreply@github.com>2025-03-04 09:39:30 -0800
commit6018930ef1fa62315c3e02b8b8b775056bd5224d (patch)
treebdc103a21d323232b4196d2a7490ef62f97bc687 /llvm/lib/Object/WasmObjectFile.cpp
parentbbbdb23c33ef56a518072754f4dc4d123655276d (diff)
downloadllvm-6018930ef1fa62315c3e02b8b8b775056bd5224d.zip
llvm-6018930ef1fa62315c3e02b8b8b775056bd5224d.tar.gz
llvm-6018930ef1fa62315c3e02b8b8b775056bd5224d.tar.bz2
[lld][WebAssembly] Support for the custom-page-sizes WebAssembly proposal (#128942)
This commit adds support for WebAssembly's custom-page-sizes proposal to `wasm-ld`. An overview of the proposal can be found [here](https://github.com/WebAssembly/custom-page-sizes/blob/main/proposals/custom-page-sizes/Overview.md). In a sentence, it allows customizing a Wasm memory's page size, enabling Wasm to target environments with less than 64KiB of memory (the default Wasm page size) available for Wasm memories. This commit contains the following: * Adds a `--page-size=N` CLI flag to `wasm-ld` for configuring the linked Wasm binary's linear memory's page size. * When the page size is configured to a non-default value, then the final Wasm binary will use the encodings defined in the custom-page-sizes proposal to declare the linear memory's page size. * Defines a `__wasm_first_page_end` symbol, whose address points to the first page in the Wasm linear memory, a.k.a. is the Wasm memory's page size. This allows writing code that is compatible with any page size, and doesn't require re-compiling its object code. At the same time, because it just lowers to a constant rather than a memory access or something, it enables link-time optimization. * Adds tests for these new features. r? @sbc100 cc @sunfishcode
Diffstat (limited to 'llvm/lib/Object/WasmObjectFile.cpp')
-rw-r--r--llvm/lib/Object/WasmObjectFile.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp
index 98c4b9d..ee7a306 100644
--- a/llvm/lib/Object/WasmObjectFile.cpp
+++ b/llvm/lib/Object/WasmObjectFile.cpp
@@ -291,6 +291,12 @@ static wasm::WasmLimits readLimits(WasmObjectFile::ReadContext &Ctx) {
Result.Minimum = readVaruint64(Ctx);
if (Result.Flags & wasm::WASM_LIMITS_FLAG_HAS_MAX)
Result.Maximum = readVaruint64(Ctx);
+ if (Result.Flags & wasm::WASM_LIMITS_FLAG_HAS_PAGE_SIZE) {
+ uint32_t PageSizeLog2 = readVaruint32(Ctx);
+ if (PageSizeLog2 >= 32)
+ report_fatal_error("log2(wasm page size) too large");
+ Result.PageSize = 1 << PageSizeLog2;
+ }
return Result;
}