# link.Wasm: fix incremental update crash · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/d7bf0dab8243d23e95c49ad9b27f54d21df116f0)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: d7bf0dab8243d23e95c49ad9b27f54d21df116f0

Requested commit: d7bf0dab8243d23e95c49ad9b27f54d21df116f0

Commit: d7bf0dab8243d23e95c49ad9b27f54d21df116f0

Tree: d75635fd5d0982da152aab3d4028a48036279714

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
link.Wasm: fix incremental update crash

Description of problem:

- wasm linker does GC in flush()
- it has the mechanism where it tracks the end index of a bunch of
  ArrayHashMap before flush() and after flush, shrinkRetainingCapacity()
  them to restore them to pre-flush() state
- this includes `functions`, which contains `__divti3`
- flush() notices the call to `__divti3` and calls markFunctionImport(),
  but that function does nothing on a second update because `alive` is
  already set to `true` so it incorrectly skips adding the intrinsic
  back to `functions`

I tried to remember why I thought it was OK to use this `alive` flag
which is state that's not being restored after flush(). If I remember
correctly, I was just leaving the code how it was before, with the plan
to change the data layout after encountering this exact problem.

However, I found a solution that doesn't require changing data layout,
and still takes advantage of the 1-bit-per-symbol data layout.

```

## Parents

- [3ad9a6a6045aec32b590387eddbc8ba3d598bcfc](https://git.cafe/gitcafe/zig/commit/3ad9a6a6045aec32b590387eddbc8ba3d598bcfc?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/d7bf0dab8243d23e95c49ad9b27f54d21df116f0?format=markdown)
