From 691090f3429b8625252dd5cfec101f2a9e171463 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Mon, 22 Nov 2021 14:15:46 +0100 Subject: [PATCH] zld: parse ObjC ivars and eh_types in tapi v3 and v4 --- src/link/MachO/Dylib.zig | 60 ++++++++++++++++++++++++++++++++++++++++ src/link/tapi.zig | 8 ++++++ 2 files changed, 68 insertions(+) diff --git a/src/link/MachO/Dylib.zig b/src/link/MachO/Dylib.zig index 5b4ab6aa180289099340d6f427a68407737d7241..3d3089f4682b58f422f780f1be015865d022a987 100644 --- a/src/link/MachO/Dylib.zig +++ b/src/link/MachO/Dylib.zig @@ -255,6 +255,18 @@ fn addObjCClassSymbol(self: *Dylib, allocator: *Allocator, sym_name: []const u8) } } +fn addObjCIVarSymbol(self: *Dylib, allocator: *Allocator, sym_name: []const u8) !void { + const expanded = try std.fmt.allocPrint(allocator, "_OBJC_IVAR_$_{s}", .{sym_name}); + if (self.symbols.contains(expanded)) return; + try self.symbols.putNoClobber(allocator, expanded, .{}); +} + +fn addObjCEhTypeSymbol(self: *Dylib, allocator: *Allocator, sym_name: []const u8) !void { + const expanded = try std.fmt.allocPrint(allocator, "_OBJC_EHTYPE_$_{s}", .{sym_name}); + if (self.symbols.contains(expanded)) return; + try self.symbols.putNoClobber(allocator, expanded, .{}); +} + fn addSymbol(self: *Dylib, allocator: *Allocator, sym_name: []const u8) !void { if (self.symbols.contains(sym_name)) return; try self.symbols.putNoClobber(allocator, try allocator.dupe(u8, sym_name), {}); @@ -385,6 +397,18 @@ pub fn parseFromStub(self: *Dylib, allocator: *Allocator, target: std.Target, li } } + if (exp.objc_ivars) |objc_ivars| { + for (objc_ivars) |ivar| { + try self.addObjCIVarSymbol(allocator, ivar); + } + } + + if (exp.objc_eh_types) |objc_eh_types| { + for (objc_eh_types) |eht| { + try self.addObjCEhTypeSymbol(allocator, eht); + } + } + // TODO track which libs were already parsed in different steps if (exp.re_exports) |re_exports| { for (re_exports) |lib| { @@ -415,6 +439,18 @@ pub fn parseFromStub(self: *Dylib, allocator: *Allocator, target: std.Target, li try self.addObjCClassSymbol(allocator, sym_name); } } + + if (exp.objc_ivars) |objc_ivars| { + for (objc_ivars) |ivar| { + try self.addObjCIVarSymbol(allocator, ivar); + } + } + + if (exp.objc_eh_types) |objc_eh_types| { + for (objc_eh_types) |eht| { + try self.addObjCEhTypeSymbol(allocator, eht); + } + } } } @@ -433,6 +469,18 @@ pub fn parseFromStub(self: *Dylib, allocator: *Allocator, target: std.Target, li try self.addObjCClassSymbol(allocator, sym_name); } } + + if (reexp.objc_ivars) |objc_ivars| { + for (objc_ivars) |ivar| { + try self.addObjCIVarSymbol(allocator, ivar); + } + } + + if (reexp.objc_eh_types) |objc_eh_types| { + for (objc_eh_types) |eht| { + try self.addObjCEhTypeSymbol(allocator, eht); + } + } } } @@ -441,6 +489,18 @@ pub fn parseFromStub(self: *Dylib, allocator: *Allocator, target: std.Target, li try self.addObjCClassSymbol(allocator, sym_name); } } + + if (stub.objc_ivars) |objc_ivars| { + for (objc_ivars) |ivar| { + try self.addObjCIVarSymbol(allocator, ivar); + } + } + + if (stub.objc_eh_types) |objc_eh_types| { + for (objc_eh_types) |eht| { + try self.addObjCEhTypeSymbol(allocator, eht); + } + } }, } } diff --git a/src/link/tapi.zig b/src/link/tapi.zig index 3da84102c9bd98f0b1c61c5c0d60748b5c65606c..0bde3100ddfb09ca3594951aea68848b2901f56a 100644 --- a/src/link/tapi.zig +++ b/src/link/tapi.zig @@ -27,6 +27,8 @@ pub const TbdV3 = struct { re_exports: ?[]const []const u8, symbols: ?[]const []const u8, objc_classes: ?[]const []const u8, + objc_ivars: ?[]const []const u8, + objc_eh_types: ?[]const []const u8, }, }; @@ -52,17 +54,23 @@ pub const TbdV4 = struct { targets: []const []const u8, symbols: ?[]const []const u8, objc_classes: ?[]const []const u8, + objc_ivars: ?[]const []const u8, + objc_eh_types: ?[]const []const u8, }, reexports: ?[]const struct { targets: []const []const u8, symbols: ?[]const []const u8, objc_classes: ?[]const []const u8, + objc_ivars: ?[]const []const u8, + objc_eh_types: ?[]const []const u8, }, allowable_clients: ?[]const struct { targets: []const []const u8, clients: []const []const u8, }, objc_classes: ?[]const []const u8, + objc_ivars: ?[]const []const u8, + objc_eh_types: ?[]const []const u8, }; pub const Tbd = union(enum) { -- 2.54.0