authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-02-09 00:20:11+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-02-09 00:20:11+01:00
log925273bcc8b92b84e1880a20e25fa8507ac904bd
treee502c8ae25c102f1067ae0edd4616f105dd7bad4
parent738853459062ccfa9fdea7434b7746e6fe172e3a

macho: align memory size with file size when emitting relocatable


2 files changed, 7 insertions(+), 6 deletions(-)

src/link/MachO.zig+6-6
...@@ -3223,6 +3223,12 @@ fn detectAllocCollision(self: *MachO, start: u64, size: u64) ?u64 {...@@ -3223,6 +3223,12 @@ fn detectAllocCollision(self: *MachO, start: u64, size: u64) ?u64 {
3223}3223}
32243224
3225fn detectAllocCollisionVirtual(self: *MachO, start: u64, size: u64) ?u64 {3225fn detectAllocCollisionVirtual(self: *MachO, start: u64, size: u64) ?u64 {
3226 // Conservatively commit one page size as reserved space for the headers as we
3227 // expect it to grow and everything else be moved in flush anyhow.
3228 const header_size = self.getPageSize();
3229 if (start < header_size)
3230 return header_size;
3231
3226 const end = start + padToIdeal(size);3232 const end = start + padToIdeal(size);
32273233
3228 if (self.base.isRelocatable()) {3234 if (self.base.isRelocatable()) {
...@@ -3234,12 +3240,6 @@ fn detectAllocCollisionVirtual(self: *MachO, start: u64, size: u64) ?u64 {...@@ -3234,12 +3240,6 @@ fn detectAllocCollisionVirtual(self: *MachO, start: u64, size: u64) ?u64 {
3234 }3240 }
3235 }3241 }
3236 } else {3242 } else {
3237 // Conservatively commit one page size as reserved space for the headers as we
3238 // expect it to grow and everything else be moved in flush anyhow.
3239 const header_size = self.getPageSize();
3240 if (start < header_size)
3241 return header_size;
3242
3243 for (self.segments.items) |seg| {3243 for (self.segments.items) |seg| {
3244 const increased_size = padToIdeal(seg.vmsize);3244 const increased_size = padToIdeal(seg.vmsize);
3245 const test_end = seg.vmaddr +| increased_size;3245 const test_end = seg.vmaddr +| increased_size;
test/link/macho.zig+1
...@@ -849,6 +849,7 @@ fn testLinkingStaticLib(b: *Build, opts: Options) *Step {...@@ -849,6 +849,7 @@ fn testLinkingStaticLib(b: *Build, opts: Options) *Step {
849 const obj = addObject(b, opts, .{849 const obj = addObject(b, opts, .{
850 .name = "bobj",850 .name = "bobj",
851 .zig_source_bytes = "export var bar: i32 = -42;",851 .zig_source_bytes = "export var bar: i32 = -42;",
852 .strip = true, // TODO for self-hosted, we don't really emit any valid DWARF yet since we only export a global
852 });853 });
853854
854 const lib = addStaticLibrary(b, opts, .{855 const lib = addStaticLibrary(b, opts, .{