| ... | ... | @@ -257,6 +257,12 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre |
| 257 | 257 | pub const Lib = struct { |
| 258 | 258 | name: []const u8, |
| 259 | 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 | 268 | pub const libs = [_]Lib{ |
| ... | ... | @@ -269,6 +275,7 @@ pub const libs = [_]Lib{ |
| 269 | 275 | .{ .name = "ld", .sover = 1 }, |
| 270 | 276 | .{ .name = "util", .sover = 9 }, |
| 271 | 277 | .{ .name = "execinfo", .sover = 1 }, |
| 278 | .{ .name = "sys", .sover = 7, .added_in = .{ .major = 15, .minor = 0, .patch = 0 } }, |
| 272 | 279 | }; |
| 273 | 280 | |
| 274 | 281 | pub const ABI = struct { |
| ... | ... | @@ -434,7 +441,8 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 434 | 441 | |
| 435 | 442 | const target = comp.getTarget(); |
| 436 | 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 | 447 | // Use the global cache directory. |
| 440 | 448 | var cache: Cache = .{ |
| ... | ... | @@ -452,7 +460,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 452 | 460 | man.hash.addBytes(build_options.version); |
| 453 | 461 | man.hash.add(target.cpu.arch); |
| 454 | 462 | man.hash.add(target.abi); |
| 455 | | man.hash.add(target_version); |
| 463 | man.hash.add(target_os_version); |
| 456 | 464 | |
| 457 | 465 | const full_abilists_path = try comp.dirs.zig_lib.join(arena, &.{abilists_path}); |
| 458 | 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 | 502 | }; |
| 495 | 503 | |
| 496 | 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 | 506 | .eq => break i, |
| 499 | 507 | .lt => continue, |
| 500 | 508 | .gt => { |
| 501 | 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 | 511 | return error.InvalidTargetLibCVersion; |
| 504 | 512 | }, |
| 505 | 513 | } |
| 506 | 514 | } else blk: { |
| 507 | 515 | const latest_index = metadata.all_versions.len - 1; |
| 508 | 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 | 519 | break :blk latest_index; |
| 512 | 520 | }; |
| ... | ... | @@ -524,6 +532,11 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 524 | 532 | defer stubs_asm.deinit(); |
| 525 | 533 | |
| 526 | 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 | 540 | stubs_asm.shrinkRetainingCapacity(0); |
| 528 | 541 | |
| 529 | 542 | try stubs_asm.appendSlice(".text\n"); |
| ... | ... | @@ -983,6 +996,9 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 983 | 996 | } |
| 984 | 997 | |
| 985 | 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 | 1002 | assert(comp.freebsd_so_files == null); |
| 987 | 1003 | comp.freebsd_so_files = so_files; |
| 988 | 1004 | |
| ... | ... | @@ -994,10 +1010,14 @@ fn queueSharedObjects(comp: *Compilation, so_files: BuiltSharedObjects) void { |
| 994 | 1010 | defer comp.mutex.unlock(); |
| 995 | 1011 | |
| 996 | 1012 | for (libs) |lib| { |
| 1013 | if (lib.added_in) |add_in| { |
| 1014 | if (target_os_version.order(add_in) == .lt) continue; |
| 1015 | } |
| 1016 | |
| 997 | 1017 | const so_path: Path = .{ |
| 998 | 1018 | .root_dir = so_files.dir_path.root_dir, |
| 999 | 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 | 1021 | }) catch return comp.setAllocFailure(), |
| 1002 | 1022 | }; |
| 1003 | 1023 | task_buffer[task_buffer_i] = .{ .load_dso = so_path }; |
| ... | ... | @@ -1019,10 +1039,13 @@ fn buildSharedLib( |
| 1019 | 1039 | const tracy = trace(@src()); |
| 1020 | 1040 | defer tracy.end(); |
| 1021 | 1041 | |
| 1042 | const target = comp.getTarget(); |
| 1043 | |
| 1022 | 1044 | const io = comp.io; |
| 1023 | | const basename = try std.fmt.allocPrint(arena, "lib{s}.so.{d}", .{ lib.name, lib.sover }); |
| 1024 | | const version: Version = .{ .major = lib.sover, .minor = 0, .patch = 0 }; |
| 1025 | | const ld_basename = path.basename(comp.getTarget().standardDynamicLinkerPath().get().?); |
| 1045 | const sover = lib.getSoVersion(&target.os); |
| 1046 | const basename = try std.fmt.allocPrint(arena, "lib{s}.so.{d}", .{ lib.name, sover }); |
| 1047 | const version: Version = .{ .major = sover, .minor = 0, .patch = 0 }; |
| 1048 | const ld_basename = path.basename(target.standardDynamicLinkerPath().get().?); |
| 1026 | 1049 | const soname = if (mem.eql(u8, lib.name, "ld")) ld_basename else basename; |
| 1027 | 1050 | const map_file_path = try path.join(arena, &.{ bin_directory.path.?, all_map_basename }); |
| 1028 | 1051 | |