diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-06-24 16:58:19 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-24 16:58:19 -0700 |
| commit | 146b79af153bbd5dafda0ba12a040385c7fc58f8 (patch) | |
| tree | 67e3db8b444d65c667e314770fc983a7fc8ba293 /src/link/MachO/Object.zig | |
| parent | 13853bef0df3c90633021850cc6d6abaeea03282 (diff) | |
| parent | 21ac0beb436f49fe49c6982a872f2dc48e4bea5e (diff) | |
| download | zig-146b79af153bbd5dafda0ba12a040385c7fc58f8.tar.gz zig-146b79af153bbd5dafda0ba12a040385c7fc58f8.zip | |
Merge pull request #16163 from mlugg/feat/builtins-infer-dest-ty
Infer destination type of cast builtins using result type
Diffstat (limited to 'src/link/MachO/Object.zig')
| -rw-r--r-- | src/link/MachO/Object.zig | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/src/link/MachO/Object.zig b/src/link/MachO/Object.zig index 105a806075..29fe2988b6 100644 --- a/src/link/MachO/Object.zig +++ b/src/link/MachO/Object.zig @@ -164,7 +164,7 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch) else => {}, } else return; - self.in_symtab = @ptrCast([*]align(1) const macho.nlist_64, self.contents.ptr + symtab.symoff)[0..symtab.nsyms]; + self.in_symtab = @as([*]align(1) const macho.nlist_64, @ptrCast(self.contents.ptr + symtab.symoff))[0..symtab.nsyms]; self.in_strtab = self.contents[symtab.stroff..][0..symtab.strsize]; self.symtab = try allocator.alloc(macho.nlist_64, self.in_symtab.?.len + nsects); @@ -202,7 +202,7 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch) defer sorted_all_syms.deinit(); for (self.in_symtab.?, 0..) |_, index| { - sorted_all_syms.appendAssumeCapacity(.{ .index = @intCast(u32, index) }); + sorted_all_syms.appendAssumeCapacity(.{ .index = @as(u32, @intCast(index)) }); } // We sort by type: defined < undefined, and @@ -225,18 +225,18 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch) } } if (sym.sect() and section_index_lookup == null) { - section_index_lookup = .{ .start = @intCast(u32, i), .len = 1 }; + section_index_lookup = .{ .start = @as(u32, @intCast(i)), .len = 1 }; } prev_sect_id = sym.n_sect; self.symtab[i] = sym; self.source_symtab_lookup[i] = sym_id.index; - self.reverse_symtab_lookup[sym_id.index] = @intCast(u32, i); - self.source_address_lookup[i] = if (sym.undf()) -1 else @intCast(i64, sym.n_value); + self.reverse_symtab_lookup[sym_id.index] = @as(u32, @intCast(i)); + self.source_address_lookup[i] = if (sym.undf()) -1 else @as(i64, @intCast(sym.n_value)); - const sym_name_len = mem.sliceTo(@ptrCast([*:0]const u8, self.in_strtab.?.ptr + sym.n_strx), 0).len + 1; - self.strtab_lookup[i] = @intCast(u32, sym_name_len); + const sym_name_len = mem.sliceTo(@as([*:0]const u8, @ptrCast(self.in_strtab.?.ptr + sym.n_strx)), 0).len + 1; + self.strtab_lookup[i] = @as(u32, @intCast(sym_name_len)); } // If there were no undefined symbols, make sure we populate the @@ -267,7 +267,7 @@ const SymbolAtIndex = struct { fn getSymbolName(self: SymbolAtIndex, ctx: Context) []const u8 { const off = self.getSymbol(ctx).n_strx; - return mem.sliceTo(@ptrCast([*:0]const u8, ctx.in_strtab.?.ptr + off), 0); + return mem.sliceTo(@as([*:0]const u8, @ptrCast(ctx.in_strtab.?.ptr + off)), 0); } fn getSymbolSeniority(self: SymbolAtIndex, ctx: Context) u2 { @@ -338,7 +338,7 @@ fn filterSymbolsBySection(symbols: []macho.nlist_64, n_sect: u8) struct { .n_sect = n_sect, }); - return .{ .index = @intCast(u32, index), .len = @intCast(u32, len) }; + return .{ .index = @as(u32, @intCast(index)), .len = @as(u32, @intCast(len)) }; } fn filterSymbolsByAddress(symbols: []macho.nlist_64, start_addr: u64, end_addr: u64) struct { @@ -360,7 +360,7 @@ fn filterSymbolsByAddress(symbols: []macho.nlist_64, start_addr: u64, end_addr: .addr = end_addr, }); - return .{ .index = @intCast(u32, index), .len = @intCast(u32, len) }; + return .{ .index = @as(u32, @intCast(index)), .len = @as(u32, @intCast(len)) }; } const SortedSection = struct { @@ -400,7 +400,7 @@ pub fn splitRegularSections(self: *Object, zld: *Zld, object_id: u32) !void { }; if (sect.size == 0) continue; - const sect_id = @intCast(u8, id); + const sect_id = @as(u8, @intCast(id)); const sym = self.getSectionAliasSymbolPtr(sect_id); sym.* = .{ .n_strx = 0, @@ -417,7 +417,7 @@ pub fn splitRegularSections(self: *Object, zld: *Zld, object_id: u32) !void { const out_sect_id = (try zld.getOutputSection(sect)) orelse continue; if (sect.size == 0) continue; - const sect_id = @intCast(u8, id); + const sect_id = @as(u8, @intCast(id)); const sym_index = self.getSectionAliasSymbolIndex(sect_id); const atom_index = try self.createAtomFromSubsection( zld, @@ -459,7 +459,7 @@ pub fn splitRegularSections(self: *Object, zld: *Zld, object_id: u32) !void { defer gpa.free(sorted_sections); for (sections, 0..) |sect, id| { - sorted_sections[id] = .{ .header = sect, .id = @intCast(u8, id) }; + sorted_sections[id] = .{ .header = sect, .id = @as(u8, @intCast(id)) }; } mem.sort(SortedSection, sorted_sections, {}, sectionLessThanByAddress); @@ -651,7 +651,7 @@ fn filterRelocs( const start = @import("zld.zig").bsearch(macho.relocation_info, relocs, Predicate{ .addr = end_addr }); const len = @import("zld.zig").lsearch(macho.relocation_info, relocs[start..], LPredicate{ .addr = start_addr }); - return .{ .start = @intCast(u32, start), .len = @intCast(u32, len) }; + return .{ .start = @as(u32, @intCast(start)), .len = @as(u32, @intCast(len)) }; } /// Parse all relocs for the input section, and sort in descending order. @@ -659,7 +659,7 @@ fn filterRelocs( /// section in a sorted manner which is simply not true. fn parseRelocs(self: *Object, gpa: Allocator, sect_id: u8) !void { const section = self.getSourceSection(sect_id); - const start = @intCast(u32, self.relocations.items.len); + const start = @as(u32, @intCast(self.relocations.items.len)); if (self.getSourceRelocs(section)) |relocs| { try self.relocations.ensureUnusedCapacity(gpa, relocs.len); self.relocations.appendUnalignedSliceAssumeCapacity(relocs); @@ -677,8 +677,8 @@ fn cacheRelocs(self: *Object, zld: *Zld, atom_index: AtomIndex) !void { // If there was no matching symbol present in the source symtab, this means // we are dealing with either an entire section, or part of it, but also // starting at the beginning. - const nbase = @intCast(u32, self.in_symtab.?.len); - const sect_id = @intCast(u8, atom.sym_index - nbase); + const nbase = @as(u32, @intCast(self.in_symtab.?.len)); + const sect_id = @as(u8, @intCast(atom.sym_index - nbase)); break :blk sect_id; }; const source_sect = self.getSourceSection(source_sect_id); @@ -745,7 +745,7 @@ fn parseEhFrameSection(self: *Object, zld: *Zld, object_id: u32) !void { .object_id = object_id, .rel = rel, .code = it.data[offset..], - .base_offset = @intCast(i32, offset), + .base_offset = @as(i32, @intCast(offset)), }); break :blk target; }, @@ -798,7 +798,7 @@ fn parseUnwindInfo(self: *Object, zld: *Zld, object_id: u32) !void { _ = try zld.initSection("__TEXT", "__unwind_info", .{}); } - try self.unwind_records_lookup.ensureTotalCapacity(gpa, @intCast(u32, self.exec_atoms.items.len)); + try self.unwind_records_lookup.ensureTotalCapacity(gpa, @as(u32, @intCast(self.exec_atoms.items.len))); const unwind_records = self.getUnwindRecords(); @@ -834,14 +834,14 @@ fn parseUnwindInfo(self: *Object, zld: *Zld, object_id: u32) !void { .object_id = object_id, .rel = rel, .code = mem.asBytes(&record), - .base_offset = @intCast(i32, offset), + .base_offset = @as(i32, @intCast(offset)), }); log.debug("unwind record {d} tracks {s}", .{ record_id, zld.getSymbolName(target) }); if (target.getFile() != object_id) { self.unwind_relocs_lookup[record_id].dead = true; } else { const atom_index = self.getAtomIndexForSymbol(target.sym_index).?; - self.unwind_records_lookup.putAssumeCapacityNoClobber(atom_index, @intCast(u32, record_id)); + self.unwind_records_lookup.putAssumeCapacityNoClobber(atom_index, @as(u32, @intCast(record_id))); } } } @@ -869,7 +869,7 @@ pub fn getSourceSectionIndexByName(self: Object, segname: []const u8, sectname: const sections = self.getSourceSections(); for (sections, 0..) |sect, i| { if (mem.eql(u8, segname, sect.segName()) and mem.eql(u8, sectname, sect.sectName())) - return @intCast(u8, i); + return @as(u8, @intCast(i)); } else return null; } @@ -898,7 +898,7 @@ pub fn parseDataInCode(self: *Object, gpa: Allocator) !void { } } else return; const ndice = @divExact(cmd.datasize, @sizeOf(macho.data_in_code_entry)); - const dice = @ptrCast([*]align(1) const macho.data_in_code_entry, self.contents.ptr + cmd.dataoff)[0..ndice]; + const dice = @as([*]align(1) const macho.data_in_code_entry, @ptrCast(self.contents.ptr + cmd.dataoff))[0..ndice]; try self.data_in_code.ensureTotalCapacityPrecise(gpa, dice.len); self.data_in_code.appendUnalignedSliceAssumeCapacity(dice); mem.sort(macho.data_in_code_entry, self.data_in_code.items, {}, diceLessThan); @@ -945,12 +945,12 @@ pub fn parseDwarfInfo(self: Object) DwarfInfo { } pub fn getSectionContents(self: Object, sect: macho.section_64) []const u8 { - const size = @intCast(usize, sect.size); + const size = @as(usize, @intCast(sect.size)); return self.contents[sect.offset..][0..size]; } pub fn getSectionAliasSymbolIndex(self: Object, sect_id: u8) u32 { - const start = @intCast(u32, self.in_symtab.?.len); + const start = @as(u32, @intCast(self.in_symtab.?.len)); return start + sect_id; } @@ -964,7 +964,7 @@ pub fn getSectionAliasSymbolPtr(self: *Object, sect_id: u8) *macho.nlist_64 { fn getSourceRelocs(self: Object, sect: macho.section_64) ?[]align(1) const macho.relocation_info { if (sect.nreloc == 0) return null; - return @ptrCast([*]align(1) const macho.relocation_info, self.contents.ptr + sect.reloff)[0..sect.nreloc]; + return @as([*]align(1) const macho.relocation_info, @ptrCast(self.contents.ptr + sect.reloff))[0..sect.nreloc]; } pub fn getRelocs(self: Object, sect_id: u8) []const macho.relocation_info { @@ -1005,25 +1005,25 @@ pub fn getSymbolByAddress(self: Object, addr: u64, sect_hint: ?u8) u32 { const target_sym_index = @import("zld.zig").lsearch( i64, self.source_address_lookup[lookup.start..][0..lookup.len], - Predicate{ .addr = @intCast(i64, addr) }, + Predicate{ .addr = @as(i64, @intCast(addr)) }, ); if (target_sym_index > 0) { - return @intCast(u32, lookup.start + target_sym_index - 1); + return @as(u32, @intCast(lookup.start + target_sym_index - 1)); } } return self.getSectionAliasSymbolIndex(sect_id); } const target_sym_index = @import("zld.zig").lsearch(i64, self.source_address_lookup, Predicate{ - .addr = @intCast(i64, addr), + .addr = @as(i64, @intCast(addr)), }); assert(target_sym_index > 0); - return @intCast(u32, target_sym_index - 1); + return @as(u32, @intCast(target_sym_index - 1)); } pub fn getGlobal(self: Object, sym_index: u32) ?u32 { if (self.globals_lookup[sym_index] == -1) return null; - return @intCast(u32, self.globals_lookup[sym_index]); + return @as(u32, @intCast(self.globals_lookup[sym_index])); } pub fn getAtomIndexForSymbol(self: Object, sym_index: u32) ?AtomIndex { @@ -1041,7 +1041,7 @@ pub fn getUnwindRecords(self: Object) []align(1) const macho.compact_unwind_entr const sect = self.getSourceSection(sect_id); const data = self.getSectionContents(sect); const num_entries = @divExact(data.len, @sizeOf(macho.compact_unwind_entry)); - return @ptrCast([*]align(1) const macho.compact_unwind_entry, data)[0..num_entries]; + return @as([*]align(1) const macho.compact_unwind_entry, @ptrCast(data))[0..num_entries]; } pub fn hasEhFrameRecords(self: Object) bool { |
