authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-04-03 09:14:36+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-04-03 09:14:36+02:00
logad8dfd367384a104f588bdc393cabae90c47c82f
tree60d59eb9fe9c81d91a1edaa3eef94b77293656ba
parenta31450375eaadfead340c28c32dd414160a99e65

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


4 files changed, 19 insertions(+), 32 deletions(-)

src/link/Coff.zig+5-8
......@@ -155,6 +155,7 @@ const LazySymbolTable = std.ArrayHashMapUnmanaged(
155155const LazySymbolMetadata = struct {
156156 atom: Atom.Index,
157157 section: u16,
158 alignment: u32,
158159};
159160
160161const DeclMetadata = struct {
......@@ -625,7 +626,6 @@ fn allocateAtom(self: *Coff, atom_index: Atom.Index, new_atom_size: u32, alignme
625626 {
626627 const atom_ptr = self.getAtomPtr(atom_index);
627628 atom_ptr.size = new_atom_size;
628 atom_ptr.alignment = alignment;
629629 }
630630
631631 if (atom.prev_index) |prev_index| {
......@@ -739,7 +739,6 @@ pub fn createAtom(self: *Coff) !Atom.Index {
739739 .sym_index = sym_index,
740740 .file = null,
741741 .size = 0,
742 .alignment = 0,
743742 .prev_index = null,
744743 .next_index = null,
745744 };
......@@ -751,11 +750,10 @@ fn createGotAtom(self: *Coff, target: SymbolWithLoc) !Atom.Index {
751750 const atom_index = try self.createAtom();
752751 const atom = self.getAtomPtr(atom_index);
753752 atom.size = @sizeOf(u64);
754 atom.alignment = @alignOf(u64);
755753
756754 const sym = atom.getSymbolPtr(self);
757755 sym.section_number = @intToEnum(coff.SectionNumber, self.got_section_index.? + 1);
758 sym.value = try self.allocateAtom(atom_index, atom.size, atom.alignment);
756 sym.value = try self.allocateAtom(atom_index, atom.size, @sizeOf(u64));
759757
760758 log.debug("allocated GOT atom at 0x{x}", .{sym.value});
761759
......@@ -1116,9 +1114,8 @@ pub fn lowerUnnamedConst(self: *Coff, tv: TypedValue, decl_index: Module.Decl.In
11161114
11171115 const required_alignment = tv.ty.abiAlignment(self.base.options.target);
11181116 const atom = self.getAtomPtr(atom_index);
1119 atom.alignment = required_alignment;
11201117 atom.size = @intCast(u32, code.len);
1121 atom.getSymbolPtr(self).value = try self.allocateAtom(atom_index, atom.size, atom.alignment);
1118 atom.getSymbolPtr(self).value = try self.allocateAtom(atom_index, atom.size, required_alignment);
11221119 errdefer self.freeAtom(atom_index);
11231120
11241121 try unnamed_consts.append(gpa, atom_index);
......@@ -1228,7 +1225,7 @@ fn updateLazySymbol(
12281225 },
12291226 };
12301227
1231 const required_alignment = atom.alignment;
1228 const required_alignment = lazy_metadata.alignment;
12321229 const code_len = @intCast(u32, code.len);
12331230 const symbol = atom.getSymbolPtr(self);
12341231 try self.setSymbolName(symbol, name);
......@@ -1271,8 +1268,8 @@ pub fn getOrCreateAtomForLazySymbol(
12711268 .code => self.text_section_index.?,
12721269 .const_data => self.rdata_section_index.?,
12731270 },
1271 .alignment = alignment,
12741272 };
1275 self.getAtomPtr(gop.value_ptr.atom).alignment = alignment;
12761273 }
12771274 return gop.value_ptr.atom;
12781275}
src/link/Coff/Atom.zig+1-4
......@@ -19,12 +19,9 @@ sym_index: u32,
1919/// null means symbol defined by Zig source.
2020file: ?u32,
2121
22/// Used size of the atom
22/// Size of the atom
2323size: u32,
2424
25/// Alignment of the atom
26alignment: u32,
27
2825/// Points to the previous and next neighbors, based on the `text_offset`.
2926/// This can be used to find, for example, the capacity of this `Atom`.
3027prev_index: ?Index,
src/link/MachO.zig+13-16
......@@ -242,6 +242,7 @@ const LazySymbolTable = std.ArrayHashMapUnmanaged(
242242const LazySymbolMetadata = struct {
243243 atom: Atom.Index,
244244 section: u8,
245 alignment: u32,
245246};
246247
247248const DeclMetadata = struct {
......@@ -1205,7 +1206,6 @@ pub fn createAtom(self: *MachO) !Atom.Index {
12051206 .sym_index = sym_index,
12061207 .file = null,
12071208 .size = 0,
1208 .alignment = 0,
12091209 .prev_index = null,
12101210 .next_index = null,
12111211 };
......@@ -1217,7 +1217,6 @@ pub fn createGotAtom(self: *MachO, target: SymbolWithLoc) !Atom.Index {
12171217 const atom_index = try self.createAtom();
12181218 const atom = self.getAtomPtr(atom_index);
12191219 atom.size = @sizeOf(u64);
1220 atom.alignment = @alignOf(u64);
12211220
12221221 const sym = atom.getSymbolPtr(self);
12231222 sym.n_type = macho.N_SECT;
......@@ -1259,7 +1258,6 @@ pub fn createDyldPrivateAtom(self: *MachO) !void {
12591258 const atom_index = try self.createAtom();
12601259 const atom = self.getAtomPtr(atom_index);
12611260 atom.size = @sizeOf(u64);
1262 atom.alignment = @alignOf(u64);
12631261
12641262 const sym = atom.getSymbolPtr(self);
12651263 sym.n_type = macho.N_SECT;
......@@ -1285,7 +1283,8 @@ pub fn createStubHelperPreambleAtom(self: *MachO) !void {
12851283 const atom_index = try self.createAtom();
12861284 const atom = self.getAtomPtr(atom_index);
12871285 atom.size = size;
1288 atom.alignment = switch (arch) {
1286
1287 const required_alignment: u32 = switch (arch) {
12891288 .x86_64 => 1,
12901289 .aarch64 => @alignOf(u32),
12911290 else => unreachable,
......@@ -1392,7 +1391,7 @@ pub fn createStubHelperPreambleAtom(self: *MachO) !void {
13921391 }
13931392 self.stub_helper_preamble_atom_index = atom_index;
13941393
1395 sym.n_value = try self.allocateAtom(atom_index, size, atom.alignment);
1394 sym.n_value = try self.allocateAtom(atom_index, size, required_alignment);
13961395 log.debug("allocated stub preamble atom at 0x{x}", .{sym.n_value});
13971396 try self.writeAtom(atom_index, code);
13981397}
......@@ -1408,7 +1407,8 @@ pub fn createStubHelperAtom(self: *MachO) !Atom.Index {
14081407 const atom_index = try self.createAtom();
14091408 const atom = self.getAtomPtr(atom_index);
14101409 atom.size = size;
1411 atom.alignment = switch (arch) {
1410
1411 const required_alignment: u32 = switch (arch) {
14121412 .x86_64 => 1,
14131413 .aarch64 => @alignOf(u32),
14141414 else => unreachable,
......@@ -1470,7 +1470,7 @@ pub fn createStubHelperAtom(self: *MachO) !Atom.Index {
14701470 else => unreachable,
14711471 }
14721472
1473 sym.n_value = try self.allocateAtom(atom_index, size, atom.alignment);
1473 sym.n_value = try self.allocateAtom(atom_index, size, required_alignment);
14741474 log.debug("allocated stub helper atom at 0x{x}", .{sym.n_value});
14751475 try self.writeAtom(atom_index, code);
14761476
......@@ -1481,7 +1481,6 @@ pub fn createLazyPointerAtom(self: *MachO, stub_sym_index: u32, target: SymbolWi
14811481 const atom_index = try self.createAtom();
14821482 const atom = self.getAtomPtr(atom_index);
14831483 atom.size = @sizeOf(u64);
1484 atom.alignment = @alignOf(u64);
14851484
14861485 const sym = atom.getSymbolPtr(self);
14871486 sym.n_type = macho.N_SECT;
......@@ -1523,7 +1522,8 @@ pub fn createStubAtom(self: *MachO, laptr_sym_index: u32) !Atom.Index {
15231522 const atom_index = try self.createAtom();
15241523 const atom = self.getAtomPtr(atom_index);
15251524 atom.size = size;
1526 atom.alignment = switch (arch) {
1525
1526 const required_alignment: u32 = switch (arch) {
15271527 .x86_64 => 1,
15281528 .aarch64 => @alignOf(u32),
15291529 else => unreachable, // unhandled architecture type
......@@ -1587,7 +1587,7 @@ pub fn createStubAtom(self: *MachO, laptr_sym_index: u32) !Atom.Index {
15871587 else => unreachable,
15881588 }
15891589
1590 sym.n_value = try self.allocateAtom(atom_index, size, atom.alignment);
1590 sym.n_value = try self.allocateAtom(atom_index, size, required_alignment);
15911591 log.debug("allocated stub atom at 0x{x}", .{sym.n_value});
15921592 try self.writeAtom(atom_index, code);
15931593
......@@ -2217,7 +2217,6 @@ pub fn lowerUnnamedConst(self: *MachO, typed_value: TypedValue, decl_index: Modu
22172217 const required_alignment = typed_value.ty.abiAlignment(self.base.options.target);
22182218 const atom = self.getAtomPtr(atom_index);
22192219 atom.size = code.len;
2220 atom.alignment = required_alignment;
22212220 // TODO: work out logic for disambiguating functions from function pointers
22222221 // const sect_id = self.getDeclOutputSection(decl_index);
22232222 const sect_id = self.data_const_section_index.?;
......@@ -2355,7 +2354,7 @@ fn updateLazySymbol(self: *MachO, lazy_sym: File.LazySymbol, lazy_metadata: Lazy
23552354 },
23562355 };
23572356
2358 const required_alignment = atom.alignment;
2357 const required_alignment = lazy_metadata.alignment;
23592358 const symbol = atom.getSymbolPtr(self);
23602359 symbol.n_strx = name_str_index;
23612360 symbol.n_type = macho.N_SECT;
......@@ -2398,8 +2397,8 @@ pub fn getOrCreateAtomForLazySymbol(
23982397 .code => self.text_section_index.?,
23992398 .const_data => self.data_const_section_index.?,
24002399 },
2400 .alignment = alignment,
24012401 };
2402 self.getAtomPtr(gop.value_ptr.atom).alignment = alignment;
24032402 }
24042403 return gop.value_ptr.atom;
24052404}
......@@ -3222,7 +3221,6 @@ fn allocateAtom(self: *MachO, atom_index: Atom.Index, new_atom_size: u64, alignm
32223221 {
32233222 const atom_ptr = self.getAtomPtr(atom_index);
32243223 atom_ptr.size = new_atom_size;
3225 atom_ptr.alignment = @intCast(u32, alignment);
32263224 }
32273225
32283226 if (atom.prev_index) |prev_index| {
......@@ -4510,12 +4508,11 @@ pub fn logAtom(self: *MachO, atom_index: Atom.Index) void {
45104508 const atom = self.getAtom(atom_index);
45114509 const sym = atom.getSymbol(self);
45124510 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})", .{
45144512 atom.getSymbolIndex(),
45154513 sym_name,
45164514 sym.n_value,
45174515 atom.size,
4518 atom.alignment,
45194516 atom.file,
45204517 sym.n_sect,
45214518 });
src/link/MachO/Atom.zig-4
......@@ -33,10 +33,6 @@ file: ?u32,
3333/// the atom since macho.nlist_64 lacks this information.
3434size: u64,
3535
36/// Alignment of this atom as a power of 2.
37/// For instance, alignment of 0 should be read as 2^0 = 1 byte aligned.
38alignment: u32,
39
4036/// Points to the previous and next neighbours
4137/// TODO use the same trick as with symbols: reserve index 0 as null atom
4238next_index: ?Index,