From 3c6bde03ecf2aa7dac605f0a55a1be201f3d4c5f Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Fri, 2 Aug 2019 15:41:27 -0400 Subject: [PATCH 5/5] [RFC] [POC] switch i386 to 64-bit time_t this is a proof of concept for converting one 32-bit arch, i386, to 64-bit time_t. known issues: 1. the switchover of timespec padding is a hack, and needs to be done right, but that involves making alltypes.h aware of endianness, which probably should have been done a long time ago anyway and would get rid of inappropriate inclusion of in some places. 2. the rusage, utmpx, and timex structs are not correct with regard to ABI or functionality. they need to be fixed before this is safe to use. 3. Makefile change should be its own thing. there are likely a lot more problems. before upstreaming this can even be considered, heavy review of the new ABI that's produced is needed. once this is in use, mistakes will be permanent. we may also need to review for interfaces where the new type is not likely to match whatever glibc ends up adopting, and renaming the redirected symbols for those interfaces to names that don't overlap with what glibc intends to use, so that producing future ABI-compat layers is less painful. --- Makefile | 5 +++-- arch/i386/arch.mak | 1 + arch/i386/bits/alltypes.h.in | 5 +++-- arch/i386/bits/ipcstat.h | 2 +- arch/i386/bits/msg.h | 15 +++++++++------ arch/i386/bits/sem.h | 10 ++++++---- arch/i386/bits/shm.h | 16 ++++++++++------ arch/i386/bits/stat.h | 6 +++++- arch/i386/syscall_arch.h | 4 +++- include/alltypes.h.in | 2 +- 10 files changed, 42 insertions(+), 24 deletions(-) create mode 100644 arch/i386/arch.mak diff --git a/Makefile b/Makefile index b46f8ca4..d636f5a9 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ includedir = $(prefix)/include libdir = $(prefix)/lib syslibdir = /lib -SRC_DIRS = $(addprefix $(srcdir)/,src/* crt ldso) +SRC_DIRS = $(addprefix $(srcdir)/,src/* crt ldso $(COMPAT_SRC_DIRS)) BASE_GLOBS = $(addsuffix /*.c,$(SRC_DIRS)) ARCH_GLOBS = $(addsuffix /$(ARCH)/*.[csS],$(SRC_DIRS)) BASE_SRCS = $(sort $(wildcard $(BASE_GLOBS))) @@ -27,7 +27,7 @@ ARCH_OBJS = $(patsubst $(srcdir)/%,%.o,$(basename $(ARCH_SRCS))) REPLACED_OBJS = $(sort $(subst /$(ARCH)/,/,$(ARCH_OBJS))) ALL_OBJS = $(addprefix obj/, $(filter-out $(REPLACED_OBJS), $(sort $(BASE_OBJS) $(ARCH_OBJS)))) -LIBC_OBJS = $(filter obj/src/%,$(ALL_OBJS)) +LIBC_OBJS = $(filter obj/src/%,$(ALL_OBJS)) $(filter obj/compat/%,$(ALL_OBJS)) LDSO_OBJS = $(filter obj/ldso/%,$(ALL_OBJS:%.o=%.lo)) CRT_OBJS = $(filter obj/crt/%,$(ALL_OBJS)) @@ -75,6 +75,7 @@ WRAPCC_CLANG = clang LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH)$(SUBARCH).so.1 -include config.mak +-include arch/$(ARCH)/arch.mak ifeq ($(ARCH),) diff --git a/arch/i386/arch.mak b/arch/i386/arch.mak new file mode 100644 index 00000000..aa4d05ce --- /dev/null +++ b/arch/i386/arch.mak @@ -0,0 +1 @@ +COMPAT_SRC_DIRS = compat/time32 diff --git a/arch/i386/bits/alltypes.h.in b/arch/i386/bits/alltypes.h.in index 1a8432d3..8069271b 100644 --- a/arch/i386/bits/alltypes.h.in +++ b/arch/i386/bits/alltypes.h.in @@ -1,3 +1,4 @@ +#define _REDIR_TIME64 1 #define _Addr int #define _Int64 long long #define _Reg int @@ -34,8 +35,8 @@ TYPEDEF struct { __attribute__((__aligned__(8))) long long __ll; long double __l TYPEDEF struct { alignas(8) long long __ll; long double __ld; } max_align_t; #endif -TYPEDEF long time_t; -TYPEDEF long suseconds_t; +TYPEDEF long long time_t; +TYPEDEF long long suseconds_t; TYPEDEF struct { union { int __i[9]; volatile int __vi[9]; unsigned __s[9]; } __u; } pthread_attr_t; TYPEDEF struct { union { int __i[6]; volatile int __vi[6]; volatile void *volatile __p[6]; } __u; } pthread_mutex_t; diff --git a/arch/i386/bits/ipcstat.h b/arch/i386/bits/ipcstat.h index 0018ad1e..4f4fcb0c 100644 --- a/arch/i386/bits/ipcstat.h +++ b/arch/i386/bits/ipcstat.h @@ -1 +1 @@ -#define IPC_STAT 2 +#define IPC_STAT 0x102 diff --git a/arch/i386/bits/msg.h b/arch/i386/bits/msg.h index bc8436c4..7bbbb2bf 100644 --- a/arch/i386/bits/msg.h +++ b/arch/i386/bits/msg.h @@ -1,15 +1,18 @@ struct msqid_ds { struct ipc_perm msg_perm; - time_t msg_stime; - int __unused1; - time_t msg_rtime; - int __unused2; - time_t msg_ctime; - int __unused3; + unsigned long __msg_stime_lo; + unsigned long __msg_stime_hi; + unsigned long __msg_rtime_lo; + unsigned long __msg_rtime_hi; + unsigned long __msg_ctime_lo; + unsigned long __msg_ctime_hi; unsigned long msg_cbytes; msgqnum_t msg_qnum; msglen_t msg_qbytes; pid_t msg_lspid; pid_t msg_lrpid; unsigned long __unused[2]; + time_t msg_stime; + time_t msg_rtime; + time_t msg_ctime; }; diff --git a/arch/i386/bits/sem.h b/arch/i386/bits/sem.h index e61571c1..65661542 100644 --- a/arch/i386/bits/sem.h +++ b/arch/i386/bits/sem.h @@ -1,11 +1,13 @@ struct semid_ds { struct ipc_perm sem_perm; - time_t sem_otime; - long __unused1; - time_t sem_ctime; - long __unused2; + unsigned long __sem_otime_lo; + unsigned long __sem_otime_hi; + unsigned long __sem_ctime_lo; + unsigned long __sem_ctime_hi; unsigned short sem_nsems; char __sem_nsems_pad[sizeof(long)-sizeof(short)]; long __unused3; long __unused4; + time_t sem_otime; + time_t sem_ctime; }; diff --git a/arch/i386/bits/shm.h b/arch/i386/bits/shm.h index 81b2a29a..725fb469 100644 --- a/arch/i386/bits/shm.h +++ b/arch/i386/bits/shm.h @@ -3,17 +3,21 @@ struct shmid_ds { struct ipc_perm shm_perm; size_t shm_segsz; - time_t shm_atime; - int __unused1; - time_t shm_dtime; - int __unused2; - time_t shm_ctime; - int __unused3; + unsigned long __shm_atime_lo; + unsigned long __shm_atime_hi; + unsigned long __shm_dtime_lo; + unsigned long __shm_dtime_hi; + unsigned long __shm_ctime_lo; + unsigned long __shm_ctime_hi; pid_t shm_cpid; pid_t shm_lpid; unsigned long shm_nattch; unsigned long __pad1; unsigned long __pad2; + unsigned long __pad3; + time_t shm_atime; + time_t shm_dtime; + time_t shm_ctime; }; struct shminfo { diff --git a/arch/i386/bits/stat.h b/arch/i386/bits/stat.h index 22b19bbf..5d7828cf 100644 --- a/arch/i386/bits/stat.h +++ b/arch/i386/bits/stat.h @@ -14,8 +14,12 @@ struct stat { off_t st_size; blksize_t st_blksize; blkcnt_t st_blocks; + struct { + long tv_sec; + long tv_nsec; + } __st_atim32, __st_mtim32, __st_ctim32; + ino_t st_ino; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; - ino_t st_ino; }; diff --git a/arch/i386/syscall_arch.h b/arch/i386/syscall_arch.h index 22b0b28b..69642e57 100644 --- a/arch/i386/syscall_arch.h +++ b/arch/i386/syscall_arch.h @@ -83,7 +83,9 @@ static inline long __syscall6(long n, long a1, long a2, long a3, long a4, long a } #define VDSO_USEFUL -#define VDSO_CGT_SYM "__vdso_clock_gettime" +#define VDSO_CGT32_SYM "__vdso_clock_gettime" +#define VDSO_CGT32_VER "LINUX_2.6" +#define VDSO_CGT_SYM "__vdso_clock_gettime64" #define VDSO_CGT_VER "LINUX_2.6" #define SYSCALL_USE_SOCKETCALL diff --git a/include/alltypes.h.in b/include/alltypes.h.in index 4cc879b1..b90ea7fa 100644 --- a/include/alltypes.h.in +++ b/include/alltypes.h.in @@ -35,7 +35,7 @@ TYPEDEF void * timer_t; TYPEDEF int clockid_t; TYPEDEF long clock_t; STRUCT timeval { time_t tv_sec; suseconds_t tv_usec; }; -STRUCT timespec { time_t tv_sec; long tv_nsec; }; +STRUCT timespec { time_t tv_sec; long tv_nsec; long :8*(sizeof(time_t)-sizeof(long)); }; TYPEDEF int pid_t; TYPEDEF unsigned id_t; -- 2.21.0