From 33d1942f2772af525ca46fa13d5a8719be9a7fb9 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Wed, 19 Oct 2022 17:33:30 +0200 Subject: [PATCH] macho: always create __TEXT segment --- src/link/MachO/zld.zig | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/link/MachO/zld.zig b/src/link/MachO/zld.zig index 2c7326358af90b5b8306ae4cb2d237385171d9d0..bdb868303ddb7395d4266d550c2168a7ae2528e0 100644 --- a/src/link/MachO/zld.zig +++ b/src/link/MachO/zld.zig @@ -1476,6 +1476,17 @@ pub const Zld = struct { }); } + // __TEXT segment is non-optional + { + const protection = getSegmentMemoryProtection("__TEXT"); + try self.segments.append(self.gpa, .{ + .cmdsize = @sizeOf(macho.segment_command_64), + .segname = makeStaticString("__TEXT"), + .maxprot = protection, + .initprot = protection, + }); + } + for (self.sections.items(.header)) |header, sect_id| { if (header.size == 0) continue; // empty section @@ -1498,14 +1509,12 @@ pub const Zld = struct { self.sections.items(.segment_index)[sect_id] = segment_id; } + // __LINKEDIT always comes last { const protection = getSegmentMemoryProtection("__LINKEDIT"); - const base = self.getSegmentAllocBase(@intCast(u8, self.segments.items.len)); try self.segments.append(self.gpa, .{ .cmdsize = @sizeOf(macho.segment_command_64), .segname = makeStaticString("__LINKEDIT"), - .vmaddr = base.vmaddr, - .fileoff = base.fileoff, .maxprot = protection, .initprot = protection, }); -- 2.54.0