authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-11-22 14:15:46+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-11-22 18:01:15+01:00
log691090f3429b8625252dd5cfec101f2a9e171463
tree8fb49640c9848defe5340ae936432e8abc1f5424
parente17c4a497ff77a9da11393886a86a216705eb687

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


2 files changed, 68 insertions(+), 0 deletions(-)

src/link/MachO/Dylib.zig+60
......@@ -255,6 +255,18 @@ fn addObjCClassSymbol(self: *Dylib, allocator: *Allocator, sym_name: []const u8)
255255 }
256256}
257257
258fn addObjCIVarSymbol(self: *Dylib, allocator: *Allocator, sym_name: []const u8) !void {
259 const expanded = try std.fmt.allocPrint(allocator, "_OBJC_IVAR_$_{s}", .{sym_name});
260 if (self.symbols.contains(expanded)) return;
261 try self.symbols.putNoClobber(allocator, expanded, .{});
262}
263
264fn addObjCEhTypeSymbol(self: *Dylib, allocator: *Allocator, sym_name: []const u8) !void {
265 const expanded = try std.fmt.allocPrint(allocator, "_OBJC_EHTYPE_$_{s}", .{sym_name});
266 if (self.symbols.contains(expanded)) return;
267 try self.symbols.putNoClobber(allocator, expanded, .{});
268}
269
258270fn addSymbol(self: *Dylib, allocator: *Allocator, sym_name: []const u8) !void {
259271 if (self.symbols.contains(sym_name)) return;
260272 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
385397 }
386398 }
387399
400 if (exp.objc_ivars) |objc_ivars| {
401 for (objc_ivars) |ivar| {
402 try self.addObjCIVarSymbol(allocator, ivar);
403 }
404 }
405
406 if (exp.objc_eh_types) |objc_eh_types| {
407 for (objc_eh_types) |eht| {
408 try self.addObjCEhTypeSymbol(allocator, eht);
409 }
410 }
411
388412 // TODO track which libs were already parsed in different steps
389413 if (exp.re_exports) |re_exports| {
390414 for (re_exports) |lib| {
......@@ -415,6 +439,18 @@ pub fn parseFromStub(self: *Dylib, allocator: *Allocator, target: std.Target, li
415439 try self.addObjCClassSymbol(allocator, sym_name);
416440 }
417441 }
442
443 if (exp.objc_ivars) |objc_ivars| {
444 for (objc_ivars) |ivar| {
445 try self.addObjCIVarSymbol(allocator, ivar);
446 }
447 }
448
449 if (exp.objc_eh_types) |objc_eh_types| {
450 for (objc_eh_types) |eht| {
451 try self.addObjCEhTypeSymbol(allocator, eht);
452 }
453 }
418454 }
419455 }
420456
......@@ -433,6 +469,18 @@ pub fn parseFromStub(self: *Dylib, allocator: *Allocator, target: std.Target, li
433469 try self.addObjCClassSymbol(allocator, sym_name);
434470 }
435471 }
472
473 if (reexp.objc_ivars) |objc_ivars| {
474 for (objc_ivars) |ivar| {
475 try self.addObjCIVarSymbol(allocator, ivar);
476 }
477 }
478
479 if (reexp.objc_eh_types) |objc_eh_types| {
480 for (objc_eh_types) |eht| {
481 try self.addObjCEhTypeSymbol(allocator, eht);
482 }
483 }
436484 }
437485 }
438486
......@@ -441,6 +489,18 @@ pub fn parseFromStub(self: *Dylib, allocator: *Allocator, target: std.Target, li
441489 try self.addObjCClassSymbol(allocator, sym_name);
442490 }
443491 }
492
493 if (stub.objc_ivars) |objc_ivars| {
494 for (objc_ivars) |ivar| {
495 try self.addObjCIVarSymbol(allocator, ivar);
496 }
497 }
498
499 if (stub.objc_eh_types) |objc_eh_types| {
500 for (objc_eh_types) |eht| {
501 try self.addObjCEhTypeSymbol(allocator, eht);
502 }
503 }
444504 },
445505 }
446506 }
src/link/tapi.zig+8
......@@ -27,6 +27,8 @@ pub const TbdV3 = struct {
2727 re_exports: ?[]const []const u8,
2828 symbols: ?[]const []const u8,
2929 objc_classes: ?[]const []const u8,
30 objc_ivars: ?[]const []const u8,
31 objc_eh_types: ?[]const []const u8,
3032 },
3133};
3234
......@@ -52,17 +54,23 @@ pub const TbdV4 = struct {
5254 targets: []const []const u8,
5355 symbols: ?[]const []const u8,
5456 objc_classes: ?[]const []const u8,
57 objc_ivars: ?[]const []const u8,
58 objc_eh_types: ?[]const []const u8,
5559 },
5660 reexports: ?[]const struct {
5761 targets: []const []const u8,
5862 symbols: ?[]const []const u8,
5963 objc_classes: ?[]const []const u8,
64 objc_ivars: ?[]const []const u8,
65 objc_eh_types: ?[]const []const u8,
6066 },
6167 allowable_clients: ?[]const struct {
6268 targets: []const []const u8,
6369 clients: []const []const u8,
6470 },
6571 objc_classes: ?[]const []const u8,
72 objc_ivars: ?[]const []const u8,
73 objc_eh_types: ?[]const []const u8,
6674};
6775
6876pub const Tbd = union(enum) {