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 {
890890 };
891891 const adjusted_len = @min(max_count, buf.len);
892892
893 const pread_sym = if (builtin.os.tag == .linux and builtin.link_libc)
894 system.pread64
895 else
896 system.pread;
893 const pread_sym = if (lfs64_abi) system.pread64 else system.pread;
897894
898895 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
899896 while (true) {
......@@ -966,10 +963,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
966963 }
967964
968965 while (true) {
969 const ftruncate_sym = if (builtin.os.tag == .linux and builtin.link_libc)
970 system.ftruncate64
971 else
972 system.ftruncate;
966 const ftruncate_sym = if (lfs64_abi) system.ftruncate64 else system.ftruncate;
973967
974968 const ilen = @bitCast(i64, length); // the OS treats this as unsigned
975969 switch (errno(ftruncate_sym(fd, ilen))) {
......@@ -1034,10 +1028,7 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {
10341028
10351029 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)
1038 system.preadv64
1039 else
1040 system.preadv;
1031 const preadv_sym = if (lfs64_abi) system.preadv64 else system.preadv;
10411032
10421033 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
10431034 while (true) {
......@@ -1311,10 +1302,7 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {
13111302 };
13121303 const adjusted_len = @min(max_count, bytes.len);
13131304
1314 const pwrite_sym = if (builtin.os.tag == .linux and builtin.link_libc)
1315 system.pwrite64
1316 else
1317 system.pwrite;
1305 const pwrite_sym = if (lfs64_abi) system.pwrite64 else system.pwrite;
13181306
13191307 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
13201308 while (true) {
......@@ -1400,10 +1388,7 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz
14001388 }
14011389 }
14021390
1403 const pwritev_sym = if (builtin.os.tag == .linux and builtin.link_libc)
1404 system.pwritev64
1405 else
1406 system.pwritev;
1391 const pwritev_sym = if (lfs64_abi) system.pwritev64 else system.pwritev;
14071392
14081393 const iov_count = if (iov.len > IOV_MAX) IOV_MAX else @intCast(u31, iov.len);
14091394 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
15141499 return open(mem.sliceTo(file_path, 0), flags, perm);
15151500 }
15161501
1517 const open_sym = if (builtin.os.tag == .linux and builtin.link_libc)
1518 system.open64
1519 else
1520 system.open;
1502 const open_sym = if (lfs64_abi) system.open64 else system.open;
15211503
15221504 while (true) {
15231505 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)
17301712 return openat(dir_fd, mem.sliceTo(file_path, 0), flags, mode);
17311713 }
17321714
1733 const openat_sym = if (builtin.os.tag == .linux and builtin.link_libc)
1734 system.openat64
1735 else
1736 system.openat;
1715 const openat_sym = if (lfs64_abi) system.openat64 else system.openat;
17371716
17381717 while (true) {
17391718 const rc = openat_sym(dir_fd, file_path, flags, mode);
......@@ -4117,10 +4096,7 @@ pub fn fstat(fd: fd_t) FStatError!Stat {
41174096 @compileError("fstat is not yet implemented on Windows");
41184097 }
41194098
4120 const fstat_sym = if (builtin.os.tag == .linux and builtin.link_libc)
4121 system.fstat64
4122 else
4123 system.fstat;
4099 const fstat_sym = if (lfs64_abi) system.fstat64 else system.fstat;
41244100
41254101 var stat = mem.zeroes(Stat);
41264102 switch (errno(fstat_sym(fd, &stat))) {
......@@ -4176,10 +4152,7 @@ pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!S
41764152 return fstatatWasi(dirfd, mem.sliceTo(pathname), flags);
41774153 }
41784154
4179 const fstatat_sym = if (builtin.os.tag == .linux and builtin.link_libc)
4180 system.fstatat64
4181 else
4182 system.fstatat;
4155 const fstatat_sym = if (lfs64_abi) system.fstatat64 else system.fstatat;
41834156
41844157 var stat = mem.zeroes(Stat);
41854158 switch (errno(fstatat_sym(dirfd, pathname, &stat, flags))) {
......@@ -4416,10 +4389,7 @@ pub fn mmap(
44164389 fd: fd_t,
44174390 offset: u64,
44184391) MMapError![]align(mem.page_size) u8 {
4419 const mmap_sym = if (builtin.os.tag == .linux and builtin.link_libc)
4420 system.mmap64
4421 else
4422 system.mmap;
4392 const mmap_sym = if (lfs64_abi) system.mmap64 else system.mmap;
44234393
44244394 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
44254395 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 {
48234793 }
48244794 }
48254795
4826 const lseek_sym = if (builtin.os.tag == .linux and builtin.link_libc)
4827 system.lseek64
4828 else
4829 system.lseek;
4796 const lseek_sym = if (lfs64_abi) system.lseek64 else system.lseek;
48304797
48314798 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
48324799 switch (errno(lseek_sym(fd, ioffset, SEEK.SET))) {
......@@ -4870,10 +4837,7 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
48704837 else => |err| return unexpectedErrno(err),
48714838 }
48724839 }
4873 const lseek_sym = if (builtin.os.tag == .linux and builtin.link_libc)
4874 system.lseek64
4875 else
4876 system.lseek;
4840 const lseek_sym = if (lfs64_abi) system.lseek64 else system.lseek;
48774841
48784842 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
48794843 switch (errno(lseek_sym(fd, ioffset, SEEK.CUR))) {
......@@ -4917,10 +4881,7 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {
49174881 else => |err| return unexpectedErrno(err),
49184882 }
49194883 }
4920 const lseek_sym = if (builtin.os.tag == .linux and builtin.link_libc)
4921 system.lseek64
4922 else
4923 system.lseek;
4884 const lseek_sym = if (lfs64_abi) system.lseek64 else system.lseek;
49244885
49254886 const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
49264887 switch (errno(lseek_sym(fd, ioffset, SEEK.END))) {
......@@ -4964,10 +4925,7 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {
49644925 else => |err| return unexpectedErrno(err),
49654926 }
49664927 }
4967 const lseek_sym = if (builtin.os.tag == .linux and builtin.link_libc)
4968 system.lseek64
4969 else
4970 system.lseek;
4928 const lseek_sym = if (lfs64_abi) system.lseek64 else system.lseek;
49714929
49724930 const rc = lseek_sym(fd, 0, SEEK.CUR);
49734931 switch (errno(rc)) {
......@@ -6169,10 +6127,7 @@ pub fn sendfile(
61696127 // TODO we should not need this cast; improve return type of @min
61706128 const adjusted_count = @intCast(usize, adjusted_count_tmp);
61716129
6172 const sendfile_sym = if (builtin.link_libc)
6173 system.sendfile64
6174 else
6175 system.sendfile;
6130 const sendfile_sym = if (lfs64_abi) system.sendfile64 else system.sendfile;
61766131
61776132 while (true) {
61786133 var offset: off_t = @bitCast(off_t, in_offset);
......@@ -7050,10 +7005,7 @@ pub fn prctl(option: PR, args: anytype) PrctlError!u31 {
70507005pub const GetrlimitError = UnexpectedError;
70517006
70527007pub fn getrlimit(resource: rlimit_resource) GetrlimitError!rlimit {
7053 const getrlimit_sym = if (builtin.os.tag == .linux and builtin.link_libc)
7054 system.getrlimit64
7055 else
7056 system.getrlimit;
7008 const getrlimit_sym = if (lfs64_abi) system.getrlimit64 else system.getrlimit;
70577009
70587010 var limits: rlimit = undefined;
70597011 switch (errno(getrlimit_sym(resource, &limits))) {
......@@ -7067,10 +7019,7 @@ pub fn getrlimit(resource: rlimit_resource) GetrlimitError!rlimit {
70677019pub const SetrlimitError = error{ PermissionDenied, LimitTooBig } || UnexpectedError;
70687020
70697021pub fn setrlimit(resource: rlimit_resource, limits: rlimit) SetrlimitError!void {
7070 const setrlimit_sym = if (builtin.os.tag == .linux and builtin.link_libc)
7071 system.setrlimit64
7072 else
7073 system.setrlimit;
7022 const setrlimit_sym = if (lfs64_abi) system.setrlimit64 else system.setrlimit;
70747023
70757024 switch (errno(setrlimit_sym(resource, &limits))) {
70767025 .SUCCESS => return,
......@@ -7339,3 +7288,5 @@ pub fn ptrace(request: u32, pid: pid_t, addr: usize, signal: usize) PtraceError!
73397288 },
73407289 };
73417290}
7291
7292const lfs64_abi = builtin.os.tag == .linux and builtin.link_libc and builtin.abi.isGnu();