WebAssembly Dependent Features
******************************

Notes
=====

While WebAssembly provides its own module format for executables, this documentation describes how to use AS to produce intermediate ELF object format files.

Syntax
======

The assembler syntax directly encodes sequences of opcodes as defined in the WebAssembly binary encoding specification at https://github.com/webassembly/spec/BinaryEncoding.md.  Structured sexp-style expressions are not supported as input.

Special Characters
------------------

# and ; are the line comment characters.  Note that if # is the first character on a line then it can also be a logical line number directive (see Comments) or a preprocessor control command (see Preprocessing).

Relocations
-----------

Special relocations are available by using the @PLT, @GOT, or @GOT suffixes after a constant expression, which correspond to the R_ASMJS_LEB128_PLT, R_ASMJS_LEB128_GOT, and R_ASMJS_LEB128_GOT_CODE relocations, respectively.

The @PLT suffix is followed by a symbol name in braces; the symbol value is used to determine the function signature for which a PLT stub is generated. Currently, the symbol name is parsed from its last F character to determine the argument count of the function, which is also necessary for generating a PLT stub.

Signatures
----------

Function signatures are specified with the signature pseudo-opcode, followed by a simple function signature imitating a C++-mangled function type: F followed by an optional v, then a sequence of i, l, f, and d characters to mark i32, i64, f32, and f64 parameters, respectively; followed by a final E to mark the end of the function signature.

Floating Point
==============

WebAssembly uses little-endian IEEE floating-point numbers.

Regular Opcodes
===============

Ordinary instructions are encoded with the WebAssembly mnemonics as listed at: https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md.

Opcodes are written directly in the order in which they are encoded, without going through an intermediate sexp-style expression as in the was format.

For ``typed'' opcodes (block, if, etc.), the type of the block is specified in square brackets following the opcode: if[i], if[].

WebAssembly Module Layout
=========================

AS will only produce ELF output, not a valid WebAssembly module. It is possible to make AS produce output in a single ELF section which becomes a valid WebAssembly module, but a linker script to do so may be preferrable, as it doesn't require running the entire module through the assembler at once.