authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-18 14:36:52+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-24 12:34:41+01:00
log55c8b82b50a6b1f2d65775f8d2ad313833549067
treefa322044cdb51ecf7f94b1365245c4e61e0ac3fb
parenta6ed54ea2243bd9053333c09da6de5324c799b47

macho: set alignment of pre-allocated sections


1 files changed, 15 insertions(+), 6 deletions(-)

src/link/MachO.zig+15-6
...@@ -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;
32243224
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 }
32313236
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 }
32363243
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 }
32413248
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 }
32463253
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}
33293336
3330const AddSectionOpts = struct {3337const 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,