1
-
2
1
Emscripten Compiler Frontend (emcc)
3
2
***********************************
4
3
@@ -40,28 +39,24 @@ Options that are modified or new in *emcc* are listed below:
40
39
No optimizations (default). This is the recommended setting for
41
40
starting to port a project, as it includes various assertions.
42
41
43
- "-O1"
44
- Simple optimizations. These include using **asm.js**, LLVM "-O1"
45
- optimizations, relooping, removing runtime assertions and C++
46
- exception catching, and enabling "-s ALIASING_FUNCTION_POINTERS=1".
47
- This is the recommended setting when you want a reasonably
48
- optimized build that is generated as quickly as possible (it builds
49
- much faster than "-O2").
50
-
51
- Note:
52
-
53
- * For details on the effects of different optimization levels,
54
- see "apply_opt_level()" in tools/shared.py and also
55
- src/settings.js.
42
+ This and other optimization settings are meaningful both during
43
+ compile and during link. During compile it affects LLVM
44
+ optimizations, and during link it affects final optimization of the
45
+ code in Binaryen as well as optimization of the JS. (For fast
46
+ incremental builds "-O0" is best, while for release you should link
47
+ with something higher.)
56
48
57
- * To re-enable C++ exception catching, use -s
58
- DISABLE_EXCEPTION_CATCHING=0.
49
+ "-O1"
50
+ Simple optimizations. During the compile step these include LLVM
51
+ "-O1" optimizations. During the link step this removes various
52
+ runtime assertions in JS and also runs the Binaryen optimizer (that
53
+ makes link slower, so even if you compiled with a higher
54
+ optimization level, you may want to link with "-O0" for fast
55
+ incremental builds).
59
56
60
57
"-O2"
61
- Like "-O1", but with various JavaScript-level optimizations and
62
- LLVM "-O3" optimizations.
63
-
64
- Note: This is a reasonable setting for a release build.
58
+ Like "-O1", but enables more optimizations. During link this will
59
+ also enable various JavaScript optimizations.
65
60
66
61
Note: These JavaScript optimizations can reduce code size by
67
62
removing things that the compiler does not see being used, in
@@ -72,23 +67,18 @@ Options that are modified or new in *emcc* are listed below:
72
67
"EXTRA_EXPORTED_RUNTIME_METHODS", see src/settings.js.
73
68
74
69
"-O3"
75
- Like "-O2", but with additional JavaScript optimizations that can
76
- take a significant amount of compilation time .
70
+ Like "-O2", but with additional optimizations that may take longer
71
+ to run .
77
72
78
73
Note: This is a good setting for a release build.
79
74
80
75
"-Os"
81
- Like "-O3", but with extra optimizations that reduce code size at
82
- the expense of performance. This can affect both bitcode generation
83
- and JavaScript.
76
+ Like "-O3", but focuses more on code size (and may make tradeoffs
77
+ with speed). This can affect both wasm and JavaScript.
84
78
85
79
"-Oz"
86
- Like "-Os", but reduces code size even further. This can affect
87
- both bitcode generation and JavaScript.
88
-
89
- For JavaScript, this turns on some code size reduction
90
- optimizations that can take a significant amount of compilation
91
- time.
80
+ Like "-Os", but reduces code size even further, and may take longer
81
+ to run. This can affect both wasm and JavaScript.
92
82
93
83
Note: For more tips on optimizing your code, see Optimizing Code.
94
84
@@ -126,67 +116,37 @@ Options that are modified or new in *emcc* are listed below:
126
116
"-g"
127
117
Preserve debug information.
128
118
129
- * When compiling to bitcode , this is the same as in *Clang* and
130
- *gcc* ( it adds debug information to the object files) .
119
+ * When compiling to object files , this is the same as in *Clang*
120
+ and *gcc*, it adds debug information to the object files.
131
121
132
- * When compiling from source to JavaScript or bitcode to
133
- JavaScript, it is equivalent to -g3 (discards LLVM debug info
134
- including C/C++ line numbers, but otherwise keeps as much debug
135
- information as possible). Use -g4 to get line number debugging
136
- information in JavaScript.
122
+ * When linking, this is equivalent to -g3 (preserve JS whitespace
123
+ and compiled function names).
137
124
138
125
"-g<level>"
139
- Controls how much debug information is kept when compiling from
140
- bitcode to JavaScript. Each level builds on the previous level :
126
+ Controls the level of debuggability. Each level builds on the
127
+ previous one :
141
128
142
- * "-g0": Make no effort to keep code debuggable. Will discard
143
- LLVM debug information (this is done by default in -01 and
144
- higher).
129
+ * "-g0": Make no effort to keep code debuggable.
145
130
146
- * "-g1": Preserve whitespace (do not minify) .
131
+ * "-g1": When linking, preserve whitespace in JavaScript .
147
132
148
- function a(a, b) {
149
- a = a | 0;
150
- b = b | 0;
151
- f(a + b | 0);
152
- }
133
+ * "-g2": When linking, preserve function names in compiled
134
+ code.
153
135
154
- * "-g2": Preserve function names.
136
+ * "-g3": When compiling to object files, keep debug info (this
137
+ is the same as -g).
155
138
156
- function _addAndPrint(a, b) {
157
- a = a | 0;
158
- b = b | 0;
159
- _printAnInteger(a + b | 0); // _printAnInteger is human readable.
160
- }
139
+ * "-g4": When linking, generate a source map using LLVM debug
140
+ information (which must be present in object files, i.e., they
141
+ should have been compiled with "-g").
161
142
162
- * "-g3": Preserve variable names (this is the same as -g).
143
+ Note:
163
144
164
- function _addAndPrint($left, $right) {
165
- $left = $left | 0;
166
- $right = $right | 0;
167
- _printAnInteger($left + $right | 0);
168
- }
145
+ * Source maps allow you to view and debug the *C/C++
146
+ source code* in your browser's debugger!
169
147
170
- Note: Variable names in the output will not necessarily
171
- match the original variable names in source. They are,
172
- however, usually similar enough to infer the purpose of
173
- the variables.
174
-
175
- * "-g4": Preserve LLVM debug information. This is the highest
176
- level of debuggability. If "-g" was used when compiling the
177
- C/C++ sources, this shows line number debug comments, and
178
- generates source maps.
179
-
180
- Note:
181
-
182
- * This debugging level may make compilation at
183
- optimization level -O1 and above significantly slower,
184
- because JavaScript optimization will be limited to one
185
- core (the default in "-O0").
186
-
187
- * Source maps allow you to view and debug the *C/C++
188
- source code* in your browser's debugger! This works in
189
- Firefox, Chrome and Safari.
148
+ * This debugging level may make compilation significantly
149
+ slower (this is why we only do it on "-g4").
190
150
191
151
"--profiling"
192
152
Use reasonable defaults when emitting JavaScript to make the build
@@ -225,9 +185,8 @@ Options that are modified or new in *emcc* are listed below:
225
185
optimization level will set a good value.
226
186
227
187
Note: Some options might override this flag (e.g. "EMTERPRETIFY",
228
- "DEAD_FUNCTIONS", "SAFE_HEAP" and
229
- "SPLIT_MEMORY" override the value with "js-opts=1"), because they
230
- depend on the js-optimizer.
188
+ "DEAD_FUNCTIONS", "SAFE_HEAP" and "SPLIT_MEMORY" override the
189
+ value with "js-opts=1"), because they depend on the js-optimizer.
231
190
232
191
"--llvm-opts <level>"
233
192
Enables LLVM optimizations, relevant when we call the LLVM
@@ -306,15 +265,6 @@ Options that are modified or new in *emcc* are listed below:
306
265
* Closure is only run if JavaScript opts are being done ("-O2"
307
266
or above, or "--js-opts 1").
308
267
309
- "--closure-args <args>"
310
- Specifies extra arguments to pass to Closure compiler. Use quotes
311
- to escape multiple arguments to be passed, e.g.
312
-
313
- --closure-args "--externs myExterns.js"
314
-
315
- Multiple passed --closure-args directives will be concatenated
316
- left to right.
317
-
318
268
"--pre-js <file>"
319
269
Specify a file whose contents are added before the emitted code and
320
270
optimized together with it. Note that this might not literally be
@@ -508,21 +458,20 @@ Options that are modified or new in *emcc* are listed below:
508
458
and applied; you cannot call any C functions until it arrives.
509
459
This is the default setting when compiling with -O2 or higher.
510
460
511
- Note: The safest way to ensure that it is safe to call C
512
- functions (the initialisation file has loaded) is to call
513
- a notifier function from "main()".
514
-
515
- Note: If you assign a network request to
516
- "Module.memoryInitializerRequest" (before the script
517
- runs), then it will use that request instead of
518
- automatically starting a download for you. This is
519
- beneficial in that you can, in your HTML, fire off a
520
- request for the memory init file before the script
521
- actually arrives. For this to work, the network request
522
- should be an XMLHttpRequest with responseType set to
523
- "'arraybuffer'". (You can also put any other object here,
524
- all it must provide is a ".response" property containing
525
- an ArrayBuffer.)
461
+ Note: The safest way to ensure that it is safe to call C
462
+ functions (the initialisation file has loaded) is to call a
463
+ notifier function from "main()".
464
+
465
+ Note: If you assign a network request to
466
+ "Module.memoryInitializerRequest" (before the script runs),
467
+ then it will use that request instead of automatically
468
+ starting a download for you. This is beneficial in that you
469
+ can, in your HTML, fire off a request for the memory init
470
+ file before the script actually arrives. For this to work,
471
+ the network request should be an XMLHttpRequest with
472
+ responseType set to "'arraybuffer'". (You can also put any
473
+ other object here, all it must provide is a ".response"
474
+ property containing an ArrayBuffer.)
526
475
527
476
"-Wwarn-absolute-paths"
528
477
Enables warnings about the use of absolute paths in "-I" and "-L"
@@ -599,7 +548,7 @@ Options that are modified or new in *emcc* are listed below:
599
548
WebAssembly object.
600
549
601
550
* <name> **.wasm** : WebAssembly without JavaScript support
602
- code ("standalone wasm").
551
+ code ("standalone wasm"; this enables "STANDALONE_WASM" ).
603
552
604
553
Note: If "--memory-init-file" is used, a **.mem** file will be
605
554
created in addition to the generated **.js** and/or **.html**
@@ -639,8 +588,6 @@ Environment variables
639
588
640
589
* "EMMAKEN_JUST_CONFIGURE_RECURSE"
641
590
642
- * "EMCONFIGURE_JS"
643
-
644
591
* "CONFIGURE_CC"
645
592
646
593
* "EMMAKEN_CXX"
0 commit comments