Skip to content
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

Handle weak undefined globals/functions #47

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
30 changes: 18 additions & 12 deletions Linking.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ The current set of valid flags for symbols are:
discarded if any strong definitions exist; then if multiple weak definitions
exist all but one (unspecified) are discarded; and finally it is an error if
more than one definition remains.

It is an error to apply this flag to undefined global symbols; when linking,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just "This flag may not be applied to symbols of type SYMBOL_TYPE_GLOBAL"?

(Also I think the abort SYMTAB_XXX should be more like SYMBOL_TYPE_XX)

all global symbols must have a definition provided so imports must be strong.
- `2 / WASM_SYM_BINDING_LOCAL` - Indicating that this is a local symbol (this
is exclusive with `WASM_SYM_BINDING_WEAK`). Local symbols are not to be
exported, or linked to other modules/sections. The names of all non-local
Expand Down Expand Up @@ -346,18 +349,21 @@ Finally, when processing table relocations for symbols which have neither an
import nor a definition (namely, weakly-undefined function symbols), the value
`0` is written out as the value of the relocation.

`R_WEBASSEMBLY_FUNCTION_INDEX_LEB` relocations may fail to be processed, in
which case linking fails. This occurs if there is a weakly-undefined function
symbol, in which case there is no legal value that can be written as the target
of any `call` instruction. The frontend must generate calls to undefined weak
symbols via a `call_indirect` instruction.

`R_WEBASSEMBLY_GLOBAL_INDEX_LEB` relocations may fail to be processed, in which
case linking fails. This occurs if there is a weakly-undefined global symbol,
in which case there is no legal value that can be written as the target of any
`get_global` or `set_global` instruction. The frontend must not weak globals
which may not be defined; a definition or import must exist for all global
symbols in the linked output.
`R_WEBASSEMBLY_FUNCTION_INDEX_LEB` relocations shall not fail to be processed.
In case where the function symbol is weakly-undefined, there is no function
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don''t think you need the first sentence of this para.

provided to the linker which can be used as the value of the relocation, and,
a `call` instruction must refer to a function for the module to validate.
Therefore, the linker must synthesise a function which aborts at runtime, to
use as the target of the relocation. Note that this synthetic stub _must not_
be placed in the table; a TABLE_INDEX relocation for the same function symbol
must resolve to `0` (the null pointer) and not to a function table entry
referencing the synthetic stub.

`R_WEBASSEMBLY_GLOBAL_INDEX_LEB` relocations cannot fail, since global symbols
must either be defined (weakly or strongly), or if undefined must be strong.
Hence, there is always a global in the final output to use as the target of
the relocation. (If weak undefined globals were permitted, there would be no
Wasm global in the final output for the relocation to target.)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need this last paragraph either. If you do want to keep it perhaps it can be at least shortened.


`R_WEBASSEMBLY_MEMORY_ADDR_LEB`, `R_WEBASSEMBLY_MEMORY_ADDR_SLEB` and
`R_WEBASSEMBLY_MEMORY_ADDR_I32` relocations cannot fail. The relocation's value
Expand Down