mirror of
https://github.com/ziglang/zig.git
synced 2026-02-20 16:24:51 +00:00
macho+coff: remove alignment from Atom as it is unused
This commit is contained in:
parent
a31450375e
commit
ad8dfd3673
@ -155,6 +155,7 @@ const LazySymbolTable = std.ArrayHashMapUnmanaged(
|
|||||||
const LazySymbolMetadata = struct {
|
const LazySymbolMetadata = struct {
|
||||||
atom: Atom.Index,
|
atom: Atom.Index,
|
||||||
section: u16,
|
section: u16,
|
||||||
|
alignment: u32,
|
||||||
};
|
};
|
||||||
|
|
||||||
const DeclMetadata = struct {
|
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);
|
const atom_ptr = self.getAtomPtr(atom_index);
|
||||||
atom_ptr.size = new_atom_size;
|
atom_ptr.size = new_atom_size;
|
||||||
atom_ptr.alignment = alignment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (atom.prev_index) |prev_index| {
|
if (atom.prev_index) |prev_index| {
|
||||||
@ -739,7 +739,6 @@ pub fn createAtom(self: *Coff) !Atom.Index {
|
|||||||
.sym_index = sym_index,
|
.sym_index = sym_index,
|
||||||
.file = null,
|
.file = null,
|
||||||
.size = 0,
|
.size = 0,
|
||||||
.alignment = 0,
|
|
||||||
.prev_index = null,
|
.prev_index = null,
|
||||||
.next_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_index = try self.createAtom();
|
||||||
const atom = self.getAtomPtr(atom_index);
|
const atom = self.getAtomPtr(atom_index);
|
||||||
atom.size = @sizeOf(u64);
|
atom.size = @sizeOf(u64);
|
||||||
atom.alignment = @alignOf(u64);
|
|
||||||
|
|
||||||
const sym = atom.getSymbolPtr(self);
|
const sym = atom.getSymbolPtr(self);
|
||||||
sym.section_number = @intToEnum(coff.SectionNumber, self.got_section_index.? + 1);
|
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});
|
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 required_alignment = tv.ty.abiAlignment(self.base.options.target);
|
||||||
const atom = self.getAtomPtr(atom_index);
|
const atom = self.getAtomPtr(atom_index);
|
||||||
atom.alignment = required_alignment;
|
|
||||||
atom.size = @intCast(u32, code.len);
|
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);
|
errdefer self.freeAtom(atom_index);
|
||||||
|
|
||||||
try unnamed_consts.append(gpa, 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 code_len = @intCast(u32, code.len);
|
||||||
const symbol = atom.getSymbolPtr(self);
|
const symbol = atom.getSymbolPtr(self);
|
||||||
try self.setSymbolName(symbol, name);
|
try self.setSymbolName(symbol, name);
|
||||||
@ -1271,8 +1268,8 @@ pub fn getOrCreateAtomForLazySymbol(
|
|||||||
.code => self.text_section_index.?,
|
.code => self.text_section_index.?,
|
||||||
.const_data => self.rdata_section_index.?,
|
.const_data => self.rdata_section_index.?,
|
||||||
},
|
},
|
||||||
|
.alignment = alignment,
|
||||||
};
|
};
|
||||||
self.getAtomPtr(gop.value_ptr.atom).alignment = alignment;
|
|
||||||
}
|
}
|
||||||
return gop.value_ptr.atom;
|
return gop.value_ptr.atom;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,12 +19,9 @@ sym_index: u32,
|
|||||||
/// null means symbol defined by Zig source.
|
/// null means symbol defined by Zig source.
|
||||||
file: ?u32,
|
file: ?u32,
|
||||||
|
|
||||||
/// Used size of the atom
|
/// Size of the atom
|
||||||
size: u32,
|
size: u32,
|
||||||
|
|
||||||
/// Alignment of the atom
|
|
||||||
alignment: u32,
|
|
||||||
|
|
||||||
/// Points to the previous and next neighbors, based on the `text_offset`.
|
/// 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`.
|
/// This can be used to find, for example, the capacity of this `Atom`.
|
||||||
prev_index: ?Index,
|
prev_index: ?Index,
|
||||||
|
|||||||
@ -242,6 +242,7 @@ const LazySymbolTable = std.ArrayHashMapUnmanaged(
|
|||||||
const LazySymbolMetadata = struct {
|
const LazySymbolMetadata = struct {
|
||||||
atom: Atom.Index,
|
atom: Atom.Index,
|
||||||
section: u8,
|
section: u8,
|
||||||
|
alignment: u32,
|
||||||
};
|
};
|
||||||
|
|
||||||
const DeclMetadata = struct {
|
const DeclMetadata = struct {
|
||||||
@ -1205,7 +1206,6 @@ pub fn createAtom(self: *MachO) !Atom.Index {
|
|||||||
.sym_index = sym_index,
|
.sym_index = sym_index,
|
||||||
.file = null,
|
.file = null,
|
||||||
.size = 0,
|
.size = 0,
|
||||||
.alignment = 0,
|
|
||||||
.prev_index = null,
|
.prev_index = null,
|
||||||
.next_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_index = try self.createAtom();
|
||||||
const atom = self.getAtomPtr(atom_index);
|
const atom = self.getAtomPtr(atom_index);
|
||||||
atom.size = @sizeOf(u64);
|
atom.size = @sizeOf(u64);
|
||||||
atom.alignment = @alignOf(u64);
|
|
||||||
|
|
||||||
const sym = atom.getSymbolPtr(self);
|
const sym = atom.getSymbolPtr(self);
|
||||||
sym.n_type = macho.N_SECT;
|
sym.n_type = macho.N_SECT;
|
||||||
@ -1259,7 +1258,6 @@ pub fn createDyldPrivateAtom(self: *MachO) !void {
|
|||||||
const atom_index = try self.createAtom();
|
const atom_index = try self.createAtom();
|
||||||
const atom = self.getAtomPtr(atom_index);
|
const atom = self.getAtomPtr(atom_index);
|
||||||
atom.size = @sizeOf(u64);
|
atom.size = @sizeOf(u64);
|
||||||
atom.alignment = @alignOf(u64);
|
|
||||||
|
|
||||||
const sym = atom.getSymbolPtr(self);
|
const sym = atom.getSymbolPtr(self);
|
||||||
sym.n_type = macho.N_SECT;
|
sym.n_type = macho.N_SECT;
|
||||||
@ -1285,7 +1283,8 @@ pub fn createStubHelperPreambleAtom(self: *MachO) !void {
|
|||||||
const atom_index = try self.createAtom();
|
const atom_index = try self.createAtom();
|
||||||
const atom = self.getAtomPtr(atom_index);
|
const atom = self.getAtomPtr(atom_index);
|
||||||
atom.size = size;
|
atom.size = size;
|
||||||
atom.alignment = switch (arch) {
|
|
||||||
|
const required_alignment: u32 = switch (arch) {
|
||||||
.x86_64 => 1,
|
.x86_64 => 1,
|
||||||
.aarch64 => @alignOf(u32),
|
.aarch64 => @alignOf(u32),
|
||||||
else => unreachable,
|
else => unreachable,
|
||||||
@ -1392,7 +1391,7 @@ pub fn createStubHelperPreambleAtom(self: *MachO) !void {
|
|||||||
}
|
}
|
||||||
self.stub_helper_preamble_atom_index = atom_index;
|
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});
|
log.debug("allocated stub preamble atom at 0x{x}", .{sym.n_value});
|
||||||
try self.writeAtom(atom_index, code);
|
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_index = try self.createAtom();
|
||||||
const atom = self.getAtomPtr(atom_index);
|
const atom = self.getAtomPtr(atom_index);
|
||||||
atom.size = size;
|
atom.size = size;
|
||||||
atom.alignment = switch (arch) {
|
|
||||||
|
const required_alignment: u32 = switch (arch) {
|
||||||
.x86_64 => 1,
|
.x86_64 => 1,
|
||||||
.aarch64 => @alignOf(u32),
|
.aarch64 => @alignOf(u32),
|
||||||
else => unreachable,
|
else => unreachable,
|
||||||
@ -1470,7 +1470,7 @@ pub fn createStubHelperAtom(self: *MachO) !Atom.Index {
|
|||||||
else => unreachable,
|
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});
|
log.debug("allocated stub helper atom at 0x{x}", .{sym.n_value});
|
||||||
try self.writeAtom(atom_index, code);
|
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_index = try self.createAtom();
|
||||||
const atom = self.getAtomPtr(atom_index);
|
const atom = self.getAtomPtr(atom_index);
|
||||||
atom.size = @sizeOf(u64);
|
atom.size = @sizeOf(u64);
|
||||||
atom.alignment = @alignOf(u64);
|
|
||||||
|
|
||||||
const sym = atom.getSymbolPtr(self);
|
const sym = atom.getSymbolPtr(self);
|
||||||
sym.n_type = macho.N_SECT;
|
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_index = try self.createAtom();
|
||||||
const atom = self.getAtomPtr(atom_index);
|
const atom = self.getAtomPtr(atom_index);
|
||||||
atom.size = size;
|
atom.size = size;
|
||||||
atom.alignment = switch (arch) {
|
|
||||||
|
const required_alignment: u32 = switch (arch) {
|
||||||
.x86_64 => 1,
|
.x86_64 => 1,
|
||||||
.aarch64 => @alignOf(u32),
|
.aarch64 => @alignOf(u32),
|
||||||
else => unreachable, // unhandled architecture type
|
else => unreachable, // unhandled architecture type
|
||||||
@ -1587,7 +1587,7 @@ pub fn createStubAtom(self: *MachO, laptr_sym_index: u32) !Atom.Index {
|
|||||||
else => unreachable,
|
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});
|
log.debug("allocated stub atom at 0x{x}", .{sym.n_value});
|
||||||
try self.writeAtom(atom_index, code);
|
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 required_alignment = typed_value.ty.abiAlignment(self.base.options.target);
|
||||||
const atom = self.getAtomPtr(atom_index);
|
const atom = self.getAtomPtr(atom_index);
|
||||||
atom.size = code.len;
|
atom.size = code.len;
|
||||||
atom.alignment = required_alignment;
|
|
||||||
// TODO: work out logic for disambiguating functions from function pointers
|
// TODO: work out logic for disambiguating functions from function pointers
|
||||||
// const sect_id = self.getDeclOutputSection(decl_index);
|
// const sect_id = self.getDeclOutputSection(decl_index);
|
||||||
const sect_id = self.data_const_section_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);
|
const symbol = atom.getSymbolPtr(self);
|
||||||
symbol.n_strx = name_str_index;
|
symbol.n_strx = name_str_index;
|
||||||
symbol.n_type = macho.N_SECT;
|
symbol.n_type = macho.N_SECT;
|
||||||
@ -2398,8 +2397,8 @@ pub fn getOrCreateAtomForLazySymbol(
|
|||||||
.code => self.text_section_index.?,
|
.code => self.text_section_index.?,
|
||||||
.const_data => self.data_const_section_index.?,
|
.const_data => self.data_const_section_index.?,
|
||||||
},
|
},
|
||||||
|
.alignment = alignment,
|
||||||
};
|
};
|
||||||
self.getAtomPtr(gop.value_ptr.atom).alignment = alignment;
|
|
||||||
}
|
}
|
||||||
return gop.value_ptr.atom;
|
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);
|
const atom_ptr = self.getAtomPtr(atom_index);
|
||||||
atom_ptr.size = new_atom_size;
|
atom_ptr.size = new_atom_size;
|
||||||
atom_ptr.alignment = @intCast(u32, alignment);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (atom.prev_index) |prev_index| {
|
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 atom = self.getAtom(atom_index);
|
||||||
const sym = atom.getSymbol(self);
|
const sym = atom.getSymbol(self);
|
||||||
const sym_name = atom.getName(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(),
|
atom.getSymbolIndex(),
|
||||||
sym_name,
|
sym_name,
|
||||||
sym.n_value,
|
sym.n_value,
|
||||||
atom.size,
|
atom.size,
|
||||||
atom.alignment,
|
|
||||||
atom.file,
|
atom.file,
|
||||||
sym.n_sect,
|
sym.n_sect,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -33,10 +33,6 @@ file: ?u32,
|
|||||||
/// the atom since macho.nlist_64 lacks this information.
|
/// the atom since macho.nlist_64 lacks this information.
|
||||||
size: u64,
|
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
|
/// Points to the previous and next neighbours
|
||||||
/// TODO use the same trick as with symbols: reserve index 0 as null atom
|
/// TODO use the same trick as with symbols: reserve index 0 as null atom
|
||||||
next_index: ?Index,
|
next_index: ?Index,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user