(target, options, wasm_target)
| 2278 | |
| 2279 | @ToolchainProfiler.profile_block('binaryen') |
| 2280 | def phase_binaryen(target, options, wasm_target): |
| 2281 | global final_js |
| 2282 | logger.debug('using binaryen') |
| 2283 | # whether we need to emit -g (function name debug info) in the final wasm |
| 2284 | debug_function_names = settings.DEBUG_LEVEL >= 2 or settings.EMIT_NAME_SECTION |
| 2285 | # whether we need to emit -g in the intermediate binaryen invocations (but not |
| 2286 | # necessarily at the very end). this is necessary if we depend on debug info |
| 2287 | # during compilation, even if we do not emit it at the end. |
| 2288 | # we track the number of causes for needing intermediate debug info so |
| 2289 | # that we can stop emitting it when possible - in particular, that is |
| 2290 | # important so that we stop emitting it before the end, and it is not in the |
| 2291 | # final binary (if it shouldn't be) |
| 2292 | intermediate_debug_info = 0 |
| 2293 | if debug_function_names: |
| 2294 | intermediate_debug_info += 1 |
| 2295 | if options.emit_symbol_map: |
| 2296 | intermediate_debug_info += 1 |
| 2297 | if settings.ASYNCIFY == 1: |
| 2298 | intermediate_debug_info += 1 |
| 2299 | |
| 2300 | # run wasm-opt if we have work for it: either passes, or if we are using |
| 2301 | # source maps (which requires some extra processing to keep the source map |
| 2302 | # but remove DWARF) |
| 2303 | passes = get_binaryen_passes(options) |
| 2304 | if passes: |
| 2305 | # if asyncify is used, we will use it in the next stage, and so if it is |
| 2306 | # the only reason we need intermediate debug info, we can stop keeping it |
| 2307 | if settings.ASYNCIFY == 1: |
| 2308 | intermediate_debug_info -= 1 |
| 2309 | # currently binaryen's DWARF support will limit some optimizations; warn on |
| 2310 | # that. see https://github.com/emscripten-core/emscripten/issues/15269 |
| 2311 | if settings.GENERATE_DWARF and should_run_binaryen_optimizer(): |
| 2312 | diagnostics.warning('limited-postlink-optimizations', 'running limited binaryen optimizations because DWARF info requested (or indirectly required)') |
| 2313 | with ToolchainProfiler.profile_block('wasm_opt'): |
| 2314 | building.run_wasm_opt(wasm_target, |
| 2315 | wasm_target, |
| 2316 | args=passes, |
| 2317 | debug=intermediate_debug_info) |
| 2318 | building.save_intermediate(wasm_target, 'byn.wasm') |
| 2319 | |
| 2320 | if settings.EVAL_CTORS: |
| 2321 | with ToolchainProfiler.profile_block('eval_ctors'): |
| 2322 | building.eval_ctors(final_js, wasm_target, debug_info=intermediate_debug_info) |
| 2323 | building.save_intermediate(wasm_target, 'ctors.wasm') |
| 2324 | |
| 2325 | # after generating the wasm, do some final operations |
| 2326 | |
| 2327 | if final_js: |
| 2328 | # >=2GB heap support requires pointers in JS to be unsigned. rather than |
| 2329 | # require all pointers to be unsigned by default, which increases code size |
| 2330 | # a little, keep them signed, and just unsign them here if we need that. |
| 2331 | if settings.CAN_ADDRESS_2GB: |
| 2332 | with ToolchainProfiler.profile_block('use_unsigned_pointers_in_js'): |
| 2333 | final_js = building.use_unsigned_pointers_in_js(final_js) |
| 2334 | |
| 2335 | if settings.USE_ASAN: |
| 2336 | final_js = building.instrument_js_for_asan(final_js) |
| 2337 |
no test coverage detected