# wasm linker: fix data segments memory flow · gitcafe/zig

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

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

Visibility: public

Requested revision: 766284fec8184e7765b9a7900aea1a7494214153

Requested commit: 766284fec8184e7765b9a7900aea1a7494214153

Commit: 766284fec8184e7765b9a7900aea1a7494214153

Tree: 85ff71a3e4d28f684f108e3e50d0a2b4ef0b3c8c

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
wasm linker: fix data segments memory flow

Recognize three distinct phases:
* before prelink ("object phase")
* after prelink, before flush ("zcu phase")
* during flush ("flush phase")

With this setup, we create data structures during the object phase, then
mutate them during the zcu phase, and then further mutate them during
the flush phase. In order to make the flush phase repeatable, the data
structures are copied just before starting the flush phase.

Further Zcu updates occur against the non-copied data structures.

What's not implemented is frontend garbage collection, in which case
some more changes will be needed in this linker logic to achieve a valid
state with data invariants intact.

```

## Parents

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

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