| author | |
| committer | |
| log | 7647db327328bffea7dc8d7286cb6be9265080be |
| tree | 3bc09c167f68ff1763ab90728dc7e14576639a5b |
| parent | 16b66588f02743aafeb5972644271d92bdcf1051 |
3 files changed, 31 insertions(+), 30 deletions(-)
src/link/MachO.zig+16-15| ... | ... | @@ -93,11 +93,11 @@ zig_data_seg_index: ?u8 = null, |
| 93 | 93 | zig_bss_seg_index: ?u8 = null, |
| 94 | 94 | |
| 95 | 95 | /// Tracked section headers with incremental updates to Zig object. |
| 96 | zig_text_section_index: ?u8 = null, | |
| 97 | zig_got_section_index: ?u8 = null, | |
| 98 | zig_const_section_index: ?u8 = null, | |
| 99 | zig_data_section_index: ?u8 = null, | |
| 100 | zig_bss_section_index: ?u8 = null, | |
| 96 | zig_text_sect_index: ?u8 = null, | |
| 97 | zig_got_sect_index: ?u8 = null, | |
| 98 | zig_const_sect_index: ?u8 = null, | |
| 99 | zig_data_sect_index: ?u8 = null, | |
| 100 | zig_bss_sect_index: ?u8 = null, | |
| 101 | 101 | |
| 102 | 102 | has_tlv: bool = false, |
| 103 | 103 | binds_to_weak: bool = false, |
| ... | ... | @@ -2423,6 +2423,7 @@ fn initDyldInfoSections(self: *MachO) !void { |
| 2423 | 2423 | |
| 2424 | 2424 | const gpa = self.base.comp.gpa; |
| 2425 | 2425 | |
| 2426 | if (self.zig_got_sect_index != null) try self.zig_got.addDyldRelocs(self); | |
| 2426 | 2427 | if (self.got_sect_index != null) try self.got.addDyldRelocs(self); |
| 2427 | 2428 | if (self.tlv_ptr_sect_index != null) try self.tlv_ptr.addDyldRelocs(self); |
| 2428 | 2429 | if (self.la_symbol_ptr_sect_index != null) try self.la_symbol_ptr.addDyldRelocs(self); |
| ... | ... | @@ -3291,7 +3292,7 @@ fn initMetadata(self: *MachO, options: InitMetadataOptions) !void { |
| 3291 | 3292 | }.appendSect; |
| 3292 | 3293 | |
| 3293 | 3294 | { |
| 3294 | self.zig_text_section_index = try self.addSection("__TEXT_ZIG", "__text_zig", .{ | |
| 3295 | self.zig_text_sect_index = try self.addSection("__TEXT_ZIG", "__text_zig", .{ | |
| 3295 | 3296 | .alignment = switch (self.getTarget().cpu.arch) { |
| 3296 | 3297 | .aarch64 => 2, |
| 3297 | 3298 | .x86_64 => 0, |
| ... | ... | @@ -3299,31 +3300,31 @@ fn initMetadata(self: *MachO, options: InitMetadataOptions) !void { |
| 3299 | 3300 | }, |
| 3300 | 3301 | .flags = macho.S_REGULAR | macho.S_ATTR_PURE_INSTRUCTIONS | macho.S_ATTR_SOME_INSTRUCTIONS, |
| 3301 | 3302 | }); |
| 3302 | appendSect(self, self.zig_text_section_index.?, self.zig_text_seg_index.?); | |
| 3303 | appendSect(self, self.zig_text_sect_index.?, self.zig_text_seg_index.?); | |
| 3303 | 3304 | } |
| 3304 | 3305 | |
| 3305 | 3306 | if (!self.base.isRelocatable()) { |
| 3306 | self.zig_got_section_index = try self.addSection("__GOT_ZIG", "__got_zig", .{ | |
| 3307 | self.zig_got_sect_index = try self.addSection("__GOT_ZIG", "__got_zig", .{ | |
| 3307 | 3308 | .alignment = 3, |
| 3308 | 3309 | }); |
| 3309 | appendSect(self, self.zig_got_section_index.?, self.zig_got_seg_index.?); | |
| 3310 | appendSect(self, self.zig_got_sect_index.?, self.zig_got_seg_index.?); | |
| 3310 | 3311 | } |
| 3311 | 3312 | |
| 3312 | 3313 | { |
| 3313 | self.zig_const_section_index = try self.addSection("__CONST_ZIG", "__const_zig", .{}); | |
| 3314 | appendSect(self, self.zig_const_section_index.?, self.zig_const_seg_index.?); | |
| 3314 | self.zig_const_sect_index = try self.addSection("__CONST_ZIG", "__const_zig", .{}); | |
| 3315 | appendSect(self, self.zig_const_sect_index.?, self.zig_const_seg_index.?); | |
| 3315 | 3316 | } |
| 3316 | 3317 | |
| 3317 | 3318 | { |
| 3318 | self.zig_data_section_index = try self.addSection("__DATA_ZIG", "__data_zig", .{}); | |
| 3319 | appendSect(self, self.zig_data_section_index.?, self.zig_data_seg_index.?); | |
| 3319 | self.zig_data_sect_index = try self.addSection("__DATA_ZIG", "__data_zig", .{}); | |
| 3320 | appendSect(self, self.zig_data_sect_index.?, self.zig_data_seg_index.?); | |
| 3320 | 3321 | } |
| 3321 | 3322 | |
| 3322 | 3323 | { |
| 3323 | self.zig_bss_section_index = try self.addSection("__BSS_ZIG", "__bss_zig", .{ | |
| 3324 | self.zig_bss_sect_index = try self.addSection("__BSS_ZIG", "__bss_zig", .{ | |
| 3324 | 3325 | .flags = macho.S_ZEROFILL, |
| 3325 | 3326 | }); |
| 3326 | appendSect(self, self.zig_bss_section_index.?, self.zig_bss_seg_index.?); | |
| 3327 | appendSect(self, self.zig_bss_sect_index.?, self.zig_bss_seg_index.?); | |
| 3327 | 3328 | } |
| 3328 | 3329 | } |
| 3329 | 3330 |
src/link/MachO/ZigObject.zig+11-11| ... | ... | @@ -416,7 +416,7 @@ pub fn lowerAnonDecl( |
| 416 | 416 | name, |
| 417 | 417 | tv, |
| 418 | 418 | decl_alignment, |
| 419 | macho_file.zig_const_section_index.?, | |
| 419 | macho_file.zig_const_sect_index.?, | |
| 420 | 420 | src_loc, |
| 421 | 421 | ) catch |err| switch (err) { |
| 422 | 422 | error.OutOfMemory => return error.OutOfMemory, |
| ... | ... | @@ -712,7 +712,7 @@ fn getDeclOutputSection( |
| 712 | 712 | const any_non_single_threaded = macho_file.base.comp.config.any_non_single_threaded; |
| 713 | 713 | _ = any_non_single_threaded; |
| 714 | 714 | const sect_id: u8 = switch (decl.ty.zigTypeTag(mod)) { |
| 715 | .Fn => macho_file.zig_text_section_index.?, | |
| 715 | .Fn => macho_file.zig_text_sect_index.?, | |
| 716 | 716 | else => blk: { |
| 717 | 717 | if (decl.getOwnedVariable(mod)) |variable| { |
| 718 | 718 | // if (variable.is_threadlocal and any_non_single_threaded) { |
| ... | ... | @@ -731,13 +731,13 @@ fn getDeclOutputSection( |
| 731 | 731 | // ); |
| 732 | 732 | // } |
| 733 | 733 | |
| 734 | if (variable.is_const) break :blk macho_file.zig_const_section_index.?; | |
| 734 | if (variable.is_const) break :blk macho_file.zig_const_sect_index.?; | |
| 735 | 735 | if (Value.fromInterned(variable.init).isUndefDeep(mod)) { |
| 736 | 736 | // TODO: get the optimize_mode from the Module that owns the decl instead |
| 737 | 737 | // of using the root module here. |
| 738 | 738 | break :blk switch (macho_file.base.comp.root_mod.optimize_mode) { |
| 739 | .Debug, .ReleaseSafe => macho_file.zig_data_section_index.?, | |
| 740 | .ReleaseFast, .ReleaseSmall => macho_file.zig_bss_section_index.?, | |
| 739 | .Debug, .ReleaseSafe => macho_file.zig_data_sect_index.?, | |
| 740 | .ReleaseFast, .ReleaseSmall => macho_file.zig_bss_sect_index.?, | |
| 741 | 741 | }; |
| 742 | 742 | } |
| 743 | 743 | |
| ... | ... | @@ -746,10 +746,10 @@ fn getDeclOutputSection( |
| 746 | 746 | const is_all_zeroes = for (code) |byte| { |
| 747 | 747 | if (byte != 0) break false; |
| 748 | 748 | } else true; |
| 749 | if (is_all_zeroes) break :blk macho_file.zig_bss_section_index.?; | |
| 750 | break :blk macho_file.zig_data_section_index.?; | |
| 749 | if (is_all_zeroes) break :blk macho_file.zig_bss_sect_index.?; | |
| 750 | break :blk macho_file.zig_data_sect_index.?; | |
| 751 | 751 | } |
| 752 | break :blk macho_file.zig_const_section_index.?; | |
| 752 | break :blk macho_file.zig_const_sect_index.?; | |
| 753 | 753 | }, |
| 754 | 754 | }; |
| 755 | 755 | return sect_id; |
| ... | ... | @@ -778,7 +778,7 @@ pub fn lowerUnnamedConst( |
| 778 | 778 | name, |
| 779 | 779 | typed_value, |
| 780 | 780 | typed_value.ty.abiAlignment(mod), |
| 781 | macho_file.zig_const_section_index.?, | |
| 781 | macho_file.zig_const_sect_index.?, | |
| 782 | 782 | decl.srcLoc(mod), |
| 783 | 783 | )) { |
| 784 | 784 | .ok => |sym_index| sym_index, |
| ... | ... | @@ -995,8 +995,8 @@ fn updateLazySymbol( |
| 995 | 995 | }; |
| 996 | 996 | |
| 997 | 997 | const output_section_index = switch (lazy_sym.kind) { |
| 998 | .code => macho_file.zig_text_section_index.?, | |
| 999 | .const_data => macho_file.zig_const_section_index.?, | |
| 998 | .code => macho_file.zig_text_sect_index.?, | |
| 999 | .const_data => macho_file.zig_const_sect_index.?, | |
| 1000 | 1000 | }; |
| 1001 | 1001 | const sym = macho_file.getSymbol(symbol_index); |
| 1002 | 1002 | sym.name = name_str_index; |
src/link/MachO/synthetic.zig+4-4| ... | ... | @@ -32,13 +32,13 @@ pub const ZigGotSection = struct { |
| 32 | 32 | |
| 33 | 33 | pub fn entryOffset(zig_got: ZigGotSection, index: Index, macho_file: *MachO) u64 { |
| 34 | 34 | _ = zig_got; |
| 35 | const sect = macho_file.sections.items(.header)[macho_file.zig_got_section_index.?]; | |
| 35 | const sect = macho_file.sections.items(.header)[macho_file.zig_got_sect_index.?]; | |
| 36 | 36 | return sect.offset + @sizeOf(u64) * index; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | pub fn entryAddress(zig_got: ZigGotSection, index: Index, macho_file: *MachO) u64 { |
| 40 | 40 | _ = zig_got; |
| 41 | const sect = macho_file.sections.items(.header)[macho_file.zig_got_section_index.?]; | |
| 41 | const sect = macho_file.sections.items(.header)[macho_file.zig_got_sect_index.?]; | |
| 42 | 42 | return sect.addr + @sizeOf(u64) * index; |
| 43 | 43 | } |
| 44 | 44 | |
| ... | ... | @@ -50,7 +50,7 @@ pub const ZigGotSection = struct { |
| 50 | 50 | pub fn writeOne(zig_got: *ZigGotSection, macho_file: *MachO, index: Index) !void { |
| 51 | 51 | if (zig_got.dirty) { |
| 52 | 52 | const needed_size = zig_got.size(macho_file); |
| 53 | try macho_file.growSection(macho_file.zig_got_section_index.?, needed_size); | |
| 53 | try macho_file.growSection(macho_file.zig_got_sect_index.?, needed_size); | |
| 54 | 54 | zig_got.dirty = false; |
| 55 | 55 | } |
| 56 | 56 | const off = zig_got.entryOffset(index, macho_file); |
| ... | ... | @@ -77,7 +77,7 @@ pub const ZigGotSection = struct { |
| 77 | 77 | const seg_id = macho_file.sections.items(.segment_id)[macho_file.zig_got_sect_index.?]; |
| 78 | 78 | const seg = macho_file.segments.items[seg_id]; |
| 79 | 79 | |
| 80 | for (0..zig_got.symbols.items.len) |idx| { | |
| 80 | for (0..zig_got.entries.items.len) |idx| { | |
| 81 | 81 | const addr = zig_got.entryAddress(@intCast(idx), macho_file); |
| 82 | 82 | try macho_file.rebase.entries.append(gpa, .{ |
| 83 | 83 | .offset = addr - seg.vmaddr, |