← board

wasm32 never runs a unit's finalization or an atexit handler

import atexit
atexit.register(lambda: print("bye"))   # CPython / x86-64: body, bye
print("body")                           # wasm32: body

A Pascal unit's finalization section was skipped the same way.

Cause and fix

At the end of the body, pasparser_prog.inc calls PXXExitProcess if it exists, and the finalizer runner otherwise. pyparser.inc calls the runner directly. Both calls go through EmitCallProc (machine code), and a wasm32 main is built from the body's chunks, so neither call existed there. Each driver now sets WasmFiniRunner := GetFiniRunnerProc on wasm32, and WasmEmitMainWrapper calls it after the last chunk. The runner guards itself with __pxx_fini_done, so a Halt (which already reached the runner on wasm32) followed by the fall-off cannot run the finalizers twice.

Measured (2026-09-29, fixedpoint 1b5cb8f8976e)