| ... | @@ -257,6 +257,12 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre | ... | @@ -257,6 +257,12 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre |
| 257 | pub const Lib = struct { | 257 | pub const Lib = struct { |
| 258 | name: []const u8, | 258 | name: []const u8, |
| 259 | sover: u8, | 259 | sover: u8, |
| | 260 | added_in: ?Version = null, |
| | 261 | |
| | 262 | pub fn getSoVersion(lib: Lib, os: *const std.Target.Os) u8 { |
| | 263 | if (std.mem.eql(u8, lib.name, "util") and os.version_range.semver.min.major >= 15) return 10; |
| | 264 | return lib.sover; |
| | 265 | } |
| 260 | }; | 266 | }; |
| 261 | | 267 | |
| 262 | pub const libs = [_]Lib{ | 268 | pub const libs = [_]Lib{ |
| ... | @@ -269,6 +275,7 @@ pub const libs = [_]Lib{ | ... | @@ -269,6 +275,7 @@ pub const libs = [_]Lib{ |
| 269 | .{ .name = "ld", .sover = 1 }, | 275 | .{ .name = "ld", .sover = 1 }, |
| 270 | .{ .name = "util", .sover = 9 }, | 276 | .{ .name = "util", .sover = 9 }, |
| 271 | .{ .name = "execinfo", .sover = 1 }, | 277 | .{ .name = "execinfo", .sover = 1 }, |
| | 278 | .{ .name = "sys", .sover = 7, .added_in = .{ .major = 15, .minor = 0, .patch = 0 } }, |
| 272 | }; | 279 | }; |
| 273 | | 280 | |
| 274 | pub const ABI = struct { | 281 | pub const ABI = struct { |
| ... | @@ -434,7 +441,8 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye | ... | @@ -434,7 +441,8 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 434 | | 441 | |
| 435 | const target = comp.getTarget(); | 442 | const target = comp.getTarget(); |
| 436 | // FreeBSD 7 == FBSD_1.0, ..., FreeBSD 14 == FBSD_1.7 | 443 | // FreeBSD 7 == FBSD_1.0, ..., FreeBSD 14 == FBSD_1.7 |
| 437 | const target_version: Version = .{ .major = 1, .minor = target.os.version_range.semver.min.major - 7, .patch = 0 }; | 444 | const target_os_version: Version = target.os.version_range.semver.min; |
| | 445 | const target_libc_version: Version = .{ .major = 1, .minor = target_os_version.major - 7, .patch = 0 }; |
| 438 | | 446 | |
| 439 | // Use the global cache directory. | 447 | // Use the global cache directory. |
| 440 | var cache: Cache = .{ | 448 | var cache: Cache = .{ |
| ... | @@ -452,7 +460,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye | ... | @@ -452,7 +460,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 452 | man.hash.addBytes(build_options.version); | 460 | man.hash.addBytes(build_options.version); |
| 453 | man.hash.add(target.cpu.arch); | 461 | man.hash.add(target.cpu.arch); |
| 454 | man.hash.add(target.abi); | 462 | man.hash.add(target.abi); |
| 455 | man.hash.add(target_version); | 463 | man.hash.add(target_os_version); |
| 456 | | 464 | |
| 457 | const full_abilists_path = try comp.dirs.zig_lib.join(arena, &.{abilists_path}); | 465 | const full_abilists_path = try comp.dirs.zig_lib.join(arena, &.{abilists_path}); |
| 458 | const abilists_index = try man.addFile(full_abilists_path, abilists_max_size); | 466 | const abilists_index = try man.addFile(full_abilists_path, abilists_max_size); |
| ... | @@ -494,19 +502,19 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye | ... | @@ -494,19 +502,19 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 494 | }; | 502 | }; |
| 495 | | 503 | |
| 496 | const target_ver_index = for (metadata.all_versions, 0..) |ver, i| { | 504 | const target_ver_index = for (metadata.all_versions, 0..) |ver, i| { |
| 497 | switch (ver.order(target_version)) { | 505 | switch (ver.order(target_libc_version)) { |
| 498 | .eq => break i, | 506 | .eq => break i, |
| 499 | .lt => continue, | 507 | .lt => continue, |
| 500 | .gt => { | 508 | .gt => { |
| 501 | // TODO Expose via compile error mechanism instead of log. | 509 | // TODO Expose via compile error mechanism instead of log. |
| 502 | log.warn("invalid target FreeBSD libc version: {f}", .{target_version}); | 510 | log.warn("invalid target FreeBSD libc version: {f}", .{target_libc_version}); |
| 503 | return error.InvalidTargetLibCVersion; | 511 | return error.InvalidTargetLibCVersion; |
| 504 | }, | 512 | }, |
| 505 | } | 513 | } |
| 506 | } else blk: { | 514 | } else blk: { |
| 507 | const latest_index = metadata.all_versions.len - 1; | 515 | const latest_index = metadata.all_versions.len - 1; |
| 508 | log.warn("zig cannot build new FreeBSD libc version {f}; providing instead {f}", .{ | 516 | log.warn("zig cannot build new FreeBSD libc version {f}; providing instead {f}", .{ |
| 509 | target_version, metadata.all_versions[latest_index], | 517 | target_libc_version, metadata.all_versions[latest_index], |
| 510 | }); | 518 | }); |
| 511 | break :blk latest_index; | 519 | break :blk latest_index; |
| 512 | }; | 520 | }; |
| ... | @@ -524,6 +532,11 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye | ... | @@ -524,6 +532,11 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 524 | defer stubs_asm.deinit(); | 532 | defer stubs_asm.deinit(); |
| 525 | | 533 | |
| 526 | for (libs, 0..) |lib, lib_i| { | 534 | for (libs, 0..) |lib, lib_i| { |
| | 535 | if (lib.added_in) |add_in| { |
| | 536 | // Note: Compare OS version, not libc version. |
| | 537 | if (target.os.version_range.semver.min.order(add_in) == .lt) continue; |
| | 538 | } |
| | 539 | |
| 527 | stubs_asm.shrinkRetainingCapacity(0); | 540 | stubs_asm.shrinkRetainingCapacity(0); |
| 528 | | 541 | |
| 529 | try stubs_asm.appendSlice(".text\n"); | 542 | try stubs_asm.appendSlice(".text\n"); |
| ... | @@ -983,6 +996,9 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye | ... | @@ -983,6 +996,9 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 983 | } | 996 | } |
| 984 | | 997 | |
| 985 | fn queueSharedObjects(comp: *Compilation, so_files: BuiltSharedObjects) void { | 998 | fn queueSharedObjects(comp: *Compilation, so_files: BuiltSharedObjects) void { |
| | 999 | const target = comp.getTarget(); |
| | 1000 | const target_os_version = target.os.version_range.semver.min; |
| | 1001 | |
| 986 | assert(comp.freebsd_so_files == null); | 1002 | assert(comp.freebsd_so_files == null); |
| 987 | comp.freebsd_so_files = so_files; | 1003 | comp.freebsd_so_files = so_files; |
| 988 | | 1004 | |
| ... | @@ -994,10 +1010,14 @@ fn queueSharedObjects(comp: *Compilation, so_files: BuiltSharedObjects) void { | ... | @@ -994,10 +1010,14 @@ fn queueSharedObjects(comp: *Compilation, so_files: BuiltSharedObjects) void { |
| 994 | defer comp.mutex.unlock(); | 1010 | defer comp.mutex.unlock(); |
| 995 | | 1011 | |
| 996 | for (libs) |lib| { | 1012 | for (libs) |lib| { |
| | 1013 | if (lib.added_in) |add_in| { |
| | 1014 | if (target_os_version.order(add_in) == .lt) continue; |
| | 1015 | } |
| | 1016 | |
| 997 | const so_path: Path = .{ | 1017 | const so_path: Path = .{ |
| 998 | .root_dir = so_files.dir_path.root_dir, | 1018 | .root_dir = so_files.dir_path.root_dir, |
| 999 | .sub_path = std.fmt.allocPrint(comp.arena, "{s}{c}lib{s}.so.{d}", .{ | 1019 | .sub_path = std.fmt.allocPrint(comp.arena, "{s}{c}lib{s}.so.{d}", .{ |
| 1000 | so_files.dir_path.sub_path, fs.path.sep, lib.name, lib.sover, | 1020 | so_files.dir_path.sub_path, fs.path.sep, lib.name, lib.getSoVersion(&target.os), |
| 1001 | }) catch return comp.setAllocFailure(), | 1021 | }) catch return comp.setAllocFailure(), |
| 1002 | }; | 1022 | }; |
| 1003 | task_buffer[task_buffer_i] = .{ .load_dso = so_path }; | 1023 | task_buffer[task_buffer_i] = .{ .load_dso = so_path }; |
| ... | @@ -1019,10 +1039,13 @@ fn buildSharedLib( | ... | @@ -1019,10 +1039,13 @@ fn buildSharedLib( |
| 1019 | const tracy = trace(@src()); | 1039 | const tracy = trace(@src()); |
| 1020 | defer tracy.end(); | 1040 | defer tracy.end(); |
| 1021 | | 1041 | |
| | 1042 | const target = comp.getTarget(); |
| | 1043 | |
| 1022 | const io = comp.io; | 1044 | const io = comp.io; |
| 1023 | const basename = try std.fmt.allocPrint(arena, "lib{s}.so.{d}", .{ lib.name, lib.sover }); | 1045 | const sover = lib.getSoVersion(&target.os); |
| 1024 | const version: Version = .{ .major = lib.sover, .minor = 0, .patch = 0 }; | 1046 | const basename = try std.fmt.allocPrint(arena, "lib{s}.so.{d}", .{ lib.name, sover }); |
| 1025 | const ld_basename = path.basename(comp.getTarget().standardDynamicLinkerPath().get().?); | 1047 | const version: Version = .{ .major = sover, .minor = 0, .patch = 0 }; |
| | 1048 | const ld_basename = path.basename(target.standardDynamicLinkerPath().get().?); |
| 1026 | const soname = if (mem.eql(u8, lib.name, "ld")) ld_basename else basename; | 1049 | const soname = if (mem.eql(u8, lib.name, "ld")) ld_basename else basename; |
| 1027 | const map_file_path = try path.join(arena, &.{ bin_directory.path.?, all_map_basename }); | 1050 | const map_file_path = try path.join(arena, &.{ bin_directory.path.?, all_map_basename }); |
| 1028 | | 1051 | |