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 {
32223222 }
32233223 }.appendSect;
32243224
3225 if (self.zig_text_section_index == null) {
3225 {
32263226 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 },
32273232 .flags = macho.S_REGULAR | macho.S_ATTR_PURE_INSTRUCTIONS | macho.S_ATTR_SOME_INSTRUCTIONS,
32283233 });
32293234 appendSect(self, self.zig_text_section_index.?, self.zig_text_seg_index.?);
32303235 }
32313236
3232 if (self.zig_got_section_index == null and !self.base.isRelocatable()) {
3233 self.zig_got_section_index = try self.addSection("__GOT_ZIG", "__got_zig", .{});
3237 if (!self.base.isRelocatable()) {
3238 self.zig_got_section_index = try self.addSection("__GOT_ZIG", "__got_zig", .{
3239 .alignment = 3,
3240 });
32343241 appendSect(self, self.zig_got_section_index.?, self.zig_got_seg_index.?);
32353242 }
32363243
3237 if (self.zig_const_section_index == null) {
3244 {
32383245 self.zig_const_section_index = try self.addSection("__CONST_ZIG", "__const_zig", .{});
32393246 appendSect(self, self.zig_const_section_index.?, self.zig_const_seg_index.?);
32403247 }
32413248
3242 if (self.zig_data_section_index == null) {
3249 {
32433250 self.zig_data_section_index = try self.addSection("__DATA_ZIG", "__data_zig", .{});
32443251 appendSect(self, self.zig_data_section_index.?, self.zig_data_seg_index.?);
32453252 }
32463253
3247 if (self.zig_bss_section_index == null) {
3254 {
32483255 self.zig_bss_section_index = try self.addSection("__BSS_ZIG", "__bss_zig", .{
32493256 .flags = macho.S_ZEROFILL,
32503257 });
......@@ -3328,6 +3335,7 @@ pub fn addSegment(self: *MachO, name: []const u8, opts: struct {
33283335}
33293336
33303337const AddSectionOpts = struct {
3338 alignment: u32 = 0,
33313339 flags: u32 = macho.S_REGULAR,
33323340 reserved1: u32 = 0,
33333341 reserved2: u32 = 0,
......@@ -3346,6 +3354,7 @@ pub fn addSection(
33463354 .header = .{
33473355 .sectname = makeStaticString(sectname),
33483356 .segname = makeStaticString(segname),
3357 .@"align" = opts.alignment,
33493358 .flags = opts.flags,
33503359 .reserved1 = opts.reserved1,
33513360 .reserved2 = opts.reserved2,