| author | |
| committer | |
| log | f37ca3fa7370c501c630c53b370fecdeb313e3be |
| tree | 5025974bf1873d55e6281a15f31fae016a15a922 |
| parent | 10a4c2269d110d636e7817677fb50c6f418bff34 |
This gets the alignment from the code that creates a lazy symbol instead
of guessing it at every use.5 files changed, 18 insertions(+), 40 deletions(-)
src/arch/x86_64/CodeGen.zig-6| ... | @@ -6416,7 +6416,6 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -6416,7 +6416,6 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void { |
| 6416 | if (self.bin_file.cast(link.File.Elf)) |elf_file| { | 6416 | if (self.bin_file.cast(link.File.Elf)) |elf_file| { |
| 6417 | const atom_index = try elf_file.getOrCreateAtomForLazySymbol( | 6417 | const atom_index = try elf_file.getOrCreateAtomForLazySymbol( |
| 6418 | .{ .kind = .const_data, .ty = Type.anyerror }, | 6418 | .{ .kind = .const_data, .ty = Type.anyerror }, |
| 6419 | 4, // dword alignment | ||
| 6420 | ); | 6419 | ); |
| 6421 | const atom = elf_file.getAtom(atom_index); | 6420 | const atom = elf_file.getAtom(atom_index); |
| 6422 | _ = try atom.getOrCreateOffsetTableEntry(elf_file); | 6421 | _ = try atom.getOrCreateOffsetTableEntry(elf_file); |
| ... | @@ -6429,14 +6428,12 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -6429,14 +6428,12 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void { |
| 6429 | } else if (self.bin_file.cast(link.File.Coff)) |coff_file| { | 6428 | } else if (self.bin_file.cast(link.File.Coff)) |coff_file| { |
| 6430 | const atom_index = try coff_file.getOrCreateAtomForLazySymbol( | 6429 | const atom_index = try coff_file.getOrCreateAtomForLazySymbol( |
| 6431 | .{ .kind = .const_data, .ty = Type.anyerror }, | 6430 | .{ .kind = .const_data, .ty = Type.anyerror }, |
| 6432 | 4, // dword alignment | ||
| 6433 | ); | 6431 | ); |
| 6434 | const sym_index = coff_file.getAtom(atom_index).getSymbolIndex().?; | 6432 | const sym_index = coff_file.getAtom(atom_index).getSymbolIndex().?; |
| 6435 | try self.genSetReg(addr_reg, Type.usize, .{ .lea_got = sym_index }); | 6433 | try self.genSetReg(addr_reg, Type.usize, .{ .lea_got = sym_index }); |
| 6436 | } else if (self.bin_file.cast(link.File.MachO)) |macho_file| { | 6434 | } else if (self.bin_file.cast(link.File.MachO)) |macho_file| { |
| 6437 | const atom_index = try macho_file.getOrCreateAtomForLazySymbol( | 6435 | const atom_index = try macho_file.getOrCreateAtomForLazySymbol( |
| 6438 | .{ .kind = .const_data, .ty = Type.anyerror }, | 6436 | .{ .kind = .const_data, .ty = Type.anyerror }, |
| 6439 | 4, // dword alignment | ||
| 6440 | ); | 6437 | ); |
| 6441 | const sym_index = macho_file.getAtom(atom_index).getSymbolIndex().?; | 6438 | const sym_index = macho_file.getAtom(atom_index).getSymbolIndex().?; |
| 6442 | try self.genSetReg(addr_reg, Type.usize, .{ .lea_got = sym_index }); | 6439 | try self.genSetReg(addr_reg, Type.usize, .{ .lea_got = sym_index }); |
| ... | @@ -8504,7 +8501,6 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -8504,7 +8501,6 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void { |
| 8504 | if (self.bin_file.cast(link.File.Elf)) |elf_file| { | 8501 | if (self.bin_file.cast(link.File.Elf)) |elf_file| { |
| 8505 | const atom_index = try elf_file.getOrCreateAtomForLazySymbol( | 8502 | const atom_index = try elf_file.getOrCreateAtomForLazySymbol( |
| 8506 | .{ .kind = .const_data, .ty = Type.anyerror }, | 8503 | .{ .kind = .const_data, .ty = Type.anyerror }, |
| 8507 | 4, // dword alignment | ||
| 8508 | ); | 8504 | ); |
| 8509 | const atom = elf_file.getAtom(atom_index); | 8505 | const atom = elf_file.getAtom(atom_index); |
| 8510 | _ = try atom.getOrCreateOffsetTableEntry(elf_file); | 8506 | _ = try atom.getOrCreateOffsetTableEntry(elf_file); |
| ... | @@ -8517,14 +8513,12 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -8517,14 +8513,12 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void { |
| 8517 | } else if (self.bin_file.cast(link.File.Coff)) |coff_file| { | 8513 | } else if (self.bin_file.cast(link.File.Coff)) |coff_file| { |
| 8518 | const atom_index = try coff_file.getOrCreateAtomForLazySymbol( | 8514 | const atom_index = try coff_file.getOrCreateAtomForLazySymbol( |
| 8519 | .{ .kind = .const_data, .ty = Type.anyerror }, | 8515 | .{ .kind = .const_data, .ty = Type.anyerror }, |
| 8520 | 4, // dword alignment | ||
| 8521 | ); | 8516 | ); |
| 8522 | const sym_index = coff_file.getAtom(atom_index).getSymbolIndex().?; | 8517 | const sym_index = coff_file.getAtom(atom_index).getSymbolIndex().?; |
| 8523 | try self.genSetReg(addr_reg, Type.usize, .{ .lea_got = sym_index }); | 8518 | try self.genSetReg(addr_reg, Type.usize, .{ .lea_got = sym_index }); |
| 8524 | } else if (self.bin_file.cast(link.File.MachO)) |macho_file| { | 8519 | } else if (self.bin_file.cast(link.File.MachO)) |macho_file| { |
| 8525 | const atom_index = try macho_file.getOrCreateAtomForLazySymbol( | 8520 | const atom_index = try macho_file.getOrCreateAtomForLazySymbol( |
| 8526 | .{ .kind = .const_data, .ty = Type.anyerror }, | 8521 | .{ .kind = .const_data, .ty = Type.anyerror }, |
| 8527 | 4, // dword alignment | ||
| 8528 | ); | 8522 | ); |
| 8529 | const sym_index = macho_file.getAtom(atom_index).getSymbolIndex().?; | 8523 | const sym_index = macho_file.getAtom(atom_index).getSymbolIndex().?; |
| 8530 | try self.genSetReg(addr_reg, Type.usize, .{ .lea_got = sym_index }); | 8524 | try self.genSetReg(addr_reg, Type.usize, .{ .lea_got = sym_index }); |
src/codegen.zig+4-4| ... | @@ -104,7 +104,7 @@ pub fn generateLazySymbol( | ... | @@ -104,7 +104,7 @@ pub fn generateLazySymbol( |
| 104 | code: *std.ArrayList(u8), | 104 | code: *std.ArrayList(u8), |
| 105 | debug_output: DebugInfoOutput, | 105 | debug_output: DebugInfoOutput, |
| 106 | reloc_info: RelocInfo, | 106 | reloc_info: RelocInfo, |
| 107 | ) CodeGenError!Result { | 107 | ) CodeGenError!struct { res: Result, alignment: u32 } { |
| 108 | _ = debug_output; | 108 | _ = debug_output; |
| 109 | _ = reloc_info; | 109 | _ = reloc_info; |
| 110 | 110 | ||
| ... | @@ -133,13 +133,13 @@ pub fn generateLazySymbol( | ... | @@ -133,13 +133,13 @@ pub fn generateLazySymbol( |
| 133 | code.appendAssumeCapacity(0); | 133 | code.appendAssumeCapacity(0); |
| 134 | } | 134 | } |
| 135 | mem.writeInt(u32, code.items[offset..][0..4], @intCast(u32, code.items.len), endian); | 135 | mem.writeInt(u32, code.items[offset..][0..4], @intCast(u32, code.items.len), endian); |
| 136 | return Result.ok; | 136 | return .{ .res = Result.ok, .alignment = 4 }; |
| 137 | } else return .{ .fail = try ErrorMsg.create( | 137 | } else return .{ .res = .{ .fail = try ErrorMsg.create( |
| 138 | bin_file.allocator, | 138 | bin_file.allocator, |
| 139 | src_loc, | 139 | src_loc, |
| 140 | "TODO implement generateLazySymbol for {s} {}", | 140 | "TODO implement generateLazySymbol for {s} {}", |
| 141 | .{ @tagName(lazy_sym.kind), lazy_sym.ty.fmt(mod) }, | 141 | .{ @tagName(lazy_sym.kind), lazy_sym.ty.fmt(mod) }, |
| 142 | ) }; | 142 | ) }, .alignment = undefined }; |
| 143 | } | 143 | } |
| 144 | 144 | ||
| 145 | pub fn generateSymbol( | 145 | pub fn generateSymbol( |
src/link/Coff.zig+5-13| ... | @@ -145,7 +145,6 @@ const LazySymbolTable = std.AutoArrayHashMapUnmanaged(Module.Decl.OptionalIndex, | ... | @@ -145,7 +145,6 @@ const LazySymbolTable = std.AutoArrayHashMapUnmanaged(Module.Decl.OptionalIndex, |
| 145 | const LazySymbolMetadata = struct { | 145 | const LazySymbolMetadata = struct { |
| 146 | text_atom: ?Atom.Index = null, | 146 | text_atom: ?Atom.Index = null, |
| 147 | rdata_atom: ?Atom.Index = null, | 147 | rdata_atom: ?Atom.Index = null, |
| 148 | alignment: u32, | ||
| 149 | }; | 148 | }; |
| 150 | 149 | ||
| 151 | const DeclMetadata = struct { | 150 | const DeclMetadata = struct { |
| ... | @@ -1195,13 +1194,11 @@ fn updateLazySymbol(self: *Coff, decl: Module.Decl.OptionalIndex, metadata: Lazy | ... | @@ -1195,13 +1194,11 @@ fn updateLazySymbol(self: *Coff, decl: Module.Decl.OptionalIndex, metadata: Lazy |
| 1195 | link.File.LazySymbol.initDecl(.code, decl, mod), | 1194 | link.File.LazySymbol.initDecl(.code, decl, mod), |
| 1196 | atom, | 1195 | atom, |
| 1197 | self.text_section_index.?, | 1196 | self.text_section_index.?, |
| 1198 | metadata.alignment, | ||
| 1199 | ); | 1197 | ); |
| 1200 | if (metadata.rdata_atom) |atom| try self.updateLazySymbolAtom( | 1198 | if (metadata.rdata_atom) |atom| try self.updateLazySymbolAtom( |
| 1201 | link.File.LazySymbol.initDecl(.const_data, decl, mod), | 1199 | link.File.LazySymbol.initDecl(.const_data, decl, mod), |
| 1202 | atom, | 1200 | atom, |
| 1203 | self.rdata_section_index.?, | 1201 | self.rdata_section_index.?, |
| 1204 | metadata.alignment, | ||
| 1205 | ); | 1202 | ); |
| 1206 | } | 1203 | } |
| 1207 | 1204 | ||
| ... | @@ -1210,7 +1207,6 @@ fn updateLazySymbolAtom( | ... | @@ -1210,7 +1207,6 @@ fn updateLazySymbolAtom( |
| 1210 | sym: link.File.LazySymbol, | 1207 | sym: link.File.LazySymbol, |
| 1211 | atom_index: Atom.Index, | 1208 | atom_index: Atom.Index, |
| 1212 | section_index: u16, | 1209 | section_index: u16, |
| 1213 | required_alignment: u32, | ||
| 1214 | ) !void { | 1210 | ) !void { |
| 1215 | const gpa = self.base.allocator; | 1211 | const gpa = self.base.allocator; |
| 1216 | const mod = self.base.options.module.?; | 1212 | const mod = self.base.options.module.?; |
| ... | @@ -1238,7 +1234,7 @@ fn updateLazySymbolAtom( | ... | @@ -1238,7 +1234,7 @@ fn updateLazySymbolAtom( |
| 1238 | const res = try codegen.generateLazySymbol(&self.base, src, sym, &code_buffer, .none, .{ | 1234 | const res = try codegen.generateLazySymbol(&self.base, src, sym, &code_buffer, .none, .{ |
| 1239 | .parent_atom_index = local_sym_index, | 1235 | .parent_atom_index = local_sym_index, |
| 1240 | }); | 1236 | }); |
| 1241 | const code = switch (res) { | 1237 | const code = switch (res.res) { |
| 1242 | .ok => code_buffer.items, | 1238 | .ok => code_buffer.items, |
| 1243 | .fail => |em| { | 1239 | .fail => |em| { |
| 1244 | log.err("{s}", .{em.msg}); | 1240 | log.err("{s}", .{em.msg}); |
| ... | @@ -1252,11 +1248,11 @@ fn updateLazySymbolAtom( | ... | @@ -1252,11 +1248,11 @@ fn updateLazySymbolAtom( |
| 1252 | symbol.section_number = @intToEnum(coff.SectionNumber, section_index + 1); | 1248 | symbol.section_number = @intToEnum(coff.SectionNumber, section_index + 1); |
| 1253 | symbol.type = .{ .complex_type = .NULL, .base_type = .NULL }; | 1249 | symbol.type = .{ .complex_type = .NULL, .base_type = .NULL }; |
| 1254 | 1250 | ||
| 1255 | const vaddr = try self.allocateAtom(atom_index, code_len, required_alignment); | 1251 | const vaddr = try self.allocateAtom(atom_index, code_len, res.alignment); |
| 1256 | errdefer self.freeAtom(atom_index); | 1252 | errdefer self.freeAtom(atom_index); |
| 1257 | 1253 | ||
| 1258 | log.debug("allocated atom for {s} at 0x{x}", .{ name, vaddr }); | 1254 | log.debug("allocated atom for {s} at 0x{x}", .{ name, vaddr }); |
| 1259 | log.debug(" (required alignment 0x{x})", .{required_alignment}); | 1255 | log.debug(" (required alignment 0x{x})", .{res.alignment}); |
| 1260 | 1256 | ||
| 1261 | atom.size = code_len; | 1257 | atom.size = code_len; |
| 1262 | symbol.value = vaddr; | 1258 | symbol.value = vaddr; |
| ... | @@ -1265,14 +1261,10 @@ fn updateLazySymbolAtom( | ... | @@ -1265,14 +1261,10 @@ fn updateLazySymbolAtom( |
| 1265 | try self.writeAtom(atom_index, code); | 1261 | try self.writeAtom(atom_index, code); |
| 1266 | } | 1262 | } |
| 1267 | 1263 | ||
| 1268 | pub fn getOrCreateAtomForLazySymbol( | 1264 | pub fn getOrCreateAtomForLazySymbol(self: *Coff, sym: link.File.LazySymbol) !Atom.Index { |
| 1269 | self: *Coff, | ||
| 1270 | sym: link.File.LazySymbol, | ||
| 1271 | alignment: u32, | ||
| 1272 | ) !Atom.Index { | ||
| 1273 | const gop = try self.lazy_syms.getOrPut(self.base.allocator, sym.getDecl()); | 1265 | const gop = try self.lazy_syms.getOrPut(self.base.allocator, sym.getDecl()); |
| 1274 | errdefer _ = self.lazy_syms.pop(); | 1266 | errdefer _ = self.lazy_syms.pop(); |
| 1275 | if (!gop.found_existing) gop.value_ptr.* = .{ .alignment = alignment }; | 1267 | if (!gop.found_existing) gop.value_ptr.* = .{}; |
| 1276 | const atom = switch (sym.kind) { | 1268 | const atom = switch (sym.kind) { |
| 1277 | .code => &gop.value_ptr.text_atom, | 1269 | .code => &gop.value_ptr.text_atom, |
| 1278 | .const_data => &gop.value_ptr.rdata_atom, | 1270 | .const_data => &gop.value_ptr.rdata_atom, |
src/link/Elf.zig+4-8| ... | @@ -67,7 +67,6 @@ const Section = struct { | ... | @@ -67,7 +67,6 @@ const Section = struct { |
| 67 | const LazySymbolMetadata = struct { | 67 | const LazySymbolMetadata = struct { |
| 68 | text_atom: ?Atom.Index = null, | 68 | text_atom: ?Atom.Index = null, |
| 69 | rodata_atom: ?Atom.Index = null, | 69 | rodata_atom: ?Atom.Index = null, |
| 70 | alignment: u32, | ||
| 71 | }; | 70 | }; |
| 72 | 71 | ||
| 73 | const DeclMetadata = struct { | 72 | const DeclMetadata = struct { |
| ... | @@ -2377,10 +2376,10 @@ pub fn freeDecl(self: *Elf, decl_index: Module.Decl.Index) void { | ... | @@ -2377,10 +2376,10 @@ pub fn freeDecl(self: *Elf, decl_index: Module.Decl.Index) void { |
| 2377 | } | 2376 | } |
| 2378 | } | 2377 | } |
| 2379 | 2378 | ||
| 2380 | pub fn getOrCreateAtomForLazySymbol(self: *Elf, sym: File.LazySymbol, alignment: u32) !Atom.Index { | 2379 | pub fn getOrCreateAtomForLazySymbol(self: *Elf, sym: File.LazySymbol) !Atom.Index { |
| 2381 | const gop = try self.lazy_syms.getOrPut(self.base.allocator, sym.getDecl()); | 2380 | const gop = try self.lazy_syms.getOrPut(self.base.allocator, sym.getDecl()); |
| 2382 | errdefer _ = self.lazy_syms.pop(); | 2381 | errdefer _ = self.lazy_syms.pop(); |
| 2383 | if (!gop.found_existing) gop.value_ptr.* = .{ .alignment = alignment }; | 2382 | if (!gop.found_existing) gop.value_ptr.* = .{}; |
| 2384 | const atom = switch (sym.kind) { | 2383 | const atom = switch (sym.kind) { |
| 2385 | .code => &gop.value_ptr.text_atom, | 2384 | .code => &gop.value_ptr.text_atom, |
| 2386 | .const_data => &gop.value_ptr.rodata_atom, | 2385 | .const_data => &gop.value_ptr.rodata_atom, |
| ... | @@ -2663,13 +2662,11 @@ fn updateLazySymbol(self: *Elf, decl: Module.Decl.OptionalIndex, metadata: LazyS | ... | @@ -2663,13 +2662,11 @@ fn updateLazySymbol(self: *Elf, decl: Module.Decl.OptionalIndex, metadata: LazyS |
| 2663 | File.LazySymbol.initDecl(.code, decl, mod), | 2662 | File.LazySymbol.initDecl(.code, decl, mod), |
| 2664 | atom, | 2663 | atom, |
| 2665 | self.text_section_index.?, | 2664 | self.text_section_index.?, |
| 2666 | metadata.alignment, | ||
| 2667 | ); | 2665 | ); |
| 2668 | if (metadata.rodata_atom) |atom| try self.updateLazySymbolAtom( | 2666 | if (metadata.rodata_atom) |atom| try self.updateLazySymbolAtom( |
| 2669 | File.LazySymbol.initDecl(.const_data, decl, mod), | 2667 | File.LazySymbol.initDecl(.const_data, decl, mod), |
| 2670 | atom, | 2668 | atom, |
| 2671 | self.rodata_section_index.?, | 2669 | self.rodata_section_index.?, |
| 2672 | metadata.alignment, | ||
| 2673 | ); | 2670 | ); |
| 2674 | } | 2671 | } |
| 2675 | 2672 | ||
| ... | @@ -2678,7 +2675,6 @@ fn updateLazySymbolAtom( | ... | @@ -2678,7 +2675,6 @@ fn updateLazySymbolAtom( |
| 2678 | sym: File.LazySymbol, | 2675 | sym: File.LazySymbol, |
| 2679 | atom_index: Atom.Index, | 2676 | atom_index: Atom.Index, |
| 2680 | shdr_index: u16, | 2677 | shdr_index: u16, |
| 2681 | required_alignment: u32, | ||
| 2682 | ) !void { | 2678 | ) !void { |
| 2683 | const gpa = self.base.allocator; | 2679 | const gpa = self.base.allocator; |
| 2684 | const mod = self.base.options.module.?; | 2680 | const mod = self.base.options.module.?; |
| ... | @@ -2710,7 +2706,7 @@ fn updateLazySymbolAtom( | ... | @@ -2710,7 +2706,7 @@ fn updateLazySymbolAtom( |
| 2710 | const res = try codegen.generateLazySymbol(&self.base, src, sym, &code_buffer, .none, .{ | 2706 | const res = try codegen.generateLazySymbol(&self.base, src, sym, &code_buffer, .none, .{ |
| 2711 | .parent_atom_index = local_sym_index, | 2707 | .parent_atom_index = local_sym_index, |
| 2712 | }); | 2708 | }); |
| 2713 | const code = switch (res) { | 2709 | const code = switch (res.res) { |
| 2714 | .ok => code_buffer.items, | 2710 | .ok => code_buffer.items, |
| 2715 | .fail => |em| { | 2711 | .fail => |em| { |
| 2716 | log.err("{s}", .{em.msg}); | 2712 | log.err("{s}", .{em.msg}); |
| ... | @@ -2728,7 +2724,7 @@ fn updateLazySymbolAtom( | ... | @@ -2728,7 +2724,7 @@ fn updateLazySymbolAtom( |
| 2728 | .st_value = 0, | 2724 | .st_value = 0, |
| 2729 | .st_size = 0, | 2725 | .st_size = 0, |
| 2730 | }; | 2726 | }; |
| 2731 | const vaddr = try self.allocateAtom(atom_index, code.len, required_alignment); | 2727 | const vaddr = try self.allocateAtom(atom_index, code.len, res.alignment); |
| 2732 | errdefer self.freeAtom(atom_index); | 2728 | errdefer self.freeAtom(atom_index); |
| 2733 | log.debug("allocated text block for {s} at 0x{x}", .{ name, vaddr }); | 2729 | log.debug("allocated text block for {s} at 0x{x}", .{ name, vaddr }); |
| 2734 | 2730 |
src/link/MachO.zig+5-9| ... | @@ -238,7 +238,6 @@ const LazySymbolTable = std.AutoArrayHashMapUnmanaged(Module.Decl.OptionalIndex, | ... | @@ -238,7 +238,6 @@ const LazySymbolTable = std.AutoArrayHashMapUnmanaged(Module.Decl.OptionalIndex, |
| 238 | const LazySymbolMetadata = struct { | 238 | const LazySymbolMetadata = struct { |
| 239 | text_atom: ?Atom.Index = null, | 239 | text_atom: ?Atom.Index = null, |
| 240 | data_const_atom: ?Atom.Index = null, | 240 | data_const_atom: ?Atom.Index = null, |
| 241 | alignment: u32, | ||
| 242 | }; | 241 | }; |
| 243 | 242 | ||
| 244 | const TlvSymbolTable = std.AutoArrayHashMapUnmanaged(SymbolWithLoc, Atom.Index); | 243 | const TlvSymbolTable = std.AutoArrayHashMapUnmanaged(SymbolWithLoc, Atom.Index); |
| ... | @@ -2043,13 +2042,11 @@ fn updateLazySymbol(self: *MachO, decl: Module.Decl.OptionalIndex, metadata: Laz | ... | @@ -2043,13 +2042,11 @@ fn updateLazySymbol(self: *MachO, decl: Module.Decl.OptionalIndex, metadata: Laz |
| 2043 | File.LazySymbol.initDecl(.code, decl, mod), | 2042 | File.LazySymbol.initDecl(.code, decl, mod), |
| 2044 | atom, | 2043 | atom, |
| 2045 | self.text_section_index.?, | 2044 | self.text_section_index.?, |
| 2046 | metadata.alignment, | ||
| 2047 | ); | 2045 | ); |
| 2048 | if (metadata.data_const_atom) |atom| try self.updateLazySymbolAtom( | 2046 | if (metadata.data_const_atom) |atom| try self.updateLazySymbolAtom( |
| 2049 | File.LazySymbol.initDecl(.const_data, decl, mod), | 2047 | File.LazySymbol.initDecl(.const_data, decl, mod), |
| 2050 | atom, | 2048 | atom, |
| 2051 | self.data_const_section_index.?, | 2049 | self.data_const_section_index.?, |
| 2052 | metadata.alignment, | ||
| 2053 | ); | 2050 | ); |
| 2054 | } | 2051 | } |
| 2055 | 2052 | ||
| ... | @@ -2058,7 +2055,6 @@ fn updateLazySymbolAtom( | ... | @@ -2058,7 +2055,6 @@ fn updateLazySymbolAtom( |
| 2058 | sym: File.LazySymbol, | 2055 | sym: File.LazySymbol, |
| 2059 | atom_index: Atom.Index, | 2056 | atom_index: Atom.Index, |
| 2060 | section_index: u8, | 2057 | section_index: u8, |
| 2061 | required_alignment: u32, | ||
| 2062 | ) !void { | 2058 | ) !void { |
| 2063 | const gpa = self.base.allocator; | 2059 | const gpa = self.base.allocator; |
| 2064 | const mod = self.base.options.module.?; | 2060 | const mod = self.base.options.module.?; |
| ... | @@ -2090,7 +2086,7 @@ fn updateLazySymbolAtom( | ... | @@ -2090,7 +2086,7 @@ fn updateLazySymbolAtom( |
| 2090 | const res = try codegen.generateLazySymbol(&self.base, src, sym, &code_buffer, .none, .{ | 2086 | const res = try codegen.generateLazySymbol(&self.base, src, sym, &code_buffer, .none, .{ |
| 2091 | .parent_atom_index = local_sym_index, | 2087 | .parent_atom_index = local_sym_index, |
| 2092 | }); | 2088 | }); |
| 2093 | const code = switch (res) { | 2089 | const code = switch (res.res) { |
| 2094 | .ok => code_buffer.items, | 2090 | .ok => code_buffer.items, |
| 2095 | .fail => |em| { | 2091 | .fail => |em| { |
| 2096 | log.err("{s}", .{em.msg}); | 2092 | log.err("{s}", .{em.msg}); |
| ... | @@ -2104,11 +2100,11 @@ fn updateLazySymbolAtom( | ... | @@ -2104,11 +2100,11 @@ fn updateLazySymbolAtom( |
| 2104 | symbol.n_sect = section_index + 1; | 2100 | symbol.n_sect = section_index + 1; |
| 2105 | symbol.n_desc = 0; | 2101 | symbol.n_desc = 0; |
| 2106 | 2102 | ||
| 2107 | const vaddr = try self.allocateAtom(atom_index, code.len, required_alignment); | 2103 | const vaddr = try self.allocateAtom(atom_index, code.len, res.alignment); |
| 2108 | errdefer self.freeAtom(atom_index); | 2104 | errdefer self.freeAtom(atom_index); |
| 2109 | 2105 | ||
| 2110 | log.debug("allocated atom for {s} at 0x{x}", .{ name, vaddr }); | 2106 | log.debug("allocated atom for {s} at 0x{x}", .{ name, vaddr }); |
| 2111 | log.debug(" (required alignment 0x{x}", .{required_alignment}); | 2107 | log.debug(" (required alignment 0x{x}", .{res.alignment}); |
| 2112 | 2108 | ||
| 2113 | atom.size = code.len; | 2109 | atom.size = code.len; |
| 2114 | symbol.n_value = vaddr; | 2110 | symbol.n_value = vaddr; |
| ... | @@ -2117,10 +2113,10 @@ fn updateLazySymbolAtom( | ... | @@ -2117,10 +2113,10 @@ fn updateLazySymbolAtom( |
| 2117 | try self.writeAtom(atom_index, code); | 2113 | try self.writeAtom(atom_index, code); |
| 2118 | } | 2114 | } |
| 2119 | 2115 | ||
| 2120 | pub fn getOrCreateAtomForLazySymbol(self: *MachO, sym: File.LazySymbol, alignment: u32) !Atom.Index { | 2116 | pub fn getOrCreateAtomForLazySymbol(self: *MachO, sym: File.LazySymbol) !Atom.Index { |
| 2121 | const gop = try self.lazy_syms.getOrPut(self.base.allocator, sym.getDecl()); | 2117 | const gop = try self.lazy_syms.getOrPut(self.base.allocator, sym.getDecl()); |
| 2122 | errdefer _ = self.lazy_syms.pop(); | 2118 | errdefer _ = self.lazy_syms.pop(); |
| 2123 | if (!gop.found_existing) gop.value_ptr.* = .{ .alignment = alignment }; | 2119 | if (!gop.found_existing) gop.value_ptr.* = .{}; |
| 2124 | const atom = switch (sym.kind) { | 2120 | const atom = switch (sym.kind) { |
| 2125 | .code => &gop.value_ptr.text_atom, | 2121 | .code => &gop.value_ptr.text_atom, |
| 2126 | .const_data => &gop.value_ptr.data_const_atom, | 2122 | .const_data => &gop.value_ptr.data_const_atom, |