aboutsummaryrefslogtreecommitdiff
path: root/src/link/MachO/TextBlock.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2021-07-22 22:19:15 +0200
committerJakub Konka <kubkon@jakubkonka.com>2021-07-22 23:13:13 +0200
commita4feb97cdfb330207f3da05402983bf3a71de64e (patch)
treea2afbbb4567f128b4c1785c26d3a5bdb129dc9ce /src/link/MachO/TextBlock.zig
parent4fd0cb7618ffb5428981672f6a21c411599f51b2 (diff)
downloadzig-a4feb97cdfb330207f3da05402983bf3a71de64e.tar.gz
zig-a4feb97cdfb330207f3da05402983bf3a71de64e.zip
macho: assign and cache section ordinals upon creation
then, when sorting sections within segments, clear and redo the ordinals since we re-apply them to symbols anyway. It is vital to have the ordinals consistent with parsing and resolving relocs however.
Diffstat (limited to 'src/link/MachO/TextBlock.zig')
-rw-r--r--src/link/MachO/TextBlock.zig6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/link/MachO/TextBlock.zig b/src/link/MachO/TextBlock.zig
index 9dc02d1f4d..17d1d82db8 100644
--- a/src/link/MachO/TextBlock.zig
+++ b/src/link/MachO/TextBlock.zig
@@ -620,7 +620,7 @@ fn initRelocFromObject(rel: macho.relocation_info, object: *Object, ctx: RelocCo
try ctx.macho_file.locals.append(ctx.macho_file.base.allocator, .{
.n_strx = try ctx.macho_file.makeString(sym_name),
.n_type = macho.N_SECT,
- .n_sect = ctx.macho_file.sectionId(match),
+ .n_sect = ctx.macho_file.section_to_ordinal.get(match) orelse unreachable,
.n_desc = 0,
.n_value = sect.addr,
});
@@ -832,7 +832,7 @@ pub fn parseRelocsFromObject(
},
.local => {
const source_sym = ctx.macho_file.locals.items[self.local_sym_index];
- const match = ctx.macho_file.unpackSectionId(source_sym.n_sect);
+ const match = ctx.macho_file.section_ordinals.items[source_sym.n_sect];
const seg = ctx.macho_file.load_commands.items[match.seg].Segment;
const sect = seg.sections.items[match.sect];
const sect_type = commands.sectionType(sect);
@@ -1096,7 +1096,7 @@ pub fn resolveRelocs(self: *TextBlock, macho_file: *MachO) !void {
const sym = macho_file.locals.items[rel.where_index];
const is_tlv = is_tlv: {
const source_sym = macho_file.locals.items[self.local_sym_index];
- const match = macho_file.unpackSectionId(source_sym.n_sect);
+ const match = macho_file.section_ordinals.items[source_sym.n_sect];
const seg = macho_file.load_commands.items[match.seg].Segment;
const sect = seg.sections.items[match.sect];
break :is_tlv commands.sectionType(sect) == macho.S_THREAD_LOCAL_VARIABLES;