aboutsummaryrefslogtreecommitdiff
path: root/src/link/MachO/Object.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2024-01-02 14:11:27 -0800
committerGitHub <noreply@github.com>2024-01-02 14:11:27 -0800
commit289ae45c1b58e952867c4fa1e246d0ef7bc2ff64 (patch)
tree5dd034143a2354b7b44496e684f1c764e2f9664c /src/link/MachO/Object.zig
parentc89bb3e141ee215add0b52930d48bffd8dae8342 (diff)
parentc546ddb3edc557fae4b932e5239b9dcb66117832 (diff)
downloadzig-289ae45c1b58e952867c4fa1e246d0ef7bc2ff64.tar.gz
zig-289ae45c1b58e952867c4fa1e246d0ef7bc2ff64.zip
Merge pull request #18160 from ziglang/std-build-module
Move many settings from being per-Compilation to being per-Module
Diffstat (limited to 'src/link/MachO/Object.zig')
-rw-r--r--src/link/MachO/Object.zig49
1 files changed, 29 insertions, 20 deletions
diff --git a/src/link/MachO/Object.zig b/src/link/MachO/Object.zig
index 0c68d70644..ad069b845e 100644
--- a/src/link/MachO/Object.zig
+++ b/src/link/MachO/Object.zig
@@ -342,19 +342,23 @@ pub const SplitIntoAtomsError = error{
};
pub fn splitIntoAtoms(self: *Object, macho_file: *MachO, object_id: u32) SplitIntoAtomsError!void {
+ const comp = macho_file.base.comp;
+ const gpa = comp.gpa;
log.debug("splitting object({d}, {s}) into atoms", .{ object_id, self.name });
try self.splitRegularSections(macho_file, object_id);
try self.parseEhFrameSection(macho_file, object_id);
try self.parseUnwindInfo(macho_file, object_id);
- try self.parseDataInCode(macho_file.base.allocator);
+ try self.parseDataInCode(gpa);
}
/// Splits input regular sections into Atoms.
/// If the Object was compiled with `MH_SUBSECTIONS_VIA_SYMBOLS`, splits section
/// into subsections where each subsection then represents an Atom.
pub fn splitRegularSections(self: *Object, macho_file: *MachO, object_id: u32) !void {
- const gpa = macho_file.base.allocator;
+ const comp = macho_file.base.comp;
+ const gpa = comp.gpa;
+ const target = macho_file.base.comp.root_mod.resolved_target.result;
const sections = self.getSourceSections();
for (sections, 0..) |sect, id| {
@@ -448,7 +452,7 @@ pub fn splitRegularSections(self: *Object, macho_file: *MachO, object_id: u32) !
try self.parseRelocs(gpa, section.id);
- const cpu_arch = macho_file.base.options.target.cpu.arch;
+ const cpu_arch = target.cpu.arch;
const sect_loc = filterSymbolsBySection(symtab[sect_sym_index..], sect_id + 1);
const sect_start_index = sect_sym_index + sect_loc.index;
@@ -554,7 +558,8 @@ fn createAtomFromSubsection(
alignment: Alignment,
out_sect_id: u8,
) !Atom.Index {
- const gpa = macho_file.base.allocator;
+ const comp = macho_file.base.comp;
+ const gpa = comp.gpa;
const atom_index = try macho_file.createAtom(sym_index, .{
.size = size,
.alignment = alignment,
@@ -670,13 +675,15 @@ fn parseEhFrameSection(self: *Object, macho_file: *MachO, object_id: u32) !void
log.debug("parsing __TEXT,__eh_frame section", .{});
- const gpa = macho_file.base.allocator;
+ const comp = macho_file.base.comp;
+ const gpa = comp.gpa;
if (macho_file.eh_frame_section_index == null) {
macho_file.eh_frame_section_index = try macho_file.initSection("__TEXT", "__eh_frame", .{});
}
- const cpu_arch = macho_file.base.options.target.cpu.arch;
+ const target = macho_file.base.comp.root_mod.resolved_target.result;
+ const cpu_arch = target.cpu.arch;
try self.parseRelocs(gpa, sect_id);
const relocs = self.getRelocs(sect_id);
@@ -704,7 +711,7 @@ fn parseEhFrameSection(self: *Object, macho_file: *MachO, object_id: u32) !void
});
if (record.tag == .fde) {
- const target = blk: {
+ const reloc_target = blk: {
switch (cpu_arch) {
.aarch64 => {
assert(rel_pos.len > 0); // TODO convert to an error as the FDE eh frame is malformed
@@ -714,13 +721,13 @@ fn parseEhFrameSection(self: *Object, macho_file: *MachO, object_id: u32) !void
@as(macho.reloc_type_arm64, @enumFromInt(rel.r_type)) == .ARM64_RELOC_UNSIGNED)
break rel;
} else unreachable;
- const target = Atom.parseRelocTarget(macho_file, .{
+ const reloc_target = Atom.parseRelocTarget(macho_file, .{
.object_id = object_id,
.rel = rel,
.code = it.data[offset..],
.base_offset = @as(i32, @intCast(offset)),
});
- break :blk target;
+ break :blk reloc_target;
},
.x86_64 => {
const target_address = record.getTargetSymbolAddress(.{
@@ -728,16 +735,16 @@ fn parseEhFrameSection(self: *Object, macho_file: *MachO, object_id: u32) !void
.base_offset = offset,
});
const target_sym_index = self.getSymbolByAddress(target_address, null);
- const target = if (self.getGlobal(target_sym_index)) |global_index|
+ const reloc_target = if (self.getGlobal(target_sym_index)) |global_index|
macho_file.globals.items[global_index]
else
SymbolWithLoc{ .sym_index = target_sym_index, .file = object_id + 1 };
- break :blk target;
+ break :blk reloc_target;
},
else => unreachable,
}
};
- if (target.getFile() != object_id) {
+ if (reloc_target.getFile() != object_id) {
log.debug("FDE at offset {x} marked DEAD", .{offset});
self.eh_frame_relocs_lookup.getPtr(offset).?.dead = true;
} else {
@@ -746,12 +753,12 @@ fn parseEhFrameSection(self: *Object, macho_file: *MachO, object_id: u32) !void
// very problematic when using Zig's @export feature to re-export symbols under
// additional names. For that reason, we need to ensure we record aliases here
// too so that we can tie them with their matching unwind records and vice versa.
- const aliases = self.getSymbolAliases(target.sym_index);
+ const aliases = self.getSymbolAliases(reloc_target.sym_index);
var i: u32 = 0;
while (i < aliases.len) : (i += 1) {
const actual_target = SymbolWithLoc{
.sym_index = i + aliases.start,
- .file = target.file,
+ .file = reloc_target.file,
};
log.debug("FDE at offset {x} tracks {s}", .{
offset,
@@ -765,8 +772,10 @@ fn parseEhFrameSection(self: *Object, macho_file: *MachO, object_id: u32) !void
}
fn parseUnwindInfo(self: *Object, macho_file: *MachO, object_id: u32) !void {
- const gpa = macho_file.base.allocator;
- const cpu_arch = macho_file.base.options.target.cpu.arch;
+ const comp = macho_file.base.comp;
+ const gpa = comp.gpa;
+ const target = macho_file.base.comp.root_mod.resolved_target.result;
+ const cpu_arch = target.cpu.arch;
const sect_id = self.unwind_info_sect_id orelse {
// If it so happens that the object had `__eh_frame` section defined but no `__compact_unwind`,
// we will try fully synthesising unwind info records to somewhat match Apple ld's
@@ -818,13 +827,13 @@ fn parseUnwindInfo(self: *Object, macho_file: *MachO, object_id: u32) !void {
// Find function symbol that this record describes
const rel = relocs[rel_pos.start..][rel_pos.len - 1];
- const target = Atom.parseRelocTarget(macho_file, .{
+ const reloc_target = Atom.parseRelocTarget(macho_file, .{
.object_id = object_id,
.rel = rel,
.code = mem.asBytes(&record),
.base_offset = @as(i32, @intCast(offset)),
});
- if (target.getFile() != object_id) {
+ if (reloc_target.getFile() != object_id) {
log.debug("unwind record {d} marked DEAD", .{record_id});
self.unwind_relocs_lookup[record_id].dead = true;
} else {
@@ -833,12 +842,12 @@ fn parseUnwindInfo(self: *Object, macho_file: *MachO, object_id: u32) !void {
// very problematic when using Zig's @export feature to re-export symbols under
// additional names. For that reason, we need to ensure we record aliases here
// too so that we can tie them with their matching unwind records and vice versa.
- const aliases = self.getSymbolAliases(target.sym_index);
+ const aliases = self.getSymbolAliases(reloc_target.sym_index);
var i: u32 = 0;
while (i < aliases.len) : (i += 1) {
const actual_target = SymbolWithLoc{
.sym_index = i + aliases.start,
- .file = target.file,
+ .file = reloc_target.file,
};
log.debug("unwind record {d} tracks {s}", .{
record_id,