# std.os.linux.start_pie: Rewrite relocate\(\) to avoid jump tables and libcalls\. · gitcafe/zig

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

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

Visibility: public

Requested revision: 2386bfe854826e0726b7002c04cd9fc4c08d68f3

Requested commit: 2386bfe854826e0726b7002c04cd9fc4c08d68f3

Commit: 2386bfe854826e0726b7002c04cd9fc4c08d68f3

Tree: d0f5634fbea27b77f895b12629fe96b37f156dab

Author: Alex Rønne Petersen

Committer: Alex Rønne Petersen

## Message

```
std.os.linux.start_pie: Rewrite relocate() to avoid jump tables and libcalls.

The code would cause LLVM to emit a jump table for the switch in the loop over
the dynamic tags. That jump table was far enough away that the compiler decided
to go through the GOT, which would of course break at this early stage as we
haven't applied MIPS's local GOT relocations yet, nor can we until we've walked
through the _DYNAMIC array.

The first attempt at rewriting this used code like this:

    var sorted_dynv = [_]elf.Addr{0} ** elf.DT_NUM;

But this is also problematic as it results in a memcpy() call. Instead, we
explicitly initialize it to undefined and use a loop of volatile stores to
clear it.

```

## Parents

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

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