| ... | @@ -242,6 +242,7 @@ const LazySymbolTable = std.ArrayHashMapUnmanaged( | ... | @@ -242,6 +242,7 @@ const LazySymbolTable = std.ArrayHashMapUnmanaged( |
| 242 | const LazySymbolMetadata = struct { | 242 | const LazySymbolMetadata = struct { |
| 243 | atom: Atom.Index, | 243 | atom: Atom.Index, |
| 244 | section: u8, | 244 | section: u8, |
| | 245 | alignment: u32, |
| 245 | }; | 246 | }; |
| 246 | | 247 | |
| 247 | const DeclMetadata = struct { | 248 | const DeclMetadata = struct { |
| ... | @@ -1205,7 +1206,6 @@ pub fn createAtom(self: *MachO) !Atom.Index { | ... | @@ -1205,7 +1206,6 @@ pub fn createAtom(self: *MachO) !Atom.Index { |
| 1205 | .sym_index = sym_index, | 1206 | .sym_index = sym_index, |
| 1206 | .file = null, | 1207 | .file = null, |
| 1207 | .size = 0, | 1208 | .size = 0, |
| 1208 | .alignment = 0, | | |
| 1209 | .prev_index = null, | 1209 | .prev_index = null, |
| 1210 | .next_index = null, | 1210 | .next_index = null, |
| 1211 | }; | 1211 | }; |
| ... | @@ -1217,7 +1217,6 @@ pub fn createGotAtom(self: *MachO, target: SymbolWithLoc) !Atom.Index { | ... | @@ -1217,7 +1217,6 @@ pub fn createGotAtom(self: *MachO, target: SymbolWithLoc) !Atom.Index { |
| 1217 | const atom_index = try self.createAtom(); | 1217 | const atom_index = try self.createAtom(); |
| 1218 | const atom = self.getAtomPtr(atom_index); | 1218 | const atom = self.getAtomPtr(atom_index); |
| 1219 | atom.size = @sizeOf(u64); | 1219 | atom.size = @sizeOf(u64); |
| 1220 | atom.alignment = @alignOf(u64); | | |
| 1221 | | 1220 | |
| 1222 | const sym = atom.getSymbolPtr(self); | 1221 | const sym = atom.getSymbolPtr(self); |
| 1223 | sym.n_type = macho.N_SECT; | 1222 | sym.n_type = macho.N_SECT; |
| ... | @@ -1259,7 +1258,6 @@ pub fn createDyldPrivateAtom(self: *MachO) !void { | ... | @@ -1259,7 +1258,6 @@ pub fn createDyldPrivateAtom(self: *MachO) !void { |
| 1259 | const atom_index = try self.createAtom(); | 1258 | const atom_index = try self.createAtom(); |
| 1260 | const atom = self.getAtomPtr(atom_index); | 1259 | const atom = self.getAtomPtr(atom_index); |
| 1261 | atom.size = @sizeOf(u64); | 1260 | atom.size = @sizeOf(u64); |
| 1262 | atom.alignment = @alignOf(u64); | | |
| 1263 | | 1261 | |
| 1264 | const sym = atom.getSymbolPtr(self); | 1262 | const sym = atom.getSymbolPtr(self); |
| 1265 | sym.n_type = macho.N_SECT; | 1263 | sym.n_type = macho.N_SECT; |
| ... | @@ -1285,7 +1283,8 @@ pub fn createStubHelperPreambleAtom(self: *MachO) !void { | ... | @@ -1285,7 +1283,8 @@ pub fn createStubHelperPreambleAtom(self: *MachO) !void { |
| 1285 | const atom_index = try self.createAtom(); | 1283 | const atom_index = try self.createAtom(); |
| 1286 | const atom = self.getAtomPtr(atom_index); | 1284 | const atom = self.getAtomPtr(atom_index); |
| 1287 | atom.size = size; | 1285 | atom.size = size; |
| 1288 | atom.alignment = switch (arch) { | 1286 | |
| | 1287 | const required_alignment: u32 = switch (arch) { |
| 1289 | .x86_64 => 1, | 1288 | .x86_64 => 1, |
| 1290 | .aarch64 => @alignOf(u32), | 1289 | .aarch64 => @alignOf(u32), |
| 1291 | else => unreachable, | 1290 | else => unreachable, |
| ... | @@ -1392,7 +1391,7 @@ pub fn createStubHelperPreambleAtom(self: *MachO) !void { | ... | @@ -1392,7 +1391,7 @@ pub fn createStubHelperPreambleAtom(self: *MachO) !void { |
| 1392 | } | 1391 | } |
| 1393 | self.stub_helper_preamble_atom_index = atom_index; | 1392 | self.stub_helper_preamble_atom_index = atom_index; |
| 1394 | | 1393 | |
| 1395 | sym.n_value = try self.allocateAtom(atom_index, size, atom.alignment); | 1394 | sym.n_value = try self.allocateAtom(atom_index, size, required_alignment); |
| 1396 | log.debug("allocated stub preamble atom at 0x{x}", .{sym.n_value}); | 1395 | log.debug("allocated stub preamble atom at 0x{x}", .{sym.n_value}); |
| 1397 | try self.writeAtom(atom_index, code); | 1396 | try self.writeAtom(atom_index, code); |
| 1398 | } | 1397 | } |
| ... | @@ -1408,7 +1407,8 @@ pub fn createStubHelperAtom(self: *MachO) !Atom.Index { | ... | @@ -1408,7 +1407,8 @@ pub fn createStubHelperAtom(self: *MachO) !Atom.Index { |
| 1408 | const atom_index = try self.createAtom(); | 1407 | const atom_index = try self.createAtom(); |
| 1409 | const atom = self.getAtomPtr(atom_index); | 1408 | const atom = self.getAtomPtr(atom_index); |
| 1410 | atom.size = size; | 1409 | atom.size = size; |
| 1411 | atom.alignment = switch (arch) { | 1410 | |
| | 1411 | const required_alignment: u32 = switch (arch) { |
| 1412 | .x86_64 => 1, | 1412 | .x86_64 => 1, |
| 1413 | .aarch64 => @alignOf(u32), | 1413 | .aarch64 => @alignOf(u32), |
| 1414 | else => unreachable, | 1414 | else => unreachable, |
| ... | @@ -1470,7 +1470,7 @@ pub fn createStubHelperAtom(self: *MachO) !Atom.Index { | ... | @@ -1470,7 +1470,7 @@ pub fn createStubHelperAtom(self: *MachO) !Atom.Index { |
| 1470 | else => unreachable, | 1470 | else => unreachable, |
| 1471 | } | 1471 | } |
| 1472 | | 1472 | |
| 1473 | sym.n_value = try self.allocateAtom(atom_index, size, atom.alignment); | 1473 | sym.n_value = try self.allocateAtom(atom_index, size, required_alignment); |
| 1474 | log.debug("allocated stub helper atom at 0x{x}", .{sym.n_value}); | 1474 | log.debug("allocated stub helper atom at 0x{x}", .{sym.n_value}); |
| 1475 | try self.writeAtom(atom_index, code); | 1475 | try self.writeAtom(atom_index, code); |
| 1476 | | 1476 | |
| ... | @@ -1481,7 +1481,6 @@ pub fn createLazyPointerAtom(self: *MachO, stub_sym_index: u32, target: SymbolWi | ... | @@ -1481,7 +1481,6 @@ pub fn createLazyPointerAtom(self: *MachO, stub_sym_index: u32, target: SymbolWi |
| 1481 | const atom_index = try self.createAtom(); | 1481 | const atom_index = try self.createAtom(); |
| 1482 | const atom = self.getAtomPtr(atom_index); | 1482 | const atom = self.getAtomPtr(atom_index); |
| 1483 | atom.size = @sizeOf(u64); | 1483 | atom.size = @sizeOf(u64); |
| 1484 | atom.alignment = @alignOf(u64); | | |
| 1485 | | 1484 | |
| 1486 | const sym = atom.getSymbolPtr(self); | 1485 | const sym = atom.getSymbolPtr(self); |
| 1487 | sym.n_type = macho.N_SECT; | 1486 | sym.n_type = macho.N_SECT; |
| ... | @@ -1523,7 +1522,8 @@ pub fn createStubAtom(self: *MachO, laptr_sym_index: u32) !Atom.Index { | ... | @@ -1523,7 +1522,8 @@ pub fn createStubAtom(self: *MachO, laptr_sym_index: u32) !Atom.Index { |
| 1523 | const atom_index = try self.createAtom(); | 1522 | const atom_index = try self.createAtom(); |
| 1524 | const atom = self.getAtomPtr(atom_index); | 1523 | const atom = self.getAtomPtr(atom_index); |
| 1525 | atom.size = size; | 1524 | atom.size = size; |
| 1526 | atom.alignment = switch (arch) { | 1525 | |
| | 1526 | const required_alignment: u32 = switch (arch) { |
| 1527 | .x86_64 => 1, | 1527 | .x86_64 => 1, |
| 1528 | .aarch64 => @alignOf(u32), | 1528 | .aarch64 => @alignOf(u32), |
| 1529 | else => unreachable, // unhandled architecture type | 1529 | else => unreachable, // unhandled architecture type |
| ... | @@ -1587,7 +1587,7 @@ pub fn createStubAtom(self: *MachO, laptr_sym_index: u32) !Atom.Index { | ... | @@ -1587,7 +1587,7 @@ pub fn createStubAtom(self: *MachO, laptr_sym_index: u32) !Atom.Index { |
| 1587 | else => unreachable, | 1587 | else => unreachable, |
| 1588 | } | 1588 | } |
| 1589 | | 1589 | |
| 1590 | sym.n_value = try self.allocateAtom(atom_index, size, atom.alignment); | 1590 | sym.n_value = try self.allocateAtom(atom_index, size, required_alignment); |
| 1591 | log.debug("allocated stub atom at 0x{x}", .{sym.n_value}); | 1591 | log.debug("allocated stub atom at 0x{x}", .{sym.n_value}); |
| 1592 | try self.writeAtom(atom_index, code); | 1592 | try self.writeAtom(atom_index, code); |
| 1593 | | 1593 | |
| ... | @@ -2217,7 +2217,6 @@ pub fn lowerUnnamedConst(self: *MachO, typed_value: TypedValue, decl_index: Modu | ... | @@ -2217,7 +2217,6 @@ pub fn lowerUnnamedConst(self: *MachO, typed_value: TypedValue, decl_index: Modu |
| 2217 | const required_alignment = typed_value.ty.abiAlignment(self.base.options.target); | 2217 | const required_alignment = typed_value.ty.abiAlignment(self.base.options.target); |
| 2218 | const atom = self.getAtomPtr(atom_index); | 2218 | const atom = self.getAtomPtr(atom_index); |
| 2219 | atom.size = code.len; | 2219 | atom.size = code.len; |
| 2220 | atom.alignment = required_alignment; | | |
| 2221 | // TODO: work out logic for disambiguating functions from function pointers | 2220 | // TODO: work out logic for disambiguating functions from function pointers |
| 2222 | // const sect_id = self.getDeclOutputSection(decl_index); | 2221 | // const sect_id = self.getDeclOutputSection(decl_index); |
| 2223 | const sect_id = self.data_const_section_index.?; | 2222 | const sect_id = self.data_const_section_index.?; |
| ... | @@ -2355,7 +2354,7 @@ fn updateLazySymbol(self: *MachO, lazy_sym: File.LazySymbol, lazy_metadata: Lazy | ... | @@ -2355,7 +2354,7 @@ fn updateLazySymbol(self: *MachO, lazy_sym: File.LazySymbol, lazy_metadata: Lazy |
| 2355 | }, | 2354 | }, |
| 2356 | }; | 2355 | }; |
| 2357 | | 2356 | |
| 2358 | const required_alignment = atom.alignment; | 2357 | const required_alignment = lazy_metadata.alignment; |
| 2359 | const symbol = atom.getSymbolPtr(self); | 2358 | const symbol = atom.getSymbolPtr(self); |
| 2360 | symbol.n_strx = name_str_index; | 2359 | symbol.n_strx = name_str_index; |
| 2361 | symbol.n_type = macho.N_SECT; | 2360 | symbol.n_type = macho.N_SECT; |
| ... | @@ -2398,8 +2397,8 @@ pub fn getOrCreateAtomForLazySymbol( | ... | @@ -2398,8 +2397,8 @@ pub fn getOrCreateAtomForLazySymbol( |
| 2398 | .code => self.text_section_index.?, | 2397 | .code => self.text_section_index.?, |
| 2399 | .const_data => self.data_const_section_index.?, | 2398 | .const_data => self.data_const_section_index.?, |
| 2400 | }, | 2399 | }, |
| | 2400 | .alignment = alignment, |
| 2401 | }; | 2401 | }; |
| 2402 | self.getAtomPtr(gop.value_ptr.atom).alignment = alignment; | | |
| 2403 | } | 2402 | } |
| 2404 | return gop.value_ptr.atom; | 2403 | return gop.value_ptr.atom; |
| 2405 | } | 2404 | } |
| ... | @@ -3222,7 +3221,6 @@ fn allocateAtom(self: *MachO, atom_index: Atom.Index, new_atom_size: u64, alignm | ... | @@ -3222,7 +3221,6 @@ fn allocateAtom(self: *MachO, atom_index: Atom.Index, new_atom_size: u64, alignm |
| 3222 | { | 3221 | { |
| 3223 | const atom_ptr = self.getAtomPtr(atom_index); | 3222 | const atom_ptr = self.getAtomPtr(atom_index); |
| 3224 | atom_ptr.size = new_atom_size; | 3223 | atom_ptr.size = new_atom_size; |
| 3225 | atom_ptr.alignment = @intCast(u32, alignment); | | |
| 3226 | } | 3224 | } |
| 3227 | | 3225 | |
| 3228 | if (atom.prev_index) |prev_index| { | 3226 | if (atom.prev_index) |prev_index| { |
| ... | @@ -4510,12 +4508,11 @@ pub fn logAtom(self: *MachO, atom_index: Atom.Index) void { | ... | @@ -4510,12 +4508,11 @@ pub fn logAtom(self: *MachO, atom_index: Atom.Index) void { |
| 4510 | const atom = self.getAtom(atom_index); | 4508 | const atom = self.getAtom(atom_index); |
| 4511 | const sym = atom.getSymbol(self); | 4509 | const sym = atom.getSymbol(self); |
| 4512 | const sym_name = atom.getName(self); | 4510 | const sym_name = atom.getName(self); |
| 4513 | log.debug(" ATOM(%{?d}, '{s}') @ {x} (sizeof({x}), alignof({x})) in object({?d}) in sect({d})", .{ | 4511 | log.debug(" ATOM(%{?d}, '{s}') @ {x} sizeof({x}) in object({?d}) in sect({d})", .{ |
| 4514 | atom.getSymbolIndex(), | 4512 | atom.getSymbolIndex(), |
| 4515 | sym_name, | 4513 | sym_name, |
| 4516 | sym.n_value, | 4514 | sym.n_value, |
| 4517 | atom.size, | 4515 | atom.size, |
| 4518 | atom.alignment, | | |
| 4519 | atom.file, | 4516 | atom.file, |
| 4520 | sym.n_sect, | 4517 | sym.n_sect, |
| 4521 | }); | 4518 | }); |