macho+coff: remove alignment from Atom as it is unused

This commit is contained in:
Jakub Konka 2023-04-03 09:14:36 +02:00
parent a31450375e
commit ad8dfd3673
4 changed files with 19 additions and 32 deletions

View File

@ -155,6 +155,7 @@ const LazySymbolTable = std.ArrayHashMapUnmanaged(
const LazySymbolMetadata = struct {
atom: Atom.Index,
section: u16,
alignment: u32,
};
const DeclMetadata = struct {
@ -625,7 +626,6 @@ fn allocateAtom(self: *Coff, atom_index: Atom.Index, new_atom_size: u32, alignme
{
const atom_ptr = self.getAtomPtr(atom_index);
atom_ptr.size = new_atom_size;
atom_ptr.alignment = alignment;
}
if (atom.prev_index) |prev_index| {
@ -739,7 +739,6 @@ pub fn createAtom(self: *Coff) !Atom.Index {
.sym_index = sym_index,
.file = null,
.size = 0,
.alignment = 0,
.prev_index = null,
.next_index = null,
};
@ -751,11 +750,10 @@ fn createGotAtom(self: *Coff, target: SymbolWithLoc) !Atom.Index {
const atom_index = try self.createAtom();
const atom = self.getAtomPtr(atom_index);
atom.size = @sizeOf(u64);
atom.alignment = @alignOf(u64);
const sym = atom.getSymbolPtr(self);
sym.section_number = @intToEnum(coff.SectionNumber, self.got_section_index.? + 1);
sym.value = try self.allocateAtom(atom_index, atom.size, atom.alignment);
sym.value = try self.allocateAtom(atom_index, atom.size, @sizeOf(u64));
log.debug("allocated GOT atom at 0x{x}", .{sym.value});
@ -1116,9 +1114,8 @@ pub fn lowerUnnamedConst(self: *Coff, tv: TypedValue, decl_index: Module.Decl.In
const required_alignment = tv.ty.abiAlignment(self.base.options.target);
const atom = self.getAtomPtr(atom_index);
atom.alignment = required_alignment;
atom.size = @intCast(u32, code.len);
atom.getSymbolPtr(self).value = try self.allocateAtom(atom_index, atom.size, atom.alignment);
atom.getSymbolPtr(self).value = try self.allocateAtom(atom_index, atom.size, required_alignment);
errdefer self.freeAtom(atom_index);
try unnamed_consts.append(gpa, atom_index);
@ -1228,7 +1225,7 @@ fn updateLazySymbol(
},
};
const required_alignment = atom.alignment;
const required_alignment = lazy_metadata.alignment;
const code_len = @intCast(u32, code.len);
const symbol = atom.getSymbolPtr(self);
try self.setSymbolName(symbol, name);
@ -1271,8 +1268,8 @@ pub fn getOrCreateAtomForLazySymbol(
.code => self.text_section_index.?,
.const_data => self.rdata_section_index.?,
},
.alignment = alignment,
};
self.getAtomPtr(gop.value_ptr.atom).alignment = alignment;
}
return gop.value_ptr.atom;
}

View File

@ -19,12 +19,9 @@ sym_index: u32,
/// null means symbol defined by Zig source.
file: ?u32,
/// Used size of the atom
/// Size of the atom
size: u32,
/// Alignment of the atom
alignment: u32,
/// Points to the previous and next neighbors, based on the `text_offset`.
/// This can be used to find, for example, the capacity of this `Atom`.
prev_index: ?Index,

View File

@ -242,6 +242,7 @@ const LazySymbolTable = std.ArrayHashMapUnmanaged(
const LazySymbolMetadata = struct {
atom: Atom.Index,
section: u8,
alignment: u32,
};
const DeclMetadata = struct {
@ -1205,7 +1206,6 @@ pub fn createAtom(self: *MachO) !Atom.Index {
.sym_index = sym_index,
.file = null,
.size = 0,
.alignment = 0,
.prev_index = null,
.next_index = null,
};
@ -1217,7 +1217,6 @@ pub fn createGotAtom(self: *MachO, target: SymbolWithLoc) !Atom.Index {
const atom_index = try self.createAtom();
const atom = self.getAtomPtr(atom_index);
atom.size = @sizeOf(u64);
atom.alignment = @alignOf(u64);
const sym = atom.getSymbolPtr(self);
sym.n_type = macho.N_SECT;
@ -1259,7 +1258,6 @@ pub fn createDyldPrivateAtom(self: *MachO) !void {
const atom_index = try self.createAtom();
const atom = self.getAtomPtr(atom_index);
atom.size = @sizeOf(u64);
atom.alignment = @alignOf(u64);
const sym = atom.getSymbolPtr(self);
sym.n_type = macho.N_SECT;
@ -1285,7 +1283,8 @@ pub fn createStubHelperPreambleAtom(self: *MachO) !void {
const atom_index = try self.createAtom();
const atom = self.getAtomPtr(atom_index);
atom.size = size;
atom.alignment = switch (arch) {
const required_alignment: u32 = switch (arch) {
.x86_64 => 1,
.aarch64 => @alignOf(u32),
else => unreachable,
@ -1392,7 +1391,7 @@ pub fn createStubHelperPreambleAtom(self: *MachO) !void {
}
self.stub_helper_preamble_atom_index = atom_index;
sym.n_value = try self.allocateAtom(atom_index, size, atom.alignment);
sym.n_value = try self.allocateAtom(atom_index, size, required_alignment);
log.debug("allocated stub preamble atom at 0x{x}", .{sym.n_value});
try self.writeAtom(atom_index, code);
}
@ -1408,7 +1407,8 @@ pub fn createStubHelperAtom(self: *MachO) !Atom.Index {
const atom_index = try self.createAtom();
const atom = self.getAtomPtr(atom_index);
atom.size = size;
atom.alignment = switch (arch) {
const required_alignment: u32 = switch (arch) {
.x86_64 => 1,
.aarch64 => @alignOf(u32),
else => unreachable,
@ -1470,7 +1470,7 @@ pub fn createStubHelperAtom(self: *MachO) !Atom.Index {
else => unreachable,
}
sym.n_value = try self.allocateAtom(atom_index, size, atom.alignment);
sym.n_value = try self.allocateAtom(atom_index, size, required_alignment);
log.debug("allocated stub helper atom at 0x{x}", .{sym.n_value});
try self.writeAtom(atom_index, code);
@ -1481,7 +1481,6 @@ pub fn createLazyPointerAtom(self: *MachO, stub_sym_index: u32, target: SymbolWi
const atom_index = try self.createAtom();
const atom = self.getAtomPtr(atom_index);
atom.size = @sizeOf(u64);
atom.alignment = @alignOf(u64);
const sym = atom.getSymbolPtr(self);
sym.n_type = macho.N_SECT;
@ -1523,7 +1522,8 @@ pub fn createStubAtom(self: *MachO, laptr_sym_index: u32) !Atom.Index {
const atom_index = try self.createAtom();
const atom = self.getAtomPtr(atom_index);
atom.size = size;
atom.alignment = switch (arch) {
const required_alignment: u32 = switch (arch) {
.x86_64 => 1,
.aarch64 => @alignOf(u32),
else => unreachable, // unhandled architecture type
@ -1587,7 +1587,7 @@ pub fn createStubAtom(self: *MachO, laptr_sym_index: u32) !Atom.Index {
else => unreachable,
}
sym.n_value = try self.allocateAtom(atom_index, size, atom.alignment);
sym.n_value = try self.allocateAtom(atom_index, size, required_alignment);
log.debug("allocated stub atom at 0x{x}", .{sym.n_value});
try self.writeAtom(atom_index, code);
@ -2217,7 +2217,6 @@ pub fn lowerUnnamedConst(self: *MachO, typed_value: TypedValue, decl_index: Modu
const required_alignment = typed_value.ty.abiAlignment(self.base.options.target);
const atom = self.getAtomPtr(atom_index);
atom.size = code.len;
atom.alignment = required_alignment;
// TODO: work out logic for disambiguating functions from function pointers
// const sect_id = self.getDeclOutputSection(decl_index);
const sect_id = self.data_const_section_index.?;
@ -2355,7 +2354,7 @@ fn updateLazySymbol(self: *MachO, lazy_sym: File.LazySymbol, lazy_metadata: Lazy
},
};
const required_alignment = atom.alignment;
const required_alignment = lazy_metadata.alignment;
const symbol = atom.getSymbolPtr(self);
symbol.n_strx = name_str_index;
symbol.n_type = macho.N_SECT;
@ -2398,8 +2397,8 @@ pub fn getOrCreateAtomForLazySymbol(
.code => self.text_section_index.?,
.const_data => self.data_const_section_index.?,
},
.alignment = alignment,
};
self.getAtomPtr(gop.value_ptr.atom).alignment = alignment;
}
return gop.value_ptr.atom;
}
@ -3222,7 +3221,6 @@ fn allocateAtom(self: *MachO, atom_index: Atom.Index, new_atom_size: u64, alignm
{
const atom_ptr = self.getAtomPtr(atom_index);
atom_ptr.size = new_atom_size;
atom_ptr.alignment = @intCast(u32, alignment);
}
if (atom.prev_index) |prev_index| {
@ -4510,12 +4508,11 @@ pub fn logAtom(self: *MachO, atom_index: Atom.Index) void {
const atom = self.getAtom(atom_index);
const sym = atom.getSymbol(self);
const sym_name = atom.getName(self);
log.debug(" ATOM(%{?d}, '{s}') @ {x} (sizeof({x}), alignof({x})) in object({?d}) in sect({d})", .{
log.debug(" ATOM(%{?d}, '{s}') @ {x} sizeof({x}) in object({?d}) in sect({d})", .{
atom.getSymbolIndex(),
sym_name,
sym.n_value,
atom.size,
atom.alignment,
atom.file,
sym.n_sect,
});

View File

@ -33,10 +33,6 @@ file: ?u32,
/// the atom since macho.nlist_64 lacks this information.
size: u64,
/// Alignment of this atom as a power of 2.
/// For instance, alignment of 0 should be read as 2^0 = 1 byte aligned.
alignment: u32,
/// Points to the previous and next neighbours
/// TODO use the same trick as with symbols: reserve index 0 as null atom
next_index: ?Index,