Commit 3deb9ab30a

Andrew Kelley <andrew@ziglang.org>
2024-10-22 05:50:26
use unstable sort in relocatable writeSyntheticSections
unstable sort is always better if you have no ties
1 parent 336466c
Changed files (1)
src
src/link/Elf/relocatable.zig
@@ -382,11 +382,12 @@ fn writeSyntheticSections(elf_file: *Elf) !void {
         const SortRelocs = struct {
             pub fn lessThan(ctx: void, lhs: elf.Elf64_Rela, rhs: elf.Elf64_Rela) bool {
                 _ = ctx;
+                assert(lhs.r_offset != rhs.r_offset);
                 return lhs.r_offset < rhs.r_offset;
             }
         };
 
-        mem.sort(elf.Elf64_Rela, relocs.items, {}, SortRelocs.lessThan);
+        mem.sortUnstable(elf.Elf64_Rela, relocs.items, {}, SortRelocs.lessThan);
 
         log.debug("writing {s} from 0x{x} to 0x{x}", .{
             elf_file.getShString(shdr.sh_name),