Commit 52519f79e0

Alex Rønne Petersen <alex@alexrp.com>
2024-07-25 23:55:42
std.os.linux.start_pie: Apply MIPS local GOT relocations.
1 parent 2386bfe
Changed files (1)
lib
std
os
lib/std/os/linux/start_pie.zig
@@ -222,6 +222,24 @@ pub fn relocate(phdrs: []elf.Phdr) void {
         }
     }
 
+    // Deal with the GOT relocations that MIPS uses first.
+    if (builtin.cpu.arch.isMIPS()) {
+        const count: elf.Addr = blk: {
+            // This is an architecture-specific tag, so not part of `sorted_dynv`.
+            var i: usize = 0;
+            while (dynv[i].d_tag != elf.DT_NULL) : (i += 1) {
+                if (dynv[i].d_tag == elf.DT_MIPS_LOCAL_GOTNO) break :blk dynv[i].d_val;
+            }
+
+            break :blk 0;
+        };
+
+        const got: [*]usize = @ptrFromInt(base_addr + sorted_dynv[elf.DT_PLTGOT]);
+
+        for (0..count) |i| {
+            got[i] += base_addr;
+        }
+    }
 
     // Apply normal relocations.