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)...@@ -255,6 +255,18 @@ fn addObjCClassSymbol(self: *Dylib, allocator: *Allocator, sym_name: []const u8)
255 }255 }
256}256}
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
258fn addSymbol(self: *Dylib, allocator: *Allocator, sym_name: []const u8) !void {270fn addSymbol(self: *Dylib, allocator: *Allocator, sym_name: []const u8) !void {
259 if (self.symbols.contains(sym_name)) return;271 if (self.symbols.contains(sym_name)) return;
260 try self.symbols.putNoClobber(allocator, try allocator.dupe(u8, sym_name), {});272 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...@@ -385,6 +397,18 @@ pub fn parseFromStub(self: *Dylib, allocator: *Allocator, target: std.Target, li
385 }397 }
386 }398 }
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
388 // TODO track which libs were already parsed in different steps412 // TODO track which libs were already parsed in different steps
389 if (exp.re_exports) |re_exports| {413 if (exp.re_exports) |re_exports| {
390 for (re_exports) |lib| {414 for (re_exports) |lib| {
...@@ -415,6 +439,18 @@ pub fn parseFromStub(self: *Dylib, allocator: *Allocator, target: std.Target, li...@@ -415,6 +439,18 @@ pub fn parseFromStub(self: *Dylib, allocator: *Allocator, target: std.Target, li
415 try self.addObjCClassSymbol(allocator, sym_name);439 try self.addObjCClassSymbol(allocator, sym_name);
416 }440 }
417 }441 }
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 }
418 }454 }
419 }455 }
420456
...@@ -433,6 +469,18 @@ pub fn parseFromStub(self: *Dylib, allocator: *Allocator, target: std.Target, li...@@ -433,6 +469,18 @@ pub fn parseFromStub(self: *Dylib, allocator: *Allocator, target: std.Target, li
433 try self.addObjCClassSymbol(allocator, sym_name);469 try self.addObjCClassSymbol(allocator, sym_name);
434 }470 }
435 }471 }
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 }
436 }484 }
437 }485 }
438486
...@@ -441,6 +489,18 @@ pub fn parseFromStub(self: *Dylib, allocator: *Allocator, target: std.Target, li...@@ -441,6 +489,18 @@ pub fn parseFromStub(self: *Dylib, allocator: *Allocator, target: std.Target, li
441 try self.addObjCClassSymbol(allocator, sym_name);489 try self.addObjCClassSymbol(allocator, sym_name);
442 }490 }
443 }491 }
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 }
444 },504 },
445 }505 }
446 }506 }
src/link/tapi.zig+8
...@@ -27,6 +27,8 @@ pub const TbdV3 = struct {...@@ -27,6 +27,8 @@ pub const TbdV3 = struct {
27 re_exports: ?[]const []const u8,27 re_exports: ?[]const []const u8,
28 symbols: ?[]const []const u8,28 symbols: ?[]const []const u8,
29 objc_classes: ?[]const []const u8,29 objc_classes: ?[]const []const u8,
30 objc_ivars: ?[]const []const u8,
31 objc_eh_types: ?[]const []const u8,
30 },32 },
31};33};
3234
...@@ -52,17 +54,23 @@ pub const TbdV4 = struct {...@@ -52,17 +54,23 @@ pub const TbdV4 = struct {
52 targets: []const []const u8,54 targets: []const []const u8,
53 symbols: ?[]const []const u8,55 symbols: ?[]const []const u8,
54 objc_classes: ?[]const []const u8,56 objc_classes: ?[]const []const u8,
57 objc_ivars: ?[]const []const u8,
58 objc_eh_types: ?[]const []const u8,
55 },59 },
56 reexports: ?[]const struct {60 reexports: ?[]const struct {
57 targets: []const []const u8,61 targets: []const []const u8,
58 symbols: ?[]const []const u8,62 symbols: ?[]const []const u8,
59 objc_classes: ?[]const []const u8,63 objc_classes: ?[]const []const u8,
64 objc_ivars: ?[]const []const u8,
65 objc_eh_types: ?[]const []const u8,
60 },66 },
61 allowable_clients: ?[]const struct {67 allowable_clients: ?[]const struct {
62 targets: []const []const u8,68 targets: []const []const u8,
63 clients: []const []const u8,69 clients: []const []const u8,
64 },70 },
65 objc_classes: ?[]const []const u8,71 objc_classes: ?[]const []const u8,
72 objc_ivars: ?[]const []const u8,
73 objc_eh_types: ?[]const []const u8,
66};74};
6775
68pub const Tbd = union(enum) {76pub const Tbd = union(enum) {