aboutsummaryrefslogtreecommitdiff
path: root/gas/doc/c-wasm32.texi
blob: 997838867927c75e9c3e86d49a3f3e81afc091e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
@c Copyright (C) 2017-2021 Free Software Foundation, Inc.
@c This is part of the GAS manual.
@c For copying conditions, see the file as.texinfo.
@c man end

@ifset GENERIC
@page
@node WebAssembly-Dependent
@chapter WebAssembly Dependent Features
@end ifset

@ifclear GENERIC
@node Machine Dependencies
@chapter WebAssembly Dependent Features
@end ifclear

@cindex WebAssembly support
@menu
* WebAssembly-Notes::                Notes
* WebAssembly-Syntax::               Syntax
* WebAssembly-Floating-Point::       Floating Point
* WebAssembly-Opcodes::              Opcodes
* WebAssembly-module-layout::        Module Layout
@end menu

@node WebAssembly-Notes
@section Notes
@cindex WebAssembly notes
@cindex notes for WebAssembly

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

@node WebAssembly-Syntax
@section Syntax
@cindex WebAssembly 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.

@menu
* WebAssembly-Chars::                Special Characters
* WebAssembly-Relocs::               Relocations
* WebAssembly-Signatures::           Signatures
@end menu

@node WebAssembly-Chars
@subsection Special Characters

@cindex line comment character, WebAssembly
@cindex WebAssembly line comment character
@samp{#} and @samp{;} are the line comment characters.  Note that if
@samp{#} is the first character on a line then it can also be a
logical line number directive (@pxref{Comments}) or a preprocessor
control command (@pxref{Preprocessing}).

@node WebAssembly-Relocs
@subsection Relocations
@cindex WebAssembly relocations
@cindex relocations, WebAssembly

Special relocations are available by using the @samp{@@@var{plt}},
@samp{@@@var{got}}, or @samp{@@@var{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 @samp{@@@var{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 @emph{name} is parsed
from its last @samp{F} character to determine the argument count of
the function, which is also necessary for generating a PLT stub.

@node WebAssembly-Signatures
@subsection Signatures
@cindex WebAssembly signatures
@cindex signatures, WebAssembly

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

@node WebAssembly-Floating-Point
@section Floating Point
@cindex floating point, WebAssembly (@sc{ieee})
@cindex WebAssembly floating point (@sc{ieee})
WebAssembly uses little-endian @sc{ieee} floating-point numbers.

@node WebAssembly-Opcodes
@section Regular Opcodes
@cindex opcodes, WebAssembly
@cindex WebAssembly opcodes
Ordinary instructions are encoded with the WebAssembly mnemonics as
listed at:
@url{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
@code{was} format.

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

@node WebAssembly-module-layout
@section WebAssembly Module Layout
@cindex module layout, WebAssembly
@cindex WebAssembly module layout
@code{@value{AS}} will only produce ELF output, not a valid
WebAssembly module. It is possible to make @code{@value{AS}} produce
output in a single ELF section which becomes a valid WebAssembly
module, but a linker script to do so may be preferable, as it doesn't
require running the entire module through the assembler at once.