| ... | @@ -3222,29 +3222,36 @@ fn initMetadata(self: *MachO, options: InitMetadataOptions) !void { | ... | @@ -3222,29 +3222,36 @@ fn initMetadata(self: *MachO, options: InitMetadataOptions) !void { |
| 3222 | } | 3222 | } |
| 3223 | }.appendSect; | 3223 | }.appendSect; |
| 3224 | | 3224 | |
| 3225 | if (self.zig_text_section_index == null) { | 3225 | { |
| 3226 | self.zig_text_section_index = try self.addSection("__TEXT_ZIG", "__text_zig", .{ | 3226 | self.zig_text_section_index = try self.addSection("__TEXT_ZIG", "__text_zig", .{ |
| | 3227 | .alignment = switch (self.getTarget().cpu.arch) { |
| | 3228 | .aarch64 => 2, |
| | 3229 | .x86_64 => 0, |
| | 3230 | else => unreachable, |
| | 3231 | }, |
| 3227 | .flags = macho.S_REGULAR | macho.S_ATTR_PURE_INSTRUCTIONS | macho.S_ATTR_SOME_INSTRUCTIONS, | 3232 | .flags = macho.S_REGULAR | macho.S_ATTR_PURE_INSTRUCTIONS | macho.S_ATTR_SOME_INSTRUCTIONS, |
| 3228 | }); | 3233 | }); |
| 3229 | appendSect(self, self.zig_text_section_index.?, self.zig_text_seg_index.?); | 3234 | appendSect(self, self.zig_text_section_index.?, self.zig_text_seg_index.?); |
| 3230 | } | 3235 | } |
| 3231 | | 3236 | |
| 3232 | if (self.zig_got_section_index == null and !self.base.isRelocatable()) { | 3237 | if (!self.base.isRelocatable()) { |
| 3233 | self.zig_got_section_index = try self.addSection("__GOT_ZIG", "__got_zig", .{}); | 3238 | self.zig_got_section_index = try self.addSection("__GOT_ZIG", "__got_zig", .{ |
| | 3239 | .alignment = 3, |
| | 3240 | }); |
| 3234 | appendSect(self, self.zig_got_section_index.?, self.zig_got_seg_index.?); | 3241 | appendSect(self, self.zig_got_section_index.?, self.zig_got_seg_index.?); |
| 3235 | } | 3242 | } |
| 3236 | | 3243 | |
| 3237 | if (self.zig_const_section_index == null) { | 3244 | { |
| 3238 | self.zig_const_section_index = try self.addSection("__CONST_ZIG", "__const_zig", .{}); | 3245 | self.zig_const_section_index = try self.addSection("__CONST_ZIG", "__const_zig", .{}); |
| 3239 | appendSect(self, self.zig_const_section_index.?, self.zig_const_seg_index.?); | 3246 | appendSect(self, self.zig_const_section_index.?, self.zig_const_seg_index.?); |
| 3240 | } | 3247 | } |
| 3241 | | 3248 | |
| 3242 | if (self.zig_data_section_index == null) { | 3249 | { |
| 3243 | self.zig_data_section_index = try self.addSection("__DATA_ZIG", "__data_zig", .{}); | 3250 | self.zig_data_section_index = try self.addSection("__DATA_ZIG", "__data_zig", .{}); |
| 3244 | appendSect(self, self.zig_data_section_index.?, self.zig_data_seg_index.?); | 3251 | appendSect(self, self.zig_data_section_index.?, self.zig_data_seg_index.?); |
| 3245 | } | 3252 | } |
| 3246 | | 3253 | |
| 3247 | if (self.zig_bss_section_index == null) { | 3254 | { |
| 3248 | self.zig_bss_section_index = try self.addSection("__BSS_ZIG", "__bss_zig", .{ | 3255 | self.zig_bss_section_index = try self.addSection("__BSS_ZIG", "__bss_zig", .{ |
| 3249 | .flags = macho.S_ZEROFILL, | 3256 | .flags = macho.S_ZEROFILL, |
| 3250 | }); | 3257 | }); |
| ... | @@ -3328,6 +3335,7 @@ pub fn addSegment(self: *MachO, name: []const u8, opts: struct { | ... | @@ -3328,6 +3335,7 @@ pub fn addSegment(self: *MachO, name: []const u8, opts: struct { |
| 3328 | } | 3335 | } |
| 3329 | | 3336 | |
| 3330 | const AddSectionOpts = struct { | 3337 | const AddSectionOpts = struct { |
| | 3338 | alignment: u32 = 0, |
| 3331 | flags: u32 = macho.S_REGULAR, | 3339 | flags: u32 = macho.S_REGULAR, |
| 3332 | reserved1: u32 = 0, | 3340 | reserved1: u32 = 0, |
| 3333 | reserved2: u32 = 0, | 3341 | reserved2: u32 = 0, |
| ... | @@ -3346,6 +3354,7 @@ pub fn addSection( | ... | @@ -3346,6 +3354,7 @@ pub fn addSection( |
| 3346 | .header = .{ | 3354 | .header = .{ |
| 3347 | .sectname = makeStaticString(sectname), | 3355 | .sectname = makeStaticString(sectname), |
| 3348 | .segname = makeStaticString(segname), | 3356 | .segname = makeStaticString(segname), |
| | 3357 | .@"align" = opts.alignment, |
| 3349 | .flags = opts.flags, | 3358 | .flags = opts.flags, |
| 3350 | .reserved1 = opts.reserved1, | 3359 | .reserved1 = opts.reserved1, |
| 3351 | .reserved2 = opts.reserved2, | 3360 | .reserved2 = opts.reserved2, |