authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-19 15:17:01-07:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-06-20 12:55:38-04:00
logb20ccff515364cdb8f3e733cc950e53ab77656db
treef2a9c73481efaec5112105ac8d74ab8fc09e83a8
parenta5d8c310eef494594ae29a2319a5baf496c3434f

std.os: update logic for 64-bit symbol choice

musl v1.2.4 dropped the "64"-suffixed aliases for legacy "LFS64" ("large file support") interfaces, so this commit changes the corresponding Zig logic to call the correct names.

1 files changed, 19 insertions(+), 68 deletions(-)

lib/std/os.zig+19-68
...@@ -890,10 +890,7 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize {...@@ -890,10 +890,7 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize {
890 };890 };
891 const adjusted_len = @min(max_count, buf.len);891 const adjusted_len = @min(max_count, buf.len);
892892
893 const pread_sym = if (builtin.os.tag == .linux and builtin.link_libc)893 const pread_sym = if (lfs64_abi) system.pread64 else system.pread;
894 system.pread64
895 else
896 system.pread;
897894
898 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned895 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
899 while (true) {896 while (true) {
...@@ -966,10 +963,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {...@@ -966,10 +963,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
966 }963 }
967964
968 while (true) {965 while (true) {
969 const ftruncate_sym = if (builtin.os.tag == .linux and builtin.link_libc)966 const ftruncate_sym = if (lfs64_abi) system.ftruncate64 else system.ftruncate;
970 system.ftruncate64
971 else
972 system.ftruncate;
973967
974 const ilen = @bitCast(i64, length); // the OS treats this as unsigned968 const ilen = @bitCast(i64, length); // the OS treats this as unsigned
975 switch (errno(ftruncate_sym(fd, ilen))) {969 switch (errno(ftruncate_sym(fd, ilen))) {
...@@ -1034,10 +1028,7 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {...@@ -1034,10 +1028,7 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {
10341028
1035 const iov_count = math.cast(u31, iov.len) orelse math.maxInt(u31);1029 const iov_count = math.cast(u31, iov.len) orelse math.maxInt(u31);
10361030
1037 const preadv_sym = if (builtin.os.tag == .linux and builtin.link_libc)1031 const preadv_sym = if (lfs64_abi) system.preadv64 else system.preadv;
1038 system.preadv64
1039 else
1040 system.preadv;
10411032
1042 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned1033 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
1043 while (true) {1034 while (true) {
...@@ -1311,10 +1302,7 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {...@@ -1311,10 +1302,7 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {
1311 };1302 };
1312 const adjusted_len = @min(max_count, bytes.len);1303 const adjusted_len = @min(max_count, bytes.len);
13131304
1314 const pwrite_sym = if (builtin.os.tag == .linux and builtin.link_libc)1305 const pwrite_sym = if (lfs64_abi) system.pwrite64 else system.pwrite;
1315 system.pwrite64
1316 else
1317 system.pwrite;
13181306
1319 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned1307 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
1320 while (true) {1308 while (true) {
...@@ -1400,10 +1388,7 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz...@@ -1400,10 +1388,7 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz
1400 }1388 }
1401 }1389 }
14021390
1403 const pwritev_sym = if (builtin.os.tag == .linux and builtin.link_libc)1391 const pwritev_sym = if (lfs64_abi) system.pwritev64 else system.pwritev;
1404 system.pwritev64
1405 else
1406 system.pwritev;
14071392
1408 const iov_count = if (iov.len > IOV_MAX) IOV_MAX else @intCast(u31, iov.len);1393 const iov_count = if (iov.len > IOV_MAX) IOV_MAX else @intCast(u31, iov.len);
1409 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned1394 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
...@@ -1514,10 +1499,7 @@ pub fn openZ(file_path: [*:0]const u8, flags: u32, perm: mode_t) OpenError!fd_t...@@ -1514,10 +1499,7 @@ pub fn openZ(file_path: [*:0]const u8, flags: u32, perm: mode_t) OpenError!fd_t
1514 return open(mem.sliceTo(file_path, 0), flags, perm);1499 return open(mem.sliceTo(file_path, 0), flags, perm);
1515 }1500 }
15161501
1517 const open_sym = if (builtin.os.tag == .linux and builtin.link_libc)1502 const open_sym = if (lfs64_abi) system.open64 else system.open;
1518 system.open64
1519 else
1520 system.open;
15211503
1522 while (true) {1504 while (true) {
1523 const rc = open_sym(file_path, flags, perm);1505 const rc = open_sym(file_path, flags, perm);
...@@ -1730,10 +1712,7 @@ pub fn openatZ(dir_fd: fd_t, file_path: [*:0]const u8, flags: u32, mode: mode_t)...@@ -1730,10 +1712,7 @@ pub fn openatZ(dir_fd: fd_t, file_path: [*:0]const u8, flags: u32, mode: mode_t)
1730 return openat(dir_fd, mem.sliceTo(file_path, 0), flags, mode);1712 return openat(dir_fd, mem.sliceTo(file_path, 0), flags, mode);
1731 }1713 }
17321714
1733 const openat_sym = if (builtin.os.tag == .linux and builtin.link_libc)1715 const openat_sym = if (lfs64_abi) system.openat64 else system.openat;
1734 system.openat64
1735 else
1736 system.openat;
17371716
1738 while (true) {1717 while (true) {
1739 const rc = openat_sym(dir_fd, file_path, flags, mode);1718 const rc = openat_sym(dir_fd, file_path, flags, mode);
...@@ -4117,10 +4096,7 @@ pub fn fstat(fd: fd_t) FStatError!Stat {...@@ -4117,10 +4096,7 @@ pub fn fstat(fd: fd_t) FStatError!Stat {
4117 @compileError("fstat is not yet implemented on Windows");4096 @compileError("fstat is not yet implemented on Windows");
4118 }4097 }
41194098
4120 const fstat_sym = if (builtin.os.tag == .linux and builtin.link_libc)4099 const fstat_sym = if (lfs64_abi) system.fstat64 else system.fstat;
4121 system.fstat64
4122 else
4123 system.fstat;
41244100
4125 var stat = mem.zeroes(Stat);4101 var stat = mem.zeroes(Stat);
4126 switch (errno(fstat_sym(fd, &stat))) {4102 switch (errno(fstat_sym(fd, &stat))) {
...@@ -4176,10 +4152,7 @@ pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!S...@@ -4176,10 +4152,7 @@ pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!S
4176 return fstatatWasi(dirfd, mem.sliceTo(pathname), flags);4152 return fstatatWasi(dirfd, mem.sliceTo(pathname), flags);
4177 }4153 }
41784154
4179 const fstatat_sym = if (builtin.os.tag == .linux and builtin.link_libc)4155 const fstatat_sym = if (lfs64_abi) system.fstatat64 else system.fstatat;
4180 system.fstatat64
4181 else
4182 system.fstatat;
41834156
4184 var stat = mem.zeroes(Stat);4157 var stat = mem.zeroes(Stat);
4185 switch (errno(fstatat_sym(dirfd, pathname, &stat, flags))) {4158 switch (errno(fstatat_sym(dirfd, pathname, &stat, flags))) {
...@@ -4416,10 +4389,7 @@ pub fn mmap(...@@ -4416,10 +4389,7 @@ pub fn mmap(
4416 fd: fd_t,4389 fd: fd_t,
4417 offset: u64,4390 offset: u64,
4418) MMapError![]align(mem.page_size) u8 {4391) MMapError![]align(mem.page_size) u8 {
4419 const mmap_sym = if (builtin.os.tag == .linux and builtin.link_libc)4392 const mmap_sym = if (lfs64_abi) system.mmap64 else system.mmap;
4420 system.mmap64
4421 else
4422 system.mmap;
44234393
4424 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned4394 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
4425 const rc = mmap_sym(ptr, length, prot, flags, fd, ioffset);4395 const rc = mmap_sym(ptr, length, prot, flags, fd, ioffset);
...@@ -4823,10 +4793,7 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {...@@ -4823,10 +4793,7 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
4823 }4793 }
4824 }4794 }
48254795
4826 const lseek_sym = if (builtin.os.tag == .linux and builtin.link_libc)4796 const lseek_sym = if (lfs64_abi) system.lseek64 else system.lseek;
4827 system.lseek64
4828 else
4829 system.lseek;
48304797
4831 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned4798 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
4832 switch (errno(lseek_sym(fd, ioffset, SEEK.SET))) {4799 switch (errno(lseek_sym(fd, ioffset, SEEK.SET))) {
...@@ -4870,10 +4837,7 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {...@@ -4870,10 +4837,7 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
4870 else => |err| return unexpectedErrno(err),4837 else => |err| return unexpectedErrno(err),
4871 }4838 }
4872 }4839 }
4873 const lseek_sym = if (builtin.os.tag == .linux and builtin.link_libc)4840 const lseek_sym = if (lfs64_abi) system.lseek64 else system.lseek;
4874 system.lseek64
4875 else
4876 system.lseek;
48774841
4878 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned4842 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
4879 switch (errno(lseek_sym(fd, ioffset, SEEK.CUR))) {4843 switch (errno(lseek_sym(fd, ioffset, SEEK.CUR))) {
...@@ -4917,10 +4881,7 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {...@@ -4917,10 +4881,7 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {
4917 else => |err| return unexpectedErrno(err),4881 else => |err| return unexpectedErrno(err),
4918 }4882 }
4919 }4883 }
4920 const lseek_sym = if (builtin.os.tag == .linux and builtin.link_libc)4884 const lseek_sym = if (lfs64_abi) system.lseek64 else system.lseek;
4921 system.lseek64
4922 else
4923 system.lseek;
49244885
4925 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned4886 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
4926 switch (errno(lseek_sym(fd, ioffset, SEEK.END))) {4887 switch (errno(lseek_sym(fd, ioffset, SEEK.END))) {
...@@ -4964,10 +4925,7 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {...@@ -4964,10 +4925,7 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {
4964 else => |err| return unexpectedErrno(err),4925 else => |err| return unexpectedErrno(err),
4965 }4926 }
4966 }4927 }
4967 const lseek_sym = if (builtin.os.tag == .linux and builtin.link_libc)4928 const lseek_sym = if (lfs64_abi) system.lseek64 else system.lseek;
4968 system.lseek64
4969 else
4970 system.lseek;
49714929
4972 const rc = lseek_sym(fd, 0, SEEK.CUR);4930 const rc = lseek_sym(fd, 0, SEEK.CUR);
4973 switch (errno(rc)) {4931 switch (errno(rc)) {
...@@ -6169,10 +6127,7 @@ pub fn sendfile(...@@ -6169,10 +6127,7 @@ pub fn sendfile(
6169 // TODO we should not need this cast; improve return type of @min6127 // TODO we should not need this cast; improve return type of @min
6170 const adjusted_count = @intCast(usize, adjusted_count_tmp);6128 const adjusted_count = @intCast(usize, adjusted_count_tmp);
61716129
6172 const sendfile_sym = if (builtin.link_libc)6130 const sendfile_sym = if (lfs64_abi) system.sendfile64 else system.sendfile;
6173 system.sendfile64
6174 else
6175 system.sendfile;
61766131
6177 while (true) {6132 while (true) {
6178 var offset: off_t = @bitCast(off_t, in_offset);6133 var offset: off_t = @bitCast(off_t, in_offset);
...@@ -7050,10 +7005,7 @@ pub fn prctl(option: PR, args: anytype) PrctlError!u31 {...@@ -7050,10 +7005,7 @@ pub fn prctl(option: PR, args: anytype) PrctlError!u31 {
7050pub const GetrlimitError = UnexpectedError;7005pub const GetrlimitError = UnexpectedError;
70517006
7052pub fn getrlimit(resource: rlimit_resource) GetrlimitError!rlimit {7007pub fn getrlimit(resource: rlimit_resource) GetrlimitError!rlimit {
7053 const getrlimit_sym = if (builtin.os.tag == .linux and builtin.link_libc)7008 const getrlimit_sym = if (lfs64_abi) system.getrlimit64 else system.getrlimit;
7054 system.getrlimit64
7055 else
7056 system.getrlimit;
70577009
7058 var limits: rlimit = undefined;7010 var limits: rlimit = undefined;
7059 switch (errno(getrlimit_sym(resource, &limits))) {7011 switch (errno(getrlimit_sym(resource, &limits))) {
...@@ -7067,10 +7019,7 @@ pub fn getrlimit(resource: rlimit_resource) GetrlimitError!rlimit {...@@ -7067,10 +7019,7 @@ pub fn getrlimit(resource: rlimit_resource) GetrlimitError!rlimit {
7067pub const SetrlimitError = error{ PermissionDenied, LimitTooBig } || UnexpectedError;7019pub const SetrlimitError = error{ PermissionDenied, LimitTooBig } || UnexpectedError;
70687020
7069pub fn setrlimit(resource: rlimit_resource, limits: rlimit) SetrlimitError!void {7021pub fn setrlimit(resource: rlimit_resource, limits: rlimit) SetrlimitError!void {
7070 const setrlimit_sym = if (builtin.os.tag == .linux and builtin.link_libc)7022 const setrlimit_sym = if (lfs64_abi) system.setrlimit64 else system.setrlimit;
7071 system.setrlimit64
7072 else
7073 system.setrlimit;
70747023
7075 switch (errno(setrlimit_sym(resource, &limits))) {7024 switch (errno(setrlimit_sym(resource, &limits))) {
7076 .SUCCESS => return,7025 .SUCCESS => return,
...@@ -7339,3 +7288,5 @@ pub fn ptrace(request: u32, pid: pid_t, addr: usize, signal: usize) PtraceError!...@@ -7339,3 +7288,5 @@ pub fn ptrace(request: u32, pid: pid_t, addr: usize, signal: usize) PtraceError!
7339 },7288 },
7340 };7289 };
7341}7290}
7291
7292const lfs64_abi = builtin.os.tag == .linux and builtin.link_libc and builtin.abi.isGnu();