Commit 925273bcc8

Jakub Konka <kubkon@jakubkonka.com>
2024-02-09 00:20:11
macho: align memory size with file size when emitting relocatable
1 parent 7388534
Changed files (2)
src
test
src/link/MachO.zig
@@ -3223,6 +3223,12 @@ fn detectAllocCollision(self: *MachO, start: u64, size: u64) ?u64 {
 }
 
 fn detectAllocCollisionVirtual(self: *MachO, start: u64, size: u64) ?u64 {
+    // Conservatively commit one page size as reserved space for the headers as we
+    // expect it to grow and everything else be moved in flush anyhow.
+    const header_size = self.getPageSize();
+    if (start < header_size)
+        return header_size;
+
     const end = start + padToIdeal(size);
 
     if (self.base.isRelocatable()) {
@@ -3234,12 +3240,6 @@ fn detectAllocCollisionVirtual(self: *MachO, start: u64, size: u64) ?u64 {
             }
         }
     } else {
-        // Conservatively commit one page size as reserved space for the headers as we
-        // expect it to grow and everything else be moved in flush anyhow.
-        const header_size = self.getPageSize();
-        if (start < header_size)
-            return header_size;
-
         for (self.segments.items) |seg| {
             const increased_size = padToIdeal(seg.vmsize);
             const test_end = seg.vmaddr +| increased_size;
test/link/macho.zig
@@ -849,6 +849,7 @@ fn testLinkingStaticLib(b: *Build, opts: Options) *Step {
     const obj = addObject(b, opts, .{
         .name = "bobj",
         .zig_source_bytes = "export var bar: i32 = -42;",
+        .strip = true, // TODO for self-hosted, we don't really emit any valid DWARF yet since we only export a global
     });
 
     const lib = addStaticLibrary(b, opts, .{