# stage2: lower unnamed constants in Elf and MachO · gitcafe/zig

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

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

Visibility: public

Requested revision: 5944e89016219138f6d5d9c818c7ce323eb64c1d

Requested commit: 5944e89016219138f6d5d9c818c7ce323eb64c1d

Commit: 5944e89016219138f6d5d9c818c7ce323eb64c1d

Tree: 611427b002732130e0b2112bf5bf4c3fbd1f8432

Author: Jakub Konka

Committer: Jakub Konka

## Message

```
stage2: lower unnamed constants in Elf and MachO

* link: add a virtual function `lowerUnnamedConsts`, similar to
  `updateFunc` or `updateDecl` which needs to be implemented by the
  linker backend in order to be used with the `CodeGen` code
* elf: implement `lowerUnnamedConsts` specialization where we
  lower unnamed constants to `.rodata` section. We keep track of the
  atoms encompassing the lowered unnamed consts in a global table
  indexed by parent `Decl`. When the `Decl` is updated or destroyed,
  we clear the unnamed consts referenced within the `Decl`.
* macho: implement `lowerUnnamedConsts` specialization where we
  lower unnamed constants to `__TEXT,__const` section. We keep track of the
  atoms encompassing the lowered unnamed consts in a global table
  indexed by parent `Decl`. When the `Decl` is updated or destroyed,
  we clear the unnamed consts referenced within the `Decl`.
* x64: change `MCValue.linker_sym_index` into two `MCValue`s: `.got_load` and
  `.direct_load`. The former signifies to the emitter that it should
  emit a GOT load relocation, while the latter that it should emit
  a direct load (`SIGNED`) relocation.
* x64: lower `struct` instantiations

```

## Parents

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

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