diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-08-24 20:43:43 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-09-21 14:48:40 -0700 |
| commit | accd5701c251c2741479fe08e56c8271c444f021 (patch) | |
| tree | 78871f150609687a9210063e90f8f4eb53997c38 /src/link/MachO/Object.zig | |
| parent | 0345d7866347c9066b0646f9e46be9a068dcfaa3 (diff) | |
| download | zig-accd5701c251c2741479fe08e56c8271c444f021.tar.gz zig-accd5701c251c2741479fe08e56c8271c444f021.zip | |
compiler: move struct types into InternPool proper
Structs were previously using `SegmentedList` to be given indexes, but
were not actually backed by the InternPool arrays.
After this, the only remaining uses of `SegmentedList` in the compiler
are `Module.Decl` and `Module.Namespace`. Once those last two are
migrated to become backed by InternPool arrays as well, we can introduce
state serialization via writing these arrays to disk all at once.
Unfortunately there are a lot of source code locations that touch the
struct type API, so this commit is still work-in-progress. Once I get it
compiling and passing the test suite, I can provide some interesting
data points such as how it affected the InternPool memory size and
performance comparison against master branch.
I also couldn't resist migrating over a bunch of alignment API over to
use the log2 Alignment type rather than a mismash of u32 and u64 byte
units with 0 meaning something implicitly different and special at every
location. Turns out you can do all the math you need directly on the
log2 representation of alignments.
Diffstat (limited to 'src/link/MachO/Object.zig')
| -rw-r--r-- | src/link/MachO/Object.zig | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/link/MachO/Object.zig b/src/link/MachO/Object.zig index ab12ede5d7..b0b87c8c34 100644 --- a/src/link/MachO/Object.zig +++ b/src/link/MachO/Object.zig @@ -382,7 +382,7 @@ pub fn splitRegularSections(self: *Object, macho_file: *MachO, object_id: u32) ! const out_sect_id = (try Atom.getOutputSection(macho_file, sect)) orelse continue; if (sect.size == 0) continue; - const sect_id = @as(u8, @intCast(id)); + const sect_id: u8 = @intCast(id); const sym_index = self.getSectionAliasSymbolIndex(sect_id); const atom_index = try self.createAtomFromSubsection( macho_file, @@ -391,7 +391,7 @@ pub fn splitRegularSections(self: *Object, macho_file: *MachO, object_id: u32) ! sym_index, 1, sect.size, - sect.@"align", + Alignment.fromLog2Units(sect.@"align"), out_sect_id, ); macho_file.addAtomToSection(atom_index); @@ -470,7 +470,7 @@ pub fn splitRegularSections(self: *Object, macho_file: *MachO, object_id: u32) ! sym_index, 1, atom_size, - sect.@"align", + Alignment.fromLog2Units(sect.@"align"), out_sect_id, ); if (!sect.isZerofill()) { @@ -494,10 +494,10 @@ pub fn splitRegularSections(self: *Object, macho_file: *MachO, object_id: u32) ! else sect.addr + sect.size - addr; - const atom_align = if (addr > 0) + const atom_align = Alignment.fromLog2Units(if (addr > 0) @min(@ctz(addr), sect.@"align") else - sect.@"align"; + sect.@"align"); const atom_index = try self.createAtomFromSubsection( macho_file, @@ -532,7 +532,7 @@ pub fn splitRegularSections(self: *Object, macho_file: *MachO, object_id: u32) ! sect_start_index, sect_loc.len, sect.size, - sect.@"align", + Alignment.fromLog2Units(sect.@"align"), out_sect_id, ); if (!sect.isZerofill()) { @@ -551,11 +551,14 @@ fn createAtomFromSubsection( inner_sym_index: u32, inner_nsyms_trailing: u32, size: u64, - alignment: u32, + alignment: Alignment, out_sect_id: u8, ) !Atom.Index { const gpa = macho_file.base.allocator; - const atom_index = try macho_file.createAtom(sym_index, .{ .size = size, .alignment = alignment }); + const atom_index = try macho_file.createAtom(sym_index, .{ + .size = size, + .alignment = alignment, + }); const atom = macho_file.getAtomPtr(atom_index); atom.inner_sym_index = inner_sym_index; atom.inner_nsyms_trailing = inner_nsyms_trailing; @@ -1115,3 +1118,4 @@ const MachO = @import("../MachO.zig"); const Platform = @import("load_commands.zig").Platform; const SymbolWithLoc = MachO.SymbolWithLoc; const UnwindInfo = @import("UnwindInfo.zig"); +const Alignment = Atom.Alignment; |
