macho: align memory size with file size when emitting relocatable

This commit is contained in:
Jakub Konka 2024-02-09 00:20:11 +01:00
parent 7388534590
commit 925273bcc8
2 changed files with 7 additions and 6 deletions

View File

@ -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;

View File

@ -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, .{