Skip to content

Commit 691090f

Browse files
committed
zld: parse ObjC ivars and eh_types in tapi v3 and v4
1 parent e17c4a4 commit 691090f

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

src/link/MachO/Dylib.zig

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,18 @@ fn addObjCClassSymbol(self: *Dylib, allocator: *Allocator, sym_name: []const u8)
255255
}
256256
}
257257

258+
fn 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+
264+
fn 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+
258270
fn 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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

6876
pub const Tbd = union(enum) {

0 commit comments

Comments
 (0)