# stage2: add naive impl of pointer type in ELF · gitcafe/zig

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

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

Visibility: public

Requested revision: 53c668d3a9dad430749cbc642d7bf8cf45eefba1

Requested commit: 53c668d3a9dad430749cbc642d7bf8cf45eefba1

Commit: 53c668d3a9dad430749cbc642d7bf8cf45eefba1

Tree: 38b4ab6279aa9cd396b2a6622451c78116f35dea

Author: Jakub Konka

Committer: Jakub Konka

## Message

````
stage2: add naive impl of pointer type in ELF

Augment relocation tracking mechanism to de-duplicate potential
creation of base as well as composite types while unrolling
composite types in the linker - there is still potential for
further space optimisation by moving all type information into
a separate section `.debug_types` and providing references to
entries within that section whenever required (e.g., `ref4` form).
Currently, we duplicate type definitions on a per-decl basis.

Anyhow, with this patch, an example function signature of the following
type:

```zig
fn byPtrPtr(ptr_ptr_x: **u32, ptr_x: *u32) void {
    ptr_ptr_x.* = ptr_x;
}
```

will generate the following `.debug_info` for formal parameters:

```
 <1><1aa>: Abbrev Number: 3 (DW_TAG_subprogram)
    <1ab>   DW_AT_low_pc      : 0x8000197
    <1b3>   DW_AT_high_pc     : 0x2c
    <1b7>   DW_AT_name        : byPtrPtr
 <2><1c0>: Abbrev Number: 7 (DW_TAG_formal_parameter)
    <1c1>   DW_AT_location    : 1 byte block: 55        (DW_OP_reg5 (rdi))
    <1c3>   DW_AT_type        : <0x1df>
    <1c7>   DW_AT_name        : ptr_ptr_x
 <2><1d1>: Abbrev Number: 7 (DW_TAG_formal_parameter)
    <1d2>   DW_AT_location    : 1 byte block: 54        (DW_OP_reg4 (rsi))
    <1d4>   DW_AT_type        : <0x1e4>
    <1d8>   DW_AT_name        : ptr_x
 <2><1de>: Abbrev Number: 0
 <1><1df>: Abbrev Number: 5 (DW_TAG_pointer_type)
    <1e0>   DW_AT_type        : <0x1e4>
 <1><1e4>: Abbrev Number: 5 (DW_TAG_pointer_type)
    <1e5>   DW_AT_type        : <0x1e9>
 <1><1e9>: Abbrev Number: 4 (DW_TAG_base_type)
    <1ea>   DW_AT_encoding    : 7       (unsigned)
    <1eb>   DW_AT_byte_size   : 4
    <1ec>   DW_AT_name        : u32
```

````

## Parents

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

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