# link/Elf: ensure we always sort all relocations by r_offset in \-r mode · gitcafe/zig

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

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

Visibility: public

Requested revision: 6ff267dc2635177b57bda1d398374ab96ed40179

Requested commit: 6ff267dc2635177b57bda1d398374ab96ed40179

Commit: 6ff267dc2635177b57bda1d398374ab96ed40179

Tree: 7ba6df1b5ec1a308c6166b1990247e4015622857

Author: Jakub Konka

Committer: Andrew Kelley

## Message

```
link/Elf: ensure we always sort all relocations by r_offset in -r mode

According to a comment in mold, this is the expected (and desired)
condition by the linkers, except for some architectures (RISCV and
Loongarch) where this condition does not have to upheld.

If you follow the changes in this patch and in particular doc comments
I have linked the comment/code in mold that explains and implements
this.

I have also modified `testEhFrameRelocatable` test to now test both
cases such that `zig ld -r a.o b.o -o c.o` and `zig ld -r b.o a.o -o
d.o`. In both cases, `c.o` and `d.o` should produce valid object
files which was not the case before this patch.

```

## Parents

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

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