| author | |
| committer | |
| log | d41111d7ef531f6f55a19c56205d6d2f1134c224 |
| tree | 14d7b7764a64fa2d4d274c0726a1a587484c4999 |
| parent | 5baa05664e6dac0f473c8411f6e9d8e0f62555a9 |
Anecdote 1: The generic version is way more popular than the non-generic
one in Zig codebase:
git grep -w alignForward | wc -l
56
git grep -w alignForwardGeneric | wc -l
149
git grep -w alignBackward | wc -l
6
git grep -w alignBackwardGeneric | wc -l
15
Anecdote 2: In my project (turbonss) that does much arithmetic and
alignment I exclusively use the Generic functions.
Anecdote 3: we used only the Generic versions in the Macho Man's linker
workshop.39 files changed, 223 insertions(+), 232 deletions(-)
lib/std/Thread.zig+4-4| ... | @@ -931,18 +931,18 @@ const LinuxThreadImpl = struct { | ... | @@ -931,18 +931,18 @@ const LinuxThreadImpl = struct { |
| 931 | guard_offset = bytes; | 931 | guard_offset = bytes; |
| 932 | 932 | ||
| 933 | bytes += @max(page_size, config.stack_size); | 933 | bytes += @max(page_size, config.stack_size); |
| 934 | bytes = std.mem.alignForward(bytes, page_size); | 934 | bytes = std.mem.alignForward(usize, bytes, page_size); |
| 935 | stack_offset = bytes; | 935 | stack_offset = bytes; |
| 936 | 936 | ||
| 937 | bytes = std.mem.alignForward(bytes, linux.tls.tls_image.alloc_align); | 937 | bytes = std.mem.alignForward(usize, bytes, linux.tls.tls_image.alloc_align); |
| 938 | tls_offset = bytes; | 938 | tls_offset = bytes; |
| 939 | bytes += linux.tls.tls_image.alloc_size; | 939 | bytes += linux.tls.tls_image.alloc_size; |
| 940 | 940 | ||
| 941 | bytes = std.mem.alignForward(bytes, @alignOf(Instance)); | 941 | bytes = std.mem.alignForward(usize, bytes, @alignOf(Instance)); |
| 942 | instance_offset = bytes; | 942 | instance_offset = bytes; |
| 943 | bytes += @sizeOf(Instance); | 943 | bytes += @sizeOf(Instance); |
| 944 | 944 | ||
| 945 | bytes = std.mem.alignForward(bytes, page_size); | 945 | bytes = std.mem.alignForward(usize, bytes, page_size); |
| 946 | break :blk bytes; | 946 | break :blk bytes; |
| 947 | }; | 947 | }; |
| 948 | 948 |
lib/std/dynamic_library.zig+2-2| ... | @@ -124,7 +124,7 @@ pub const ElfDynLib = struct { | ... | @@ -124,7 +124,7 @@ pub const ElfDynLib = struct { |
| 124 | // corresponding to the actual LOAD sections. | 124 | // corresponding to the actual LOAD sections. |
| 125 | const file_bytes = try os.mmap( | 125 | const file_bytes = try os.mmap( |
| 126 | null, | 126 | null, |
| 127 | mem.alignForward(size, mem.page_size), | 127 | mem.alignForward(usize, size, mem.page_size), |
| 128 | os.PROT.READ, | 128 | os.PROT.READ, |
| 129 | os.MAP.PRIVATE, | 129 | os.MAP.PRIVATE, |
| 130 | fd, | 130 | fd, |
| ... | @@ -187,7 +187,7 @@ pub const ElfDynLib = struct { | ... | @@ -187,7 +187,7 @@ pub const ElfDynLib = struct { |
| 187 | // extra nonsense mapped before/after the VirtAddr,MemSiz | 187 | // extra nonsense mapped before/after the VirtAddr,MemSiz |
| 188 | const aligned_addr = (base + ph.p_vaddr) & ~(@as(usize, mem.page_size) - 1); | 188 | const aligned_addr = (base + ph.p_vaddr) & ~(@as(usize, mem.page_size) - 1); |
| 189 | const extra_bytes = (base + ph.p_vaddr) - aligned_addr; | 189 | const extra_bytes = (base + ph.p_vaddr) - aligned_addr; |
| 190 | const extended_memsz = mem.alignForward(ph.p_memsz + extra_bytes, mem.page_size); | 190 | const extended_memsz = mem.alignForward(usize, ph.p_memsz + extra_bytes, mem.page_size); |
| 191 | const ptr = @intToPtr([*]align(mem.page_size) u8, aligned_addr); | 191 | const ptr = @intToPtr([*]align(mem.page_size) u8, aligned_addr); |
| 192 | const prot = elfToMmapProt(ph.p_flags); | 192 | const prot = elfToMmapProt(ph.p_flags); |
| 193 | if ((ph.p_flags & elf.PF_W) == 0) { | 193 | if ((ph.p_flags & elf.PF_W) == 0) { |
lib/std/hash_map.zig+6-6| ... | @@ -1545,13 +1545,13 @@ pub fn HashMapUnmanaged( | ... | @@ -1545,13 +1545,13 @@ pub fn HashMapUnmanaged( |
| 1545 | const meta_size = @sizeOf(Header) + new_capacity * @sizeOf(Metadata); | 1545 | const meta_size = @sizeOf(Header) + new_capacity * @sizeOf(Metadata); |
| 1546 | comptime assert(@alignOf(Metadata) == 1); | 1546 | comptime assert(@alignOf(Metadata) == 1); |
| 1547 | 1547 | ||
| 1548 | const keys_start = std.mem.alignForward(meta_size, key_align); | 1548 | const keys_start = std.mem.alignForward(usize, meta_size, key_align); |
| 1549 | const keys_end = keys_start + new_capacity * @sizeOf(K); | 1549 | const keys_end = keys_start + new_capacity * @sizeOf(K); |
| 1550 | 1550 | ||
| 1551 | const vals_start = std.mem.alignForward(keys_end, val_align); | 1551 | const vals_start = std.mem.alignForward(usize, keys_end, val_align); |
| 1552 | const vals_end = vals_start + new_capacity * @sizeOf(V); | 1552 | const vals_end = vals_start + new_capacity * @sizeOf(V); |
| 1553 | 1553 | ||
| 1554 | const total_size = std.mem.alignForward(vals_end, max_align); | 1554 | const total_size = std.mem.alignForward(usize, vals_end, max_align); |
| 1555 | 1555 | ||
| 1556 | const slice = try allocator.alignedAlloc(u8, max_align, total_size); | 1556 | const slice = try allocator.alignedAlloc(u8, max_align, total_size); |
| 1557 | const ptr = @ptrToInt(slice.ptr); | 1557 | const ptr = @ptrToInt(slice.ptr); |
| ... | @@ -1581,13 +1581,13 @@ pub fn HashMapUnmanaged( | ... | @@ -1581,13 +1581,13 @@ pub fn HashMapUnmanaged( |
| 1581 | const meta_size = @sizeOf(Header) + cap * @sizeOf(Metadata); | 1581 | const meta_size = @sizeOf(Header) + cap * @sizeOf(Metadata); |
| 1582 | comptime assert(@alignOf(Metadata) == 1); | 1582 | comptime assert(@alignOf(Metadata) == 1); |
| 1583 | 1583 | ||
| 1584 | const keys_start = std.mem.alignForward(meta_size, key_align); | 1584 | const keys_start = std.mem.alignForward(usize, meta_size, key_align); |
| 1585 | const keys_end = keys_start + cap * @sizeOf(K); | 1585 | const keys_end = keys_start + cap * @sizeOf(K); |
| 1586 | 1586 | ||
| 1587 | const vals_start = std.mem.alignForward(keys_end, val_align); | 1587 | const vals_start = std.mem.alignForward(usize, keys_end, val_align); |
| 1588 | const vals_end = vals_start + cap * @sizeOf(V); | 1588 | const vals_end = vals_start + cap * @sizeOf(V); |
| 1589 | 1589 | ||
| 1590 | const total_size = std.mem.alignForward(vals_end, max_align); | 1590 | const total_size = std.mem.alignForward(usize, vals_end, max_align); |
| 1591 | 1591 | ||
| 1592 | const slice = @intToPtr([*]align(max_align) u8, @ptrToInt(self.header()))[0..total_size]; | 1592 | const slice = @intToPtr([*]align(max_align) u8, @ptrToInt(self.header()))[0..total_size]; |
| 1593 | allocator.free(slice); | 1593 | allocator.free(slice); |
lib/std/heap.zig+4-4| ... | @@ -83,7 +83,7 @@ const CAllocator = struct { | ... | @@ -83,7 +83,7 @@ const CAllocator = struct { |
| 83 | // the aligned address. | 83 | // the aligned address. |
| 84 | var unaligned_ptr = @ptrCast([*]u8, c.malloc(len + alignment - 1 + @sizeOf(usize)) orelse return null); | 84 | var unaligned_ptr = @ptrCast([*]u8, c.malloc(len + alignment - 1 + @sizeOf(usize)) orelse return null); |
| 85 | const unaligned_addr = @ptrToInt(unaligned_ptr); | 85 | const unaligned_addr = @ptrToInt(unaligned_ptr); |
| 86 | const aligned_addr = mem.alignForward(unaligned_addr + @sizeOf(usize), alignment); | 86 | const aligned_addr = mem.alignForward(usize, unaligned_addr + @sizeOf(usize), alignment); |
| 87 | var aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr); | 87 | var aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr); |
| 88 | getHeader(aligned_ptr).* = unaligned_ptr; | 88 | getHeader(aligned_ptr).* = unaligned_ptr; |
| 89 | 89 | ||
| ... | @@ -249,7 +249,7 @@ pub const wasm_allocator = Allocator{ | ... | @@ -249,7 +249,7 @@ pub const wasm_allocator = Allocator{ |
| 249 | /// Verifies that the adjusted length will still map to the full length | 249 | /// Verifies that the adjusted length will still map to the full length |
| 250 | pub fn alignPageAllocLen(full_len: usize, len: usize) usize { | 250 | pub fn alignPageAllocLen(full_len: usize, len: usize) usize { |
| 251 | const aligned_len = mem.alignAllocLen(full_len, len); | 251 | const aligned_len = mem.alignAllocLen(full_len, len); |
| 252 | assert(mem.alignForward(aligned_len, mem.page_size) == full_len); | 252 | assert(mem.alignForward(usize, aligned_len, mem.page_size) == full_len); |
| 253 | return aligned_len; | 253 | return aligned_len; |
| 254 | } | 254 | } |
| 255 | 255 | ||
| ... | @@ -307,7 +307,7 @@ pub const HeapAllocator = switch (builtin.os.tag) { | ... | @@ -307,7 +307,7 @@ pub const HeapAllocator = switch (builtin.os.tag) { |
| 307 | }; | 307 | }; |
| 308 | const ptr = os.windows.kernel32.HeapAlloc(heap_handle, 0, amt) orelse return null; | 308 | const ptr = os.windows.kernel32.HeapAlloc(heap_handle, 0, amt) orelse return null; |
| 309 | const root_addr = @ptrToInt(ptr); | 309 | const root_addr = @ptrToInt(ptr); |
| 310 | const aligned_addr = mem.alignForward(root_addr, ptr_align); | 310 | const aligned_addr = mem.alignForward(usize, root_addr, ptr_align); |
| 311 | const buf = @intToPtr([*]u8, aligned_addr)[0..n]; | 311 | const buf = @intToPtr([*]u8, aligned_addr)[0..n]; |
| 312 | getRecordPtr(buf).* = root_addr; | 312 | getRecordPtr(buf).* = root_addr; |
| 313 | return buf.ptr; | 313 | return buf.ptr; |
| ... | @@ -840,7 +840,7 @@ pub fn testAllocatorAlignedShrink(base_allocator: mem.Allocator) !void { | ... | @@ -840,7 +840,7 @@ pub fn testAllocatorAlignedShrink(base_allocator: mem.Allocator) !void { |
| 840 | // which is 16 pages, hence the 32. This test may require to increase | 840 | // which is 16 pages, hence the 32. This test may require to increase |
| 841 | // the size of the allocations feeding the `allocator` parameter if they | 841 | // the size of the allocations feeding the `allocator` parameter if they |
| 842 | // fail, because of this high over-alignment we want to have. | 842 | // fail, because of this high over-alignment we want to have. |
| 843 | while (@ptrToInt(slice.ptr) == mem.alignForward(@ptrToInt(slice.ptr), mem.page_size * 32)) { | 843 | while (@ptrToInt(slice.ptr) == mem.alignForward(usize, @ptrToInt(slice.ptr), mem.page_size * 32)) { |
| 844 | try stuff_to_free.append(slice); | 844 | try stuff_to_free.append(slice); |
| 845 | slice = try allocator.alignedAlloc(u8, 16, alloc_size); | 845 | slice = try allocator.alignedAlloc(u8, 16, alloc_size); |
| 846 | } | 846 | } |
lib/std/heap/PageAllocator.zig+6-6| ... | @@ -17,7 +17,7 @@ fn alloc(_: *anyopaque, n: usize, log2_align: u8, ra: usize) ?[*]u8 { | ... | @@ -17,7 +17,7 @@ fn alloc(_: *anyopaque, n: usize, log2_align: u8, ra: usize) ?[*]u8 { |
| 17 | _ = log2_align; | 17 | _ = log2_align; |
| 18 | assert(n > 0); | 18 | assert(n > 0); |
| 19 | if (n > maxInt(usize) - (mem.page_size - 1)) return null; | 19 | if (n > maxInt(usize) - (mem.page_size - 1)) return null; |
| 20 | const aligned_len = mem.alignForward(n, mem.page_size); | 20 | const aligned_len = mem.alignForward(usize, n, mem.page_size); |
| 21 | 21 | ||
| 22 | if (builtin.os.tag == .windows) { | 22 | if (builtin.os.tag == .windows) { |
| 23 | const w = os.windows; | 23 | const w = os.windows; |
| ... | @@ -54,14 +54,14 @@ fn resize( | ... | @@ -54,14 +54,14 @@ fn resize( |
| 54 | ) bool { | 54 | ) bool { |
| 55 | _ = log2_buf_align; | 55 | _ = log2_buf_align; |
| 56 | _ = return_address; | 56 | _ = return_address; |
| 57 | const new_size_aligned = mem.alignForward(new_size, mem.page_size); | 57 | const new_size_aligned = mem.alignForward(usize, new_size, mem.page_size); |
| 58 | 58 | ||
| 59 | if (builtin.os.tag == .windows) { | 59 | if (builtin.os.tag == .windows) { |
| 60 | const w = os.windows; | 60 | const w = os.windows; |
| 61 | if (new_size <= buf_unaligned.len) { | 61 | if (new_size <= buf_unaligned.len) { |
| 62 | const base_addr = @ptrToInt(buf_unaligned.ptr); | 62 | const base_addr = @ptrToInt(buf_unaligned.ptr); |
| 63 | const old_addr_end = base_addr + buf_unaligned.len; | 63 | const old_addr_end = base_addr + buf_unaligned.len; |
| 64 | const new_addr_end = mem.alignForward(base_addr + new_size, mem.page_size); | 64 | const new_addr_end = mem.alignForward(usize, base_addr + new_size, mem.page_size); |
| 65 | if (old_addr_end > new_addr_end) { | 65 | if (old_addr_end > new_addr_end) { |
| 66 | // For shrinking that is not releasing, we will only | 66 | // For shrinking that is not releasing, we will only |
| 67 | // decommit the pages not needed anymore. | 67 | // decommit the pages not needed anymore. |
| ... | @@ -73,14 +73,14 @@ fn resize( | ... | @@ -73,14 +73,14 @@ fn resize( |
| 73 | } | 73 | } |
| 74 | return true; | 74 | return true; |
| 75 | } | 75 | } |
| 76 | const old_size_aligned = mem.alignForward(buf_unaligned.len, mem.page_size); | 76 | const old_size_aligned = mem.alignForward(usize, buf_unaligned.len, mem.page_size); |
| 77 | if (new_size_aligned <= old_size_aligned) { | 77 | if (new_size_aligned <= old_size_aligned) { |
| 78 | return true; | 78 | return true; |
| 79 | } | 79 | } |
| 80 | return false; | 80 | return false; |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | const buf_aligned_len = mem.alignForward(buf_unaligned.len, mem.page_size); | 83 | const buf_aligned_len = mem.alignForward(usize, buf_unaligned.len, mem.page_size); |
| 84 | if (new_size_aligned == buf_aligned_len) | 84 | if (new_size_aligned == buf_aligned_len) |
| 85 | return true; | 85 | return true; |
| 86 | 86 | ||
| ... | @@ -103,7 +103,7 @@ fn free(_: *anyopaque, slice: []u8, log2_buf_align: u8, return_address: usize) v | ... | @@ -103,7 +103,7 @@ fn free(_: *anyopaque, slice: []u8, log2_buf_align: u8, return_address: usize) v |
| 103 | if (builtin.os.tag == .windows) { | 103 | if (builtin.os.tag == .windows) { |
| 104 | os.windows.VirtualFree(slice.ptr, 0, os.windows.MEM_RELEASE); | 104 | os.windows.VirtualFree(slice.ptr, 0, os.windows.MEM_RELEASE); |
| 105 | } else { | 105 | } else { |
| 106 | const buf_aligned_len = mem.alignForward(slice.len, mem.page_size); | 106 | const buf_aligned_len = mem.alignForward(usize, slice.len, mem.page_size); |
| 107 | const ptr = @alignCast(mem.page_size, slice.ptr); | 107 | const ptr = @alignCast(mem.page_size, slice.ptr); |
| 108 | os.munmap(ptr[0..buf_aligned_len]); | 108 | os.munmap(ptr[0..buf_aligned_len]); |
| 109 | } | 109 | } |
lib/std/heap/WasmPageAllocator.zig+3-3| ... | @@ -100,7 +100,7 @@ fn extendedOffset() usize { | ... | @@ -100,7 +100,7 @@ fn extendedOffset() usize { |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | fn nPages(memsize: usize) usize { | 102 | fn nPages(memsize: usize) usize { |
| 103 | return mem.alignForward(memsize, mem.page_size) / mem.page_size; | 103 | return mem.alignForward(usize, memsize, mem.page_size) / mem.page_size; |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | fn alloc(ctx: *anyopaque, len: usize, log2_align: u8, ra: usize) ?[*]u8 { | 106 | fn alloc(ctx: *anyopaque, len: usize, log2_align: u8, ra: usize) ?[*]u8 { |
| ... | @@ -170,7 +170,7 @@ fn resize( | ... | @@ -170,7 +170,7 @@ fn resize( |
| 170 | _ = ctx; | 170 | _ = ctx; |
| 171 | _ = log2_buf_align; | 171 | _ = log2_buf_align; |
| 172 | _ = return_address; | 172 | _ = return_address; |
| 173 | const aligned_len = mem.alignForward(buf.len, mem.page_size); | 173 | const aligned_len = mem.alignForward(usize, buf.len, mem.page_size); |
| 174 | if (new_len > aligned_len) return false; | 174 | if (new_len > aligned_len) return false; |
| 175 | const current_n = nPages(aligned_len); | 175 | const current_n = nPages(aligned_len); |
| 176 | const new_n = nPages(new_len); | 176 | const new_n = nPages(new_len); |
| ... | @@ -190,7 +190,7 @@ fn free( | ... | @@ -190,7 +190,7 @@ fn free( |
| 190 | _ = ctx; | 190 | _ = ctx; |
| 191 | _ = log2_buf_align; | 191 | _ = log2_buf_align; |
| 192 | _ = return_address; | 192 | _ = return_address; |
| 193 | const aligned_len = mem.alignForward(buf.len, mem.page_size); | 193 | const aligned_len = mem.alignForward(usize, buf.len, mem.page_size); |
| 194 | const current_n = nPages(aligned_len); | 194 | const current_n = nPages(aligned_len); |
| 195 | const base = nPages(@ptrToInt(buf.ptr)); | 195 | const base = nPages(@ptrToInt(buf.ptr)); |
| 196 | freePages(base, base + current_n); | 196 | freePages(base, base + current_n); |
lib/std/heap/arena_allocator.zig+1-1| ... | @@ -186,7 +186,7 @@ pub const ArenaAllocator = struct { | ... | @@ -186,7 +186,7 @@ pub const ArenaAllocator = struct { |
| 186 | const cur_alloc_buf = @ptrCast([*]u8, cur_node)[0..cur_node.data]; | 186 | const cur_alloc_buf = @ptrCast([*]u8, cur_node)[0..cur_node.data]; |
| 187 | const cur_buf = cur_alloc_buf[@sizeOf(BufNode)..]; | 187 | const cur_buf = cur_alloc_buf[@sizeOf(BufNode)..]; |
| 188 | const addr = @ptrToInt(cur_buf.ptr) + self.state.end_index; | 188 | const addr = @ptrToInt(cur_buf.ptr) + self.state.end_index; |
| 189 | const adjusted_addr = mem.alignForward(addr, ptr_align); | 189 | const adjusted_addr = mem.alignForward(usize, addr, ptr_align); |
| 190 | const adjusted_index = self.state.end_index + (adjusted_addr - addr); | 190 | const adjusted_index = self.state.end_index + (adjusted_addr - addr); |
| 191 | const new_end_index = adjusted_index + n; | 191 | const new_end_index = adjusted_index + n; |
| 192 | 192 |
lib/std/heap/general_purpose_allocator.zig+1| ... | @@ -309,6 +309,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { | ... | @@ -309,6 +309,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { |
| 309 | 309 | ||
| 310 | fn bucketStackFramesStart(size_class: usize) usize { | 310 | fn bucketStackFramesStart(size_class: usize) usize { |
| 311 | return mem.alignForward( | 311 | return mem.alignForward( |
| 312 | usize, | ||
| 312 | @sizeOf(BucketHeader) + usedBitsCount(size_class), | 313 | @sizeOf(BucketHeader) + usedBitsCount(size_class), |
| 313 | @alignOf(usize), | 314 | @alignOf(usize), |
| 314 | ); | 315 | ); |
lib/std/mem.zig+23-33| ... | @@ -4213,23 +4213,17 @@ test "sliceAsBytes preserves pointer attributes" { | ... | @@ -4213,23 +4213,17 @@ test "sliceAsBytes preserves pointer attributes" { |
| 4213 | /// Round an address up to the next (or current) aligned address. | 4213 | /// Round an address up to the next (or current) aligned address. |
| 4214 | /// The alignment must be a power of 2 and greater than 0. | 4214 | /// The alignment must be a power of 2 and greater than 0. |
| 4215 | /// Asserts that rounding up the address does not cause integer overflow. | 4215 | /// Asserts that rounding up the address does not cause integer overflow. |
| 4216 | pub fn alignForward(addr: usize, alignment: usize) usize { | 4216 | pub fn alignForward(comptime T: type, addr: T, alignment: T) T { |
| 4217 | return alignForwardGeneric(usize, addr, alignment); | 4217 | assert(isValidAlignGeneric(T, alignment)); |
| 4218 | return alignBackward(T, addr + (alignment - 1), alignment); | ||
| 4218 | } | 4219 | } |
| 4219 | 4220 | ||
| 4220 | pub fn alignForwardLog2(addr: usize, log2_alignment: u8) usize { | 4221 | pub fn alignForwardLog2(addr: usize, log2_alignment: u8) usize { |
| 4221 | const alignment = @as(usize, 1) << @intCast(math.Log2Int(usize), log2_alignment); | 4222 | const alignment = @as(usize, 1) << @intCast(math.Log2Int(usize), log2_alignment); |
| 4222 | return alignForward(addr, alignment); | 4223 | return alignForward(usize, addr, alignment); |
| 4223 | } | 4224 | } |
| 4224 | 4225 | ||
| 4225 | /// Round an address up to the next (or current) aligned address. | 4226 | pub const alignForwardGeneric = @compileError("renamed to alignForward"); |
| 4226 | /// The alignment must be a power of 2 and greater than 0. | ||
| 4227 | /// Asserts that rounding up the address does not cause integer overflow. | ||
| 4228 | pub fn alignForwardGeneric(comptime T: type, addr: T, alignment: T) T { | ||
| 4229 | assert(alignment > 0); | ||
| 4230 | assert(std.math.isPowerOfTwo(alignment)); | ||
| 4231 | return alignBackwardGeneric(T, addr + (alignment - 1), alignment); | ||
| 4232 | } | ||
| 4233 | 4227 | ||
| 4234 | /// Force an evaluation of the expression; this tries to prevent | 4228 | /// Force an evaluation of the expression; this tries to prevent |
| 4235 | /// the compiler from optimizing the computation away even if the | 4229 | /// the compiler from optimizing the computation away even if the |
| ... | @@ -4322,38 +4316,32 @@ test "doNotOptimizeAway" { | ... | @@ -4322,38 +4316,32 @@ test "doNotOptimizeAway" { |
| 4322 | } | 4316 | } |
| 4323 | 4317 | ||
| 4324 | test "alignForward" { | 4318 | test "alignForward" { |
| 4325 | try testing.expect(alignForward(1, 1) == 1); | 4319 | try testing.expect(alignForward(usize, 1, 1) == 1); |
| 4326 | try testing.expect(alignForward(2, 1) == 2); | 4320 | try testing.expect(alignForward(usize, 2, 1) == 2); |
| 4327 | try testing.expect(alignForward(1, 2) == 2); | 4321 | try testing.expect(alignForward(usize, 1, 2) == 2); |
| 4328 | try testing.expect(alignForward(2, 2) == 2); | 4322 | try testing.expect(alignForward(usize, 2, 2) == 2); |
| 4329 | try testing.expect(alignForward(3, 2) == 4); | 4323 | try testing.expect(alignForward(usize, 3, 2) == 4); |
| 4330 | try testing.expect(alignForward(4, 2) == 4); | 4324 | try testing.expect(alignForward(usize, 4, 2) == 4); |
| 4331 | try testing.expect(alignForward(7, 8) == 8); | 4325 | try testing.expect(alignForward(usize, 7, 8) == 8); |
| 4332 | try testing.expect(alignForward(8, 8) == 8); | 4326 | try testing.expect(alignForward(usize, 8, 8) == 8); |
| 4333 | try testing.expect(alignForward(9, 8) == 16); | 4327 | try testing.expect(alignForward(usize, 9, 8) == 16); |
| 4334 | try testing.expect(alignForward(15, 8) == 16); | 4328 | try testing.expect(alignForward(usize, 15, 8) == 16); |
| 4335 | try testing.expect(alignForward(16, 8) == 16); | 4329 | try testing.expect(alignForward(usize, 16, 8) == 16); |
| 4336 | try testing.expect(alignForward(17, 8) == 24); | 4330 | try testing.expect(alignForward(usize, 17, 8) == 24); |
| 4337 | } | 4331 | } |
| 4338 | 4332 | ||
| 4339 | /// Round an address down to the previous (or current) aligned address. | 4333 | /// Round an address down to the previous (or current) aligned address. |
| 4340 | /// Unlike `alignBackward`, `alignment` can be any positive number, not just a power of 2. | 4334 | /// Unlike `alignBackward`, `alignment` can be any positive number, not just a power of 2. |
| 4341 | pub fn alignBackwardAnyAlign(i: usize, alignment: usize) usize { | 4335 | pub fn alignBackwardAnyAlign(i: usize, alignment: usize) usize { |
| 4342 | if (isValidAlign(alignment)) | 4336 | if (isValidAlign(alignment)) |
| 4343 | return alignBackward(i, alignment); | 4337 | return alignBackward(usize, i, alignment); |
| 4344 | assert(alignment != 0); | 4338 | assert(alignment != 0); |
| 4345 | return i - @mod(i, alignment); | 4339 | return i - @mod(i, alignment); |
| 4346 | } | 4340 | } |
| 4347 | 4341 | ||
| 4348 | /// Round an address down to the previous (or current) aligned address. | 4342 | /// Round an address down to the previous (or current) aligned address. |
| 4349 | /// The alignment must be a power of 2 and greater than 0. | 4343 | /// The alignment must be a power of 2 and greater than 0. |
| 4350 | pub fn alignBackward(addr: usize, alignment: usize) usize { | 4344 | pub fn alignBackward(comptime T: type, addr: T, alignment: T) T { |
| 4351 | return alignBackwardGeneric(usize, addr, alignment); | ||
| 4352 | } | ||
| 4353 | |||
| 4354 | /// Round an address down to the previous (or current) aligned address. | ||
| 4355 | /// The alignment must be a power of 2 and greater than 0. | ||
| 4356 | pub fn alignBackwardGeneric(comptime T: type, addr: T, alignment: T) T { | ||
| 4357 | assert(isValidAlignGeneric(T, alignment)); | 4345 | assert(isValidAlignGeneric(T, alignment)); |
| 4358 | // 000010000 // example alignment | 4346 | // 000010000 // example alignment |
| 4359 | // 000001111 // subtract 1 | 4347 | // 000001111 // subtract 1 |
| ... | @@ -4361,6 +4349,8 @@ pub fn alignBackwardGeneric(comptime T: type, addr: T, alignment: T) T { | ... | @@ -4361,6 +4349,8 @@ pub fn alignBackwardGeneric(comptime T: type, addr: T, alignment: T) T { |
| 4361 | return addr & ~(alignment - 1); | 4349 | return addr & ~(alignment - 1); |
| 4362 | } | 4350 | } |
| 4363 | 4351 | ||
| 4352 | pub const alignBackwardGeneric = @compileError("renamed to alignBackward"); | ||
| 4353 | |||
| 4364 | /// Returns whether `alignment` is a valid alignment, meaning it is | 4354 | /// Returns whether `alignment` is a valid alignment, meaning it is |
| 4365 | /// a positive power of 2. | 4355 | /// a positive power of 2. |
| 4366 | pub fn isValidAlign(alignment: usize) bool { | 4356 | pub fn isValidAlign(alignment: usize) bool { |
| ... | @@ -4391,7 +4381,7 @@ pub fn isAligned(addr: usize, alignment: usize) bool { | ... | @@ -4391,7 +4381,7 @@ pub fn isAligned(addr: usize, alignment: usize) bool { |
| 4391 | } | 4381 | } |
| 4392 | 4382 | ||
| 4393 | pub fn isAlignedGeneric(comptime T: type, addr: T, alignment: T) bool { | 4383 | pub fn isAlignedGeneric(comptime T: type, addr: T, alignment: T) bool { |
| 4394 | return alignBackwardGeneric(T, addr, alignment) == addr; | 4384 | return alignBackward(T, addr, alignment) == addr; |
| 4395 | } | 4385 | } |
| 4396 | 4386 | ||
| 4397 | test "isAligned" { | 4387 | test "isAligned" { |
| ... | @@ -4439,7 +4429,7 @@ pub fn alignInBytes(bytes: []u8, comptime new_alignment: usize) ?[]align(new_ali | ... | @@ -4439,7 +4429,7 @@ pub fn alignInBytes(bytes: []u8, comptime new_alignment: usize) ?[]align(new_ali |
| 4439 | const begin_address = @ptrToInt(bytes.ptr); | 4429 | const begin_address = @ptrToInt(bytes.ptr); |
| 4440 | const end_address = begin_address + bytes.len; | 4430 | const end_address = begin_address + bytes.len; |
| 4441 | 4431 | ||
| 4442 | const begin_address_aligned = mem.alignForward(begin_address, new_alignment); | 4432 | const begin_address_aligned = mem.alignForward(usize, begin_address, new_alignment); |
| 4443 | const new_length = std.math.sub(usize, end_address, begin_address_aligned) catch |e| switch (e) { | 4433 | const new_length = std.math.sub(usize, end_address, begin_address_aligned) catch |e| switch (e) { |
| 4444 | error.Overflow => return null, | 4434 | error.Overflow => return null, |
| 4445 | }; | 4435 | }; |
lib/std/mem/Allocator.zig+2-2| ... | @@ -208,7 +208,7 @@ pub fn allocAdvancedWithRetAddr( | ... | @@ -208,7 +208,7 @@ pub fn allocAdvancedWithRetAddr( |
| 208 | comptime assert(a <= mem.page_size); | 208 | comptime assert(a <= mem.page_size); |
| 209 | 209 | ||
| 210 | if (n == 0) { | 210 | if (n == 0) { |
| 211 | const ptr = comptime std.mem.alignBackward(math.maxInt(usize), a); | 211 | const ptr = comptime std.mem.alignBackward(usize, math.maxInt(usize), a); |
| 212 | return @intToPtr([*]align(a) T, ptr)[0..0]; | 212 | return @intToPtr([*]align(a) T, ptr)[0..0]; |
| 213 | } | 213 | } |
| 214 | 214 | ||
| ... | @@ -267,7 +267,7 @@ pub fn reallocAdvanced( | ... | @@ -267,7 +267,7 @@ pub fn reallocAdvanced( |
| 267 | } | 267 | } |
| 268 | if (new_n == 0) { | 268 | if (new_n == 0) { |
| 269 | self.free(old_mem); | 269 | self.free(old_mem); |
| 270 | const ptr = comptime std.mem.alignBackward(math.maxInt(usize), Slice.alignment); | 270 | const ptr = comptime std.mem.alignBackward(usize, math.maxInt(usize), Slice.alignment); |
| 271 | return @intToPtr([*]align(Slice.alignment) T, ptr)[0..0]; | 271 | return @intToPtr([*]align(Slice.alignment) T, ptr)[0..0]; |
| 272 | } | 272 | } |
| 273 | 273 |
lib/std/meta/trailer_flags.zig+3-3| ... | @@ -105,9 +105,9 @@ pub fn TrailerFlags(comptime Fields: type) type { | ... | @@ -105,9 +105,9 @@ pub fn TrailerFlags(comptime Fields: type) type { |
| 105 | const active = (self.bits & (1 << i)) != 0; | 105 | const active = (self.bits & (1 << i)) != 0; |
| 106 | if (i == @enumToInt(field)) { | 106 | if (i == @enumToInt(field)) { |
| 107 | assert(active); | 107 | assert(active); |
| 108 | return mem.alignForwardGeneric(usize, off, @alignOf(field_info.type)); | 108 | return mem.alignForward(usize, off, @alignOf(field_info.type)); |
| 109 | } else if (active) { | 109 | } else if (active) { |
| 110 | off = mem.alignForwardGeneric(usize, off, @alignOf(field_info.type)); | 110 | off = mem.alignForward(usize, off, @alignOf(field_info.type)); |
| 111 | off += @sizeOf(field_info.type); | 111 | off += @sizeOf(field_info.type); |
| 112 | } | 112 | } |
| 113 | } | 113 | } |
| ... | @@ -123,7 +123,7 @@ pub fn TrailerFlags(comptime Fields: type) type { | ... | @@ -123,7 +123,7 @@ pub fn TrailerFlags(comptime Fields: type) type { |
| 123 | if (@sizeOf(field.type) == 0) | 123 | if (@sizeOf(field.type) == 0) |
| 124 | continue; | 124 | continue; |
| 125 | if ((self.bits & (1 << i)) != 0) { | 125 | if ((self.bits & (1 << i)) != 0) { |
| 126 | off = mem.alignForwardGeneric(usize, off, @alignOf(field.type)); | 126 | off = mem.alignForward(usize, off, @alignOf(field.type)); |
| 127 | off += @sizeOf(field.type); | 127 | off += @sizeOf(field.type); |
| 128 | } | 128 | } |
| 129 | } | 129 | } |
lib/std/os/linux/tls.zig+4-4| ... | @@ -233,7 +233,7 @@ fn initTLS(phdrs: []elf.Phdr) void { | ... | @@ -233,7 +233,7 @@ fn initTLS(phdrs: []elf.Phdr) void { |
| 233 | l += tls_align_factor - delta; | 233 | l += tls_align_factor - delta; |
| 234 | l += @sizeOf(CustomData); | 234 | l += @sizeOf(CustomData); |
| 235 | tcb_offset = l; | 235 | tcb_offset = l; |
| 236 | l += mem.alignForward(tls_tcb_size, tls_align_factor); | 236 | l += mem.alignForward(usize, tls_tcb_size, tls_align_factor); |
| 237 | data_offset = l; | 237 | data_offset = l; |
| 238 | l += tls_data_alloc_size; | 238 | l += tls_data_alloc_size; |
| 239 | break :blk l; | 239 | break :blk l; |
| ... | @@ -241,14 +241,14 @@ fn initTLS(phdrs: []elf.Phdr) void { | ... | @@ -241,14 +241,14 @@ fn initTLS(phdrs: []elf.Phdr) void { |
| 241 | .VariantII => blk: { | 241 | .VariantII => blk: { |
| 242 | var l: usize = 0; | 242 | var l: usize = 0; |
| 243 | data_offset = l; | 243 | data_offset = l; |
| 244 | l += mem.alignForward(tls_data_alloc_size, tls_align_factor); | 244 | l += mem.alignForward(usize, tls_data_alloc_size, tls_align_factor); |
| 245 | // The thread pointer is aligned to p_align | 245 | // The thread pointer is aligned to p_align |
| 246 | tcb_offset = l; | 246 | tcb_offset = l; |
| 247 | l += tls_tcb_size; | 247 | l += tls_tcb_size; |
| 248 | // The CustomData structure is right after the TCB with no padding | 248 | // The CustomData structure is right after the TCB with no padding |
| 249 | // in between so it can be easily found | 249 | // in between so it can be easily found |
| 250 | l += @sizeOf(CustomData); | 250 | l += @sizeOf(CustomData); |
| 251 | l = mem.alignForward(l, @alignOf(DTV)); | 251 | l = mem.alignForward(usize, l, @alignOf(DTV)); |
| 252 | dtv_offset = l; | 252 | dtv_offset = l; |
| 253 | l += @sizeOf(DTV); | 253 | l += @sizeOf(DTV); |
| 254 | break :blk l; | 254 | break :blk l; |
| ... | @@ -329,7 +329,7 @@ pub fn initStaticTLS(phdrs: []elf.Phdr) void { | ... | @@ -329,7 +329,7 @@ pub fn initStaticTLS(phdrs: []elf.Phdr) void { |
| 329 | 329 | ||
| 330 | // Make sure the slice is correctly aligned. | 330 | // Make sure the slice is correctly aligned. |
| 331 | const begin_addr = @ptrToInt(alloc_tls_area.ptr); | 331 | const begin_addr = @ptrToInt(alloc_tls_area.ptr); |
| 332 | const begin_aligned_addr = mem.alignForward(begin_addr, tls_image.alloc_align); | 332 | const begin_aligned_addr = mem.alignForward(usize, begin_addr, tls_image.alloc_align); |
| 333 | const start = begin_aligned_addr - begin_addr; | 333 | const start = begin_aligned_addr - begin_addr; |
| 334 | break :blk alloc_tls_area[start .. start + tls_image.alloc_size]; | 334 | break :blk alloc_tls_area[start .. start + tls_image.alloc_size]; |
| 335 | }; | 335 | }; |
lib/std/os/uefi/pool_allocator.zig+2-2| ... | @@ -24,7 +24,7 @@ const UefiPoolAllocator = struct { | ... | @@ -24,7 +24,7 @@ const UefiPoolAllocator = struct { |
| 24 | 24 | ||
| 25 | const ptr_align = @as(usize, 1) << @intCast(Allocator.Log2Align, log2_ptr_align); | 25 | const ptr_align = @as(usize, 1) << @intCast(Allocator.Log2Align, log2_ptr_align); |
| 26 | 26 | ||
| 27 | const metadata_len = mem.alignForward(@sizeOf(usize), ptr_align); | 27 | const metadata_len = mem.alignForward(usize, @sizeOf(usize), ptr_align); |
| 28 | 28 | ||
| 29 | const full_len = metadata_len + len; | 29 | const full_len = metadata_len + len; |
| 30 | 30 | ||
| ... | @@ -32,7 +32,7 @@ const UefiPoolAllocator = struct { | ... | @@ -32,7 +32,7 @@ const UefiPoolAllocator = struct { |
| 32 | if (uefi.system_table.boot_services.?.allocatePool(uefi.efi_pool_memory_type, full_len, &unaligned_ptr) != .Success) return null; | 32 | if (uefi.system_table.boot_services.?.allocatePool(uefi.efi_pool_memory_type, full_len, &unaligned_ptr) != .Success) return null; |
| 33 | 33 | ||
| 34 | const unaligned_addr = @ptrToInt(unaligned_ptr); | 34 | const unaligned_addr = @ptrToInt(unaligned_ptr); |
| 35 | const aligned_addr = mem.alignForward(unaligned_addr + @sizeOf(usize), ptr_align); | 35 | const aligned_addr = mem.alignForward(usize, unaligned_addr + @sizeOf(usize), ptr_align); |
| 36 | 36 | ||
| 37 | var aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr); | 37 | var aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr); |
| 38 | getHeader(aligned_ptr).* = unaligned_ptr; | 38 | getHeader(aligned_ptr).* = unaligned_ptr; |
lib/std/tar.zig+1-1| ... | @@ -116,7 +116,7 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi | ... | @@ -116,7 +116,7 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi |
| 116 | const header: Header = .{ .bytes = buffer[start..][0..512] }; | 116 | const header: Header = .{ .bytes = buffer[start..][0..512] }; |
| 117 | start += 512; | 117 | start += 512; |
| 118 | const file_size = try header.fileSize(); | 118 | const file_size = try header.fileSize(); |
| 119 | const rounded_file_size = std.mem.alignForwardGeneric(u64, file_size, 512); | 119 | const rounded_file_size = std.mem.alignForward(u64, file_size, 512); |
| 120 | const pad_len = @intCast(usize, rounded_file_size - file_size); | 120 | const pad_len = @intCast(usize, rounded_file_size - file_size); |
| 121 | const unstripped_file_name = try header.fullFileName(&file_name_buffer); | 121 | const unstripped_file_name = try header.fullFileName(&file_name_buffer); |
| 122 | switch (header.fileType()) { | 122 | switch (header.fileType()) { |
lib/std/target.zig+1-1| ... | @@ -1944,7 +1944,7 @@ pub const Target = struct { | ... | @@ -1944,7 +1944,7 @@ pub const Target = struct { |
| 1944 | 16 => 2, | 1944 | 16 => 2, |
| 1945 | 32 => 4, | 1945 | 32 => 4, |
| 1946 | 64 => 8, | 1946 | 64 => 8, |
| 1947 | 80 => @intCast(u16, mem.alignForward(10, c_type_alignment(t, .longdouble))), | 1947 | 80 => @intCast(u16, mem.alignForward(usize, 10, c_type_alignment(t, .longdouble))), |
| 1948 | 128 => 16, | 1948 | 128 => 16, |
| 1949 | else => unreachable, | 1949 | else => unreachable, |
| 1950 | }, | 1950 | }, |
lib/std/testing.zig+1-1| ... | @@ -305,7 +305,7 @@ pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const | ... | @@ -305,7 +305,7 @@ pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const |
| 305 | var window_start: usize = 0; | 305 | var window_start: usize = 0; |
| 306 | if (@max(actual.len, expected.len) > max_window_size) { | 306 | if (@max(actual.len, expected.len) > max_window_size) { |
| 307 | const alignment = if (T == u8) 16 else 2; | 307 | const alignment = if (T == u8) 16 else 2; |
| 308 | window_start = std.mem.alignBackward(diff_index - @min(diff_index, alignment), alignment); | 308 | window_start = std.mem.alignBackward(usize, diff_index - @min(diff_index, alignment), alignment); |
| 309 | } | 309 | } |
| 310 | const expected_window = expected[window_start..@min(expected.len, window_start + max_window_size)]; | 310 | const expected_window = expected[window_start..@min(expected.len, window_start + max_window_size)]; |
| 311 | const expected_truncated = window_start + expected_window.len < expected.len; | 311 | const expected_truncated = window_start + expected_window.len < expected.len; |
src/Module.zig+5-5| ... | @@ -1293,7 +1293,7 @@ pub const Union = struct { | ... | @@ -1293,7 +1293,7 @@ pub const Union = struct { |
| 1293 | payload_align = @max(payload_align, 1); | 1293 | payload_align = @max(payload_align, 1); |
| 1294 | if (!have_tag or !u.tag_ty.hasRuntimeBits(mod)) { | 1294 | if (!have_tag or !u.tag_ty.hasRuntimeBits(mod)) { |
| 1295 | return .{ | 1295 | return .{ |
| 1296 | .abi_size = std.mem.alignForwardGeneric(u64, payload_size, payload_align), | 1296 | .abi_size = std.mem.alignForward(u64, payload_size, payload_align), |
| 1297 | .abi_align = payload_align, | 1297 | .abi_align = payload_align, |
| 1298 | .most_aligned_field = most_aligned_field, | 1298 | .most_aligned_field = most_aligned_field, |
| 1299 | .most_aligned_field_size = most_aligned_field_size, | 1299 | .most_aligned_field_size = most_aligned_field_size, |
| ... | @@ -1314,18 +1314,18 @@ pub const Union = struct { | ... | @@ -1314,18 +1314,18 @@ pub const Union = struct { |
| 1314 | if (tag_align >= payload_align) { | 1314 | if (tag_align >= payload_align) { |
| 1315 | // {Tag, Payload} | 1315 | // {Tag, Payload} |
| 1316 | size += tag_size; | 1316 | size += tag_size; |
| 1317 | size = std.mem.alignForwardGeneric(u64, size, payload_align); | 1317 | size = std.mem.alignForward(u64, size, payload_align); |
| 1318 | size += payload_size; | 1318 | size += payload_size; |
| 1319 | const prev_size = size; | 1319 | const prev_size = size; |
| 1320 | size = std.mem.alignForwardGeneric(u64, size, tag_align); | 1320 | size = std.mem.alignForward(u64, size, tag_align); |
| 1321 | padding = @intCast(u32, size - prev_size); | 1321 | padding = @intCast(u32, size - prev_size); |
| 1322 | } else { | 1322 | } else { |
| 1323 | // {Payload, Tag} | 1323 | // {Payload, Tag} |
| 1324 | size += payload_size; | 1324 | size += payload_size; |
| 1325 | size = std.mem.alignForwardGeneric(u64, size, tag_align); | 1325 | size = std.mem.alignForward(u64, size, tag_align); |
| 1326 | size += tag_size; | 1326 | size += tag_size; |
| 1327 | const prev_size = size; | 1327 | const prev_size = size; |
| 1328 | size = std.mem.alignForwardGeneric(u64, size, payload_align); | 1328 | size = std.mem.alignForward(u64, size, payload_align); |
| 1329 | padding = @intCast(u32, size - prev_size); | 1329 | padding = @intCast(u32, size - prev_size); |
| 1330 | } | 1330 | } |
| 1331 | return .{ | 1331 | return .{ |
src/arch/aarch64/CodeGen.zig+3-3| ... | @@ -566,7 +566,7 @@ fn gen(self: *Self) !void { | ... | @@ -566,7 +566,7 @@ fn gen(self: *Self) !void { |
| 566 | 566 | ||
| 567 | // Backpatch stack offset | 567 | // Backpatch stack offset |
| 568 | const total_stack_size = self.max_end_stack + self.saved_regs_stack_space; | 568 | const total_stack_size = self.max_end_stack + self.saved_regs_stack_space; |
| 569 | const aligned_total_stack_end = mem.alignForwardGeneric(u32, total_stack_size, self.stack_align); | 569 | const aligned_total_stack_end = mem.alignForward(u32, total_stack_size, self.stack_align); |
| 570 | const stack_size = aligned_total_stack_end - self.saved_regs_stack_space; | 570 | const stack_size = aligned_total_stack_end - self.saved_regs_stack_space; |
| 571 | self.max_end_stack = stack_size; | 571 | self.max_end_stack = stack_size; |
| 572 | if (math.cast(u12, stack_size)) |size| { | 572 | if (math.cast(u12, stack_size)) |size| { |
| ... | @@ -1011,7 +1011,7 @@ fn allocMem( | ... | @@ -1011,7 +1011,7 @@ fn allocMem( |
| 1011 | std.math.ceilPowerOfTwoAssert(u32, abi_size); | 1011 | std.math.ceilPowerOfTwoAssert(u32, abi_size); |
| 1012 | 1012 | ||
| 1013 | // TODO find a free slot instead of always appending | 1013 | // TODO find a free slot instead of always appending |
| 1014 | const offset = mem.alignForwardGeneric(u32, self.next_stack_offset, adjusted_align) + abi_size; | 1014 | const offset = mem.alignForward(u32, self.next_stack_offset, adjusted_align) + abi_size; |
| 1015 | self.next_stack_offset = offset; | 1015 | self.next_stack_offset = offset; |
| 1016 | self.max_end_stack = @max(self.max_end_stack, self.next_stack_offset); | 1016 | self.max_end_stack = @max(self.max_end_stack, self.next_stack_offset); |
| 1017 | 1017 | ||
| ... | @@ -6328,7 +6328,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { | ... | @@ -6328,7 +6328,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { |
| 6328 | const param_size = @intCast(u32, ty.toType().abiSize(mod)); | 6328 | const param_size = @intCast(u32, ty.toType().abiSize(mod)); |
| 6329 | const param_alignment = ty.toType().abiAlignment(mod); | 6329 | const param_alignment = ty.toType().abiAlignment(mod); |
| 6330 | 6330 | ||
| 6331 | stack_offset = std.mem.alignForwardGeneric(u32, stack_offset, param_alignment); | 6331 | stack_offset = std.mem.alignForward(u32, stack_offset, param_alignment); |
| 6332 | result.args[i] = .{ .stack_argument_offset = stack_offset }; | 6332 | result.args[i] = .{ .stack_argument_offset = stack_offset }; |
| 6333 | stack_offset += param_size; | 6333 | stack_offset += param_size; |
| 6334 | } else { | 6334 | } else { |
src/arch/arm/CodeGen.zig+5-5| ... | @@ -560,7 +560,7 @@ fn gen(self: *Self) !void { | ... | @@ -560,7 +560,7 @@ fn gen(self: *Self) !void { |
| 560 | 560 | ||
| 561 | // Backpatch stack offset | 561 | // Backpatch stack offset |
| 562 | const total_stack_size = self.max_end_stack + self.saved_regs_stack_space; | 562 | const total_stack_size = self.max_end_stack + self.saved_regs_stack_space; |
| 563 | const aligned_total_stack_end = mem.alignForwardGeneric(u32, total_stack_size, self.stack_align); | 563 | const aligned_total_stack_end = mem.alignForward(u32, total_stack_size, self.stack_align); |
| 564 | const stack_size = aligned_total_stack_end - self.saved_regs_stack_space; | 564 | const stack_size = aligned_total_stack_end - self.saved_regs_stack_space; |
| 565 | self.max_end_stack = stack_size; | 565 | self.max_end_stack = stack_size; |
| 566 | self.mir_instructions.set(sub_reloc, .{ | 566 | self.mir_instructions.set(sub_reloc, .{ |
| ... | @@ -991,7 +991,7 @@ fn allocMem( | ... | @@ -991,7 +991,7 @@ fn allocMem( |
| 991 | assert(abi_align > 0); | 991 | assert(abi_align > 0); |
| 992 | 992 | ||
| 993 | // TODO find a free slot instead of always appending | 993 | // TODO find a free slot instead of always appending |
| 994 | const offset = mem.alignForwardGeneric(u32, self.next_stack_offset, abi_align) + abi_size; | 994 | const offset = mem.alignForward(u32, self.next_stack_offset, abi_align) + abi_size; |
| 995 | self.next_stack_offset = offset; | 995 | self.next_stack_offset = offset; |
| 996 | self.max_end_stack = @max(self.max_end_stack, self.next_stack_offset); | 996 | self.max_end_stack = @max(self.max_end_stack, self.next_stack_offset); |
| 997 | 997 | ||
| ... | @@ -6214,7 +6214,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { | ... | @@ -6214,7 +6214,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { |
| 6214 | 6214 | ||
| 6215 | for (fn_info.param_types, 0..) |ty, i| { | 6215 | for (fn_info.param_types, 0..) |ty, i| { |
| 6216 | if (ty.toType().abiAlignment(mod) == 8) | 6216 | if (ty.toType().abiAlignment(mod) == 8) |
| 6217 | ncrn = std.mem.alignForwardGeneric(usize, ncrn, 2); | 6217 | ncrn = std.mem.alignForward(usize, ncrn, 2); |
| 6218 | 6218 | ||
| 6219 | const param_size = @intCast(u32, ty.toType().abiSize(mod)); | 6219 | const param_size = @intCast(u32, ty.toType().abiSize(mod)); |
| 6220 | if (std.math.divCeil(u32, param_size, 4) catch unreachable <= 4 - ncrn) { | 6220 | if (std.math.divCeil(u32, param_size, 4) catch unreachable <= 4 - ncrn) { |
| ... | @@ -6229,7 +6229,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { | ... | @@ -6229,7 +6229,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { |
| 6229 | } else { | 6229 | } else { |
| 6230 | ncrn = 4; | 6230 | ncrn = 4; |
| 6231 | if (ty.toType().abiAlignment(mod) == 8) | 6231 | if (ty.toType().abiAlignment(mod) == 8) |
| 6232 | nsaa = std.mem.alignForwardGeneric(u32, nsaa, 8); | 6232 | nsaa = std.mem.alignForward(u32, nsaa, 8); |
| 6233 | 6233 | ||
| 6234 | result.args[i] = .{ .stack_argument_offset = nsaa }; | 6234 | result.args[i] = .{ .stack_argument_offset = nsaa }; |
| 6235 | nsaa += param_size; | 6235 | nsaa += param_size; |
| ... | @@ -6267,7 +6267,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { | ... | @@ -6267,7 +6267,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { |
| 6267 | const param_size = @intCast(u32, ty.toType().abiSize(mod)); | 6267 | const param_size = @intCast(u32, ty.toType().abiSize(mod)); |
| 6268 | const param_alignment = ty.toType().abiAlignment(mod); | 6268 | const param_alignment = ty.toType().abiAlignment(mod); |
| 6269 | 6269 | ||
| 6270 | stack_offset = std.mem.alignForwardGeneric(u32, stack_offset, param_alignment); | 6270 | stack_offset = std.mem.alignForward(u32, stack_offset, param_alignment); |
| 6271 | result.args[i] = .{ .stack_argument_offset = stack_offset }; | 6271 | result.args[i] = .{ .stack_argument_offset = stack_offset }; |
| 6272 | stack_offset += param_size; | 6272 | stack_offset += param_size; |
| 6273 | } else { | 6273 | } else { |
src/arch/arm/abi.zig+1-1| ... | @@ -13,7 +13,7 @@ pub const Class = union(enum) { | ... | @@ -13,7 +13,7 @@ pub const Class = union(enum) { |
| 13 | i64_array: u8, | 13 | i64_array: u8, |
| 14 | 14 | ||
| 15 | fn arrSize(total_size: u64, arr_size: u64) Class { | 15 | fn arrSize(total_size: u64, arr_size: u64) Class { |
| 16 | const count = @intCast(u8, std.mem.alignForwardGeneric(u64, total_size, arr_size) / arr_size); | 16 | const count = @intCast(u8, std.mem.alignForward(u64, total_size, arr_size) / arr_size); |
| 17 | if (arr_size == 32) { | 17 | if (arr_size == 32) { |
| 18 | return .{ .i32_array = count }; | 18 | return .{ .i32_array = count }; |
| 19 | } else { | 19 | } else { |
src/arch/riscv64/CodeGen.zig+1-1| ... | @@ -792,7 +792,7 @@ fn allocMem(self: *Self, inst: Air.Inst.Index, abi_size: u32, abi_align: u32) !u | ... | @@ -792,7 +792,7 @@ fn allocMem(self: *Self, inst: Air.Inst.Index, abi_size: u32, abi_align: u32) !u |
| 792 | if (abi_align > self.stack_align) | 792 | if (abi_align > self.stack_align) |
| 793 | self.stack_align = abi_align; | 793 | self.stack_align = abi_align; |
| 794 | // TODO find a free slot instead of always appending | 794 | // TODO find a free slot instead of always appending |
| 795 | const offset = mem.alignForwardGeneric(u32, self.next_stack_offset, abi_align); | 795 | const offset = mem.alignForward(u32, self.next_stack_offset, abi_align); |
| 796 | self.next_stack_offset = offset + abi_size; | 796 | self.next_stack_offset = offset + abi_size; |
| 797 | if (self.next_stack_offset > self.max_end_stack) | 797 | if (self.next_stack_offset > self.max_end_stack) |
| 798 | self.max_end_stack = self.next_stack_offset; | 798 | self.max_end_stack = self.next_stack_offset; |
src/arch/sparc64/CodeGen.zig+2-2| ... | @@ -423,7 +423,7 @@ fn gen(self: *Self) !void { | ... | @@ -423,7 +423,7 @@ fn gen(self: *Self) !void { |
| 423 | 423 | ||
| 424 | // Backpatch stack offset | 424 | // Backpatch stack offset |
| 425 | const total_stack_size = self.max_end_stack + abi.stack_reserved_area; | 425 | const total_stack_size = self.max_end_stack + abi.stack_reserved_area; |
| 426 | const stack_size = mem.alignForwardGeneric(u32, total_stack_size, self.stack_align); | 426 | const stack_size = mem.alignForward(u32, total_stack_size, self.stack_align); |
| 427 | if (math.cast(i13, stack_size)) |size| { | 427 | if (math.cast(i13, stack_size)) |size| { |
| 428 | self.mir_instructions.set(save_inst, .{ | 428 | self.mir_instructions.set(save_inst, .{ |
| 429 | .tag = .save, | 429 | .tag = .save, |
| ... | @@ -2781,7 +2781,7 @@ fn allocMem(self: *Self, inst: Air.Inst.Index, abi_size: u32, abi_align: u32) !u | ... | @@ -2781,7 +2781,7 @@ fn allocMem(self: *Self, inst: Air.Inst.Index, abi_size: u32, abi_align: u32) !u |
| 2781 | if (abi_align > self.stack_align) | 2781 | if (abi_align > self.stack_align) |
| 2782 | self.stack_align = abi_align; | 2782 | self.stack_align = abi_align; |
| 2783 | // TODO find a free slot instead of always appending | 2783 | // TODO find a free slot instead of always appending |
| 2784 | const offset = mem.alignForwardGeneric(u32, self.next_stack_offset, abi_align) + abi_size; | 2784 | const offset = mem.alignForward(u32, self.next_stack_offset, abi_align) + abi_size; |
| 2785 | self.next_stack_offset = offset; | 2785 | self.next_stack_offset = offset; |
| 2786 | if (self.next_stack_offset > self.max_end_stack) | 2786 | if (self.next_stack_offset > self.max_end_stack) |
| 2787 | self.max_end_stack = self.next_stack_offset; | 2787 | self.max_end_stack = self.next_stack_offset; |
src/arch/wasm/CodeGen.zig+4-4| ... | @@ -1286,7 +1286,7 @@ fn genFunc(func: *CodeGen) InnerError!void { | ... | @@ -1286,7 +1286,7 @@ fn genFunc(func: *CodeGen) InnerError!void { |
| 1286 | // store stack pointer so we can restore it when we return from the function | 1286 | // store stack pointer so we can restore it when we return from the function |
| 1287 | try prologue.append(.{ .tag = .local_tee, .data = .{ .label = func.initial_stack_value.local.value } }); | 1287 | try prologue.append(.{ .tag = .local_tee, .data = .{ .label = func.initial_stack_value.local.value } }); |
| 1288 | // get the total stack size | 1288 | // get the total stack size |
| 1289 | const aligned_stack = std.mem.alignForwardGeneric(u32, func.stack_size, func.stack_alignment); | 1289 | const aligned_stack = std.mem.alignForward(u32, func.stack_size, func.stack_alignment); |
| 1290 | try prologue.append(.{ .tag = .i32_const, .data = .{ .imm32 = @intCast(i32, aligned_stack) } }); | 1290 | try prologue.append(.{ .tag = .i32_const, .data = .{ .imm32 = @intCast(i32, aligned_stack) } }); |
| 1291 | // substract it from the current stack pointer | 1291 | // substract it from the current stack pointer |
| 1292 | try prologue.append(.{ .tag = .i32_sub, .data = .{ .tag = {} } }); | 1292 | try prologue.append(.{ .tag = .i32_sub, .data = .{ .tag = {} } }); |
| ... | @@ -1531,7 +1531,7 @@ fn allocStack(func: *CodeGen, ty: Type) !WValue { | ... | @@ -1531,7 +1531,7 @@ fn allocStack(func: *CodeGen, ty: Type) !WValue { |
| 1531 | func.stack_alignment = abi_align; | 1531 | func.stack_alignment = abi_align; |
| 1532 | } | 1532 | } |
| 1533 | 1533 | ||
| 1534 | const offset = std.mem.alignForwardGeneric(u32, func.stack_size, abi_align); | 1534 | const offset = std.mem.alignForward(u32, func.stack_size, abi_align); |
| 1535 | defer func.stack_size = offset + abi_size; | 1535 | defer func.stack_size = offset + abi_size; |
| 1536 | 1536 | ||
| 1537 | return WValue{ .stack_offset = .{ .value = offset, .references = 1 } }; | 1537 | return WValue{ .stack_offset = .{ .value = offset, .references = 1 } }; |
| ... | @@ -1564,7 +1564,7 @@ fn allocStackPtr(func: *CodeGen, inst: Air.Inst.Index) !WValue { | ... | @@ -1564,7 +1564,7 @@ fn allocStackPtr(func: *CodeGen, inst: Air.Inst.Index) !WValue { |
| 1564 | func.stack_alignment = abi_alignment; | 1564 | func.stack_alignment = abi_alignment; |
| 1565 | } | 1565 | } |
| 1566 | 1566 | ||
| 1567 | const offset = std.mem.alignForwardGeneric(u32, func.stack_size, abi_alignment); | 1567 | const offset = std.mem.alignForward(u32, func.stack_size, abi_alignment); |
| 1568 | defer func.stack_size = offset + abi_size; | 1568 | defer func.stack_size = offset + abi_size; |
| 1569 | 1569 | ||
| 1570 | return WValue{ .stack_offset = .{ .value = offset, .references = 1 } }; | 1570 | return WValue{ .stack_offset = .{ .value = offset, .references = 1 } }; |
| ... | @@ -2975,7 +2975,7 @@ fn lowerParentPtr(func: *CodeGen, ptr_val: Value, offset: u32) InnerError!WValue | ... | @@ -2975,7 +2975,7 @@ fn lowerParentPtr(func: *CodeGen, ptr_val: Value, offset: u32) InnerError!WValue |
| 2975 | if (layout.payload_align > layout.tag_align) break :blk 0; | 2975 | if (layout.payload_align > layout.tag_align) break :blk 0; |
| 2976 | 2976 | ||
| 2977 | // tag is stored first so calculate offset from where payload starts | 2977 | // tag is stored first so calculate offset from where payload starts |
| 2978 | break :blk @intCast(u32, std.mem.alignForwardGeneric(u64, layout.tag_size, layout.tag_align)); | 2978 | break :blk @intCast(u32, std.mem.alignForward(u64, layout.tag_size, layout.tag_align)); |
| 2979 | }, | 2979 | }, |
| 2980 | }, | 2980 | }, |
| 2981 | .Pointer => switch (parent_ty.ptrSize(mod)) { | 2981 | .Pointer => switch (parent_ty.ptrSize(mod)) { |
src/arch/x86_64/CodeGen.zig+5-5| ... | @@ -2150,7 +2150,7 @@ fn setFrameLoc( | ... | @@ -2150,7 +2150,7 @@ fn setFrameLoc( |
| 2150 | const frame_i = @enumToInt(frame_index); | 2150 | const frame_i = @enumToInt(frame_index); |
| 2151 | if (aligned) { | 2151 | if (aligned) { |
| 2152 | const alignment = @as(i32, 1) << self.frame_allocs.items(.abi_align)[frame_i]; | 2152 | const alignment = @as(i32, 1) << self.frame_allocs.items(.abi_align)[frame_i]; |
| 2153 | offset.* = mem.alignForwardGeneric(i32, offset.*, alignment); | 2153 | offset.* = mem.alignForward(i32, offset.*, alignment); |
| 2154 | } | 2154 | } |
| 2155 | self.frame_locs.set(frame_i, .{ .base = base, .disp = offset.* }); | 2155 | self.frame_locs.set(frame_i, .{ .base = base, .disp = offset.* }); |
| 2156 | offset.* += self.frame_allocs.items(.abi_size)[frame_i]; | 2156 | offset.* += self.frame_allocs.items(.abi_size)[frame_i]; |
| ... | @@ -2207,7 +2207,7 @@ fn computeFrameLayout(self: *Self) !FrameLayout { | ... | @@ -2207,7 +2207,7 @@ fn computeFrameLayout(self: *Self) !FrameLayout { |
| 2207 | self.setFrameLoc(.stack_frame, .rsp, &rsp_offset, true); | 2207 | self.setFrameLoc(.stack_frame, .rsp, &rsp_offset, true); |
| 2208 | for (stack_frame_order) |frame_index| self.setFrameLoc(frame_index, .rsp, &rsp_offset, true); | 2208 | for (stack_frame_order) |frame_index| self.setFrameLoc(frame_index, .rsp, &rsp_offset, true); |
| 2209 | rsp_offset += stack_frame_align_offset; | 2209 | rsp_offset += stack_frame_align_offset; |
| 2210 | rsp_offset = mem.alignForwardGeneric(i32, rsp_offset, @as(i32, 1) << needed_align); | 2210 | rsp_offset = mem.alignForward(i32, rsp_offset, @as(i32, 1) << needed_align); |
| 2211 | rsp_offset -= stack_frame_align_offset; | 2211 | rsp_offset -= stack_frame_align_offset; |
| 2212 | frame_size[@enumToInt(FrameIndex.call_frame)] = | 2212 | frame_size[@enumToInt(FrameIndex.call_frame)] = |
| 2213 | @intCast(u31, rsp_offset - frame_offset[@enumToInt(FrameIndex.stack_frame)]); | 2213 | @intCast(u31, rsp_offset - frame_offset[@enumToInt(FrameIndex.stack_frame)]); |
| ... | @@ -11807,7 +11807,7 @@ fn resolveCallingConventionValues( | ... | @@ -11807,7 +11807,7 @@ fn resolveCallingConventionValues( |
| 11807 | const param_size = @intCast(u31, ty.abiSize(mod)); | 11807 | const param_size = @intCast(u31, ty.abiSize(mod)); |
| 11808 | const param_align = @intCast(u31, ty.abiAlignment(mod)); | 11808 | const param_align = @intCast(u31, ty.abiAlignment(mod)); |
| 11809 | result.stack_byte_count = | 11809 | result.stack_byte_count = |
| 11810 | mem.alignForwardGeneric(u31, result.stack_byte_count, param_align); | 11810 | mem.alignForward(u31, result.stack_byte_count, param_align); |
| 11811 | arg.* = .{ .load_frame = .{ | 11811 | arg.* = .{ .load_frame = .{ |
| 11812 | .index = stack_frame_base, | 11812 | .index = stack_frame_base, |
| 11813 | .off = result.stack_byte_count, | 11813 | .off = result.stack_byte_count, |
| ... | @@ -11847,7 +11847,7 @@ fn resolveCallingConventionValues( | ... | @@ -11847,7 +11847,7 @@ fn resolveCallingConventionValues( |
| 11847 | const param_size = @intCast(u31, ty.abiSize(mod)); | 11847 | const param_size = @intCast(u31, ty.abiSize(mod)); |
| 11848 | const param_align = @intCast(u31, ty.abiAlignment(mod)); | 11848 | const param_align = @intCast(u31, ty.abiAlignment(mod)); |
| 11849 | result.stack_byte_count = | 11849 | result.stack_byte_count = |
| 11850 | mem.alignForwardGeneric(u31, result.stack_byte_count, param_align); | 11850 | mem.alignForward(u31, result.stack_byte_count, param_align); |
| 11851 | arg.* = .{ .load_frame = .{ | 11851 | arg.* = .{ .load_frame = .{ |
| 11852 | .index = stack_frame_base, | 11852 | .index = stack_frame_base, |
| 11853 | .off = result.stack_byte_count, | 11853 | .off = result.stack_byte_count, |
| ... | @@ -11858,7 +11858,7 @@ fn resolveCallingConventionValues( | ... | @@ -11858,7 +11858,7 @@ fn resolveCallingConventionValues( |
| 11858 | else => return self.fail("TODO implement function parameters and return values for {} on x86_64", .{cc}), | 11858 | else => return self.fail("TODO implement function parameters and return values for {} on x86_64", .{cc}), |
| 11859 | } | 11859 | } |
| 11860 | 11860 | ||
| 11861 | result.stack_byte_count = mem.alignForwardGeneric(u31, result.stack_byte_count, result.stack_align); | 11861 | result.stack_byte_count = mem.alignForward(u31, result.stack_byte_count, result.stack_align); |
| 11862 | return result; | 11862 | return result; |
| 11863 | } | 11863 | } |
| 11864 | 11864 |
src/codegen.zig+4-4| ... | @@ -290,7 +290,7 @@ pub fn generateSymbol( | ... | @@ -290,7 +290,7 @@ pub fn generateSymbol( |
| 290 | .fail => |em| return .{ .fail = em }, | 290 | .fail => |em| return .{ .fail = em }, |
| 291 | } | 291 | } |
| 292 | const unpadded_end = code.items.len - begin; | 292 | const unpadded_end = code.items.len - begin; |
| 293 | const padded_end = mem.alignForwardGeneric(u64, unpadded_end, abi_align); | 293 | const padded_end = mem.alignForward(u64, unpadded_end, abi_align); |
| 294 | const padding = math.cast(usize, padded_end - unpadded_end) orelse return error.Overflow; | 294 | const padding = math.cast(usize, padded_end - unpadded_end) orelse return error.Overflow; |
| 295 | 295 | ||
| 296 | if (padding > 0) { | 296 | if (padding > 0) { |
| ... | @@ -303,7 +303,7 @@ pub fn generateSymbol( | ... | @@ -303,7 +303,7 @@ pub fn generateSymbol( |
| 303 | const begin = code.items.len; | 303 | const begin = code.items.len; |
| 304 | try code.writer().writeInt(u16, err_val, endian); | 304 | try code.writer().writeInt(u16, err_val, endian); |
| 305 | const unpadded_end = code.items.len - begin; | 305 | const unpadded_end = code.items.len - begin; |
| 306 | const padded_end = mem.alignForwardGeneric(u64, unpadded_end, abi_align); | 306 | const padded_end = mem.alignForward(u64, unpadded_end, abi_align); |
| 307 | const padding = math.cast(usize, padded_end - unpadded_end) orelse return error.Overflow; | 307 | const padding = math.cast(usize, padded_end - unpadded_end) orelse return error.Overflow; |
| 308 | 308 | ||
| 309 | if (padding > 0) { | 309 | if (padding > 0) { |
| ... | @@ -1020,7 +1020,7 @@ pub fn errUnionPayloadOffset(payload_ty: Type, mod: *Module) u64 { | ... | @@ -1020,7 +1020,7 @@ pub fn errUnionPayloadOffset(payload_ty: Type, mod: *Module) u64 { |
| 1020 | if (payload_align >= error_align or !payload_ty.hasRuntimeBitsIgnoreComptime(mod)) { | 1020 | if (payload_align >= error_align or !payload_ty.hasRuntimeBitsIgnoreComptime(mod)) { |
| 1021 | return 0; | 1021 | return 0; |
| 1022 | } else { | 1022 | } else { |
| 1023 | return mem.alignForwardGeneric(u64, Type.anyerror.abiSize(mod), payload_align); | 1023 | return mem.alignForward(u64, Type.anyerror.abiSize(mod), payload_align); |
| 1024 | } | 1024 | } |
| 1025 | } | 1025 | } |
| 1026 | 1026 | ||
| ... | @@ -1029,7 +1029,7 @@ pub fn errUnionErrorOffset(payload_ty: Type, mod: *Module) u64 { | ... | @@ -1029,7 +1029,7 @@ pub fn errUnionErrorOffset(payload_ty: Type, mod: *Module) u64 { |
| 1029 | const payload_align = payload_ty.abiAlignment(mod); | 1029 | const payload_align = payload_ty.abiAlignment(mod); |
| 1030 | const error_align = Type.anyerror.abiAlignment(mod); | 1030 | const error_align = Type.anyerror.abiAlignment(mod); |
| 1031 | if (payload_align >= error_align and payload_ty.hasRuntimeBitsIgnoreComptime(mod)) { | 1031 | if (payload_align >= error_align and payload_ty.hasRuntimeBitsIgnoreComptime(mod)) { |
| 1032 | return mem.alignForwardGeneric(u64, payload_ty.abiSize(mod), error_align); | 1032 | return mem.alignForward(u64, payload_ty.abiSize(mod), error_align); |
| 1033 | } else { | 1033 | } else { |
| 1034 | return 0; | 1034 | return 0; |
| 1035 | } | 1035 | } |
src/codegen/llvm.zig+22-22| ... | @@ -1633,7 +1633,7 @@ pub const Object = struct { | ... | @@ -1633,7 +1633,7 @@ pub const Object = struct { |
| 1633 | 1633 | ||
| 1634 | var offset: u64 = 0; | 1634 | var offset: u64 = 0; |
| 1635 | offset += ptr_size; | 1635 | offset += ptr_size; |
| 1636 | offset = std.mem.alignForwardGeneric(u64, offset, len_align); | 1636 | offset = std.mem.alignForward(u64, offset, len_align); |
| 1637 | const len_offset = offset; | 1637 | const len_offset = offset; |
| 1638 | 1638 | ||
| 1639 | const fields: [2]*llvm.DIType = .{ | 1639 | const fields: [2]*llvm.DIType = .{ |
| ... | @@ -1801,7 +1801,7 @@ pub const Object = struct { | ... | @@ -1801,7 +1801,7 @@ pub const Object = struct { |
| 1801 | 1801 | ||
| 1802 | var offset: u64 = 0; | 1802 | var offset: u64 = 0; |
| 1803 | offset += payload_size; | 1803 | offset += payload_size; |
| 1804 | offset = std.mem.alignForwardGeneric(u64, offset, non_null_align); | 1804 | offset = std.mem.alignForward(u64, offset, non_null_align); |
| 1805 | const non_null_offset = offset; | 1805 | const non_null_offset = offset; |
| 1806 | 1806 | ||
| 1807 | const fields: [2]*llvm.DIType = .{ | 1807 | const fields: [2]*llvm.DIType = .{ |
| ... | @@ -1888,12 +1888,12 @@ pub const Object = struct { | ... | @@ -1888,12 +1888,12 @@ pub const Object = struct { |
| 1888 | error_index = 0; | 1888 | error_index = 0; |
| 1889 | payload_index = 1; | 1889 | payload_index = 1; |
| 1890 | error_offset = 0; | 1890 | error_offset = 0; |
| 1891 | payload_offset = std.mem.alignForwardGeneric(u64, error_size, payload_align); | 1891 | payload_offset = std.mem.alignForward(u64, error_size, payload_align); |
| 1892 | } else { | 1892 | } else { |
| 1893 | payload_index = 0; | 1893 | payload_index = 0; |
| 1894 | error_index = 1; | 1894 | error_index = 1; |
| 1895 | payload_offset = 0; | 1895 | payload_offset = 0; |
| 1896 | error_offset = std.mem.alignForwardGeneric(u64, payload_size, error_align); | 1896 | error_offset = std.mem.alignForward(u64, payload_size, error_align); |
| 1897 | } | 1897 | } |
| 1898 | 1898 | ||
| 1899 | var fields: [2]*llvm.DIType = undefined; | 1899 | var fields: [2]*llvm.DIType = undefined; |
| ... | @@ -1995,7 +1995,7 @@ pub const Object = struct { | ... | @@ -1995,7 +1995,7 @@ pub const Object = struct { |
| 1995 | 1995 | ||
| 1996 | const field_size = field_ty.toType().abiSize(mod); | 1996 | const field_size = field_ty.toType().abiSize(mod); |
| 1997 | const field_align = field_ty.toType().abiAlignment(mod); | 1997 | const field_align = field_ty.toType().abiAlignment(mod); |
| 1998 | const field_offset = std.mem.alignForwardGeneric(u64, offset, field_align); | 1998 | const field_offset = std.mem.alignForward(u64, offset, field_align); |
| 1999 | offset = field_offset + field_size; | 1999 | offset = field_offset + field_size; |
| 2000 | 2000 | ||
| 2001 | const field_name = if (tuple.names.len != 0) | 2001 | const field_name = if (tuple.names.len != 0) |
| ... | @@ -2086,7 +2086,7 @@ pub const Object = struct { | ... | @@ -2086,7 +2086,7 @@ pub const Object = struct { |
| 2086 | const field = field_and_index.field; | 2086 | const field = field_and_index.field; |
| 2087 | const field_size = field.ty.abiSize(mod); | 2087 | const field_size = field.ty.abiSize(mod); |
| 2088 | const field_align = field.alignment(mod, layout); | 2088 | const field_align = field.alignment(mod, layout); |
| 2089 | const field_offset = std.mem.alignForwardGeneric(u64, offset, field_align); | 2089 | const field_offset = std.mem.alignForward(u64, offset, field_align); |
| 2090 | offset = field_offset + field_size; | 2090 | offset = field_offset + field_size; |
| 2091 | 2091 | ||
| 2092 | const field_name = mod.intern_pool.stringToSlice(fields.keys()[field_and_index.index]); | 2092 | const field_name = mod.intern_pool.stringToSlice(fields.keys()[field_and_index.index]); |
| ... | @@ -2242,10 +2242,10 @@ pub const Object = struct { | ... | @@ -2242,10 +2242,10 @@ pub const Object = struct { |
| 2242 | var payload_offset: u64 = undefined; | 2242 | var payload_offset: u64 = undefined; |
| 2243 | if (layout.tag_align >= layout.payload_align) { | 2243 | if (layout.tag_align >= layout.payload_align) { |
| 2244 | tag_offset = 0; | 2244 | tag_offset = 0; |
| 2245 | payload_offset = std.mem.alignForwardGeneric(u64, layout.tag_size, layout.payload_align); | 2245 | payload_offset = std.mem.alignForward(u64, layout.tag_size, layout.payload_align); |
| 2246 | } else { | 2246 | } else { |
| 2247 | payload_offset = 0; | 2247 | payload_offset = 0; |
| 2248 | tag_offset = std.mem.alignForwardGeneric(u64, layout.payload_size, layout.tag_align); | 2248 | tag_offset = std.mem.alignForward(u64, layout.payload_size, layout.tag_align); |
| 2249 | } | 2249 | } |
| 2250 | 2250 | ||
| 2251 | const tag_di = dib.createMemberType( | 2251 | const tag_di = dib.createMemberType( |
| ... | @@ -2861,9 +2861,9 @@ pub const DeclGen = struct { | ... | @@ -2861,9 +2861,9 @@ pub const DeclGen = struct { |
| 2861 | fields_buf[0] = llvm_error_type; | 2861 | fields_buf[0] = llvm_error_type; |
| 2862 | fields_buf[1] = llvm_payload_type; | 2862 | fields_buf[1] = llvm_payload_type; |
| 2863 | const payload_end = | 2863 | const payload_end = |
| 2864 | std.mem.alignForwardGeneric(u64, error_size, payload_align) + | 2864 | std.mem.alignForward(u64, error_size, payload_align) + |
| 2865 | payload_size; | 2865 | payload_size; |
| 2866 | const abi_size = std.mem.alignForwardGeneric(u64, payload_end, error_align); | 2866 | const abi_size = std.mem.alignForward(u64, payload_end, error_align); |
| 2867 | const padding = @intCast(c_uint, abi_size - payload_end); | 2867 | const padding = @intCast(c_uint, abi_size - payload_end); |
| 2868 | if (padding == 0) { | 2868 | if (padding == 0) { |
| 2869 | return dg.context.structType(&fields_buf, 2, .False); | 2869 | return dg.context.structType(&fields_buf, 2, .False); |
| ... | @@ -2874,9 +2874,9 @@ pub const DeclGen = struct { | ... | @@ -2874,9 +2874,9 @@ pub const DeclGen = struct { |
| 2874 | fields_buf[0] = llvm_payload_type; | 2874 | fields_buf[0] = llvm_payload_type; |
| 2875 | fields_buf[1] = llvm_error_type; | 2875 | fields_buf[1] = llvm_error_type; |
| 2876 | const error_end = | 2876 | const error_end = |
| 2877 | std.mem.alignForwardGeneric(u64, payload_size, error_align) + | 2877 | std.mem.alignForward(u64, payload_size, error_align) + |
| 2878 | error_size; | 2878 | error_size; |
| 2879 | const abi_size = std.mem.alignForwardGeneric(u64, error_end, payload_align); | 2879 | const abi_size = std.mem.alignForward(u64, error_end, payload_align); |
| 2880 | const padding = @intCast(c_uint, abi_size - error_end); | 2880 | const padding = @intCast(c_uint, abi_size - error_end); |
| 2881 | if (padding == 0) { | 2881 | if (padding == 0) { |
| 2882 | return dg.context.structType(&fields_buf, 2, .False); | 2882 | return dg.context.structType(&fields_buf, 2, .False); |
| ... | @@ -2910,7 +2910,7 @@ pub const DeclGen = struct { | ... | @@ -2910,7 +2910,7 @@ pub const DeclGen = struct { |
| 2910 | const field_align = field_ty.toType().abiAlignment(mod); | 2910 | const field_align = field_ty.toType().abiAlignment(mod); |
| 2911 | big_align = @max(big_align, field_align); | 2911 | big_align = @max(big_align, field_align); |
| 2912 | const prev_offset = offset; | 2912 | const prev_offset = offset; |
| 2913 | offset = std.mem.alignForwardGeneric(u64, offset, field_align); | 2913 | offset = std.mem.alignForward(u64, offset, field_align); |
| 2914 | 2914 | ||
| 2915 | const padding_len = offset - prev_offset; | 2915 | const padding_len = offset - prev_offset; |
| 2916 | if (padding_len > 0) { | 2916 | if (padding_len > 0) { |
| ... | @@ -2924,7 +2924,7 @@ pub const DeclGen = struct { | ... | @@ -2924,7 +2924,7 @@ pub const DeclGen = struct { |
| 2924 | } | 2924 | } |
| 2925 | { | 2925 | { |
| 2926 | const prev_offset = offset; | 2926 | const prev_offset = offset; |
| 2927 | offset = std.mem.alignForwardGeneric(u64, offset, big_align); | 2927 | offset = std.mem.alignForward(u64, offset, big_align); |
| 2928 | const padding_len = offset - prev_offset; | 2928 | const padding_len = offset - prev_offset; |
| 2929 | if (padding_len > 0) { | 2929 | if (padding_len > 0) { |
| 2930 | const llvm_array_ty = dg.context.intType(8).arrayType(@intCast(c_uint, padding_len)); | 2930 | const llvm_array_ty = dg.context.intType(8).arrayType(@intCast(c_uint, padding_len)); |
| ... | @@ -2979,7 +2979,7 @@ pub const DeclGen = struct { | ... | @@ -2979,7 +2979,7 @@ pub const DeclGen = struct { |
| 2979 | field_align < field_ty_align; | 2979 | field_align < field_ty_align; |
| 2980 | big_align = @max(big_align, field_align); | 2980 | big_align = @max(big_align, field_align); |
| 2981 | const prev_offset = offset; | 2981 | const prev_offset = offset; |
| 2982 | offset = std.mem.alignForwardGeneric(u64, offset, field_align); | 2982 | offset = std.mem.alignForward(u64, offset, field_align); |
| 2983 | 2983 | ||
| 2984 | const padding_len = offset - prev_offset; | 2984 | const padding_len = offset - prev_offset; |
| 2985 | if (padding_len > 0) { | 2985 | if (padding_len > 0) { |
| ... | @@ -2993,7 +2993,7 @@ pub const DeclGen = struct { | ... | @@ -2993,7 +2993,7 @@ pub const DeclGen = struct { |
| 2993 | } | 2993 | } |
| 2994 | { | 2994 | { |
| 2995 | const prev_offset = offset; | 2995 | const prev_offset = offset; |
| 2996 | offset = std.mem.alignForwardGeneric(u64, offset, big_align); | 2996 | offset = std.mem.alignForward(u64, offset, big_align); |
| 2997 | const padding_len = offset - prev_offset; | 2997 | const padding_len = offset - prev_offset; |
| 2998 | if (padding_len > 0) { | 2998 | if (padding_len > 0) { |
| 2999 | const llvm_array_ty = dg.context.intType(8).arrayType(@intCast(c_uint, padding_len)); | 2999 | const llvm_array_ty = dg.context.intType(8).arrayType(@intCast(c_uint, padding_len)); |
| ... | @@ -3552,7 +3552,7 @@ pub const DeclGen = struct { | ... | @@ -3552,7 +3552,7 @@ pub const DeclGen = struct { |
| 3552 | const field_align = field_ty.toType().abiAlignment(mod); | 3552 | const field_align = field_ty.toType().abiAlignment(mod); |
| 3553 | big_align = @max(big_align, field_align); | 3553 | big_align = @max(big_align, field_align); |
| 3554 | const prev_offset = offset; | 3554 | const prev_offset = offset; |
| 3555 | offset = std.mem.alignForwardGeneric(u64, offset, field_align); | 3555 | offset = std.mem.alignForward(u64, offset, field_align); |
| 3556 | 3556 | ||
| 3557 | const padding_len = offset - prev_offset; | 3557 | const padding_len = offset - prev_offset; |
| 3558 | if (padding_len > 0) { | 3558 | if (padding_len > 0) { |
| ... | @@ -3575,7 +3575,7 @@ pub const DeclGen = struct { | ... | @@ -3575,7 +3575,7 @@ pub const DeclGen = struct { |
| 3575 | } | 3575 | } |
| 3576 | { | 3576 | { |
| 3577 | const prev_offset = offset; | 3577 | const prev_offset = offset; |
| 3578 | offset = std.mem.alignForwardGeneric(u64, offset, big_align); | 3578 | offset = std.mem.alignForward(u64, offset, big_align); |
| 3579 | const padding_len = offset - prev_offset; | 3579 | const padding_len = offset - prev_offset; |
| 3580 | if (padding_len > 0) { | 3580 | if (padding_len > 0) { |
| 3581 | const llvm_array_ty = dg.context.intType(8).arrayType(@intCast(c_uint, padding_len)); | 3581 | const llvm_array_ty = dg.context.intType(8).arrayType(@intCast(c_uint, padding_len)); |
| ... | @@ -3650,7 +3650,7 @@ pub const DeclGen = struct { | ... | @@ -3650,7 +3650,7 @@ pub const DeclGen = struct { |
| 3650 | const field_align = field.alignment(mod, struct_obj.layout); | 3650 | const field_align = field.alignment(mod, struct_obj.layout); |
| 3651 | big_align = @max(big_align, field_align); | 3651 | big_align = @max(big_align, field_align); |
| 3652 | const prev_offset = offset; | 3652 | const prev_offset = offset; |
| 3653 | offset = std.mem.alignForwardGeneric(u64, offset, field_align); | 3653 | offset = std.mem.alignForward(u64, offset, field_align); |
| 3654 | 3654 | ||
| 3655 | const padding_len = offset - prev_offset; | 3655 | const padding_len = offset - prev_offset; |
| 3656 | if (padding_len > 0) { | 3656 | if (padding_len > 0) { |
| ... | @@ -3673,7 +3673,7 @@ pub const DeclGen = struct { | ... | @@ -3673,7 +3673,7 @@ pub const DeclGen = struct { |
| 3673 | } | 3673 | } |
| 3674 | { | 3674 | { |
| 3675 | const prev_offset = offset; | 3675 | const prev_offset = offset; |
| 3676 | offset = std.mem.alignForwardGeneric(u64, offset, big_align); | 3676 | offset = std.mem.alignForward(u64, offset, big_align); |
| 3677 | const padding_len = offset - prev_offset; | 3677 | const padding_len = offset - prev_offset; |
| 3678 | if (padding_len > 0) { | 3678 | if (padding_len > 0) { |
| 3679 | const llvm_array_ty = dg.context.intType(8).arrayType(@intCast(c_uint, padding_len)); | 3679 | const llvm_array_ty = dg.context.intType(8).arrayType(@intCast(c_uint, padding_len)); |
| ... | @@ -10274,7 +10274,7 @@ fn llvmField(ty: Type, field_index: usize, mod: *Module) ?LlvmField { | ... | @@ -10274,7 +10274,7 @@ fn llvmField(ty: Type, field_index: usize, mod: *Module) ?LlvmField { |
| 10274 | const field_align = field_ty.toType().abiAlignment(mod); | 10274 | const field_align = field_ty.toType().abiAlignment(mod); |
| 10275 | big_align = @max(big_align, field_align); | 10275 | big_align = @max(big_align, field_align); |
| 10276 | const prev_offset = offset; | 10276 | const prev_offset = offset; |
| 10277 | offset = std.mem.alignForwardGeneric(u64, offset, field_align); | 10277 | offset = std.mem.alignForward(u64, offset, field_align); |
| 10278 | 10278 | ||
| 10279 | const padding_len = offset - prev_offset; | 10279 | const padding_len = offset - prev_offset; |
| 10280 | if (padding_len > 0) { | 10280 | if (padding_len > 0) { |
| ... | @@ -10308,7 +10308,7 @@ fn llvmField(ty: Type, field_index: usize, mod: *Module) ?LlvmField { | ... | @@ -10308,7 +10308,7 @@ fn llvmField(ty: Type, field_index: usize, mod: *Module) ?LlvmField { |
| 10308 | const field_align = field.alignment(mod, layout); | 10308 | const field_align = field.alignment(mod, layout); |
| 10309 | big_align = @max(big_align, field_align); | 10309 | big_align = @max(big_align, field_align); |
| 10310 | const prev_offset = offset; | 10310 | const prev_offset = offset; |
| 10311 | offset = std.mem.alignForwardGeneric(u64, offset, field_align); | 10311 | offset = std.mem.alignForward(u64, offset, field_align); |
| 10312 | 10312 | ||
| 10313 | const padding_len = offset - prev_offset; | 10313 | const padding_len = offset - prev_offset; |
| 10314 | if (padding_len > 0) { | 10314 | if (padding_len > 0) { |
src/codegen/spirv.zig+2-2| ... | @@ -472,12 +472,12 @@ pub const DeclGen = struct { | ... | @@ -472,12 +472,12 @@ pub const DeclGen = struct { |
| 472 | try self.initializers.append(result_id); | 472 | try self.initializers.append(result_id); |
| 473 | 473 | ||
| 474 | self.partial_word.len = 0; | 474 | self.partial_word.len = 0; |
| 475 | self.size = std.mem.alignForwardGeneric(u32, self.size, @sizeOf(Word)); | 475 | self.size = std.mem.alignForward(u32, self.size, @sizeOf(Word)); |
| 476 | } | 476 | } |
| 477 | 477 | ||
| 478 | /// Fill the buffer with undefined values until the size is aligned to `align`. | 478 | /// Fill the buffer with undefined values until the size is aligned to `align`. |
| 479 | fn fillToAlign(self: *@This(), alignment: u32) !void { | 479 | fn fillToAlign(self: *@This(), alignment: u32) !void { |
| 480 | const target_size = std.mem.alignForwardGeneric(u32, self.size, alignment); | 480 | const target_size = std.mem.alignForward(u32, self.size, alignment); |
| 481 | try self.addUndef(target_size - self.size); | 481 | try self.addUndef(target_size - self.size); |
| 482 | } | 482 | } |
| 483 | 483 |
src/link/Coff.zig+15-15| ... | @@ -437,10 +437,10 @@ fn allocateSection(self: *Coff, name: []const u8, size: u32, flags: coff.Section | ... | @@ -437,10 +437,10 @@ fn allocateSection(self: *Coff, name: []const u8, size: u32, flags: coff.Section |
| 437 | const vaddr = blk: { | 437 | const vaddr = blk: { |
| 438 | if (index == 0) break :blk self.page_size; | 438 | if (index == 0) break :blk self.page_size; |
| 439 | const prev_header = self.sections.items(.header)[index - 1]; | 439 | const prev_header = self.sections.items(.header)[index - 1]; |
| 440 | break :blk mem.alignForwardGeneric(u32, prev_header.virtual_address + prev_header.virtual_size, self.page_size); | 440 | break :blk mem.alignForward(u32, prev_header.virtual_address + prev_header.virtual_size, self.page_size); |
| 441 | }; | 441 | }; |
| 442 | // We commit more memory than needed upfront so that we don't have to reallocate too soon. | 442 | // We commit more memory than needed upfront so that we don't have to reallocate too soon. |
| 443 | const memsz = mem.alignForwardGeneric(u32, size, self.page_size) * 100; | 443 | const memsz = mem.alignForward(u32, size, self.page_size) * 100; |
| 444 | log.debug("found {s} free space 0x{x} to 0x{x} (0x{x} - 0x{x})", .{ | 444 | log.debug("found {s} free space 0x{x} to 0x{x} (0x{x} - 0x{x})", .{ |
| 445 | name, | 445 | name, |
| 446 | off, | 446 | off, |
| ... | @@ -505,8 +505,8 @@ fn growSection(self: *Coff, sect_id: u32, needed_size: u32) !void { | ... | @@ -505,8 +505,8 @@ fn growSection(self: *Coff, sect_id: u32, needed_size: u32) !void { |
| 505 | fn growSectionVirtualMemory(self: *Coff, sect_id: u32, needed_size: u32) !void { | 505 | fn growSectionVirtualMemory(self: *Coff, sect_id: u32, needed_size: u32) !void { |
| 506 | const header = &self.sections.items(.header)[sect_id]; | 506 | const header = &self.sections.items(.header)[sect_id]; |
| 507 | const increased_size = padToIdeal(needed_size); | 507 | const increased_size = padToIdeal(needed_size); |
| 508 | const old_aligned_end = header.virtual_address + mem.alignForwardGeneric(u32, header.virtual_size, self.page_size); | 508 | const old_aligned_end = header.virtual_address + mem.alignForward(u32, header.virtual_size, self.page_size); |
| 509 | const new_aligned_end = header.virtual_address + mem.alignForwardGeneric(u32, increased_size, self.page_size); | 509 | const new_aligned_end = header.virtual_address + mem.alignForward(u32, increased_size, self.page_size); |
| 510 | const diff = new_aligned_end - old_aligned_end; | 510 | const diff = new_aligned_end - old_aligned_end; |
| 511 | log.debug("growing {s} in virtual memory by {x}", .{ self.getSectionName(header), diff }); | 511 | log.debug("growing {s} in virtual memory by {x}", .{ self.getSectionName(header), diff }); |
| 512 | 512 | ||
| ... | @@ -567,7 +567,7 @@ fn allocateAtom(self: *Coff, atom_index: Atom.Index, new_atom_size: u32, alignme | ... | @@ -567,7 +567,7 @@ fn allocateAtom(self: *Coff, atom_index: Atom.Index, new_atom_size: u32, alignme |
| 567 | const ideal_capacity_end_vaddr = math.add(u32, sym.value, ideal_capacity) catch ideal_capacity; | 567 | const ideal_capacity_end_vaddr = math.add(u32, sym.value, ideal_capacity) catch ideal_capacity; |
| 568 | const capacity_end_vaddr = sym.value + capacity; | 568 | const capacity_end_vaddr = sym.value + capacity; |
| 569 | const new_start_vaddr_unaligned = capacity_end_vaddr - new_atom_ideal_capacity; | 569 | const new_start_vaddr_unaligned = capacity_end_vaddr - new_atom_ideal_capacity; |
| 570 | const new_start_vaddr = mem.alignBackwardGeneric(u32, new_start_vaddr_unaligned, alignment); | 570 | const new_start_vaddr = mem.alignBackward(u32, new_start_vaddr_unaligned, alignment); |
| 571 | if (new_start_vaddr < ideal_capacity_end_vaddr) { | 571 | if (new_start_vaddr < ideal_capacity_end_vaddr) { |
| 572 | // Additional bookkeeping here to notice if this free list node | 572 | // Additional bookkeeping here to notice if this free list node |
| 573 | // should be deleted because the atom that it points to has grown to take up | 573 | // should be deleted because the atom that it points to has grown to take up |
| ... | @@ -596,11 +596,11 @@ fn allocateAtom(self: *Coff, atom_index: Atom.Index, new_atom_size: u32, alignme | ... | @@ -596,11 +596,11 @@ fn allocateAtom(self: *Coff, atom_index: Atom.Index, new_atom_size: u32, alignme |
| 596 | const last_symbol = last.getSymbol(self); | 596 | const last_symbol = last.getSymbol(self); |
| 597 | const ideal_capacity = if (header.isCode()) padToIdeal(last.size) else last.size; | 597 | const ideal_capacity = if (header.isCode()) padToIdeal(last.size) else last.size; |
| 598 | const ideal_capacity_end_vaddr = last_symbol.value + ideal_capacity; | 598 | const ideal_capacity_end_vaddr = last_symbol.value + ideal_capacity; |
| 599 | const new_start_vaddr = mem.alignForwardGeneric(u32, ideal_capacity_end_vaddr, alignment); | 599 | const new_start_vaddr = mem.alignForward(u32, ideal_capacity_end_vaddr, alignment); |
| 600 | atom_placement = last_index; | 600 | atom_placement = last_index; |
| 601 | break :blk new_start_vaddr; | 601 | break :blk new_start_vaddr; |
| 602 | } else { | 602 | } else { |
| 603 | break :blk mem.alignForwardGeneric(u32, header.virtual_address, alignment); | 603 | break :blk mem.alignForward(u32, header.virtual_address, alignment); |
| 604 | } | 604 | } |
| 605 | }; | 605 | }; |
| 606 | 606 | ||
| ... | @@ -722,7 +722,7 @@ pub fn createAtom(self: *Coff) !Atom.Index { | ... | @@ -722,7 +722,7 @@ pub fn createAtom(self: *Coff) !Atom.Index { |
| 722 | fn growAtom(self: *Coff, atom_index: Atom.Index, new_atom_size: u32, alignment: u32) !u32 { | 722 | fn growAtom(self: *Coff, atom_index: Atom.Index, new_atom_size: u32, alignment: u32) !u32 { |
| 723 | const atom = self.getAtom(atom_index); | 723 | const atom = self.getAtom(atom_index); |
| 724 | const sym = atom.getSymbol(self); | 724 | const sym = atom.getSymbol(self); |
| 725 | const align_ok = mem.alignBackwardGeneric(u32, sym.value, alignment) == sym.value; | 725 | const align_ok = mem.alignBackward(u32, sym.value, alignment) == sym.value; |
| 726 | const need_realloc = !align_ok or new_atom_size > atom.capacity(self); | 726 | const need_realloc = !align_ok or new_atom_size > atom.capacity(self); |
| 727 | if (!need_realloc) return sym.value; | 727 | if (!need_realloc) return sym.value; |
| 728 | return self.allocateAtom(atom_index, new_atom_size, alignment); | 728 | return self.allocateAtom(atom_index, new_atom_size, alignment); |
| ... | @@ -1798,7 +1798,7 @@ fn writeBaseRelocations(self: *Coff) !void { | ... | @@ -1798,7 +1798,7 @@ fn writeBaseRelocations(self: *Coff) !void { |
| 1798 | 1798 | ||
| 1799 | for (offsets.items) |offset| { | 1799 | for (offsets.items) |offset| { |
| 1800 | const rva = sym.value + offset; | 1800 | const rva = sym.value + offset; |
| 1801 | const page = mem.alignBackwardGeneric(u32, rva, self.page_size); | 1801 | const page = mem.alignBackward(u32, rva, self.page_size); |
| 1802 | const gop = try page_table.getOrPut(page); | 1802 | const gop = try page_table.getOrPut(page); |
| 1803 | if (!gop.found_existing) { | 1803 | if (!gop.found_existing) { |
| 1804 | gop.value_ptr.* = std.ArrayList(coff.BaseRelocation).init(gpa); | 1804 | gop.value_ptr.* = std.ArrayList(coff.BaseRelocation).init(gpa); |
| ... | @@ -1819,7 +1819,7 @@ fn writeBaseRelocations(self: *Coff) !void { | ... | @@ -1819,7 +1819,7 @@ fn writeBaseRelocations(self: *Coff) !void { |
| 1819 | if (sym.section_number == .UNDEFINED) continue; | 1819 | if (sym.section_number == .UNDEFINED) continue; |
| 1820 | 1820 | ||
| 1821 | const rva = @intCast(u32, header.virtual_address + index * self.ptr_width.size()); | 1821 | const rva = @intCast(u32, header.virtual_address + index * self.ptr_width.size()); |
| 1822 | const page = mem.alignBackwardGeneric(u32, rva, self.page_size); | 1822 | const page = mem.alignBackward(u32, rva, self.page_size); |
| 1823 | const gop = try page_table.getOrPut(page); | 1823 | const gop = try page_table.getOrPut(page); |
| 1824 | if (!gop.found_existing) { | 1824 | if (!gop.found_existing) { |
| 1825 | gop.value_ptr.* = std.ArrayList(coff.BaseRelocation).init(gpa); | 1825 | gop.value_ptr.* = std.ArrayList(coff.BaseRelocation).init(gpa); |
| ... | @@ -1907,7 +1907,7 @@ fn writeImportTables(self: *Coff) !void { | ... | @@ -1907,7 +1907,7 @@ fn writeImportTables(self: *Coff) !void { |
| 1907 | lookup_table_size += @intCast(u32, itable.entries.items.len + 1) * @sizeOf(coff.ImportLookupEntry64.ByName); | 1907 | lookup_table_size += @intCast(u32, itable.entries.items.len + 1) * @sizeOf(coff.ImportLookupEntry64.ByName); |
| 1908 | for (itable.entries.items) |entry| { | 1908 | for (itable.entries.items) |entry| { |
| 1909 | const sym_name = self.getSymbolName(entry); | 1909 | const sym_name = self.getSymbolName(entry); |
| 1910 | names_table_size += 2 + mem.alignForwardGeneric(u32, @intCast(u32, sym_name.len + 1), 2); | 1910 | names_table_size += 2 + mem.alignForward(u32, @intCast(u32, sym_name.len + 1), 2); |
| 1911 | } | 1911 | } |
| 1912 | dll_names_size += @intCast(u32, lib_name.len + ext.len + 1); | 1912 | dll_names_size += @intCast(u32, lib_name.len + ext.len + 1); |
| 1913 | } | 1913 | } |
| ... | @@ -2102,7 +2102,7 @@ fn writeHeader(self: *Coff) !void { | ... | @@ -2102,7 +2102,7 @@ fn writeHeader(self: *Coff) !void { |
| 2102 | }; | 2102 | }; |
| 2103 | const subsystem: coff.Subsystem = .WINDOWS_CUI; | 2103 | const subsystem: coff.Subsystem = .WINDOWS_CUI; |
| 2104 | const size_of_image: u32 = self.getSizeOfImage(); | 2104 | const size_of_image: u32 = self.getSizeOfImage(); |
| 2105 | const size_of_headers: u32 = mem.alignForwardGeneric(u32, self.getSizeOfHeaders(), default_file_alignment); | 2105 | const size_of_headers: u32 = mem.alignForward(u32, self.getSizeOfHeaders(), default_file_alignment); |
| 2106 | const image_base = self.getImageBase(); | 2106 | const image_base = self.getImageBase(); |
| 2107 | 2107 | ||
| 2108 | const base_of_code = self.sections.get(self.text_section_index.?).header.virtual_address; | 2108 | const base_of_code = self.sections.get(self.text_section_index.?).header.virtual_address; |
| ... | @@ -2247,7 +2247,7 @@ fn allocatedSize(self: *Coff, start: u32) u32 { | ... | @@ -2247,7 +2247,7 @@ fn allocatedSize(self: *Coff, start: u32) u32 { |
| 2247 | fn findFreeSpace(self: *Coff, object_size: u32, min_alignment: u32) u32 { | 2247 | fn findFreeSpace(self: *Coff, object_size: u32, min_alignment: u32) u32 { |
| 2248 | var start: u32 = 0; | 2248 | var start: u32 = 0; |
| 2249 | while (self.detectAllocCollision(start, object_size)) |item_end| { | 2249 | while (self.detectAllocCollision(start, object_size)) |item_end| { |
| 2250 | start = mem.alignForwardGeneric(u32, item_end, min_alignment); | 2250 | start = mem.alignForward(u32, item_end, min_alignment); |
| 2251 | } | 2251 | } |
| 2252 | return start; | 2252 | return start; |
| 2253 | } | 2253 | } |
| ... | @@ -2294,9 +2294,9 @@ inline fn getSectionHeadersOffset(self: Coff) u32 { | ... | @@ -2294,9 +2294,9 @@ inline fn getSectionHeadersOffset(self: Coff) u32 { |
| 2294 | } | 2294 | } |
| 2295 | 2295 | ||
| 2296 | inline fn getSizeOfImage(self: Coff) u32 { | 2296 | inline fn getSizeOfImage(self: Coff) u32 { |
| 2297 | var image_size: u32 = mem.alignForwardGeneric(u32, self.getSizeOfHeaders(), self.page_size); | 2297 | var image_size: u32 = mem.alignForward(u32, self.getSizeOfHeaders(), self.page_size); |
| 2298 | for (self.sections.items(.header)) |header| { | 2298 | for (self.sections.items(.header)) |header| { |
| 2299 | image_size += mem.alignForwardGeneric(u32, header.virtual_size, self.page_size); | 2299 | image_size += mem.alignForward(u32, header.virtual_size, self.page_size); |
| 2300 | } | 2300 | } |
| 2301 | return image_size; | 2301 | return image_size; |
| 2302 | } | 2302 | } |
src/link/Dwarf.zig+1-1| ... | @@ -2152,7 +2152,7 @@ pub fn writeDbgAranges(self: *Dwarf, addr: u64, size: u64) !void { | ... | @@ -2152,7 +2152,7 @@ pub fn writeDbgAranges(self: *Dwarf, addr: u64, size: u64) !void { |
| 2152 | di_buf.appendAssumeCapacity(0); // segment_selector_size | 2152 | di_buf.appendAssumeCapacity(0); // segment_selector_size |
| 2153 | 2153 | ||
| 2154 | const end_header_offset = di_buf.items.len; | 2154 | const end_header_offset = di_buf.items.len; |
| 2155 | const begin_entries_offset = mem.alignForward(end_header_offset, ptr_width_bytes * 2); | 2155 | const begin_entries_offset = mem.alignForward(usize, end_header_offset, ptr_width_bytes * 2); |
| 2156 | di_buf.appendNTimesAssumeCapacity(0, begin_entries_offset - end_header_offset); | 2156 | di_buf.appendNTimesAssumeCapacity(0, begin_entries_offset - end_header_offset); |
| 2157 | 2157 | ||
| 2158 | // Currently only one compilation unit is supported, so the address range is simply | 2158 | // Currently only one compilation unit is supported, so the address range is simply |
src/link/Elf.zig+5-5| ... | @@ -439,7 +439,7 @@ pub fn allocatedSize(self: *Elf, start: u64) u64 { | ... | @@ -439,7 +439,7 @@ pub fn allocatedSize(self: *Elf, start: u64) u64 { |
| 439 | pub fn findFreeSpace(self: *Elf, object_size: u64, min_alignment: u32) u64 { | 439 | pub fn findFreeSpace(self: *Elf, object_size: u64, min_alignment: u32) u64 { |
| 440 | var start: u64 = 0; | 440 | var start: u64 = 0; |
| 441 | while (self.detectAllocCollision(start, object_size)) |item_end| { | 441 | while (self.detectAllocCollision(start, object_size)) |item_end| { |
| 442 | start = mem.alignForwardGeneric(u64, item_end, min_alignment); | 442 | start = mem.alignForward(u64, item_end, min_alignment); |
| 443 | } | 443 | } |
| 444 | return start; | 444 | return start; |
| 445 | } | 445 | } |
| ... | @@ -1173,7 +1173,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node | ... | @@ -1173,7 +1173,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1173 | phdr_table.p_offset = self.findFreeSpace(needed_size, @intCast(u32, phdr_table.p_align)); | 1173 | phdr_table.p_offset = self.findFreeSpace(needed_size, @intCast(u32, phdr_table.p_align)); |
| 1174 | } | 1174 | } |
| 1175 | 1175 | ||
| 1176 | phdr_table_load.p_offset = mem.alignBackwardGeneric(u64, phdr_table.p_offset, phdr_table_load.p_align); | 1176 | phdr_table_load.p_offset = mem.alignBackward(u64, phdr_table.p_offset, phdr_table_load.p_align); |
| 1177 | const load_align_offset = phdr_table.p_offset - phdr_table_load.p_offset; | 1177 | const load_align_offset = phdr_table.p_offset - phdr_table_load.p_offset; |
| 1178 | phdr_table_load.p_filesz = load_align_offset + needed_size; | 1178 | phdr_table_load.p_filesz = load_align_offset + needed_size; |
| 1179 | phdr_table_load.p_memsz = load_align_offset + needed_size; | 1179 | phdr_table_load.p_memsz = load_align_offset + needed_size; |
| ... | @@ -2215,7 +2215,7 @@ fn shrinkAtom(self: *Elf, atom_index: Atom.Index, new_block_size: u64) void { | ... | @@ -2215,7 +2215,7 @@ fn shrinkAtom(self: *Elf, atom_index: Atom.Index, new_block_size: u64) void { |
| 2215 | fn growAtom(self: *Elf, atom_index: Atom.Index, new_block_size: u64, alignment: u64) !u64 { | 2215 | fn growAtom(self: *Elf, atom_index: Atom.Index, new_block_size: u64, alignment: u64) !u64 { |
| 2216 | const atom = self.getAtom(atom_index); | 2216 | const atom = self.getAtom(atom_index); |
| 2217 | const sym = atom.getSymbol(self); | 2217 | const sym = atom.getSymbol(self); |
| 2218 | const align_ok = mem.alignBackwardGeneric(u64, sym.st_value, alignment) == sym.st_value; | 2218 | const align_ok = mem.alignBackward(u64, sym.st_value, alignment) == sym.st_value; |
| 2219 | const need_realloc = !align_ok or new_block_size > atom.capacity(self); | 2219 | const need_realloc = !align_ok or new_block_size > atom.capacity(self); |
| 2220 | if (!need_realloc) return sym.st_value; | 2220 | if (!need_realloc) return sym.st_value; |
| 2221 | return self.allocateAtom(atom_index, new_block_size, alignment); | 2221 | return self.allocateAtom(atom_index, new_block_size, alignment); |
| ... | @@ -2269,7 +2269,7 @@ fn allocateAtom(self: *Elf, atom_index: Atom.Index, new_block_size: u64, alignme | ... | @@ -2269,7 +2269,7 @@ fn allocateAtom(self: *Elf, atom_index: Atom.Index, new_block_size: u64, alignme |
| 2269 | const ideal_capacity_end_vaddr = std.math.add(u64, big_atom_sym.st_value, ideal_capacity) catch ideal_capacity; | 2269 | const ideal_capacity_end_vaddr = std.math.add(u64, big_atom_sym.st_value, ideal_capacity) catch ideal_capacity; |
| 2270 | const capacity_end_vaddr = big_atom_sym.st_value + capacity; | 2270 | const capacity_end_vaddr = big_atom_sym.st_value + capacity; |
| 2271 | const new_start_vaddr_unaligned = capacity_end_vaddr - new_atom_ideal_capacity; | 2271 | const new_start_vaddr_unaligned = capacity_end_vaddr - new_atom_ideal_capacity; |
| 2272 | const new_start_vaddr = mem.alignBackwardGeneric(u64, new_start_vaddr_unaligned, alignment); | 2272 | const new_start_vaddr = mem.alignBackward(u64, new_start_vaddr_unaligned, alignment); |
| 2273 | if (new_start_vaddr < ideal_capacity_end_vaddr) { | 2273 | if (new_start_vaddr < ideal_capacity_end_vaddr) { |
| 2274 | // Additional bookkeeping here to notice if this free list node | 2274 | // Additional bookkeeping here to notice if this free list node |
| 2275 | // should be deleted because the block that it points to has grown to take up | 2275 | // should be deleted because the block that it points to has grown to take up |
| ... | @@ -2298,7 +2298,7 @@ fn allocateAtom(self: *Elf, atom_index: Atom.Index, new_block_size: u64, alignme | ... | @@ -2298,7 +2298,7 @@ fn allocateAtom(self: *Elf, atom_index: Atom.Index, new_block_size: u64, alignme |
| 2298 | const last_sym = last.getSymbol(self); | 2298 | const last_sym = last.getSymbol(self); |
| 2299 | const ideal_capacity = padToIdeal(last_sym.st_size); | 2299 | const ideal_capacity = padToIdeal(last_sym.st_size); |
| 2300 | const ideal_capacity_end_vaddr = last_sym.st_value + ideal_capacity; | 2300 | const ideal_capacity_end_vaddr = last_sym.st_value + ideal_capacity; |
| 2301 | const new_start_vaddr = mem.alignForwardGeneric(u64, ideal_capacity_end_vaddr, alignment); | 2301 | const new_start_vaddr = mem.alignForward(u64, ideal_capacity_end_vaddr, alignment); |
| 2302 | // Set up the metadata to be updated, after errors are no longer possible. | 2302 | // Set up the metadata to be updated, after errors are no longer possible. |
| 2303 | atom_placement = last_index; | 2303 | atom_placement = last_index; |
| 2304 | break :blk new_start_vaddr; | 2304 | break :blk new_start_vaddr; |
src/link/MachO.zig+25-25| ... | @@ -1777,7 +1777,7 @@ fn shrinkAtom(self: *MachO, atom_index: Atom.Index, new_block_size: u64) void { | ... | @@ -1777,7 +1777,7 @@ fn shrinkAtom(self: *MachO, atom_index: Atom.Index, new_block_size: u64) void { |
| 1777 | fn growAtom(self: *MachO, atom_index: Atom.Index, new_atom_size: u64, alignment: u64) !u64 { | 1777 | fn growAtom(self: *MachO, atom_index: Atom.Index, new_atom_size: u64, alignment: u64) !u64 { |
| 1778 | const atom = self.getAtom(atom_index); | 1778 | const atom = self.getAtom(atom_index); |
| 1779 | const sym = atom.getSymbol(self); | 1779 | const sym = atom.getSymbol(self); |
| 1780 | const align_ok = mem.alignBackwardGeneric(u64, sym.n_value, alignment) == sym.n_value; | 1780 | const align_ok = mem.alignBackward(u64, sym.n_value, alignment) == sym.n_value; |
| 1781 | const need_realloc = !align_ok or new_atom_size > atom.capacity(self); | 1781 | const need_realloc = !align_ok or new_atom_size > atom.capacity(self); |
| 1782 | if (!need_realloc) return sym.n_value; | 1782 | if (!need_realloc) return sym.n_value; |
| 1783 | return self.allocateAtom(atom_index, new_atom_size, alignment); | 1783 | return self.allocateAtom(atom_index, new_atom_size, alignment); |
| ... | @@ -2598,7 +2598,7 @@ fn populateMissingMetadata(self: *MachO) !void { | ... | @@ -2598,7 +2598,7 @@ fn populateMissingMetadata(self: *MachO) !void { |
| 2598 | // The first __TEXT segment is immovable and covers MachO header and load commands. | 2598 | // The first __TEXT segment is immovable and covers MachO header and load commands. |
| 2599 | self.header_segment_cmd_index = @intCast(u8, self.segments.items.len); | 2599 | self.header_segment_cmd_index = @intCast(u8, self.segments.items.len); |
| 2600 | const ideal_size = @max(self.base.options.headerpad_size orelse 0, default_headerpad_size); | 2600 | const ideal_size = @max(self.base.options.headerpad_size orelse 0, default_headerpad_size); |
| 2601 | const needed_size = mem.alignForwardGeneric(u64, padToIdeal(ideal_size), self.page_size); | 2601 | const needed_size = mem.alignForward(u64, padToIdeal(ideal_size), self.page_size); |
| 2602 | 2602 | ||
| 2603 | log.debug("found __TEXT segment (header-only) free space 0x{x} to 0x{x}", .{ 0, needed_size }); | 2603 | log.debug("found __TEXT segment (header-only) free space 0x{x} to 0x{x}", .{ 0, needed_size }); |
| 2604 | 2604 | ||
| ... | @@ -2735,7 +2735,7 @@ fn populateMissingMetadata(self: *MachO) !void { | ... | @@ -2735,7 +2735,7 @@ fn populateMissingMetadata(self: *MachO) !void { |
| 2735 | 2735 | ||
| 2736 | fn calcPagezeroSize(self: *MachO) u64 { | 2736 | fn calcPagezeroSize(self: *MachO) u64 { |
| 2737 | const pagezero_vmsize = self.base.options.pagezero_size orelse default_pagezero_vmsize; | 2737 | const pagezero_vmsize = self.base.options.pagezero_size orelse default_pagezero_vmsize; |
| 2738 | const aligned_pagezero_vmsize = mem.alignBackwardGeneric(u64, pagezero_vmsize, self.page_size); | 2738 | const aligned_pagezero_vmsize = mem.alignBackward(u64, pagezero_vmsize, self.page_size); |
| 2739 | if (self.base.options.output_mode == .Lib) return 0; | 2739 | if (self.base.options.output_mode == .Lib) return 0; |
| 2740 | if (aligned_pagezero_vmsize == 0) return 0; | 2740 | if (aligned_pagezero_vmsize == 0) return 0; |
| 2741 | if (aligned_pagezero_vmsize != pagezero_vmsize) { | 2741 | if (aligned_pagezero_vmsize != pagezero_vmsize) { |
| ... | @@ -2759,10 +2759,10 @@ fn allocateSection(self: *MachO, segname: []const u8, sectname: []const u8, opts | ... | @@ -2759,10 +2759,10 @@ fn allocateSection(self: *MachO, segname: []const u8, sectname: []const u8, opts |
| 2759 | const section_id = @intCast(u8, self.sections.slice().len); | 2759 | const section_id = @intCast(u8, self.sections.slice().len); |
| 2760 | const vmaddr = blk: { | 2760 | const vmaddr = blk: { |
| 2761 | const prev_segment = self.segments.items[segment_id - 1]; | 2761 | const prev_segment = self.segments.items[segment_id - 1]; |
| 2762 | break :blk mem.alignForwardGeneric(u64, prev_segment.vmaddr + prev_segment.vmsize, self.page_size); | 2762 | break :blk mem.alignForward(u64, prev_segment.vmaddr + prev_segment.vmsize, self.page_size); |
| 2763 | }; | 2763 | }; |
| 2764 | // We commit more memory than needed upfront so that we don't have to reallocate too soon. | 2764 | // We commit more memory than needed upfront so that we don't have to reallocate too soon. |
| 2765 | const vmsize = mem.alignForwardGeneric(u64, opts.size, self.page_size); | 2765 | const vmsize = mem.alignForward(u64, opts.size, self.page_size); |
| 2766 | const off = self.findFreeSpace(opts.size, self.page_size); | 2766 | const off = self.findFreeSpace(opts.size, self.page_size); |
| 2767 | 2767 | ||
| 2768 | log.debug("found {s},{s} free space 0x{x} to 0x{x} (0x{x} - 0x{x})", .{ | 2768 | log.debug("found {s},{s} free space 0x{x} to 0x{x} (0x{x} - 0x{x})", .{ |
| ... | @@ -2790,8 +2790,8 @@ fn allocateSection(self: *MachO, segname: []const u8, sectname: []const u8, opts | ... | @@ -2790,8 +2790,8 @@ fn allocateSection(self: *MachO, segname: []const u8, sectname: []const u8, opts |
| 2790 | var section = macho.section_64{ | 2790 | var section = macho.section_64{ |
| 2791 | .sectname = makeStaticString(sectname), | 2791 | .sectname = makeStaticString(sectname), |
| 2792 | .segname = makeStaticString(segname), | 2792 | .segname = makeStaticString(segname), |
| 2793 | .addr = mem.alignForwardGeneric(u64, vmaddr, opts.alignment), | 2793 | .addr = mem.alignForward(u64, vmaddr, opts.alignment), |
| 2794 | .offset = mem.alignForwardGeneric(u32, @intCast(u32, off), opts.alignment), | 2794 | .offset = mem.alignForward(u32, @intCast(u32, off), opts.alignment), |
| 2795 | .size = opts.size, | 2795 | .size = opts.size, |
| 2796 | .@"align" = math.log2(opts.alignment), | 2796 | .@"align" = math.log2(opts.alignment), |
| 2797 | .flags = opts.flags, | 2797 | .flags = opts.flags, |
| ... | @@ -2846,8 +2846,8 @@ fn growSection(self: *MachO, sect_id: u8, needed_size: u64) !void { | ... | @@ -2846,8 +2846,8 @@ fn growSection(self: *MachO, sect_id: u8, needed_size: u64) !void { |
| 2846 | } | 2846 | } |
| 2847 | 2847 | ||
| 2848 | header.size = needed_size; | 2848 | header.size = needed_size; |
| 2849 | segment.filesize = mem.alignForwardGeneric(u64, needed_size, self.page_size); | 2849 | segment.filesize = mem.alignForward(u64, needed_size, self.page_size); |
| 2850 | segment.vmsize = mem.alignForwardGeneric(u64, needed_size, self.page_size); | 2850 | segment.vmsize = mem.alignForward(u64, needed_size, self.page_size); |
| 2851 | } | 2851 | } |
| 2852 | 2852 | ||
| 2853 | fn growSectionVirtualMemory(self: *MachO, sect_id: u8, needed_size: u64) !void { | 2853 | fn growSectionVirtualMemory(self: *MachO, sect_id: u8, needed_size: u64) !void { |
| ... | @@ -2855,7 +2855,7 @@ fn growSectionVirtualMemory(self: *MachO, sect_id: u8, needed_size: u64) !void { | ... | @@ -2855,7 +2855,7 @@ fn growSectionVirtualMemory(self: *MachO, sect_id: u8, needed_size: u64) !void { |
| 2855 | const segment = self.getSegmentPtr(sect_id); | 2855 | const segment = self.getSegmentPtr(sect_id); |
| 2856 | const increased_size = padToIdeal(needed_size); | 2856 | const increased_size = padToIdeal(needed_size); |
| 2857 | const old_aligned_end = segment.vmaddr + segment.vmsize; | 2857 | const old_aligned_end = segment.vmaddr + segment.vmsize; |
| 2858 | const new_aligned_end = segment.vmaddr + mem.alignForwardGeneric(u64, increased_size, self.page_size); | 2858 | const new_aligned_end = segment.vmaddr + mem.alignForward(u64, increased_size, self.page_size); |
| 2859 | const diff = new_aligned_end - old_aligned_end; | 2859 | const diff = new_aligned_end - old_aligned_end; |
| 2860 | log.debug("shifting every segment after {s},{s} in virtual memory by {x}", .{ | 2860 | log.debug("shifting every segment after {s},{s} in virtual memory by {x}", .{ |
| 2861 | header.segName(), | 2861 | header.segName(), |
| ... | @@ -2927,7 +2927,7 @@ fn allocateAtom(self: *MachO, atom_index: Atom.Index, new_atom_size: u64, alignm | ... | @@ -2927,7 +2927,7 @@ fn allocateAtom(self: *MachO, atom_index: Atom.Index, new_atom_size: u64, alignm |
| 2927 | const ideal_capacity_end_vaddr = math.add(u64, sym.n_value, ideal_capacity) catch ideal_capacity; | 2927 | const ideal_capacity_end_vaddr = math.add(u64, sym.n_value, ideal_capacity) catch ideal_capacity; |
| 2928 | const capacity_end_vaddr = sym.n_value + capacity; | 2928 | const capacity_end_vaddr = sym.n_value + capacity; |
| 2929 | const new_start_vaddr_unaligned = capacity_end_vaddr - new_atom_ideal_capacity; | 2929 | const new_start_vaddr_unaligned = capacity_end_vaddr - new_atom_ideal_capacity; |
| 2930 | const new_start_vaddr = mem.alignBackwardGeneric(u64, new_start_vaddr_unaligned, alignment); | 2930 | const new_start_vaddr = mem.alignBackward(u64, new_start_vaddr_unaligned, alignment); |
| 2931 | if (new_start_vaddr < ideal_capacity_end_vaddr) { | 2931 | if (new_start_vaddr < ideal_capacity_end_vaddr) { |
| 2932 | // Additional bookkeeping here to notice if this free list node | 2932 | // Additional bookkeeping here to notice if this free list node |
| 2933 | // should be deleted because the atom that it points to has grown to take up | 2933 | // should be deleted because the atom that it points to has grown to take up |
| ... | @@ -2956,11 +2956,11 @@ fn allocateAtom(self: *MachO, atom_index: Atom.Index, new_atom_size: u64, alignm | ... | @@ -2956,11 +2956,11 @@ fn allocateAtom(self: *MachO, atom_index: Atom.Index, new_atom_size: u64, alignm |
| 2956 | const last_symbol = last.getSymbol(self); | 2956 | const last_symbol = last.getSymbol(self); |
| 2957 | const ideal_capacity = if (requires_padding) padToIdeal(last.size) else last.size; | 2957 | const ideal_capacity = if (requires_padding) padToIdeal(last.size) else last.size; |
| 2958 | const ideal_capacity_end_vaddr = last_symbol.n_value + ideal_capacity; | 2958 | const ideal_capacity_end_vaddr = last_symbol.n_value + ideal_capacity; |
| 2959 | const new_start_vaddr = mem.alignForwardGeneric(u64, ideal_capacity_end_vaddr, alignment); | 2959 | const new_start_vaddr = mem.alignForward(u64, ideal_capacity_end_vaddr, alignment); |
| 2960 | atom_placement = last_index; | 2960 | atom_placement = last_index; |
| 2961 | break :blk new_start_vaddr; | 2961 | break :blk new_start_vaddr; |
| 2962 | } else { | 2962 | } else { |
| 2963 | break :blk mem.alignForwardGeneric(u64, segment.vmaddr, alignment); | 2963 | break :blk mem.alignForward(u64, segment.vmaddr, alignment); |
| 2964 | } | 2964 | } |
| 2965 | }; | 2965 | }; |
| 2966 | 2966 | ||
| ... | @@ -3034,17 +3034,17 @@ fn writeLinkeditSegmentData(self: *MachO) !void { | ... | @@ -3034,17 +3034,17 @@ fn writeLinkeditSegmentData(self: *MachO) !void { |
| 3034 | for (self.segments.items, 0..) |segment, id| { | 3034 | for (self.segments.items, 0..) |segment, id| { |
| 3035 | if (self.linkedit_segment_cmd_index.? == @intCast(u8, id)) continue; | 3035 | if (self.linkedit_segment_cmd_index.? == @intCast(u8, id)) continue; |
| 3036 | if (seg.vmaddr < segment.vmaddr + segment.vmsize) { | 3036 | if (seg.vmaddr < segment.vmaddr + segment.vmsize) { |
| 3037 | seg.vmaddr = mem.alignForwardGeneric(u64, segment.vmaddr + segment.vmsize, self.page_size); | 3037 | seg.vmaddr = mem.alignForward(u64, segment.vmaddr + segment.vmsize, self.page_size); |
| 3038 | } | 3038 | } |
| 3039 | if (seg.fileoff < segment.fileoff + segment.filesize) { | 3039 | if (seg.fileoff < segment.fileoff + segment.filesize) { |
| 3040 | seg.fileoff = mem.alignForwardGeneric(u64, segment.fileoff + segment.filesize, self.page_size); | 3040 | seg.fileoff = mem.alignForward(u64, segment.fileoff + segment.filesize, self.page_size); |
| 3041 | } | 3041 | } |
| 3042 | } | 3042 | } |
| 3043 | 3043 | ||
| 3044 | try self.writeDyldInfoData(); | 3044 | try self.writeDyldInfoData(); |
| 3045 | try self.writeSymtabs(); | 3045 | try self.writeSymtabs(); |
| 3046 | 3046 | ||
| 3047 | seg.vmsize = mem.alignForwardGeneric(u64, seg.filesize, self.page_size); | 3047 | seg.vmsize = mem.alignForward(u64, seg.filesize, self.page_size); |
| 3048 | } | 3048 | } |
| 3049 | 3049 | ||
| 3050 | fn collectRebaseDataFromTableSection(self: *MachO, sect_id: u8, rebase: *Rebase, table: anytype) !void { | 3050 | fn collectRebaseDataFromTableSection(self: *MachO, sect_id: u8, rebase: *Rebase, table: anytype) !void { |
| ... | @@ -3236,17 +3236,17 @@ fn writeDyldInfoData(self: *MachO) !void { | ... | @@ -3236,17 +3236,17 @@ fn writeDyldInfoData(self: *MachO) !void { |
| 3236 | assert(mem.isAlignedGeneric(u64, link_seg.fileoff, @alignOf(u64))); | 3236 | assert(mem.isAlignedGeneric(u64, link_seg.fileoff, @alignOf(u64))); |
| 3237 | const rebase_off = link_seg.fileoff; | 3237 | const rebase_off = link_seg.fileoff; |
| 3238 | const rebase_size = rebase.size(); | 3238 | const rebase_size = rebase.size(); |
| 3239 | const rebase_size_aligned = mem.alignForwardGeneric(u64, rebase_size, @alignOf(u64)); | 3239 | const rebase_size_aligned = mem.alignForward(u64, rebase_size, @alignOf(u64)); |
| 3240 | log.debug("writing rebase info from 0x{x} to 0x{x}", .{ rebase_off, rebase_off + rebase_size_aligned }); | 3240 | log.debug("writing rebase info from 0x{x} to 0x{x}", .{ rebase_off, rebase_off + rebase_size_aligned }); |
| 3241 | 3241 | ||
| 3242 | const bind_off = rebase_off + rebase_size_aligned; | 3242 | const bind_off = rebase_off + rebase_size_aligned; |
| 3243 | const bind_size = bind.size(); | 3243 | const bind_size = bind.size(); |
| 3244 | const bind_size_aligned = mem.alignForwardGeneric(u64, bind_size, @alignOf(u64)); | 3244 | const bind_size_aligned = mem.alignForward(u64, bind_size, @alignOf(u64)); |
| 3245 | log.debug("writing bind info from 0x{x} to 0x{x}", .{ bind_off, bind_off + bind_size_aligned }); | 3245 | log.debug("writing bind info from 0x{x} to 0x{x}", .{ bind_off, bind_off + bind_size_aligned }); |
| 3246 | 3246 | ||
| 3247 | const lazy_bind_off = bind_off + bind_size_aligned; | 3247 | const lazy_bind_off = bind_off + bind_size_aligned; |
| 3248 | const lazy_bind_size = lazy_bind.size(); | 3248 | const lazy_bind_size = lazy_bind.size(); |
| 3249 | const lazy_bind_size_aligned = mem.alignForwardGeneric(u64, lazy_bind_size, @alignOf(u64)); | 3249 | const lazy_bind_size_aligned = mem.alignForward(u64, lazy_bind_size, @alignOf(u64)); |
| 3250 | log.debug("writing lazy bind info from 0x{x} to 0x{x}", .{ | 3250 | log.debug("writing lazy bind info from 0x{x} to 0x{x}", .{ |
| 3251 | lazy_bind_off, | 3251 | lazy_bind_off, |
| 3252 | lazy_bind_off + lazy_bind_size_aligned, | 3252 | lazy_bind_off + lazy_bind_size_aligned, |
| ... | @@ -3254,7 +3254,7 @@ fn writeDyldInfoData(self: *MachO) !void { | ... | @@ -3254,7 +3254,7 @@ fn writeDyldInfoData(self: *MachO) !void { |
| 3254 | 3254 | ||
| 3255 | const export_off = lazy_bind_off + lazy_bind_size_aligned; | 3255 | const export_off = lazy_bind_off + lazy_bind_size_aligned; |
| 3256 | const export_size = trie.size; | 3256 | const export_size = trie.size; |
| 3257 | const export_size_aligned = mem.alignForwardGeneric(u64, export_size, @alignOf(u64)); | 3257 | const export_size_aligned = mem.alignForward(u64, export_size, @alignOf(u64)); |
| 3258 | log.debug("writing export trie from 0x{x} to 0x{x}", .{ export_off, export_off + export_size_aligned }); | 3258 | log.debug("writing export trie from 0x{x} to 0x{x}", .{ export_off, export_off + export_size_aligned }); |
| 3259 | 3259 | ||
| 3260 | const needed_size = math.cast(usize, export_off + export_size_aligned - rebase_off) orelse | 3260 | const needed_size = math.cast(usize, export_off + export_size_aligned - rebase_off) orelse |
| ... | @@ -3412,7 +3412,7 @@ fn writeStrtab(self: *MachO) !void { | ... | @@ -3412,7 +3412,7 @@ fn writeStrtab(self: *MachO) !void { |
| 3412 | const offset = seg.fileoff + seg.filesize; | 3412 | const offset = seg.fileoff + seg.filesize; |
| 3413 | assert(mem.isAlignedGeneric(u64, offset, @alignOf(u64))); | 3413 | assert(mem.isAlignedGeneric(u64, offset, @alignOf(u64))); |
| 3414 | const needed_size = self.strtab.buffer.items.len; | 3414 | const needed_size = self.strtab.buffer.items.len; |
| 3415 | const needed_size_aligned = mem.alignForwardGeneric(u64, needed_size, @alignOf(u64)); | 3415 | const needed_size_aligned = mem.alignForward(u64, needed_size, @alignOf(u64)); |
| 3416 | seg.filesize = offset + needed_size_aligned - seg.fileoff; | 3416 | seg.filesize = offset + needed_size_aligned - seg.fileoff; |
| 3417 | 3417 | ||
| 3418 | log.debug("writing string table from 0x{x} to 0x{x}", .{ offset, offset + needed_size_aligned }); | 3418 | log.debug("writing string table from 0x{x} to 0x{x}", .{ offset, offset + needed_size_aligned }); |
| ... | @@ -3447,7 +3447,7 @@ fn writeDysymtab(self: *MachO, ctx: SymtabCtx) !void { | ... | @@ -3447,7 +3447,7 @@ fn writeDysymtab(self: *MachO, ctx: SymtabCtx) !void { |
| 3447 | const offset = seg.fileoff + seg.filesize; | 3447 | const offset = seg.fileoff + seg.filesize; |
| 3448 | assert(mem.isAlignedGeneric(u64, offset, @alignOf(u64))); | 3448 | assert(mem.isAlignedGeneric(u64, offset, @alignOf(u64))); |
| 3449 | const needed_size = nindirectsyms * @sizeOf(u32); | 3449 | const needed_size = nindirectsyms * @sizeOf(u32); |
| 3450 | const needed_size_aligned = mem.alignForwardGeneric(u64, needed_size, @alignOf(u64)); | 3450 | const needed_size_aligned = mem.alignForward(u64, needed_size, @alignOf(u64)); |
| 3451 | seg.filesize = offset + needed_size_aligned - seg.fileoff; | 3451 | seg.filesize = offset + needed_size_aligned - seg.fileoff; |
| 3452 | 3452 | ||
| 3453 | log.debug("writing indirect symbol table from 0x{x} to 0x{x}", .{ offset, offset + needed_size_aligned }); | 3453 | log.debug("writing indirect symbol table from 0x{x} to 0x{x}", .{ offset, offset + needed_size_aligned }); |
| ... | @@ -3514,10 +3514,10 @@ fn writeCodeSignaturePadding(self: *MachO, code_sig: *CodeSignature) !void { | ... | @@ -3514,10 +3514,10 @@ fn writeCodeSignaturePadding(self: *MachO, code_sig: *CodeSignature) !void { |
| 3514 | const seg = self.getLinkeditSegmentPtr(); | 3514 | const seg = self.getLinkeditSegmentPtr(); |
| 3515 | // Code signature data has to be 16-bytes aligned for Apple tools to recognize the file | 3515 | // Code signature data has to be 16-bytes aligned for Apple tools to recognize the file |
| 3516 | // https://github.com/opensource-apple/cctools/blob/fdb4825f303fd5c0751be524babd32958181b3ed/libstuff/checkout.c#L271 | 3516 | // https://github.com/opensource-apple/cctools/blob/fdb4825f303fd5c0751be524babd32958181b3ed/libstuff/checkout.c#L271 |
| 3517 | const offset = mem.alignForwardGeneric(u64, seg.fileoff + seg.filesize, 16); | 3517 | const offset = mem.alignForward(u64, seg.fileoff + seg.filesize, 16); |
| 3518 | const needed_size = code_sig.estimateSize(offset); | 3518 | const needed_size = code_sig.estimateSize(offset); |
| 3519 | seg.filesize = offset + needed_size - seg.fileoff; | 3519 | seg.filesize = offset + needed_size - seg.fileoff; |
| 3520 | seg.vmsize = mem.alignForwardGeneric(u64, seg.filesize, self.page_size); | 3520 | seg.vmsize = mem.alignForward(u64, seg.filesize, self.page_size); |
| 3521 | log.debug("writing code signature padding from 0x{x} to 0x{x}", .{ offset, offset + needed_size }); | 3521 | log.debug("writing code signature padding from 0x{x} to 0x{x}", .{ offset, offset + needed_size }); |
| 3522 | // Pad out the space. We need to do this to calculate valid hashes for everything in the file | 3522 | // Pad out the space. We need to do this to calculate valid hashes for everything in the file |
| 3523 | // except for code signature data. | 3523 | // except for code signature data. |
| ... | @@ -3630,7 +3630,7 @@ fn allocatedSize(self: *MachO, start: u64) u64 { | ... | @@ -3630,7 +3630,7 @@ fn allocatedSize(self: *MachO, start: u64) u64 { |
| 3630 | fn findFreeSpace(self: *MachO, object_size: u64, min_alignment: u32) u64 { | 3630 | fn findFreeSpace(self: *MachO, object_size: u64, min_alignment: u32) u64 { |
| 3631 | var start: u64 = 0; | 3631 | var start: u64 = 0; |
| 3632 | while (self.detectAllocCollision(start, object_size)) |item_end| { | 3632 | while (self.detectAllocCollision(start, object_size)) |item_end| { |
| 3633 | start = mem.alignForwardGeneric(u64, item_end, min_alignment); | 3633 | start = mem.alignForward(u64, item_end, min_alignment); |
| 3634 | } | 3634 | } |
| 3635 | return start; | 3635 | return start; |
| 3636 | } | 3636 | } |
src/link/MachO/CodeSignature.zig+4-4| ... | @@ -282,7 +282,7 @@ pub fn writeAdhocSignature( | ... | @@ -282,7 +282,7 @@ pub fn writeAdhocSignature( |
| 282 | self.code_directory.inner.execSegFlags = if (opts.output_mode == .Exe) macho.CS_EXECSEG_MAIN_BINARY else 0; | 282 | self.code_directory.inner.execSegFlags = if (opts.output_mode == .Exe) macho.CS_EXECSEG_MAIN_BINARY else 0; |
| 283 | self.code_directory.inner.codeLimit = opts.file_size; | 283 | self.code_directory.inner.codeLimit = opts.file_size; |
| 284 | 284 | ||
| 285 | const total_pages = @intCast(u32, mem.alignForward(opts.file_size, self.page_size) / self.page_size); | 285 | const total_pages = @intCast(u32, mem.alignForward(usize, opts.file_size, self.page_size) / self.page_size); |
| 286 | 286 | ||
| 287 | try self.code_directory.code_slots.ensureTotalCapacityPrecise(gpa, total_pages); | 287 | try self.code_directory.code_slots.ensureTotalCapacityPrecise(gpa, total_pages); |
| 288 | self.code_directory.code_slots.items.len = total_pages; | 288 | self.code_directory.code_slots.items.len = total_pages; |
| ... | @@ -357,7 +357,7 @@ fn parallelHash( | ... | @@ -357,7 +357,7 @@ fn parallelHash( |
| 357 | ) !void { | 357 | ) !void { |
| 358 | var wg: WaitGroup = .{}; | 358 | var wg: WaitGroup = .{}; |
| 359 | 359 | ||
| 360 | const total_num_chunks = mem.alignForward(file_size, self.page_size) / self.page_size; | 360 | const total_num_chunks = mem.alignForward(usize, file_size, self.page_size) / self.page_size; |
| 361 | assert(self.code_directory.code_slots.items.len >= total_num_chunks); | 361 | assert(self.code_directory.code_slots.items.len >= total_num_chunks); |
| 362 | 362 | ||
| 363 | const buffer = try gpa.alloc(u8, self.page_size * total_num_chunks); | 363 | const buffer = try gpa.alloc(u8, self.page_size * total_num_chunks); |
| ... | @@ -421,7 +421,7 @@ pub fn size(self: CodeSignature) u32 { | ... | @@ -421,7 +421,7 @@ pub fn size(self: CodeSignature) u32 { |
| 421 | pub fn estimateSize(self: CodeSignature, file_size: u64) u32 { | 421 | pub fn estimateSize(self: CodeSignature, file_size: u64) u32 { |
| 422 | var ssize: u64 = @sizeOf(macho.SuperBlob) + @sizeOf(macho.BlobIndex) + self.code_directory.size(); | 422 | var ssize: u64 = @sizeOf(macho.SuperBlob) + @sizeOf(macho.BlobIndex) + self.code_directory.size(); |
| 423 | // Approx code slots | 423 | // Approx code slots |
| 424 | const total_pages = mem.alignForwardGeneric(u64, file_size, self.page_size) / self.page_size; | 424 | const total_pages = mem.alignForward(u64, file_size, self.page_size) / self.page_size; |
| 425 | ssize += total_pages * hash_size; | 425 | ssize += total_pages * hash_size; |
| 426 | var n_special_slots: u32 = 0; | 426 | var n_special_slots: u32 = 0; |
| 427 | if (self.requirements) |req| { | 427 | if (self.requirements) |req| { |
| ... | @@ -436,7 +436,7 @@ pub fn estimateSize(self: CodeSignature, file_size: u64) u32 { | ... | @@ -436,7 +436,7 @@ pub fn estimateSize(self: CodeSignature, file_size: u64) u32 { |
| 436 | ssize += @sizeOf(macho.BlobIndex) + sig.size(); | 436 | ssize += @sizeOf(macho.BlobIndex) + sig.size(); |
| 437 | } | 437 | } |
| 438 | ssize += n_special_slots * hash_size; | 438 | ssize += n_special_slots * hash_size; |
| 439 | return @intCast(u32, mem.alignForwardGeneric(u64, ssize, @sizeOf(u64))); | 439 | return @intCast(u32, mem.alignForward(u64, ssize, @sizeOf(u64))); |
| 440 | } | 440 | } |
| 441 | 441 | ||
| 442 | pub fn clear(self: *CodeSignature, allocator: Allocator) void { | 442 | pub fn clear(self: *CodeSignature, allocator: Allocator) void { |
src/link/MachO/DebugSymbols.zig+9-9| ... | @@ -68,7 +68,7 @@ pub fn populateMissingMetadata(self: *DebugSymbols) !void { | ... | @@ -68,7 +68,7 @@ pub fn populateMissingMetadata(self: *DebugSymbols) !void { |
| 68 | 68 | ||
| 69 | const off = @intCast(u64, self.page_size); | 69 | const off = @intCast(u64, self.page_size); |
| 70 | const ideal_size: u16 = 200 + 128 + 160 + 250; | 70 | const ideal_size: u16 = 200 + 128 + 160 + 250; |
| 71 | const needed_size = mem.alignForwardGeneric(u64, padToIdeal(ideal_size), self.page_size); | 71 | const needed_size = mem.alignForward(u64, padToIdeal(ideal_size), self.page_size); |
| 72 | 72 | ||
| 73 | log.debug("found __DWARF segment free space 0x{x} to 0x{x}", .{ off, off + needed_size }); | 73 | log.debug("found __DWARF segment free space 0x{x} to 0x{x}", .{ off, off + needed_size }); |
| 74 | 74 | ||
| ... | @@ -213,7 +213,7 @@ fn findFreeSpace(self: *DebugSymbols, object_size: u64, min_alignment: u64) u64 | ... | @@ -213,7 +213,7 @@ fn findFreeSpace(self: *DebugSymbols, object_size: u64, min_alignment: u64) u64 |
| 213 | const segment = self.getDwarfSegmentPtr(); | 213 | const segment = self.getDwarfSegmentPtr(); |
| 214 | var offset: u64 = segment.fileoff; | 214 | var offset: u64 = segment.fileoff; |
| 215 | while (self.detectAllocCollision(offset, object_size)) |item_end| { | 215 | while (self.detectAllocCollision(offset, object_size)) |item_end| { |
| 216 | offset = mem.alignForwardGeneric(u64, item_end, min_alignment); | 216 | offset = mem.alignForward(u64, item_end, min_alignment); |
| 217 | } | 217 | } |
| 218 | return offset; | 218 | return offset; |
| 219 | } | 219 | } |
| ... | @@ -355,18 +355,18 @@ fn finalizeDwarfSegment(self: *DebugSymbols, macho_file: *MachO) void { | ... | @@ -355,18 +355,18 @@ fn finalizeDwarfSegment(self: *DebugSymbols, macho_file: *MachO) void { |
| 355 | file_size = @max(file_size, header.offset + header.size); | 355 | file_size = @max(file_size, header.offset + header.size); |
| 356 | } | 356 | } |
| 357 | 357 | ||
| 358 | const aligned_size = mem.alignForwardGeneric(u64, file_size, self.page_size); | 358 | const aligned_size = mem.alignForward(u64, file_size, self.page_size); |
| 359 | dwarf_segment.vmaddr = base_vmaddr; | 359 | dwarf_segment.vmaddr = base_vmaddr; |
| 360 | dwarf_segment.filesize = aligned_size; | 360 | dwarf_segment.filesize = aligned_size; |
| 361 | dwarf_segment.vmsize = aligned_size; | 361 | dwarf_segment.vmsize = aligned_size; |
| 362 | 362 | ||
| 363 | const linkedit = self.getLinkeditSegmentPtr(); | 363 | const linkedit = self.getLinkeditSegmentPtr(); |
| 364 | linkedit.vmaddr = mem.alignForwardGeneric( | 364 | linkedit.vmaddr = mem.alignForward( |
| 365 | u64, | 365 | u64, |
| 366 | dwarf_segment.vmaddr + aligned_size, | 366 | dwarf_segment.vmaddr + aligned_size, |
| 367 | self.page_size, | 367 | self.page_size, |
| 368 | ); | 368 | ); |
| 369 | linkedit.fileoff = mem.alignForwardGeneric( | 369 | linkedit.fileoff = mem.alignForward( |
| 370 | u64, | 370 | u64, |
| 371 | dwarf_segment.fileoff + aligned_size, | 371 | dwarf_segment.fileoff + aligned_size, |
| 372 | self.page_size, | 372 | self.page_size, |
| ... | @@ -458,7 +458,7 @@ fn writeLinkeditSegmentData(self: *DebugSymbols, macho_file: *MachO) !void { | ... | @@ -458,7 +458,7 @@ fn writeLinkeditSegmentData(self: *DebugSymbols, macho_file: *MachO) !void { |
| 458 | try self.writeStrtab(); | 458 | try self.writeStrtab(); |
| 459 | 459 | ||
| 460 | const seg = &self.segments.items[self.linkedit_segment_cmd_index.?]; | 460 | const seg = &self.segments.items[self.linkedit_segment_cmd_index.?]; |
| 461 | const aligned_size = mem.alignForwardGeneric(u64, seg.filesize, self.page_size); | 461 | const aligned_size = mem.alignForward(u64, seg.filesize, self.page_size); |
| 462 | seg.vmsize = aligned_size; | 462 | seg.vmsize = aligned_size; |
| 463 | } | 463 | } |
| 464 | 464 | ||
| ... | @@ -497,7 +497,7 @@ fn writeSymtab(self: *DebugSymbols, macho_file: *MachO) !void { | ... | @@ -497,7 +497,7 @@ fn writeSymtab(self: *DebugSymbols, macho_file: *MachO) !void { |
| 497 | const nsyms = nlocals + nexports; | 497 | const nsyms = nlocals + nexports; |
| 498 | 498 | ||
| 499 | const seg = &self.segments.items[self.linkedit_segment_cmd_index.?]; | 499 | const seg = &self.segments.items[self.linkedit_segment_cmd_index.?]; |
| 500 | const offset = mem.alignForwardGeneric(u64, seg.fileoff, @alignOf(macho.nlist_64)); | 500 | const offset = mem.alignForward(u64, seg.fileoff, @alignOf(macho.nlist_64)); |
| 501 | const needed_size = nsyms * @sizeOf(macho.nlist_64); | 501 | const needed_size = nsyms * @sizeOf(macho.nlist_64); |
| 502 | seg.filesize = offset + needed_size - seg.fileoff; | 502 | seg.filesize = offset + needed_size - seg.fileoff; |
| 503 | 503 | ||
| ... | @@ -522,8 +522,8 @@ fn writeStrtab(self: *DebugSymbols) !void { | ... | @@ -522,8 +522,8 @@ fn writeStrtab(self: *DebugSymbols) !void { |
| 522 | 522 | ||
| 523 | const seg = &self.segments.items[self.linkedit_segment_cmd_index.?]; | 523 | const seg = &self.segments.items[self.linkedit_segment_cmd_index.?]; |
| 524 | const symtab_size = @intCast(u32, self.symtab_cmd.nsyms * @sizeOf(macho.nlist_64)); | 524 | const symtab_size = @intCast(u32, self.symtab_cmd.nsyms * @sizeOf(macho.nlist_64)); |
| 525 | const offset = mem.alignForwardGeneric(u64, self.symtab_cmd.symoff + symtab_size, @alignOf(u64)); | 525 | const offset = mem.alignForward(u64, self.symtab_cmd.symoff + symtab_size, @alignOf(u64)); |
| 526 | const needed_size = mem.alignForwardGeneric(u64, self.strtab.buffer.items.len, @alignOf(u64)); | 526 | const needed_size = mem.alignForward(u64, self.strtab.buffer.items.len, @alignOf(u64)); |
| 527 | 527 | ||
| 528 | seg.filesize = offset + needed_size - seg.fileoff; | 528 | seg.filesize = offset + needed_size - seg.fileoff; |
| 529 | self.symtab_cmd.stroff = @intCast(u32, offset); | 529 | self.symtab_cmd.stroff = @intCast(u32, offset); |
src/link/MachO/load_commands.zig+4-4| ... | @@ -17,7 +17,7 @@ pub const default_dyld_path: [*:0]const u8 = "/usr/lib/dyld"; | ... | @@ -17,7 +17,7 @@ pub const default_dyld_path: [*:0]const u8 = "/usr/lib/dyld"; |
| 17 | fn calcInstallNameLen(cmd_size: u64, name: []const u8, assume_max_path_len: bool) u64 { | 17 | fn calcInstallNameLen(cmd_size: u64, name: []const u8, assume_max_path_len: bool) u64 { |
| 18 | const darwin_path_max = 1024; | 18 | const darwin_path_max = 1024; |
| 19 | const name_len = if (assume_max_path_len) darwin_path_max else name.len + 1; | 19 | const name_len = if (assume_max_path_len) darwin_path_max else name.len + 1; |
| 20 | return mem.alignForwardGeneric(u64, cmd_size + name_len, @alignOf(u64)); | 20 | return mem.alignForward(u64, cmd_size + name_len, @alignOf(u64)); |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | const CalcLCsSizeCtx = struct { | 23 | const CalcLCsSizeCtx = struct { |
| ... | @@ -149,7 +149,7 @@ pub fn calcNumOfLCs(lc_buffer: []const u8) u32 { | ... | @@ -149,7 +149,7 @@ pub fn calcNumOfLCs(lc_buffer: []const u8) u32 { |
| 149 | 149 | ||
| 150 | pub fn writeDylinkerLC(lc_writer: anytype) !void { | 150 | pub fn writeDylinkerLC(lc_writer: anytype) !void { |
| 151 | const name_len = mem.sliceTo(default_dyld_path, 0).len; | 151 | const name_len = mem.sliceTo(default_dyld_path, 0).len; |
| 152 | const cmdsize = @intCast(u32, mem.alignForwardGeneric( | 152 | const cmdsize = @intCast(u32, mem.alignForward( |
| 153 | u64, | 153 | u64, |
| 154 | @sizeOf(macho.dylinker_command) + name_len, | 154 | @sizeOf(macho.dylinker_command) + name_len, |
| 155 | @sizeOf(u64), | 155 | @sizeOf(u64), |
| ... | @@ -176,7 +176,7 @@ const WriteDylibLCCtx = struct { | ... | @@ -176,7 +176,7 @@ const WriteDylibLCCtx = struct { |
| 176 | 176 | ||
| 177 | fn writeDylibLC(ctx: WriteDylibLCCtx, lc_writer: anytype) !void { | 177 | fn writeDylibLC(ctx: WriteDylibLCCtx, lc_writer: anytype) !void { |
| 178 | const name_len = ctx.name.len + 1; | 178 | const name_len = ctx.name.len + 1; |
| 179 | const cmdsize = @intCast(u32, mem.alignForwardGeneric( | 179 | const cmdsize = @intCast(u32, mem.alignForward( |
| 180 | u64, | 180 | u64, |
| 181 | @sizeOf(macho.dylib_command) + name_len, | 181 | @sizeOf(macho.dylib_command) + name_len, |
| 182 | @sizeOf(u64), | 182 | @sizeOf(u64), |
| ... | @@ -253,7 +253,7 @@ pub fn writeRpathLCs(gpa: Allocator, options: *const link.Options, lc_writer: an | ... | @@ -253,7 +253,7 @@ pub fn writeRpathLCs(gpa: Allocator, options: *const link.Options, lc_writer: an |
| 253 | 253 | ||
| 254 | while (try it.next()) |rpath| { | 254 | while (try it.next()) |rpath| { |
| 255 | const rpath_len = rpath.len + 1; | 255 | const rpath_len = rpath.len + 1; |
| 256 | const cmdsize = @intCast(u32, mem.alignForwardGeneric( | 256 | const cmdsize = @intCast(u32, mem.alignForward( |
| 257 | u64, | 257 | u64, |
| 258 | @sizeOf(macho.rpath_command) + rpath_len, | 258 | @sizeOf(macho.rpath_command) + rpath_len, |
| 259 | @sizeOf(u64), | 259 | @sizeOf(u64), |
src/link/MachO/thunks.zig+3-3| ... | @@ -109,7 +109,7 @@ pub fn createThunks(zld: *Zld, sect_id: u8) !void { | ... | @@ -109,7 +109,7 @@ pub fn createThunks(zld: *Zld, sect_id: u8) !void { |
| 109 | 109 | ||
| 110 | while (true) { | 110 | while (true) { |
| 111 | const atom = zld.getAtom(group_end); | 111 | const atom = zld.getAtom(group_end); |
| 112 | offset = mem.alignForwardGeneric(u64, offset, try math.powi(u32, 2, atom.alignment)); | 112 | offset = mem.alignForward(u64, offset, try math.powi(u32, 2, atom.alignment)); |
| 113 | 113 | ||
| 114 | const sym = zld.getSymbolPtr(atom.getSymbolWithLoc()); | 114 | const sym = zld.getSymbolPtr(atom.getSymbolWithLoc()); |
| 115 | sym.n_value = offset; | 115 | sym.n_value = offset; |
| ... | @@ -153,7 +153,7 @@ pub fn createThunks(zld: *Zld, sect_id: u8) !void { | ... | @@ -153,7 +153,7 @@ pub fn createThunks(zld: *Zld, sect_id: u8) !void { |
| 153 | } else break; | 153 | } else break; |
| 154 | } | 154 | } |
| 155 | 155 | ||
| 156 | offset = mem.alignForwardGeneric(u64, offset, Thunk.getAlignment()); | 156 | offset = mem.alignForward(u64, offset, Thunk.getAlignment()); |
| 157 | allocateThunk(zld, thunk_index, offset, header); | 157 | allocateThunk(zld, thunk_index, offset, header); |
| 158 | offset += zld.thunks.items[thunk_index].getSize(); | 158 | offset += zld.thunks.items[thunk_index].getSize(); |
| 159 | 159 | ||
| ... | @@ -193,7 +193,7 @@ fn allocateThunk( | ... | @@ -193,7 +193,7 @@ fn allocateThunk( |
| 193 | var offset = base_offset; | 193 | var offset = base_offset; |
| 194 | while (true) { | 194 | while (true) { |
| 195 | const atom = zld.getAtom(atom_index); | 195 | const atom = zld.getAtom(atom_index); |
| 196 | offset = mem.alignForwardGeneric(u64, offset, Thunk.getAlignment()); | 196 | offset = mem.alignForward(u64, offset, Thunk.getAlignment()); |
| 197 | 197 | ||
| 198 | const sym = zld.getSymbolPtr(atom.getSymbolWithLoc()); | 198 | const sym = zld.getSymbolPtr(atom.getSymbolWithLoc()); |
| 199 | sym.n_value = offset; | 199 | sym.n_value = offset; |
src/link/MachO/zld.zig+17-17| ... | @@ -1207,7 +1207,7 @@ pub const Zld = struct { | ... | @@ -1207,7 +1207,7 @@ pub const Zld = struct { |
| 1207 | 1207 | ||
| 1208 | fn createSegments(self: *Zld) !void { | 1208 | fn createSegments(self: *Zld) !void { |
| 1209 | const pagezero_vmsize = self.options.pagezero_size orelse MachO.default_pagezero_vmsize; | 1209 | const pagezero_vmsize = self.options.pagezero_size orelse MachO.default_pagezero_vmsize; |
| 1210 | const aligned_pagezero_vmsize = mem.alignBackwardGeneric(u64, pagezero_vmsize, self.page_size); | 1210 | const aligned_pagezero_vmsize = mem.alignBackward(u64, pagezero_vmsize, self.page_size); |
| 1211 | if (self.options.output_mode != .Lib and aligned_pagezero_vmsize > 0) { | 1211 | if (self.options.output_mode != .Lib and aligned_pagezero_vmsize > 0) { |
| 1212 | if (aligned_pagezero_vmsize != pagezero_vmsize) { | 1212 | if (aligned_pagezero_vmsize != pagezero_vmsize) { |
| 1213 | log.warn("requested __PAGEZERO size (0x{x}) is not page aligned", .{pagezero_vmsize}); | 1213 | log.warn("requested __PAGEZERO size (0x{x}) is not page aligned", .{pagezero_vmsize}); |
| ... | @@ -1466,7 +1466,7 @@ pub const Zld = struct { | ... | @@ -1466,7 +1466,7 @@ pub const Zld = struct { |
| 1466 | while (true) { | 1466 | while (true) { |
| 1467 | const atom = self.getAtom(atom_index); | 1467 | const atom = self.getAtom(atom_index); |
| 1468 | const atom_alignment = try math.powi(u32, 2, atom.alignment); | 1468 | const atom_alignment = try math.powi(u32, 2, atom.alignment); |
| 1469 | const atom_offset = mem.alignForwardGeneric(u64, header.size, atom_alignment); | 1469 | const atom_offset = mem.alignForward(u64, header.size, atom_alignment); |
| 1470 | const padding = atom_offset - header.size; | 1470 | const padding = atom_offset - header.size; |
| 1471 | 1471 | ||
| 1472 | const sym = self.getSymbolPtr(atom.getSymbolWithLoc()); | 1472 | const sym = self.getSymbolPtr(atom.getSymbolWithLoc()); |
| ... | @@ -1534,7 +1534,7 @@ pub const Zld = struct { | ... | @@ -1534,7 +1534,7 @@ pub const Zld = struct { |
| 1534 | const slice = self.sections.slice(); | 1534 | const slice = self.sections.slice(); |
| 1535 | for (slice.items(.header)[indexes.start..indexes.end], 0..) |*header, sect_id| { | 1535 | for (slice.items(.header)[indexes.start..indexes.end], 0..) |*header, sect_id| { |
| 1536 | const alignment = try math.powi(u32, 2, header.@"align"); | 1536 | const alignment = try math.powi(u32, 2, header.@"align"); |
| 1537 | const start_aligned = mem.alignForwardGeneric(u64, start, alignment); | 1537 | const start_aligned = mem.alignForward(u64, start, alignment); |
| 1538 | const n_sect = @intCast(u8, indexes.start + sect_id + 1); | 1538 | const n_sect = @intCast(u8, indexes.start + sect_id + 1); |
| 1539 | 1539 | ||
| 1540 | header.offset = if (header.isZerofill()) | 1540 | header.offset = if (header.isZerofill()) |
| ... | @@ -1598,8 +1598,8 @@ pub const Zld = struct { | ... | @@ -1598,8 +1598,8 @@ pub const Zld = struct { |
| 1598 | segment.vmsize = start; | 1598 | segment.vmsize = start; |
| 1599 | } | 1599 | } |
| 1600 | 1600 | ||
| 1601 | segment.filesize = mem.alignForwardGeneric(u64, segment.filesize, self.page_size); | 1601 | segment.filesize = mem.alignForward(u64, segment.filesize, self.page_size); |
| 1602 | segment.vmsize = mem.alignForwardGeneric(u64, segment.vmsize, self.page_size); | 1602 | segment.vmsize = mem.alignForward(u64, segment.vmsize, self.page_size); |
| 1603 | } | 1603 | } |
| 1604 | 1604 | ||
| 1605 | const InitSectionOpts = struct { | 1605 | const InitSectionOpts = struct { |
| ... | @@ -1709,7 +1709,7 @@ pub const Zld = struct { | ... | @@ -1709,7 +1709,7 @@ pub const Zld = struct { |
| 1709 | try self.writeSymtabs(); | 1709 | try self.writeSymtabs(); |
| 1710 | 1710 | ||
| 1711 | const seg = self.getLinkeditSegmentPtr(); | 1711 | const seg = self.getLinkeditSegmentPtr(); |
| 1712 | seg.vmsize = mem.alignForwardGeneric(u64, seg.filesize, self.page_size); | 1712 | seg.vmsize = mem.alignForward(u64, seg.filesize, self.page_size); |
| 1713 | } | 1713 | } |
| 1714 | 1714 | ||
| 1715 | fn collectRebaseDataFromContainer( | 1715 | fn collectRebaseDataFromContainer( |
| ... | @@ -2112,17 +2112,17 @@ pub const Zld = struct { | ... | @@ -2112,17 +2112,17 @@ pub const Zld = struct { |
| 2112 | assert(mem.isAlignedGeneric(u64, link_seg.fileoff, @alignOf(u64))); | 2112 | assert(mem.isAlignedGeneric(u64, link_seg.fileoff, @alignOf(u64))); |
| 2113 | const rebase_off = link_seg.fileoff; | 2113 | const rebase_off = link_seg.fileoff; |
| 2114 | const rebase_size = rebase.size(); | 2114 | const rebase_size = rebase.size(); |
| 2115 | const rebase_size_aligned = mem.alignForwardGeneric(u64, rebase_size, @alignOf(u64)); | 2115 | const rebase_size_aligned = mem.alignForward(u64, rebase_size, @alignOf(u64)); |
| 2116 | log.debug("writing rebase info from 0x{x} to 0x{x}", .{ rebase_off, rebase_off + rebase_size_aligned }); | 2116 | log.debug("writing rebase info from 0x{x} to 0x{x}", .{ rebase_off, rebase_off + rebase_size_aligned }); |
| 2117 | 2117 | ||
| 2118 | const bind_off = rebase_off + rebase_size_aligned; | 2118 | const bind_off = rebase_off + rebase_size_aligned; |
| 2119 | const bind_size = bind.size(); | 2119 | const bind_size = bind.size(); |
| 2120 | const bind_size_aligned = mem.alignForwardGeneric(u64, bind_size, @alignOf(u64)); | 2120 | const bind_size_aligned = mem.alignForward(u64, bind_size, @alignOf(u64)); |
| 2121 | log.debug("writing bind info from 0x{x} to 0x{x}", .{ bind_off, bind_off + bind_size_aligned }); | 2121 | log.debug("writing bind info from 0x{x} to 0x{x}", .{ bind_off, bind_off + bind_size_aligned }); |
| 2122 | 2122 | ||
| 2123 | const lazy_bind_off = bind_off + bind_size_aligned; | 2123 | const lazy_bind_off = bind_off + bind_size_aligned; |
| 2124 | const lazy_bind_size = lazy_bind.size(); | 2124 | const lazy_bind_size = lazy_bind.size(); |
| 2125 | const lazy_bind_size_aligned = mem.alignForwardGeneric(u64, lazy_bind_size, @alignOf(u64)); | 2125 | const lazy_bind_size_aligned = mem.alignForward(u64, lazy_bind_size, @alignOf(u64)); |
| 2126 | log.debug("writing lazy bind info from 0x{x} to 0x{x}", .{ | 2126 | log.debug("writing lazy bind info from 0x{x} to 0x{x}", .{ |
| 2127 | lazy_bind_off, | 2127 | lazy_bind_off, |
| 2128 | lazy_bind_off + lazy_bind_size_aligned, | 2128 | lazy_bind_off + lazy_bind_size_aligned, |
| ... | @@ -2130,7 +2130,7 @@ pub const Zld = struct { | ... | @@ -2130,7 +2130,7 @@ pub const Zld = struct { |
| 2130 | 2130 | ||
| 2131 | const export_off = lazy_bind_off + lazy_bind_size_aligned; | 2131 | const export_off = lazy_bind_off + lazy_bind_size_aligned; |
| 2132 | const export_size = trie.size; | 2132 | const export_size = trie.size; |
| 2133 | const export_size_aligned = mem.alignForwardGeneric(u64, export_size, @alignOf(u64)); | 2133 | const export_size_aligned = mem.alignForward(u64, export_size, @alignOf(u64)); |
| 2134 | log.debug("writing export trie from 0x{x} to 0x{x}", .{ export_off, export_off + export_size_aligned }); | 2134 | log.debug("writing export trie from 0x{x} to 0x{x}", .{ export_off, export_off + export_size_aligned }); |
| 2135 | 2135 | ||
| 2136 | const needed_size = math.cast(usize, export_off + export_size_aligned - rebase_off) orelse | 2136 | const needed_size = math.cast(usize, export_off + export_size_aligned - rebase_off) orelse |
| ... | @@ -2268,7 +2268,7 @@ pub const Zld = struct { | ... | @@ -2268,7 +2268,7 @@ pub const Zld = struct { |
| 2268 | const offset = link_seg.fileoff + link_seg.filesize; | 2268 | const offset = link_seg.fileoff + link_seg.filesize; |
| 2269 | assert(mem.isAlignedGeneric(u64, offset, @alignOf(u64))); | 2269 | assert(mem.isAlignedGeneric(u64, offset, @alignOf(u64))); |
| 2270 | const needed_size = buffer.items.len; | 2270 | const needed_size = buffer.items.len; |
| 2271 | const needed_size_aligned = mem.alignForwardGeneric(u64, needed_size, @alignOf(u64)); | 2271 | const needed_size_aligned = mem.alignForward(u64, needed_size, @alignOf(u64)); |
| 2272 | const padding = math.cast(usize, needed_size_aligned - needed_size) orelse return error.Overflow; | 2272 | const padding = math.cast(usize, needed_size_aligned - needed_size) orelse return error.Overflow; |
| 2273 | if (padding > 0) { | 2273 | if (padding > 0) { |
| 2274 | try buffer.ensureUnusedCapacity(padding); | 2274 | try buffer.ensureUnusedCapacity(padding); |
| ... | @@ -2347,7 +2347,7 @@ pub const Zld = struct { | ... | @@ -2347,7 +2347,7 @@ pub const Zld = struct { |
| 2347 | const offset = seg.fileoff + seg.filesize; | 2347 | const offset = seg.fileoff + seg.filesize; |
| 2348 | assert(mem.isAlignedGeneric(u64, offset, @alignOf(u64))); | 2348 | assert(mem.isAlignedGeneric(u64, offset, @alignOf(u64))); |
| 2349 | const needed_size = out_dice.items.len * @sizeOf(macho.data_in_code_entry); | 2349 | const needed_size = out_dice.items.len * @sizeOf(macho.data_in_code_entry); |
| 2350 | const needed_size_aligned = mem.alignForwardGeneric(u64, needed_size, @alignOf(u64)); | 2350 | const needed_size_aligned = mem.alignForward(u64, needed_size, @alignOf(u64)); |
| 2351 | seg.filesize = offset + needed_size_aligned - seg.fileoff; | 2351 | seg.filesize = offset + needed_size_aligned - seg.fileoff; |
| 2352 | 2352 | ||
| 2353 | const buffer = try self.gpa.alloc(u8, math.cast(usize, needed_size_aligned) orelse return error.Overflow); | 2353 | const buffer = try self.gpa.alloc(u8, math.cast(usize, needed_size_aligned) orelse return error.Overflow); |
| ... | @@ -2480,7 +2480,7 @@ pub const Zld = struct { | ... | @@ -2480,7 +2480,7 @@ pub const Zld = struct { |
| 2480 | const offset = seg.fileoff + seg.filesize; | 2480 | const offset = seg.fileoff + seg.filesize; |
| 2481 | assert(mem.isAlignedGeneric(u64, offset, @alignOf(u64))); | 2481 | assert(mem.isAlignedGeneric(u64, offset, @alignOf(u64))); |
| 2482 | const needed_size = self.strtab.buffer.items.len; | 2482 | const needed_size = self.strtab.buffer.items.len; |
| 2483 | const needed_size_aligned = mem.alignForwardGeneric(u64, needed_size, @alignOf(u64)); | 2483 | const needed_size_aligned = mem.alignForward(u64, needed_size, @alignOf(u64)); |
| 2484 | seg.filesize = offset + needed_size_aligned - seg.fileoff; | 2484 | seg.filesize = offset + needed_size_aligned - seg.fileoff; |
| 2485 | 2485 | ||
| 2486 | log.debug("writing string table from 0x{x} to 0x{x}", .{ offset, offset + needed_size_aligned }); | 2486 | log.debug("writing string table from 0x{x} to 0x{x}", .{ offset, offset + needed_size_aligned }); |
| ... | @@ -2515,7 +2515,7 @@ pub const Zld = struct { | ... | @@ -2515,7 +2515,7 @@ pub const Zld = struct { |
| 2515 | const offset = seg.fileoff + seg.filesize; | 2515 | const offset = seg.fileoff + seg.filesize; |
| 2516 | assert(mem.isAlignedGeneric(u64, offset, @alignOf(u64))); | 2516 | assert(mem.isAlignedGeneric(u64, offset, @alignOf(u64))); |
| 2517 | const needed_size = nindirectsyms * @sizeOf(u32); | 2517 | const needed_size = nindirectsyms * @sizeOf(u32); |
| 2518 | const needed_size_aligned = mem.alignForwardGeneric(u64, needed_size, @alignOf(u64)); | 2518 | const needed_size_aligned = mem.alignForward(u64, needed_size, @alignOf(u64)); |
| 2519 | seg.filesize = offset + needed_size_aligned - seg.fileoff; | 2519 | seg.filesize = offset + needed_size_aligned - seg.fileoff; |
| 2520 | 2520 | ||
| 2521 | log.debug("writing indirect symbol table from 0x{x} to 0x{x}", .{ offset, offset + needed_size_aligned }); | 2521 | log.debug("writing indirect symbol table from 0x{x} to 0x{x}", .{ offset, offset + needed_size_aligned }); |
| ... | @@ -2690,7 +2690,7 @@ pub const Zld = struct { | ... | @@ -2690,7 +2690,7 @@ pub const Zld = struct { |
| 2690 | 2690 | ||
| 2691 | for (subsections[0..count]) |cut| { | 2691 | for (subsections[0..count]) |cut| { |
| 2692 | const size = cut.end - cut.start; | 2692 | const size = cut.end - cut.start; |
| 2693 | const num_chunks = mem.alignForward(size, chunk_size) / chunk_size; | 2693 | const num_chunks = mem.alignForward(usize, size, chunk_size) / chunk_size; |
| 2694 | 2694 | ||
| 2695 | var i: usize = 0; | 2695 | var i: usize = 0; |
| 2696 | while (i < num_chunks) : (i += 1) { | 2696 | while (i < num_chunks) : (i += 1) { |
| ... | @@ -2725,10 +2725,10 @@ pub const Zld = struct { | ... | @@ -2725,10 +2725,10 @@ pub const Zld = struct { |
| 2725 | const seg = self.getLinkeditSegmentPtr(); | 2725 | const seg = self.getLinkeditSegmentPtr(); |
| 2726 | // Code signature data has to be 16-bytes aligned for Apple tools to recognize the file | 2726 | // Code signature data has to be 16-bytes aligned for Apple tools to recognize the file |
| 2727 | // https://github.com/opensource-apple/cctools/blob/fdb4825f303fd5c0751be524babd32958181b3ed/libstuff/checkout.c#L271 | 2727 | // https://github.com/opensource-apple/cctools/blob/fdb4825f303fd5c0751be524babd32958181b3ed/libstuff/checkout.c#L271 |
| 2728 | const offset = mem.alignForwardGeneric(u64, seg.fileoff + seg.filesize, 16); | 2728 | const offset = mem.alignForward(u64, seg.fileoff + seg.filesize, 16); |
| 2729 | const needed_size = code_sig.estimateSize(offset); | 2729 | const needed_size = code_sig.estimateSize(offset); |
| 2730 | seg.filesize = offset + needed_size - seg.fileoff; | 2730 | seg.filesize = offset + needed_size - seg.fileoff; |
| 2731 | seg.vmsize = mem.alignForwardGeneric(u64, seg.filesize, self.page_size); | 2731 | seg.vmsize = mem.alignForward(u64, seg.filesize, self.page_size); |
| 2732 | log.debug("writing code signature padding from 0x{x} to 0x{x}", .{ offset, offset + needed_size }); | 2732 | log.debug("writing code signature padding from 0x{x} to 0x{x}", .{ offset, offset + needed_size }); |
| 2733 | // Pad out the space. We need to do this to calculate valid hashes for everything in the file | 2733 | // Pad out the space. We need to do this to calculate valid hashes for everything in the file |
| 2734 | // except for code signature data. | 2734 | // except for code signature data. |
src/link/Wasm.zig+8-8| ... | @@ -2118,7 +2118,7 @@ fn allocateAtoms(wasm: *Wasm) !void { | ... | @@ -2118,7 +2118,7 @@ fn allocateAtoms(wasm: *Wasm) !void { |
| 2118 | } | 2118 | } |
| 2119 | } | 2119 | } |
| 2120 | } | 2120 | } |
| 2121 | offset = std.mem.alignForwardGeneric(u32, offset, atom.alignment); | 2121 | offset = std.mem.alignForward(u32, offset, atom.alignment); |
| 2122 | atom.offset = offset; | 2122 | atom.offset = offset; |
| 2123 | log.debug("Atom '{s}' allocated from 0x{x:0>8} to 0x{x:0>8} size={d}", .{ | 2123 | log.debug("Atom '{s}' allocated from 0x{x:0>8} to 0x{x:0>8} size={d}", .{ |
| 2124 | symbol_loc.getName(wasm), | 2124 | symbol_loc.getName(wasm), |
| ... | @@ -2129,7 +2129,7 @@ fn allocateAtoms(wasm: *Wasm) !void { | ... | @@ -2129,7 +2129,7 @@ fn allocateAtoms(wasm: *Wasm) !void { |
| 2129 | offset += atom.size; | 2129 | offset += atom.size; |
| 2130 | atom_index = atom.prev orelse break; | 2130 | atom_index = atom.prev orelse break; |
| 2131 | } | 2131 | } |
| 2132 | segment.size = std.mem.alignForwardGeneric(u32, offset, segment.alignment); | 2132 | segment.size = std.mem.alignForward(u32, offset, segment.alignment); |
| 2133 | } | 2133 | } |
| 2134 | } | 2134 | } |
| 2135 | 2135 | ||
| ... | @@ -2731,7 +2731,7 @@ fn setupMemory(wasm: *Wasm) !void { | ... | @@ -2731,7 +2731,7 @@ fn setupMemory(wasm: *Wasm) !void { |
| 2731 | const is_obj = wasm.base.options.output_mode == .Obj; | 2731 | const is_obj = wasm.base.options.output_mode == .Obj; |
| 2732 | 2732 | ||
| 2733 | if (place_stack_first and !is_obj) { | 2733 | if (place_stack_first and !is_obj) { |
| 2734 | memory_ptr = std.mem.alignForwardGeneric(u64, memory_ptr, stack_alignment); | 2734 | memory_ptr = std.mem.alignForward(u64, memory_ptr, stack_alignment); |
| 2735 | memory_ptr += stack_size; | 2735 | memory_ptr += stack_size; |
| 2736 | // We always put the stack pointer global at index 0 | 2736 | // We always put the stack pointer global at index 0 |
| 2737 | wasm.wasm_globals.items[0].init.i32_const = @bitCast(i32, @intCast(u32, memory_ptr)); | 2737 | wasm.wasm_globals.items[0].init.i32_const = @bitCast(i32, @intCast(u32, memory_ptr)); |
| ... | @@ -2741,7 +2741,7 @@ fn setupMemory(wasm: *Wasm) !void { | ... | @@ -2741,7 +2741,7 @@ fn setupMemory(wasm: *Wasm) !void { |
| 2741 | var data_seg_it = wasm.data_segments.iterator(); | 2741 | var data_seg_it = wasm.data_segments.iterator(); |
| 2742 | while (data_seg_it.next()) |entry| { | 2742 | while (data_seg_it.next()) |entry| { |
| 2743 | const segment = &wasm.segments.items[entry.value_ptr.*]; | 2743 | const segment = &wasm.segments.items[entry.value_ptr.*]; |
| 2744 | memory_ptr = std.mem.alignForwardGeneric(u64, memory_ptr, segment.alignment); | 2744 | memory_ptr = std.mem.alignForward(u64, memory_ptr, segment.alignment); |
| 2745 | 2745 | ||
| 2746 | // set TLS-related symbols | 2746 | // set TLS-related symbols |
| 2747 | if (mem.eql(u8, entry.key_ptr.*, ".tdata")) { | 2747 | if (mem.eql(u8, entry.key_ptr.*, ".tdata")) { |
| ... | @@ -2779,7 +2779,7 @@ fn setupMemory(wasm: *Wasm) !void { | ... | @@ -2779,7 +2779,7 @@ fn setupMemory(wasm: *Wasm) !void { |
| 2779 | // create the memory init flag which is used by the init memory function | 2779 | // create the memory init flag which is used by the init memory function |
| 2780 | if (wasm.base.options.shared_memory and wasm.hasPassiveInitializationSegments()) { | 2780 | if (wasm.base.options.shared_memory and wasm.hasPassiveInitializationSegments()) { |
| 2781 | // align to pointer size | 2781 | // align to pointer size |
| 2782 | memory_ptr = mem.alignForwardGeneric(u64, memory_ptr, 4); | 2782 | memory_ptr = mem.alignForward(u64, memory_ptr, 4); |
| 2783 | const loc = try wasm.createSyntheticSymbol("__wasm_init_memory_flag", .data); | 2783 | const loc = try wasm.createSyntheticSymbol("__wasm_init_memory_flag", .data); |
| 2784 | const sym = loc.getSymbol(wasm); | 2784 | const sym = loc.getSymbol(wasm); |
| 2785 | sym.virtual_address = @intCast(u32, memory_ptr); | 2785 | sym.virtual_address = @intCast(u32, memory_ptr); |
| ... | @@ -2787,7 +2787,7 @@ fn setupMemory(wasm: *Wasm) !void { | ... | @@ -2787,7 +2787,7 @@ fn setupMemory(wasm: *Wasm) !void { |
| 2787 | } | 2787 | } |
| 2788 | 2788 | ||
| 2789 | if (!place_stack_first and !is_obj) { | 2789 | if (!place_stack_first and !is_obj) { |
| 2790 | memory_ptr = std.mem.alignForwardGeneric(u64, memory_ptr, stack_alignment); | 2790 | memory_ptr = std.mem.alignForward(u64, memory_ptr, stack_alignment); |
| 2791 | memory_ptr += stack_size; | 2791 | memory_ptr += stack_size; |
| 2792 | wasm.wasm_globals.items[0].init.i32_const = @bitCast(i32, @intCast(u32, memory_ptr)); | 2792 | wasm.wasm_globals.items[0].init.i32_const = @bitCast(i32, @intCast(u32, memory_ptr)); |
| 2793 | } | 2793 | } |
| ... | @@ -2796,7 +2796,7 @@ fn setupMemory(wasm: *Wasm) !void { | ... | @@ -2796,7 +2796,7 @@ fn setupMemory(wasm: *Wasm) !void { |
| 2796 | // We must set its virtual address so it can be used in relocations. | 2796 | // We must set its virtual address so it can be used in relocations. |
| 2797 | if (wasm.findGlobalSymbol("__heap_base")) |loc| { | 2797 | if (wasm.findGlobalSymbol("__heap_base")) |loc| { |
| 2798 | const symbol = loc.getSymbol(wasm); | 2798 | const symbol = loc.getSymbol(wasm); |
| 2799 | symbol.virtual_address = @intCast(u32, mem.alignForwardGeneric(u64, memory_ptr, heap_alignment)); | 2799 | symbol.virtual_address = @intCast(u32, mem.alignForward(u64, memory_ptr, heap_alignment)); |
| 2800 | } | 2800 | } |
| 2801 | 2801 | ||
| 2802 | // Setup the max amount of pages | 2802 | // Setup the max amount of pages |
| ... | @@ -2818,7 +2818,7 @@ fn setupMemory(wasm: *Wasm) !void { | ... | @@ -2818,7 +2818,7 @@ fn setupMemory(wasm: *Wasm) !void { |
| 2818 | } | 2818 | } |
| 2819 | memory_ptr = initial_memory; | 2819 | memory_ptr = initial_memory; |
| 2820 | } | 2820 | } |
| 2821 | memory_ptr = mem.alignForwardGeneric(u64, memory_ptr, std.wasm.page_size); | 2821 | memory_ptr = mem.alignForward(u64, memory_ptr, std.wasm.page_size); |
| 2822 | // In case we do not import memory, but define it ourselves, | 2822 | // In case we do not import memory, but define it ourselves, |
| 2823 | // set the minimum amount of pages on the memory section. | 2823 | // set the minimum amount of pages on the memory section. |
| 2824 | wasm.memories.limits.min = @intCast(u32, memory_ptr / page_size); | 2824 | wasm.memories.limits.min = @intCast(u32, memory_ptr / page_size); |
src/objcopy.zig+3-3| ... | @@ -1024,7 +1024,7 @@ fn ElfFile(comptime is_64: bool) type { | ... | @@ -1024,7 +1024,7 @@ fn ElfFile(comptime is_64: bool) type { |
| 1024 | dest.sh_size = @intCast(Elf_OffSize, data.len); | 1024 | dest.sh_size = @intCast(Elf_OffSize, data.len); |
| 1025 | 1025 | ||
| 1026 | const addralign = if (src.sh_addralign == 0 or dest.sh_type == elf.SHT_NOBITS) 1 else src.sh_addralign; | 1026 | const addralign = if (src.sh_addralign == 0 or dest.sh_type == elf.SHT_NOBITS) 1 else src.sh_addralign; |
| 1027 | dest.sh_offset = std.mem.alignForwardGeneric(Elf_OffSize, eof_offset, addralign); | 1027 | dest.sh_offset = std.mem.alignForward(Elf_OffSize, eof_offset, addralign); |
| 1028 | if (src.sh_offset != dest.sh_offset and section.segment != null and update.action != .empty and dest.sh_type != elf.SHT_NOTE) { | 1028 | if (src.sh_offset != dest.sh_offset and section.segment != null and update.action != .empty and dest.sh_type != elf.SHT_NOTE) { |
| 1029 | if (src.sh_offset > dest.sh_offset) { | 1029 | if (src.sh_offset > dest.sh_offset) { |
| 1030 | dest.sh_offset = src.sh_offset; // add padding to avoid modifing the program segments | 1030 | dest.sh_offset = src.sh_offset; // add padding to avoid modifing the program segments |
| ... | @@ -1085,7 +1085,7 @@ fn ElfFile(comptime is_64: bool) type { | ... | @@ -1085,7 +1085,7 @@ fn ElfFile(comptime is_64: bool) type { |
| 1085 | // add a ".gnu_debuglink" section | 1085 | // add a ".gnu_debuglink" section |
| 1086 | if (options.debuglink) |link| { | 1086 | if (options.debuglink) |link| { |
| 1087 | const payload = payload: { | 1087 | const payload = payload: { |
| 1088 | const crc_offset = std.mem.alignForward(link.name.len + 1, 4); | 1088 | const crc_offset = std.mem.alignForward(usize, link.name.len + 1, 4); |
| 1089 | const buf = try allocator.alignedAlloc(u8, 4, crc_offset + 4); | 1089 | const buf = try allocator.alignedAlloc(u8, 4, crc_offset + 4); |
| 1090 | @memcpy(buf[0..link.name.len], link.name); | 1090 | @memcpy(buf[0..link.name.len], link.name); |
| 1091 | @memset(buf[link.name.len..crc_offset], 0); | 1091 | @memset(buf[link.name.len..crc_offset], 0); |
| ... | @@ -1117,7 +1117,7 @@ fn ElfFile(comptime is_64: bool) type { | ... | @@ -1117,7 +1117,7 @@ fn ElfFile(comptime is_64: bool) type { |
| 1117 | 1117 | ||
| 1118 | // write the section header at the tail | 1118 | // write the section header at the tail |
| 1119 | { | 1119 | { |
| 1120 | const offset = std.mem.alignForwardGeneric(Elf_OffSize, eof_offset, @alignOf(Elf_Shdr)); | 1120 | const offset = std.mem.alignForward(Elf_OffSize, eof_offset, @alignOf(Elf_Shdr)); |
| 1121 | 1121 | ||
| 1122 | const data = std.mem.sliceAsBytes(updated_section_header); | 1122 | const data = std.mem.sliceAsBytes(updated_section_header); |
| 1123 | assert(data.len == @as(usize, updated_elf_header.e_shentsize) * new_shnum); | 1123 | assert(data.len == @as(usize, updated_elf_header.e_shentsize) * new_shnum); |
src/type.zig+11-11| ... | @@ -1339,7 +1339,7 @@ pub const Type = struct { | ... | @@ -1339,7 +1339,7 @@ pub const Type = struct { |
| 1339 | .storage = .{ .lazy_size = ty.toIntern() }, | 1339 | .storage = .{ .lazy_size = ty.toIntern() }, |
| 1340 | } })).toValue() }, | 1340 | } })).toValue() }, |
| 1341 | }; | 1341 | }; |
| 1342 | const result = std.mem.alignForwardGeneric(u32, total_bytes, alignment); | 1342 | const result = std.mem.alignForward(u32, total_bytes, alignment); |
| 1343 | return AbiSizeAdvanced{ .scalar = result }; | 1343 | return AbiSizeAdvanced{ .scalar = result }; |
| 1344 | }, | 1344 | }, |
| 1345 | 1345 | ||
| ... | @@ -1380,14 +1380,14 @@ pub const Type = struct { | ... | @@ -1380,14 +1380,14 @@ pub const Type = struct { |
| 1380 | var size: u64 = 0; | 1380 | var size: u64 = 0; |
| 1381 | if (code_align > payload_align) { | 1381 | if (code_align > payload_align) { |
| 1382 | size += code_size; | 1382 | size += code_size; |
| 1383 | size = std.mem.alignForwardGeneric(u64, size, payload_align); | 1383 | size = std.mem.alignForward(u64, size, payload_align); |
| 1384 | size += payload_size; | 1384 | size += payload_size; |
| 1385 | size = std.mem.alignForwardGeneric(u64, size, code_align); | 1385 | size = std.mem.alignForward(u64, size, code_align); |
| 1386 | } else { | 1386 | } else { |
| 1387 | size += payload_size; | 1387 | size += payload_size; |
| 1388 | size = std.mem.alignForwardGeneric(u64, size, code_align); | 1388 | size = std.mem.alignForward(u64, size, code_align); |
| 1389 | size += code_size; | 1389 | size += code_size; |
| 1390 | size = std.mem.alignForwardGeneric(u64, size, payload_align); | 1390 | size = std.mem.alignForward(u64, size, payload_align); |
| 1391 | } | 1391 | } |
| 1392 | return AbiSizeAdvanced{ .scalar = size }; | 1392 | return AbiSizeAdvanced{ .scalar = size }; |
| 1393 | }, | 1393 | }, |
| ... | @@ -1595,7 +1595,7 @@ pub const Type = struct { | ... | @@ -1595,7 +1595,7 @@ pub const Type = struct { |
| 1595 | 1595 | ||
| 1596 | fn intAbiSize(bits: u16, target: Target) u64 { | 1596 | fn intAbiSize(bits: u16, target: Target) u64 { |
| 1597 | const alignment = intAbiAlignment(bits, target); | 1597 | const alignment = intAbiAlignment(bits, target); |
| 1598 | return std.mem.alignForwardGeneric(u64, @intCast(u16, (@as(u17, bits) + 7) / 8), alignment); | 1598 | return std.mem.alignForward(u64, @intCast(u16, (@as(u17, bits) + 7) / 8), alignment); |
| 1599 | } | 1599 | } |
| 1600 | 1600 | ||
| 1601 | fn intAbiAlignment(bits: u16, target: Target) u32 { | 1601 | fn intAbiAlignment(bits: u16, target: Target) u32 { |
| ... | @@ -3194,7 +3194,7 @@ pub const Type = struct { | ... | @@ -3194,7 +3194,7 @@ pub const Type = struct { |
| 3194 | 3194 | ||
| 3195 | const field_align = field.alignment(mod, it.struct_obj.layout); | 3195 | const field_align = field.alignment(mod, it.struct_obj.layout); |
| 3196 | it.big_align = @max(it.big_align, field_align); | 3196 | it.big_align = @max(it.big_align, field_align); |
| 3197 | const field_offset = std.mem.alignForwardGeneric(u64, it.offset, field_align); | 3197 | const field_offset = std.mem.alignForward(u64, it.offset, field_align); |
| 3198 | it.offset = field_offset + field.ty.abiSize(mod); | 3198 | it.offset = field_offset + field.ty.abiSize(mod); |
| 3199 | return FieldOffset{ .field = i, .offset = field_offset }; | 3199 | return FieldOffset{ .field = i, .offset = field_offset }; |
| 3200 | } | 3200 | } |
| ... | @@ -3223,7 +3223,7 @@ pub const Type = struct { | ... | @@ -3223,7 +3223,7 @@ pub const Type = struct { |
| 3223 | return field_offset.offset; | 3223 | return field_offset.offset; |
| 3224 | } | 3224 | } |
| 3225 | 3225 | ||
| 3226 | return std.mem.alignForwardGeneric(u64, it.offset, @max(it.big_align, 1)); | 3226 | return std.mem.alignForward(u64, it.offset, @max(it.big_align, 1)); |
| 3227 | }, | 3227 | }, |
| 3228 | 3228 | ||
| 3229 | .anon_struct_type => |tuple| { | 3229 | .anon_struct_type => |tuple| { |
| ... | @@ -3239,11 +3239,11 @@ pub const Type = struct { | ... | @@ -3239,11 +3239,11 @@ pub const Type = struct { |
| 3239 | 3239 | ||
| 3240 | const field_align = field_ty.toType().abiAlignment(mod); | 3240 | const field_align = field_ty.toType().abiAlignment(mod); |
| 3241 | big_align = @max(big_align, field_align); | 3241 | big_align = @max(big_align, field_align); |
| 3242 | offset = std.mem.alignForwardGeneric(u64, offset, field_align); | 3242 | offset = std.mem.alignForward(u64, offset, field_align); |
| 3243 | if (i == index) return offset; | 3243 | if (i == index) return offset; |
| 3244 | offset += field_ty.toType().abiSize(mod); | 3244 | offset += field_ty.toType().abiSize(mod); |
| 3245 | } | 3245 | } |
| 3246 | offset = std.mem.alignForwardGeneric(u64, offset, @max(big_align, 1)); | 3246 | offset = std.mem.alignForward(u64, offset, @max(big_align, 1)); |
| 3247 | return offset; | 3247 | return offset; |
| 3248 | }, | 3248 | }, |
| 3249 | 3249 | ||
| ... | @@ -3254,7 +3254,7 @@ pub const Type = struct { | ... | @@ -3254,7 +3254,7 @@ pub const Type = struct { |
| 3254 | const layout = union_obj.getLayout(mod, true); | 3254 | const layout = union_obj.getLayout(mod, true); |
| 3255 | if (layout.tag_align >= layout.payload_align) { | 3255 | if (layout.tag_align >= layout.payload_align) { |
| 3256 | // {Tag, Payload} | 3256 | // {Tag, Payload} |
| 3257 | return std.mem.alignForwardGeneric(u64, layout.tag_size, layout.payload_align); | 3257 | return std.mem.alignForward(u64, layout.tag_size, layout.payload_align); |
| 3258 | } else { | 3258 | } else { |
| 3259 | // {Payload, Tag} | 3259 | // {Payload, Tag} |
| 3260 | return 0; | 3260 | return 0; |