Skip to content

DynamicLinking: Specify new "dylink.0" section format #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions DynamicLinking.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,48 @@ A WebAssembly dynamic library is a WebAssembly binary with a special custom
section that indicates this is a dynamic library and contains additional
information needed by the loader.

## The "dylink" Section
## The "dylink.0" Section

The "dylink" section is defined as:
The "dylink.0" is a custom section, the existence of which signals that the
module conforms the dynaminc linking ABI described in this document. This
section is expected to be the very first section in the module.

A "dylink.0" consists of a series of sub-sections using the same format as found
in the ["names"][names_sec] section:

| Field | Type | Description |
| ----------- | ------------- | ------------------------------------ |
| subsections | `subsection*` | sequence of `subsection` |

Each `subsection` is encoded as:

| Field | Type | Description |
| ------------ | ----------- | ------------------------------------ |
| type | `uint8` | code identifying type of subsection |
| payload_len | `varuint32` | size of this subsection in bytes |
| payload_data | `bytes` | content of this subsection, of length `payload_len` |

The current list of valid `type` codes are:

- `1 / WASM_DYLINK_MEM_INFO` - Specifies the memory and table space requirements of the module

- `2 / WASM_DYLINK_NEEDED` - Specifies external modules that this one depends on.

For `WASM_DYLINK_MEM_INFO` the following fields are present in the
subsection:

| Field | Type | Description |
| ---------------------- | --------------- | ------------------------------ |
| memorysize | `varuint32` | Size of the memory area the loader should reserve for the module, which will begin at `env.__memory_base` |
| memoryalignment | `varuint32` | The required alignment of the memory area, in bytes, encoded as a power of 2. |
| tablesize | `varuint32` | Size of the table area the loader should reserve for the module, which will begin at `env.__table_base` |
| tablealignment | `varuint32` | The required alignment of the table area, in elements, encoded as a power of 2. |

For `WASM_DYLINK_NEEDED` the following fields are present in the
subsection:

| Field | Type | Description |
| ---------------------- | --------------- | ------------------------------ |
| needed_dynlibs_count | `varuint32` | Number of needed shared libraries |
| needed_dynlibs_entries | `dynlib_entry*` | Repeated dynamic library entries as described below |

Expand Down Expand Up @@ -51,6 +83,8 @@ The "dylink" section should be the very first section in the module; this allows
detection of whether a binary is a dynamic library without having to scan the
entire contents.

[names_sec]: https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#name-section

## Interface and usage

A WebAssembly dynamic library must obey certain conventions. In addition to
Expand Down