zld: parse ObjC ivars and eh_types in tapi v3 and v4

This commit is contained in:
Jakub Konka 2021-11-22 14:15:46 +01:00
parent e17c4a497f
commit 691090f342
2 changed files with 68 additions and 0 deletions

View File

@ -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);
}
}
},
}
}

View File

@ -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) {