authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-11-23 15:59:49+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-11-23 15:59:49+01:00
log0c1d610015e04c96508750e95b2f88408ded8843
treecfead197cc965d08f0d618d730b645123add2809
parentde8e6124557d189d8b55f0d63d0a02fb98d51799

zld: handle -current_version and -compatibility_version

and transfer them correctly to the generated dylib as part of the dylib id load command.

4 files changed, 28 insertions(+), 3 deletions(-)

src/Compilation.zig+2
...@@ -758,6 +758,7 @@ pub const InitOptions = struct {...@@ -758,6 +758,7 @@ pub const InitOptions = struct {
758 image_base_override: ?u64 = null,758 image_base_override: ?u64 = null,
759 self_exe_path: ?[]const u8 = null,759 self_exe_path: ?[]const u8 = null,
760 version: ?std.builtin.Version = null,760 version: ?std.builtin.Version = null,
761 compatibility_version: ?std.builtin.Version = null,
761 libc_installation: ?*const LibCInstallation = null,762 libc_installation: ?*const LibCInstallation = null,
762 machine_code_model: std.builtin.CodeModel = .default,763 machine_code_model: std.builtin.CodeModel = .default,
763 clang_preprocessor_mode: ClangPreprocessorMode = .no,764 clang_preprocessor_mode: ClangPreprocessorMode = .no,
...@@ -1439,6 +1440,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -1439,6 +1440,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
1439 .extra_lld_args = options.lld_argv,1440 .extra_lld_args = options.lld_argv,
1440 .soname = options.soname,1441 .soname = options.soname,
1441 .version = options.version,1442 .version = options.version,
1443 .compatibility_version = options.compatibility_version,
1442 .libc_installation = libc_dirs.libc_installation,1444 .libc_installation = libc_dirs.libc_installation,
1443 .pic = pic,1445 .pic = pic,
1444 .pie = pie,1446 .pie = pie,
src/link.zig+1
...@@ -143,6 +143,7 @@ pub const Options = struct {...@@ -143,6 +143,7 @@ pub const Options = struct {
143 rpath_list: []const []const u8,143 rpath_list: []const []const u8,
144144
145 version: ?std.builtin.Version,145 version: ?std.builtin.Version,
146 compatibility_version: ?std.builtin.Version,
146 libc_installation: ?*const LibCInstallation,147 libc_installation: ?*const LibCInstallation,
147148
148 /// WASI-only. Type of WASI execution model ("command" or "reactor").149 /// WASI-only. Type of WASI execution model ("command" or "reactor").
src/link/MachO.zig+6-2
...@@ -4038,12 +4038,16 @@ pub fn populateMissingMetadata(self: *MachO) !void {...@@ -4038,12 +4038,16 @@ pub fn populateMissingMetadata(self: *MachO) !void {
4038 self.base.options.emit.?.sub_path,4038 self.base.options.emit.?.sub_path,
4039 });4039 });
4040 defer self.base.allocator.free(install_name);4040 defer self.base.allocator.free(install_name);
4041 const current_version = self.base.options.version orelse
4042 std.builtin.Version{ .major = 1, .minor = 0, .patch = 0 };
4043 const compat_version = self.base.options.compatibility_version orelse
4044 std.builtin.Version{ .major = 1, .minor = 0, .patch = 0 };
4041 var dylib_cmd = try commands.createLoadDylibCommand(4045 var dylib_cmd = try commands.createLoadDylibCommand(
4042 self.base.allocator,4046 self.base.allocator,
4043 install_name,4047 install_name,
4044 2,4048 2,
4045 0x10000, // TODO forward user-provided versions4049 current_version.major << 16 | current_version.minor << 8 | current_version.patch,
4046 0x10000,4050 compat_version.major << 16 | compat_version.minor << 8 | compat_version.patch,
4047 );4051 );
4048 errdefer dylib_cmd.deinit(self.base.allocator);4052 errdefer dylib_cmd.deinit(self.base.allocator);
4049 dylib_cmd.inner.cmd = macho.LC_ID_DYLIB;4053 dylib_cmd.inner.cmd = macho.LC_ID_DYLIB;
src/main.zig+19-1
...@@ -564,6 +564,7 @@ fn buildOutputType(...@@ -564,6 +564,7 @@ fn buildOutputType(
564 var root_src_file: ?[]const u8 = null;564 var root_src_file: ?[]const u8 = null;
565 var version: std.builtin.Version = .{ .major = 0, .minor = 0, .patch = 0 };565 var version: std.builtin.Version = .{ .major = 0, .minor = 0, .patch = 0 };
566 var have_version = false;566 var have_version = false;
567 var compatibility_version: ?std.builtin.Version = null;
567 var strip = false;568 var strip = false;
568 var single_threaded = false;569 var single_threaded = false;
569 var function_sections = false;570 var function_sections = false;
...@@ -1613,12 +1614,29 @@ fn buildOutputType(...@@ -1613,12 +1614,29 @@ fn buildOutputType(
1613 ) catch |err| {1614 ) catch |err| {
1614 fatal("unable to parse '{s}': {s}", .{ arg, @errorName(err) });1615 fatal("unable to parse '{s}': {s}", .{ arg, @errorName(err) });
1615 };1616 };
1616 } else if (mem.eql(u8, arg, "-weak_framework")) {1617 } else if (mem.eql(u8, arg, "-framework") or mem.eql(u8, arg, "-weak_framework")) {
1617 i += 1;1618 i += 1;
1618 if (i >= linker_args.items.len) {1619 if (i >= linker_args.items.len) {
1619 fatal("expected linker arg after '{s}'", .{arg});1620 fatal("expected linker arg after '{s}'", .{arg});
1620 }1621 }
1621 try frameworks.append(linker_args.items[i]);1622 try frameworks.append(linker_args.items[i]);
1623 } else if (mem.eql(u8, arg, "-compatibility_version")) {
1624 i += 1;
1625 if (i >= linker_args.items.len) {
1626 fatal("expected linker arg after '{s}'", .{arg});
1627 }
1628 compatibility_version = std.builtin.Version.parse(linker_args.items[i]) catch |err| {
1629 fatal("unable to parse -compatibility_version '{s}': {s}", .{ linker_args.items[i], @errorName(err) });
1630 };
1631 } else if (mem.eql(u8, arg, "-current_version")) {
1632 i += 1;
1633 if (i >= linker_args.items.len) {
1634 fatal("expected linker arg after '{s}'", .{arg});
1635 }
1636 version = std.builtin.Version.parse(linker_args.items[i]) catch |err| {
1637 fatal("unable to parse -current_version '{s}': {s}", .{ linker_args.items[i], @errorName(err) });
1638 };
1639 have_version = true;
1622 } else {1640 } else {
1623 warn("unsupported linker arg: {s}", .{arg});1641 warn("unsupported linker arg: {s}", .{arg});
1624 }1642 }