-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
musl: Change time_t
definition on 32-bit targets according to "time64"
#1848
musl: Change time_t
definition on 32-bit targets according to "time64"
#1848
Comments
Isn't this broken either way as soon as C libraries are involved or am I missing something? As documented in time64.html, C code compiled against >=1.2 assumes time_t = i64 whereas code compiled against <1.2 assumes time_t = i32 on 32 bit systems. If you use a C library that uses time_t in its interface (e.g. openssl), the time_t used by rust code must have the same size as in the musl headers. |
Any updates? I'm facing the same issue when building openssl:
|
Add a deprecation note to `time_t` on musl cc #1848
Add a deprecation note to `time_t` on musl cc #1848
The added deprecation notice is now making the libstd build to fail, as it depends on said type. This means that libstd is either stuck on 0.2.79 for indeterminate amount of time or we need to figure out a way to support either version of musl or give users ability to specify the version of musl they target? |
It's related to #1412 but we don't have any policy for supported platforms. Yes, both ways are better than just changing the type (also cc #547). |
So, we currently detect FreeBSD version, like: Lines 122 to 145 in 4c0a7e5
I wonder we could also detect musl version and separate |
See rust-lang/libc#1848 in which this type is changing from i32 to i64; the change is being announced via this deprecation.
See rust-lang/libc#1848 in which this type is changing from i32 to i64; the change is being announced via this deprecation.
See rust-lang/libc#1848 in which this type is changing from i32 to i64; the change is being announced via this deprecation.
See rust-lang/libc#1848 in which this type is changing from i32 to i64; the change is being announced via this deprecation.
See rust-lang/libc#1848 in which this type is changing from i32 to i64; the change is being announced via this deprecation. Signed-off-by: Tim Zhang <[email protected]>
How do you deal with the cross compilation case? |
Note that this is not really musl specific, the change to 64-bit time_t needs to happen on all 32-bit implementations in order to have code working beyond year 2038. glibc on riscv uses 64-bit time_t, and patches for glibc and uclibc to convert all other architectures to make this a compile-time decision are in progress. |
The type is to change from 32-bit to 64-bit. See rust-lang/libc#1848. The change is announced via a deprecation warning. Cloud Hypervisor's code does not need changing. Simply suppress these warnings. Signed-off-by: Wei Liu <[email protected]>
It feels so silly to ask this, but ... what is the actual course of action here if I have FFI code that triggers this deprecation notice? Try to ensure that |
As per rust-lang/libc#1848, we can't safely do this since the definition of time_t depends on which version of Musl you're using on 32-bit systems (the "time64" update for Musl 1.2), and this actually started biting us on the arm-unknown-linux-musleabihf cross build. Unfortunately, ISO C makes virtually no guarantees about what time_t is, so I don't see a practical way to handle the different possibilities robustly. We'll just cast from i64 or u64 to time_t in C and hope for the best.
Echoing @pkgw here. What is the right course of action here? |
Any use of time_t/timeval/timespec that does not match the libc-defined type will cause data corruption. On both musl and libc you can encounter both 32-bit and 64-bit types. With musl, this is purely dependent on the version of the library, i.e. musl-1.2 only allows compiling with a 64-bit time_t, while glibc allows both, depending on whether the _TIME_BITS macro was set to '64' when building the C code one is linking against, same as the _FILE_OFFSET_BITS macro for off_t and other types. The only portable way to do this is to avoid any use of time_t, struct timeval, struct timespec, ino_t, blkcnt_t, as well as any types derived from these, such as struct stat, struct dirent, or struct rlimit when interfacing with C/C++ code. |
|
this version is broken on 32-bit arches due to libc crate incompatibility with musl's new ABI for time_t, see: rust-lang/libc#1848
[ commit 5858e10e41fed33d2673a1a3724f96a7b18bc3cd ] this version is broken on 32-bit arches due to libc crate incompatibility with musl's new ABI for time_t, see: rust-lang/libc#1848
- time_t -> u64: see [1] - removing dynamic library as cdylib is unsupported (this is an update of 501cca6 so it can be merged) [1] rust-lang/libc#1848
rust-lang/libc#1848 This is a work in progress to resolve the time_t definition change in musl 1.2.0, where on 32 bit systems the definition has been changed from 32 bits to 64 bits. Signed-off-by: Mislav Novakovic <[email protected]>
- time_t -> u64: see [1] - removing dynamic library as cdylib is unsupported (this is an update of 501cca6 so it can be merged) [1] rust-lang/libc#1848
Is this advice for libc itself (or anyone planning to work on libc), or for downstream developers? Because there are plenty of C APIs that use these types, so any wrapper crates will have to use those types to interface with them. For eg. rusb wraps libusb, which uses So, rusb seems to have no way to avoid using |
In a specific package like rusb, the most reliable way to address this is to ensure that the underlying C library exports both time32 and time64 symbols in the way that glibc does. This way rusb can always use the time64 interface, while C based applications can pick the symbol based on their configuration. Having a generic solution is much harder since a glibc based system may have a mix of time32 and time64 libraries installed, making it impossible to know which types are used in a particular library. As 32-bit Linux distros are increasingly going away or migrating to time64, I see two options, neither of which is a complete fix: a) have some build-time feature detection to probe the defaults of the compiler, making the time_t/timespec/timeval/off_t/ino_t/... types depend on the __USE_TIME_BITS64 macro defined by the C libraries that are configured for time64. This is a lot of extra work but remains unreliable because the default flags used by the compiler may not reflect what a given library API was built with. b) Drop time32 support on 32-bit Linux/glibc rust altogether and assume that the system libraries are all built for time64, same as with musl. This fixes the glibc systems that are currently broken but in turn breaks the ones that happen to work by chance today because they have not been converted yet or never will. |
Possible solution: rust-lang/rfcs#3716 ("[RFC] Target Modifiers") |
time_t
is defined asc_long
on musl:libc/src/unix/linux_like/linux/musl/mod.rs
Line 3 in b1268e4
and
c_long
isi32
on 32-bit targets:libc/src/unix/linux_like/linux/musl/b32/mod.rs
Line 1 in b1268e4
But the
time_t
definition has been changed to 64-bit by bminor/musl@3814333, since musl 1.2.0.We will change our type to i64 on 32-bit targets as well at some point but we should announce it before changing.
cc #1846
The text was updated successfully, but these errors were encountered: