diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2021-10-10 10:33:15 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2021-10-13 16:17:10 +0200 |
| commit | fc302f00a9de5de0490f4a66720e75946763c695 (patch) | |
| tree | 3ac9dfd61b29a6dbab7054abe6e71daf7f085e6c /src/link/MachO/Object.zig | |
| parent | a3104a4a78089f3260c0dd3f4a96012c6d73a63b (diff) | |
| download | zig-fc302f00a9de5de0490f4a66720e75946763c695.tar.gz zig-fc302f00a9de5de0490f4a66720e75946763c695.zip | |
macho: redo relocation handling and lazy bind globals
* apply late symbol resolution for globals - instead of resolving
the exact location of a symbol in locals, globals or undefs,
we postpone the exact resolution until we have a full picture
for relocation resolution.
* fixup stubs to defined symbols - this is currently a hack rather
than a final solution. I'll need to work out the details to make
it more approachable. Currently, we preemptively create a stub
for a lazy bound global and fix up stub offsets in stub helper
routine if the global turns out to be undefined only. This is quite
wasteful in terms of space as we create stub, stub helper and lazy ptr
atoms but don't use them for defined globals.
* change log scope to .link for macho.
* remove redundant code paths from Object and Atom.
* drastically simplify the contents of Relocation struct (i.e., it is
now a simple superset of macho.relocation_info), clean up relocation
parsing and resolution logic.
Diffstat (limited to 'src/link/MachO/Object.zig')
| -rw-r--r-- | src/link/MachO/Object.zig | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/link/MachO/Object.zig b/src/link/MachO/Object.zig index cfa994ecfb..de747eb4c7 100644 --- a/src/link/MachO/Object.zig +++ b/src/link/MachO/Object.zig @@ -6,7 +6,7 @@ const assert = std.debug.assert; const dwarf = std.dwarf; const fs = std.fs; const io = std.io; -const log = std.log.scoped(.object); +const log = std.log.scoped(.link); const macho = std.macho; const math = std.math; const mem = std.mem; @@ -458,9 +458,15 @@ pub fn parseIntoAtoms(self: *Object, allocator: *Allocator, macho_file: *MachO) // a temp one, unless we already did that when working out the relocations // of other atoms. const atom_local_sym_index = self.sections_as_symbols.get(sect_id) orelse blk: { + const sym_name = try std.fmt.allocPrint(allocator, "{s}_{s}_{s}", .{ + self.name, + segmentName(sect), + sectionName(sect), + }); + defer allocator.free(sym_name); const atom_local_sym_index = @intCast(u32, macho_file.locals.items.len); try macho_file.locals.append(allocator, .{ - .n_strx = 0, + .n_strx = try macho_file.makeString(sym_name), .n_type = macho.N_SECT, .n_sect = @intCast(u8, macho_file.section_ordinals.getIndex(match).? + 1), .n_desc = 0, @@ -481,7 +487,6 @@ pub fn parseIntoAtoms(self: *Object, allocator: *Allocator, macho_file: *MachO) try atom.parseRelocs(relocs, .{ .base_addr = sect.addr, - .base_offset = 0, .allocator = allocator, .object = self, .macho_file = macho_file, |
