authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-30 12:11:27+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-30 20:56:20+01:00
logf63f4508d228e37965865221220f4f94103111cf
tree7a63fbfc2121c82b436123df1fe9d791ae11ca75
parentb8490c05c10193363107a1fb2e7c4ffab287f5ad

macho: fix parsing versions from TBDs if parsed as floats


2 files changed, 38 insertions(+), 1 deletions(-)

src/link/MachO/Dylib.zig+1-1
...@@ -803,7 +803,7 @@ pub const Id = struct {...@@ -803,7 +803,7 @@ pub const Id = struct {
803 },803 },
804 .float => |float| {804 .float => |float| {
805 var buf: [256]u8 = undefined;805 var buf: [256]u8 = undefined;
806 break :blk try fmt.bufPrint(&buf, "{d:.2}", .{float});806 break :blk try fmt.bufPrint(&buf, "{d}", .{float});
807 },807 },
808 .string => |string| {808 .string => |string| {
809 break :blk string;809 break :blk string;
test/link/macho.zig+37
...@@ -54,6 +54,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {...@@ -54,6 +54,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {
54 macho_step.dependOn(testEntryPointArchive(b, .{ .target = default_target }));54 macho_step.dependOn(testEntryPointArchive(b, .{ .target = default_target }));
55 macho_step.dependOn(testEntryPointDylib(b, .{ .target = default_target }));55 macho_step.dependOn(testEntryPointDylib(b, .{ .target = default_target }));
56 macho_step.dependOn(testDylib(b, .{ .target = default_target }));56 macho_step.dependOn(testDylib(b, .{ .target = default_target }));
57 macho_step.dependOn(testDylibVersionTbd(b, .{ .target = default_target }));
57 macho_step.dependOn(testNeededLibrary(b, .{ .target = default_target }));58 macho_step.dependOn(testNeededLibrary(b, .{ .target = default_target }));
58 macho_step.dependOn(testSearchStrategy(b, .{ .target = default_target }));59 macho_step.dependOn(testSearchStrategy(b, .{ .target = default_target }));
59 macho_step.dependOn(testTbdv3(b, .{ .target = default_target }));60 macho_step.dependOn(testTbdv3(b, .{ .target = default_target }));
...@@ -243,6 +244,42 @@ fn testDylib(b: *Build, opts: Options) *Step {...@@ -243,6 +244,42 @@ fn testDylib(b: *Build, opts: Options) *Step {
243 return test_step;244 return test_step;
244}245}
245246
247fn testDylibVersionTbd(b: *Build, opts: Options) *Step {
248 const test_step = addTestStep(b, "macho-dylib-version-tbd", opts);
249
250 const tbd = tbd: {
251 const wf = WriteFile.create(b);
252 break :tbd wf.add("liba.tbd",
253 \\--- !tapi-tbd
254 \\tbd-version: 4
255 \\targets: [ x86_64-macos, arm64-macos ]
256 \\uuids:
257 \\ - target: x86_64-macos
258 \\ value: DEADBEEF
259 \\ - target: arm64-macos
260 \\ value: BEEFDEAD
261 \\install-name: '@rpath/liba.dylib'
262 \\current-version: 1.2
263 \\exports:
264 \\ - targets: [ x86_64-macos, arm64-macos ]
265 \\ symbols: [ _foo ]
266 );
267 };
268
269 const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = "int main() {}" });
270 exe.root_module.linkSystemLibrary("a", .{});
271 exe.root_module.addLibraryPath(tbd.dirname());
272
273 const check = exe.checkObject();
274 check.checkInHeaders();
275 check.checkExact("cmd LOAD_DYLIB");
276 check.checkExact("name @rpath/liba.dylib");
277 check.checkExact("current version 10200");
278 test_step.dependOn(&check.step);
279
280 return test_step;
281}
282
246fn testEmptyObject(b: *Build, opts: Options) *Step {283fn testEmptyObject(b: *Build, opts: Options) *Step {
247 const test_step = addTestStep(b, "macho-empty-object", opts);284 const test_step = addTestStep(b, "macho-empty-object", opts);
248285