diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2023-04-29 19:31:34 -0400 |
|---|---|---|
| committer | Jacob Young <jacobly0@users.noreply.github.com> | 2023-05-01 19:22:52 -0400 |
| commit | f37ca3fa7370c501c630c53b370fecdeb313e3be (patch) | |
| tree | 5025974bf1873d55e6281a15f31fae016a15a922 /src/link | |
| parent | 10a4c2269d110d636e7817677fb50c6f418bff34 (diff) | |
| download | zig-f37ca3fa7370c501c630c53b370fecdeb313e3be.tar.gz zig-f37ca3fa7370c501c630c53b370fecdeb313e3be.zip | |
link: cleanup lazy alignment
This gets the alignment from the code that creates a lazy symbol instead
of guessing it at every use.
Diffstat (limited to 'src/link')
| -rw-r--r-- | src/link/Coff.zig | 18 | ||||
| -rw-r--r-- | src/link/Elf.zig | 12 | ||||
| -rw-r--r-- | src/link/MachO.zig | 14 |
3 files changed, 14 insertions, 30 deletions
diff --git a/src/link/Coff.zig b/src/link/Coff.zig index 0af681bb5e..d20d17f2b1 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -145,7 +145,6 @@ const LazySymbolTable = std.AutoArrayHashMapUnmanaged(Module.Decl.OptionalIndex, const LazySymbolMetadata = struct { text_atom: ?Atom.Index = null, rdata_atom: ?Atom.Index = null, - alignment: u32, }; const DeclMetadata = struct { @@ -1195,13 +1194,11 @@ fn updateLazySymbol(self: *Coff, decl: Module.Decl.OptionalIndex, metadata: Lazy link.File.LazySymbol.initDecl(.code, decl, mod), atom, self.text_section_index.?, - metadata.alignment, ); if (metadata.rdata_atom) |atom| try self.updateLazySymbolAtom( link.File.LazySymbol.initDecl(.const_data, decl, mod), atom, self.rdata_section_index.?, - metadata.alignment, ); } @@ -1210,7 +1207,6 @@ fn updateLazySymbolAtom( sym: link.File.LazySymbol, atom_index: Atom.Index, section_index: u16, - required_alignment: u32, ) !void { const gpa = self.base.allocator; const mod = self.base.options.module.?; @@ -1238,7 +1234,7 @@ fn updateLazySymbolAtom( const res = try codegen.generateLazySymbol(&self.base, src, sym, &code_buffer, .none, .{ .parent_atom_index = local_sym_index, }); - const code = switch (res) { + const code = switch (res.res) { .ok => code_buffer.items, .fail => |em| { log.err("{s}", .{em.msg}); @@ -1252,11 +1248,11 @@ fn updateLazySymbolAtom( symbol.section_number = @intToEnum(coff.SectionNumber, section_index + 1); symbol.type = .{ .complex_type = .NULL, .base_type = .NULL }; - const vaddr = try self.allocateAtom(atom_index, code_len, required_alignment); + const vaddr = try self.allocateAtom(atom_index, code_len, res.alignment); errdefer self.freeAtom(atom_index); log.debug("allocated atom for {s} at 0x{x}", .{ name, vaddr }); - log.debug(" (required alignment 0x{x})", .{required_alignment}); + log.debug(" (required alignment 0x{x})", .{res.alignment}); atom.size = code_len; symbol.value = vaddr; @@ -1265,14 +1261,10 @@ fn updateLazySymbolAtom( try self.writeAtom(atom_index, code); } -pub fn getOrCreateAtomForLazySymbol( - self: *Coff, - sym: link.File.LazySymbol, - alignment: u32, -) !Atom.Index { +pub fn getOrCreateAtomForLazySymbol(self: *Coff, sym: link.File.LazySymbol) !Atom.Index { const gop = try self.lazy_syms.getOrPut(self.base.allocator, sym.getDecl()); errdefer _ = self.lazy_syms.pop(); - if (!gop.found_existing) gop.value_ptr.* = .{ .alignment = alignment }; + if (!gop.found_existing) gop.value_ptr.* = .{}; const atom = switch (sym.kind) { .code => &gop.value_ptr.text_atom, .const_data => &gop.value_ptr.rdata_atom, diff --git a/src/link/Elf.zig b/src/link/Elf.zig index 48d952b6cc..b9c113f834 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -67,7 +67,6 @@ const Section = struct { const LazySymbolMetadata = struct { text_atom: ?Atom.Index = null, rodata_atom: ?Atom.Index = null, - alignment: u32, }; const DeclMetadata = struct { @@ -2377,10 +2376,10 @@ pub fn freeDecl(self: *Elf, decl_index: Module.Decl.Index) void { } } -pub fn getOrCreateAtomForLazySymbol(self: *Elf, sym: File.LazySymbol, alignment: u32) !Atom.Index { +pub fn getOrCreateAtomForLazySymbol(self: *Elf, sym: File.LazySymbol) !Atom.Index { const gop = try self.lazy_syms.getOrPut(self.base.allocator, sym.getDecl()); errdefer _ = self.lazy_syms.pop(); - if (!gop.found_existing) gop.value_ptr.* = .{ .alignment = alignment }; + if (!gop.found_existing) gop.value_ptr.* = .{}; const atom = switch (sym.kind) { .code => &gop.value_ptr.text_atom, .const_data => &gop.value_ptr.rodata_atom, @@ -2663,13 +2662,11 @@ fn updateLazySymbol(self: *Elf, decl: Module.Decl.OptionalIndex, metadata: LazyS File.LazySymbol.initDecl(.code, decl, mod), atom, self.text_section_index.?, - metadata.alignment, ); if (metadata.rodata_atom) |atom| try self.updateLazySymbolAtom( File.LazySymbol.initDecl(.const_data, decl, mod), atom, self.rodata_section_index.?, - metadata.alignment, ); } @@ -2678,7 +2675,6 @@ fn updateLazySymbolAtom( sym: File.LazySymbol, atom_index: Atom.Index, shdr_index: u16, - required_alignment: u32, ) !void { const gpa = self.base.allocator; const mod = self.base.options.module.?; @@ -2710,7 +2706,7 @@ fn updateLazySymbolAtom( const res = try codegen.generateLazySymbol(&self.base, src, sym, &code_buffer, .none, .{ .parent_atom_index = local_sym_index, }); - const code = switch (res) { + const code = switch (res.res) { .ok => code_buffer.items, .fail => |em| { log.err("{s}", .{em.msg}); @@ -2728,7 +2724,7 @@ fn updateLazySymbolAtom( .st_value = 0, .st_size = 0, }; - const vaddr = try self.allocateAtom(atom_index, code.len, required_alignment); + const vaddr = try self.allocateAtom(atom_index, code.len, res.alignment); errdefer self.freeAtom(atom_index); log.debug("allocated text block for {s} at 0x{x}", .{ name, vaddr }); diff --git a/src/link/MachO.zig b/src/link/MachO.zig index 21633dea64..a57742507d 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -238,7 +238,6 @@ const LazySymbolTable = std.AutoArrayHashMapUnmanaged(Module.Decl.OptionalIndex, const LazySymbolMetadata = struct { text_atom: ?Atom.Index = null, data_const_atom: ?Atom.Index = null, - alignment: u32, }; const TlvSymbolTable = std.AutoArrayHashMapUnmanaged(SymbolWithLoc, Atom.Index); @@ -2043,13 +2042,11 @@ fn updateLazySymbol(self: *MachO, decl: Module.Decl.OptionalIndex, metadata: Laz File.LazySymbol.initDecl(.code, decl, mod), atom, self.text_section_index.?, - metadata.alignment, ); if (metadata.data_const_atom) |atom| try self.updateLazySymbolAtom( File.LazySymbol.initDecl(.const_data, decl, mod), atom, self.data_const_section_index.?, - metadata.alignment, ); } @@ -2058,7 +2055,6 @@ fn updateLazySymbolAtom( sym: File.LazySymbol, atom_index: Atom.Index, section_index: u8, - required_alignment: u32, ) !void { const gpa = self.base.allocator; const mod = self.base.options.module.?; @@ -2090,7 +2086,7 @@ fn updateLazySymbolAtom( const res = try codegen.generateLazySymbol(&self.base, src, sym, &code_buffer, .none, .{ .parent_atom_index = local_sym_index, }); - const code = switch (res) { + const code = switch (res.res) { .ok => code_buffer.items, .fail => |em| { log.err("{s}", .{em.msg}); @@ -2104,11 +2100,11 @@ fn updateLazySymbolAtom( symbol.n_sect = section_index + 1; symbol.n_desc = 0; - const vaddr = try self.allocateAtom(atom_index, code.len, required_alignment); + const vaddr = try self.allocateAtom(atom_index, code.len, res.alignment); errdefer self.freeAtom(atom_index); log.debug("allocated atom for {s} at 0x{x}", .{ name, vaddr }); - log.debug(" (required alignment 0x{x}", .{required_alignment}); + log.debug(" (required alignment 0x{x}", .{res.alignment}); atom.size = code.len; symbol.n_value = vaddr; @@ -2117,10 +2113,10 @@ fn updateLazySymbolAtom( try self.writeAtom(atom_index, code); } -pub fn getOrCreateAtomForLazySymbol(self: *MachO, sym: File.LazySymbol, alignment: u32) !Atom.Index { +pub fn getOrCreateAtomForLazySymbol(self: *MachO, sym: File.LazySymbol) !Atom.Index { const gop = try self.lazy_syms.getOrPut(self.base.allocator, sym.getDecl()); errdefer _ = self.lazy_syms.pop(); - if (!gop.found_existing) gop.value_ptr.* = .{ .alignment = alignment }; + if (!gop.found_existing) gop.value_ptr.* = .{}; const atom = switch (sym.kind) { .code => &gop.value_ptr.text_atom, .const_data => &gop.value_ptr.data_const_atom, |
