Skip to main content

Module wasm

Module wasm 

Source
Expand description

The relocatable wasm object, which the object crate reads and does not write.

Design: section 9.3 of the WebAssembly notes, and the object format of the tool conventions (Linking.md) as LLD 23 reads it. The relocation numbers are the ones in LLVM’s WasmRelocs.def, because the conventions text does not list all of them.

§What the caller gives and what this decides

The caller gives the function bodies as bytes, the data as segments, and one list of symbols. A field in a body or a segment that names something the linker places is a Fixup: the caller reserves its bytes and says what it refers to, and this module writes the field. So the caller never needs to know an index or an address. That is the point of the split, because the numbers depend on the whole file. A function index counts the imported functions first, and a data address counts every segment before the one it is in.

A function symbol is defined when a Function names it, and imported when none does. A data symbol is defined when it has a place. Globals, tables and tags are always imported, because the only ones a C object refers to are the stack pointer, the function table and the tag of longjmp, and the linker makes all three. This module sets the UNDEFINED and EXPLICIT_NAME flags itself from these facts, so a symbol cannot say that it is defined and have no definition.

§The fields the linker patches

Every relocated field in code is a LEB128 at its widest, five bytes, and every one in data is four bytes. The linker then patches in place and does not move code. The value written here is the one the field would have if this object were the whole program, which is what clang writes too, so llvm-objdump shows the same thing for both compilers.

Structs§

Fixup
A field that names something the linker places.
FuncType
The type of a function.
Function
A function that this object defines.
Import
The module and the field of an import when they are not env and the symbol name, which is what import_module and import_name ask for.
Module
Everything in one object.
Place
Where a data symbol is: its segment, its offset in that segment and its size.
Producers
The producers section: the language and the compiler.
Segment
One data segment. Each data object has its own, which is how the linker can drop one.
Symbol
One entry of the symbol table.
Written
What write() gives: the bytes, and the names a linker can find in them.

Enums§

Error
Why an object could not be written. Each one is a mistake in the caller, not in the program.
RelocKind
What a relocated field holds.
SymbolKind
What a symbol is.
ValType
A value type of the core specification.

Constants§

EXPORTED
A symbol is exported from the final module.
HIDDEN
A symbol is hidden. Every non-static symbol is, unless -fvisibility=default says otherwise.
LOCAL
A symbol is local to the object: static, or a name the compiler made.
NO_STRIP
The linker keeps a symbol that nothing refers to.
PADDED
The width of a padded LEB128 field for a 32-bit value.
RETAIN
The linker keeps a segment that nothing refers to.
STRINGS
A segment holds strings that the linker can merge.
WEAK
A symbol is weak.

Functions§

name
Push a name: its length and its bytes.
producers
The payload of the producers section, or nothing when there is nothing to say. The -S text writes the same bytes into a custom section, so the two outputs cannot disagree about it.
sleb
Push value as a signed LEB128 at its shortest.
sleb_padded
value as a signed LEB128 of five bytes.
target_features
The payload of the target_features section, or nothing when the module names no feature. The -S text writes these bytes too.
uleb
Push value as an unsigned LEB128 at its shortest.
uleb_padded
value as an unsigned LEB128 of five bytes.
write
The object for module.