blob: 77f22f42b6035e9a5d81ce4789c7727025589560 [file] [log] [blame]
Andrew Geissler517393d2023-01-13 08:55:19 -06001From 3ecce665198e3420d70139d86ed22e74804c9379 Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Wed, 28 Dec 2022 22:35:55 -0800
4Subject: [PATCH] Do not use LFS64 on linux with musl
5
6glibc is providing open64 and other lfs64 functions but musl aliases
7them to normal equivalents since off_t is always 64-bit on musl,
8therefore check for target env along when target OS is linux before
9using open64, this is more available. Latest Musl has made these
10namespace changes [1]
11
12[1] https://git.musl-libc.org/cgit/musl/commit/?id=246f1c811448f37a44b41cd8df8d0ef9736d95f4
13
14Upstream-Status: Submitted [https://github.com/rust-lang/rust/pull/106246]
15Signed-off-by: Khem Raj <raj.khem@gmail.com>
16---
17 library/std/src/os/linux/fs.rs | 9 ++++++++-
18 library/std/src/sys/unix/fd.rs | 14 ++++++++++----
19 library/std/src/sys/unix/fs.rs | 27 ++++++++++++++++++++-------
20 3 files changed, 38 insertions(+), 12 deletions(-)
21
Andrew Geissler028142b2023-05-05 11:29:21 -050022Index: rustc-1.69.0-src/library/std/src/os/linux/fs.rs
23===================================================================
24--- rustc-1.69.0-src.orig/library/std/src/os/linux/fs.rs
25+++ rustc-1.69.0-src/library/std/src/os/linux/fs.rs
Andrew Geissler517393d2023-01-13 08:55:19 -060026@@ -329,7 +329,14 @@ pub trait MetadataExt {
27 impl MetadataExt for Metadata {
28 #[allow(deprecated)]
29 fn as_raw_stat(&self) -> &raw::stat {
30- unsafe { &*(self.as_inner().as_inner() as *const libc::stat64 as *const raw::stat) }
31+ #[cfg(target_env = "musl")]
32+ unsafe {
33+ &*(self.as_inner().as_inner() as *const libc::stat as *const raw::stat)
34+ }
35+ #[cfg(not(target_env = "musl"))]
36+ unsafe {
37+ &*(self.as_inner().as_inner() as *const libc::stat64 as *const raw::stat)
38+ }
39 }
40 fn st_dev(&self) -> u64 {
41 self.as_inner().as_inner().st_dev as u64
Andrew Geissler028142b2023-05-05 11:29:21 -050042Index: rustc-1.69.0-src/library/std/src/sys/unix/fd.rs
43===================================================================
44--- rustc-1.69.0-src.orig/library/std/src/sys/unix/fd.rs
45+++ rustc-1.69.0-src/library/std/src/sys/unix/fd.rs
46@@ -121,9 +121,12 @@ impl FileDesc {
Andrew Geissler517393d2023-01-13 08:55:19 -060047 }
48
49 pub fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result<usize> {
50- #[cfg(not(any(target_os = "linux", target_os = "android")))]
51+ #[cfg(not(any(
52+ all(target_os = "linux", not(target_env = "musl")),
53+ target_os = "android"
54+ )))]
55 use libc::pread as pread64;
56- #[cfg(any(target_os = "linux", target_os = "android"))]
57+ #[cfg(any(all(target_os = "linux", not(target_env = "musl")), target_os = "android"))]
58 use libc::pread64;
59
60 unsafe {
Andrew Geissler028142b2023-05-05 11:29:21 -050061@@ -276,9 +279,12 @@ impl FileDesc {
Andrew Geissler517393d2023-01-13 08:55:19 -060062 }
63
64 pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result<usize> {
65- #[cfg(not(any(target_os = "linux", target_os = "android")))]
66+ #[cfg(not(any(
67+ all(target_os = "linux", not(target_env = "musl")),
68+ target_os = "android"
69+ )))]
70 use libc::pwrite as pwrite64;
71- #[cfg(any(target_os = "linux", target_os = "android"))]
72+ #[cfg(any(all(target_os = "linux", not(target_env = "musl")), target_os = "android"))]
73 use libc::pwrite64;
74
75 unsafe {
Andrew Geissler028142b2023-05-05 11:29:21 -050076Index: rustc-1.69.0-src/library/std/src/sys/unix/fs.rs
77===================================================================
78--- rustc-1.69.0-src.orig/library/std/src/sys/unix/fs.rs
79+++ rustc-1.69.0-src/library/std/src/sys/unix/fs.rs
80@@ -46,9 +46,13 @@ use libc::{c_int, mode_t};
Andrew Geissler517393d2023-01-13 08:55:19 -060081 all(target_os = "linux", target_env = "gnu")
82 ))]
83 use libc::c_char;
84-#[cfg(any(target_os = "linux", target_os = "emscripten", target_os = "android"))]
85+#[cfg(any(
86+ all(target_os = "linux", not(target_env = "musl")),
87+ target_os = "emscripten",
88+ target_os = "android"
89+))]
90 use libc::dirfd;
91-#[cfg(any(target_os = "linux", target_os = "emscripten"))]
92+#[cfg(any(not(target_env = "musl"), target_os = "emscripten"))]
93 use libc::fstatat64;
94 #[cfg(any(
95 target_os = "android",
Andrew Geissler028142b2023-05-05 11:29:21 -050096@@ -57,9 +61,10 @@ use libc::fstatat64;
Andrew Geissler517393d2023-01-13 08:55:19 -060097 target_os = "redox",
Andrew Geissler028142b2023-05-05 11:29:21 -050098 target_os = "illumos",
99 target_os = "nto",
100+ target_env = "musl",
Andrew Geissler517393d2023-01-13 08:55:19 -0600101 ))]
102 use libc::readdir as readdir64;
103-#[cfg(target_os = "linux")]
104+#[cfg(all(target_os = "linux", not(target_env = "musl")))]
105 use libc::readdir64;
106 #[cfg(any(target_os = "emscripten", target_os = "l4re"))]
107 use libc::readdir64_r;
Andrew Geissler028142b2023-05-05 11:29:21 -0500108@@ -80,7 +85,13 @@ use libc::{
Andrew Geissler517393d2023-01-13 08:55:19 -0600109 dirent as dirent64, fstat as fstat64, fstatat as fstatat64, ftruncate64, lseek64,
110 lstat as lstat64, off64_t, open as open64, stat as stat64,
111 };
112+#[cfg(target_env = "musl")]
113+use libc::{
114+ dirent as dirent64, fstat as fstat64, ftruncate as ftruncate64, lseek as lseek64,
115+ lstat as lstat64, off_t as off64_t, open as open64, stat as stat64,
116+};
117 #[cfg(not(any(
118+ target_env = "musl",
119 target_os = "linux",
120 target_os = "emscripten",
121 target_os = "l4re",
Andrew Geissler028142b2023-05-05 11:29:21 -0500122@@ -90,7 +101,7 @@ use libc::{
Andrew Geissler517393d2023-01-13 08:55:19 -0600123 dirent as dirent64, fstat as fstat64, ftruncate as ftruncate64, lseek as lseek64,
124 lstat as lstat64, off_t as off64_t, open as open64, stat as stat64,
125 };
126-#[cfg(any(target_os = "linux", target_os = "emscripten", target_os = "l4re"))]
127+#[cfg(any(not(target_env = "musl"), target_os = "emscripten", target_os = "l4re"))]
128 use libc::{dirent64, fstat64, ftruncate64, lseek64, lstat64, off64_t, open64, stat64};
129
130 pub use crate::sys_common::fs::try_exists;
Andrew Geissler028142b2023-05-05 11:29:21 -0500131@@ -277,6 +288,7 @@ unsafe impl Sync for Dir {}
Andrew Geissler517393d2023-01-13 08:55:19 -0600132 #[cfg(any(
133 target_os = "android",
134 target_os = "linux",
135+ not(target_env = "musl"),
136 target_os = "solaris",
137 target_os = "illumos",
138 target_os = "fuchsia",
Andrew Geissler028142b2023-05-05 11:29:21 -0500139@@ -311,6 +323,7 @@ struct dirent64_min {
Andrew Geissler517393d2023-01-13 08:55:19 -0600140 }
141
142 #[cfg(not(any(
143+ target_env = "musl",
144 target_os = "android",
145 target_os = "linux",
146 target_os = "solaris",
Andrew Geissler028142b2023-05-05 11:29:21 -0500147@@ -786,7 +799,7 @@ impl DirEntry {
Andrew Geissler517393d2023-01-13 08:55:19 -0600148 }
149
150 #[cfg(all(
151- any(target_os = "linux", target_os = "emscripten", target_os = "android"),
152+ any(not(target_env = "musl"), target_os = "emscripten", target_os = "android"),
153 not(miri)
154 ))]
155 pub fn metadata(&self) -> io::Result<FileAttr> {
Andrew Geissler028142b2023-05-05 11:29:21 -0500156@@ -810,7 +823,7 @@ impl DirEntry {
Andrew Geissler517393d2023-01-13 08:55:19 -0600157 }
158
159 #[cfg(any(
160- not(any(target_os = "linux", target_os = "emscripten", target_os = "android")),
161+ not(any(not(target_env = "musl"), target_os = "emscripten", target_os = "android")),
162 miri
163 ))]
164 pub fn metadata(&self) -> io::Result<FileAttr> {