1//===- Wasm.h - Wasm object file format -------------------------*- C++ -*-===//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//===----------------------------------------------------------------------===//
9// This file defines manifest constants for the wasm object file format.
10// See: https://github.com/WebAssembly/design/blob/main/BinaryEncoding.md
12//===----------------------------------------------------------------------===//
14#ifndef LLVM_BINARYFORMAT_WASM_H
15#define LLVM_BINARYFORMAT_WASM_H
26// Object file magic string.
28// Wasm binary format version
30// Wasm linking metadata version
32// Wasm uses a 64k page size by default (but the custom-page-sizes proposal
54// Type immediate encodings used in various contexts.
84// Kinds of externals (for imports and exports).
93// Opcodes used in initializer expressions.
119// Opcodes in the GC-prefixed space (0xfb)
127 // any.convert_extern and extern.convert_any don't seem to be supported by
131// Opcodes used in synthetic functions.
149// Sub-opcodes for catch clauses in a try_table instruction
178// Feature policy prefixes used in the custom "target_features" section
184// Kind codes used in the custom "name" section
193// Kind codes used in the custom "linking" section
201// Kind codes used in the custom "dylink" section
210// Kind codes used in the custom "linking" section in the WASM_COMDAT_INFO
214 // GLOBAL, TAG, and TABLE are in here but LLVM doesn't use them yet.
218// Kind codes used in the custom "linking" section in the WASM_SYMBOL_TABLE
234// Kinds of tag attributes.
254 #define WASM_RELOC(name, value) name = value,
257#include "WasmRelocs.def"
267// Subset of types that a value can have
277 // Unmodeled value types include ref types with heap types other than
278 // func, extern or exn, and type-specialized funcrefs
298 std::vector<StringRef>
Needed;
// Shared library dependencies
305 std::vector<std::pair<std::string, std::string>>
Languages;
306 std::vector<std::pair<std::string, std::string>>
Tools;
307 std::vector<std::pair<std::string, std::string>>
SDKs;
350// Extended-const init exprs and exprs with GC types are not explicitly
351// modeled, but the raw body of the expr is attached.
370 uint32_t Size;
// Size of the definition in the binary's Global section
404 std::optional<StringRef>
ExportName;
// from the "export" section
412 // Present if InitFlags & WASM_DATA_SEGMENT_HAS_MEMINDEX.
414 // Present if InitFlags & WASM_DATA_SEGMENT_IS_PASSIVE == 0.
424// 3 different element segment modes are encodable. This class is currently
425// only used during decoding (see WasmElemSegment below).
428// Represents a Wasm element segment, with some limitations compared the spec:
429// 1) Does not model passive or declarative segments (Segment will end up with
430// an Offset field of i32.const 0)
431// 2) Does not model init exprs (Segment will get an empty Functions list)
432// 3) Does not model types other than basic funcref/externref/exnref (see
442// Represents the location of a Wasm data symbol within a WasmDataSegment, as
443// the index of the segment, and the offset and size within the segment.
454 int64_t
Addend;
// A value to add to the symbol.
468 // For undefined symbols the module of the import
470 // For undefined symbols the name of the import
472 // For symbols to be exported from the final module
475 // For function, table, or global symbols, the index in function, table, or
476 // global index space.
478 // For a data symbols, the address of the data relative to segment.
495// Info from the linking metadata section of a wasm object file.
500 // The linking section also contains a symbol table. This info (represented
501 // in a WasmSymbolInfo struct) is stored inside the WasmSymbol object instead
502 // of in this structure; this allows vectors of WasmSymbols and
503 // WasmLinkingDatas to be reallocated.
509 // LLVM can parse types other than functions encoded in the type section,
510 // but does not actually model them. Instead a placeholder signature is
511 // created in the Object's signature list.
513 // Support empty and tombstone instances, needed by DenseMap.
522// Useful comparison operators
524 return LHS.State ==
RHS.State &&
LHS.Returns ==
RHS.Returns &&
533 return LHS.Type ==
RHS.Type &&
LHS.Mutable ==
RHS.Mutable;
541 return LHS.Flags ==
RHS.Flags &&
LHS.Minimum ==
RHS.Minimum &&
545 ?
LHS.PageSize ==
RHS.PageSize
550 return LHS.ElemType ==
RHS.ElemType &&
LHS.Limits ==
RHS.Limits;
558}
// end namespace wasm
559}
// end namespace llvm
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
LLVM Value Representation.
const unsigned WASM_SYMBOL_UNDEFINED
const unsigned WASM_SYMBOL_NO_STRIP
@ WASM_TYPE_NULLEXTERNREF
@ WASM_OPCODE_CATCH_ALL_REF
const unsigned WASM_SYMBOL_BINDING_GLOBAL
@ WASM_TAG_ATTRIBUTE_EXCEPTION
const unsigned WASM_SYMBOL_TLS
const uint32_t WasmMetadataVersion
const unsigned WASM_SYMBOL_BINDING_WEAK
const unsigned WASM_SYMBOL_BINDING_LOCAL
@ WASM_LIMITS_FLAG_HAS_MAX
@ WASM_LIMITS_FLAG_IS_SHARED
@ WASM_LIMITS_FLAG_HAS_PAGE_SIZE
@ WASM_DATA_SEGMENT_IS_PASSIVE
@ WASM_DATA_SEGMENT_HAS_MEMINDEX
LLVM_ABI llvm::StringRef toString(WasmSymbolType type)
@ WASM_FEATURE_PREFIX_USED
@ WASM_FEATURE_PREFIX_DISALLOWED
@ WASM_SYMBOL_TYPE_GLOBAL
@ WASM_SYMBOL_TYPE_SECTION
@ WASM_SYMBOL_TYPE_FUNCTION
const uint32_t WasmVersion
const unsigned WASM_SYMBOL_EXPORTED
const unsigned WASM_SYMBOL_BINDING_MASK
@ WASM_ELEM_SEGMENT_HAS_INIT_EXPRS
@ WASM_ELEM_SEGMENT_IS_DECLARATIVE
@ WASM_ELEM_SEGMENT_HAS_TABLE_NUMBER
@ WASM_ELEM_SEGMENT_IS_PASSIVE
LLVM_ABI bool relocTypeHasAddend(uint32_t type)
@ WASM_DYLINK_RUNTIME_PATH
@ WASM_DYLINK_EXPORT_INFO
@ WASM_DYLINK_IMPORT_INFO
@ WASM_OPCODE_ARRAY_NEW_FIXED
@ WASM_OPCODE_ARRAY_NEW_DEFAULT
@ WASM_OPCODE_STRUCT_NEW_DEFAULT
@ WASM_NAMES_DATA_SEGMENT
bool operator!=(const WasmSignature &LHS, const WasmSignature &RHS)
LLVM_ABI llvm::StringRef sectionTypeToString(uint32_t type)
const uint32_t WasmDefaultPageSize
const unsigned WASM_SYMBOL_EXPLICIT_NAME
const unsigned WASM_SYMBOL_ABSOLUTE
bool operator==(const WasmSignature &LHS, const WasmSignature &RHS)
const unsigned WASM_SYMBOL_VISIBILITY_MASK
const unsigned WASM_SYMBOL_VISIBILITY_HIDDEN
const unsigned WASM_ELEM_SEGMENT_MASK_HAS_ELEM_DESC
LLVM_ABI llvm::StringRef relocTypetoString(uint32_t type)
const unsigned WASM_SYMBOL_VISIBILITY_DEFAULT
@ WASM_OPCODE_I32_ATOMIC_STORE
@ WASM_OPCODE_MEMORY_FILL
@ WASM_OPCODE_I32_ATOMIC_WAIT
@ WASM_OPCODE_MISC_PREFIX
@ WASM_OPCODE_ATOMIC_NOTIFY
@ WASM_OPCODE_I32_RMW_CMPXCHG
@ WASM_OPCODE_MEMORY_INIT
@ WASM_OPCODE_ATOMICS_PREFIX
This is an optimization pass for GlobalISel generic memory operations.
ArrayRef< uint8_t > Content
std::vector< StringRef > Needed
std::vector< StringRef > RuntimePath
std::vector< WasmDylinkExportInfo > ExportInfo
std::vector< WasmDylinkImportInfo > ImportInfo
std::vector< uint32_t > Functions
std::optional< StringRef > ExportName
std::vector< WasmLocalDecl > Locals
uint32_t CodeSectionOffset
std::vector< WasmInitFunc > InitFunctions
std::vector< StringRef > Comdats
std::vector< std::pair< std::string, std::string > > SDKs
std::vector< std::pair< std::string, std::string > > Languages
std::vector< std::pair< std::string, std::string > > Tools
WasmRelocType getType() const
WasmSignature(SmallVector< ValType, 1 > &&InReturns, SmallVector< ValType, 4 > &&InParams)
SmallVector< ValType, 1 > Returns
SmallVector< ValType, 4 > Params
std::optional< StringRef > ExportName
WasmDataReference DataRef
std::optional< StringRef > ImportModule
std::optional< StringRef > ImportName