diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2021-04-21 17:53:07 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2021-04-24 08:13:53 +0200 |
| commit | b03983b4501031e6faed47bf886586b0ad2150aa (patch) | |
| tree | 0f410332cc8949d148b4741e0e7c7135f8a92bfd /src/link/MachO | |
| parent | 4f7765de7c0203ceed3a5acbe0d4c07b678557b5 (diff) | |
| download | zig-b03983b4501031e6faed47bf886586b0ad2150aa.tar.gz zig-b03983b4501031e6faed47bf886586b0ad2150aa.zip | |
zld: analyze static initializers
Diffstat (limited to 'src/link/MachO')
| -rw-r--r-- | src/link/MachO/Object.zig | 24 | ||||
| -rw-r--r-- | src/link/MachO/Zld.zig | 2 |
2 files changed, 21 insertions, 5 deletions
diff --git a/src/link/MachO/Object.zig b/src/link/MachO/Object.zig index 7b5f23756a..8ccd320274 100644 --- a/src/link/MachO/Object.zig +++ b/src/link/MachO/Object.zig @@ -14,6 +14,7 @@ const Allocator = mem.Allocator; const Relocation = reloc.Relocation; const Symbol = @import("Symbol.zig"); const parseName = @import("Zld.zig").parseName; +const CppStatic = @import("Zld.zig").CppStatic; usingnamespace @import("commands.zig"); @@ -216,6 +217,7 @@ pub fn parse(self: *Object) !void { try self.parseSections(); if (self.symtab_cmd_index != null) try self.parseSymtab(); if (self.data_in_code_cmd_index != null) try self.readDataInCode(); + try self.parseInitializers(); try self.parseDebugInfo(); } @@ -298,28 +300,42 @@ pub fn parseSections(self: *Object) !void { var section = Section{ .inner = sect, .code = code, - .relocs = undefined, + .relocs = null, }; // Parse relocations - section.relocs = if (sect.nreloc > 0) relocs: { + if (sect.nreloc > 0) { var raw_relocs = try self.allocator.alloc(u8, @sizeOf(macho.relocation_info) * sect.nreloc); defer self.allocator.free(raw_relocs); _ = try self.file.?.preadAll(raw_relocs, sect.reloff); - break :relocs try reloc.parse( + section.relocs = try reloc.parse( self.allocator, self.arch.?, section.code, mem.bytesAsSlice(macho.relocation_info, raw_relocs), ); - } else null; + } self.sections.appendAssumeCapacity(section); } } +pub fn parseInitializers(self: *Object) !void { + for (self.sections.items) |section| { + if (section.inner.flags != macho.S_MOD_INIT_FUNC_POINTERS) continue; + log.warn("parsing initializers in {s}", .{self.name.?}); + // Parse C++ initializers + const relocs = section.relocs orelse unreachable; + for (relocs) |rel| { + const sym = self.symtab.items[rel.target.symbol]; + const sym_name = self.getString(sym.n_strx); + log.warn(" | {s}", .{sym_name}); + } + } +} + pub fn parseSymtab(self: *Object) !void { const symtab_cmd = self.load_commands.items[self.symtab_cmd_index.?].Symtab; diff --git a/src/link/MachO/Zld.zig b/src/link/MachO/Zld.zig index bc28911757..ff297c79e5 100644 --- a/src/link/MachO/Zld.zig +++ b/src/link/MachO/Zld.zig @@ -90,7 +90,7 @@ stub_helper_stubs_start_off: ?u64 = null, mappings: std.AutoHashMapUnmanaged(MappingKey, SectionMapping) = .{}, unhandled_sections: std.AutoHashMapUnmanaged(MappingKey, u0) = .{}, -const CppStatic = struct { +pub const CppStatic = struct { index: u32, target_addr: u64, file: u16, |
