From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: [musl] [RFC] [PATCH] removing __NR_clock_gettime / SYS_clock_gettime
Date: Tue, 21 Jan 2020 13:49:50 -0500 [thread overview]
Message-ID: <20200121184950.GT30412@brightrain.aerifal.cx> (raw)
In-Reply-To: <20200119163616.GE30412@brightrain.aerifal.cx>
[-- Attachment #1: Type: text/plain, Size: 1148 bytes --]
On Sun, Jan 19, 2020 at 11:36:16AM -0500, Rich Felker wrote:
> Today we discovered that libstdc++ std::chrono is broken because it's
> making direct syscalls to SYS_clock_gettime to work around glibc
> putting clock_gettime in librt. This is exactly the same issue as
> busybox https://bugs.busybox.net/show_bug.cgi?id=12091 and I would not
> be surprised if it exists in more software. It's a silent bug that's
> easy to find and fix if you know what to look for, but very confusing
> and hard to find if you don't, and it can easily slip into software
> that's not well-tested on time64.
>
> What I'd like to propose doing is removing __NR_clock_gettime and
> SYS_clock_gettime from the public sys/syscall.h (via bits headers) on
> 32-bit archs, and moving SYS_clock_gettime to
> arch/$(ARCH)/syscall_arch.h for musl-internal use. This would make it
> a hard compile-time error for any software attempting to use the
> syscall directly, and in the case of libstdc++ I think it would even
> fix the problem without patching gcc, since they have a configure
> check for the syscall.
>
> Thoughts? Is this too big a hammer?
Patch attached.
Rich
[-- Attachment #2: remove_gtod32.diff --]
[-- Type: text/plain, Size: 7664 bytes --]
diff --git a/arch/arm/bits/syscall.h.in b/arch/arm/bits/syscall.h.in
index 8ab5df1d..4d844e57 100644
--- a/arch/arm/bits/syscall.h.in
+++ b/arch/arm/bits/syscall.h.in
@@ -55,7 +55,7 @@
#define __NR_sethostname 74
#define __NR_setrlimit 75
#define __NR_getrusage 77
-#define __NR_gettimeofday 78
+#define __NR_gettimeofday_time32 78
#define __NR_settimeofday 79
#define __NR_getgroups 80
#define __NR_setgroups 81
@@ -216,7 +216,7 @@
#define __NR_timer_getoverrun 260
#define __NR_timer_delete 261
#define __NR_clock_settime 262
-#define __NR_clock_gettime 263
+#define __NR_clock_gettime32 263
#define __NR_clock_getres 264
#define __NR_clock_nanosleep 265
#define __NR_statfs64 266
diff --git a/arch/i386/bits/syscall.h.in b/arch/i386/bits/syscall.h.in
index bb841677..a96317c0 100644
--- a/arch/i386/bits/syscall.h.in
+++ b/arch/i386/bits/syscall.h.in
@@ -76,7 +76,7 @@
#define __NR_setrlimit 75
#define __NR_getrlimit 76 /* Back compatible 2Gig limited rlimit */
#define __NR_getrusage 77
-#define __NR_gettimeofday 78
+#define __NR_gettimeofday_time32 78
#define __NR_settimeofday 79
#define __NR_getgroups 80
#define __NR_setgroups 81
@@ -262,7 +262,7 @@
#define __NR_timer_getoverrun (__NR_timer_create+3)
#define __NR_timer_delete (__NR_timer_create+4)
#define __NR_clock_settime (__NR_timer_create+5)
-#define __NR_clock_gettime (__NR_timer_create+6)
+#define __NR_clock_gettime32 (__NR_timer_create+6)
#define __NR_clock_getres (__NR_timer_create+7)
#define __NR_clock_nanosleep (__NR_timer_create+8)
#define __NR_statfs64 268
diff --git a/arch/m68k/bits/syscall.h.in b/arch/m68k/bits/syscall.h.in
index e7f71a5d..e70d3472 100644
--- a/arch/m68k/bits/syscall.h.in
+++ b/arch/m68k/bits/syscall.h.in
@@ -67,7 +67,7 @@
#define __NR_setrlimit 75
#define __NR_getrlimit 76
#define __NR_getrusage 77
-#define __NR_gettimeofday 78
+#define __NR_gettimeofday_time32 78
#define __NR_settimeofday 79
#define __NR_getgroups 80
#define __NR_setgroups 81
@@ -240,7 +240,7 @@
#define __NR_timer_getoverrun 257
#define __NR_timer_delete 258
#define __NR_clock_settime 259
-#define __NR_clock_gettime 260
+#define __NR_clock_gettime32 260
#define __NR_clock_getres 261
#define __NR_clock_nanosleep 262
#define __NR_statfs64 263
diff --git a/arch/microblaze/bits/syscall.h.in b/arch/microblaze/bits/syscall.h.in
index afefb354..b23fe6ef 100644
--- a/arch/microblaze/bits/syscall.h.in
+++ b/arch/microblaze/bits/syscall.h.in
@@ -76,7 +76,7 @@
#define __NR_setrlimit 75
#define __NR_getrlimit 76
#define __NR_getrusage 77
-#define __NR_gettimeofday 78
+#define __NR_gettimeofday_time32 78
#define __NR_settimeofday 79
#define __NR_getgroups 80
#define __NR_setgroups 81
@@ -260,7 +260,7 @@
#define __NR_timer_getoverrun 262
#define __NR_timer_delete 263
#define __NR_clock_settime 264
-#define __NR_clock_gettime 265
+#define __NR_clock_gettime32 265
#define __NR_clock_getres 266
#define __NR_clock_nanosleep 267
#define __NR_statfs64 268
diff --git a/arch/mips/bits/syscall.h.in b/arch/mips/bits/syscall.h.in
index 7f9afaab..e3f2de31 100644
--- a/arch/mips/bits/syscall.h.in
+++ b/arch/mips/bits/syscall.h.in
@@ -76,7 +76,7 @@
#define __NR_setrlimit 4075
#define __NR_getrlimit 4076
#define __NR_getrusage 4077
-#define __NR_gettimeofday 4078
+#define __NR_gettimeofday_time32 4078
#define __NR_settimeofday 4079
#define __NR_getgroups 4080
#define __NR_setgroups 4081
@@ -261,7 +261,7 @@
#define __NR_timer_getoverrun 4260
#define __NR_timer_delete 4261
#define __NR_clock_settime 4262
-#define __NR_clock_gettime 4263
+#define __NR_clock_gettime32 4263
#define __NR_clock_getres 4264
#define __NR_clock_nanosleep 4265
#define __NR_tgkill 4266
diff --git a/arch/mipsn32/bits/syscall.h.in b/arch/mipsn32/bits/syscall.h.in
index 134a4f81..d13fda12 100644
--- a/arch/mipsn32/bits/syscall.h.in
+++ b/arch/mipsn32/bits/syscall.h.in
@@ -92,7 +92,7 @@
#define __NR_fchown 6091
#define __NR_lchown 6092
#define __NR_umask 6093
-#define __NR_gettimeofday 6094
+#define __NR_gettimeofday_time32 6094
#define __NR_getrlimit 6095
#define __NR_getrusage 6096
#define __NR_sysinfo 6097
@@ -224,7 +224,7 @@
#define __NR_timer_getoverrun 6223
#define __NR_timer_delete 6224
#define __NR_clock_settime 6225
-#define __NR_clock_gettime 6226
+#define __NR_clock_gettime32 6226
#define __NR_clock_getres 6227
#define __NR_clock_nanosleep 6228
#define __NR_tgkill 6229
diff --git a/arch/or1k/bits/syscall.h.in b/arch/or1k/bits/syscall.h.in
index eaa1a935..82d94b29 100644
--- a/arch/or1k/bits/syscall.h.in
+++ b/arch/or1k/bits/syscall.h.in
@@ -112,7 +112,7 @@
#define __NR_timer_settime 110
#define __NR_timer_delete 111
#define __NR_clock_settime 112
-#define __NR_clock_gettime 113
+#define __NR_clock_gettime32 113
#define __NR_clock_getres 114
#define __NR_clock_nanosleep 115
#define __NR_syslog 116
@@ -168,7 +168,7 @@
#define __NR_umask 166
#define __NR_prctl 167
#define __NR_getcpu 168
-#define __NR_gettimeofday 169
+#define __NR_gettimeofday_time32 169
#define __NR_settimeofday 170
#define __NR_adjtimex 171
#define __NR_getpid 172
diff --git a/arch/powerpc/bits/syscall.h.in b/arch/powerpc/bits/syscall.h.in
index d8b6a247..14cf79c6 100644
--- a/arch/powerpc/bits/syscall.h.in
+++ b/arch/powerpc/bits/syscall.h.in
@@ -76,7 +76,7 @@
#define __NR_setrlimit 75
#define __NR_getrlimit 76
#define __NR_getrusage 77
-#define __NR_gettimeofday 78
+#define __NR_gettimeofday_time32 78
#define __NR_settimeofday 79
#define __NR_getgroups 80
#define __NR_setgroups 81
@@ -243,7 +243,7 @@
#define __NR_timer_getoverrun 243
#define __NR_timer_delete 244
#define __NR_clock_settime 245
-#define __NR_clock_gettime 246
+#define __NR_clock_gettime32 246
#define __NR_clock_getres 247
#define __NR_clock_nanosleep 248
#define __NR_swapcontext 249
diff --git a/arch/sh/bits/syscall.h.in b/arch/sh/bits/syscall.h.in
index 4e9ae2e0..5c24f4a6 100644
--- a/arch/sh/bits/syscall.h.in
+++ b/arch/sh/bits/syscall.h.in
@@ -67,7 +67,7 @@
#define __NR_setrlimit 75
#define __NR_getrlimit 76
#define __NR_getrusage 77
-#define __NR_gettimeofday 78
+#define __NR_gettimeofday_time32 78
#define __NR_settimeofday 79
#define __NR_getgroups 80
#define __NR_setgroups 81
@@ -236,7 +236,7 @@
#define __NR_timer_getoverrun 262
#define __NR_timer_delete 263
#define __NR_clock_settime 264
-#define __NR_clock_gettime 265
+#define __NR_clock_gettime32 265
#define __NR_clock_getres 266
#define __NR_clock_nanosleep 267
#define __NR_statfs64 268
diff --git a/src/internal/syscall.h b/src/internal/syscall.h
index d768fb64..0b61f34e 100644
--- a/src/internal/syscall.h
+++ b/src/internal/syscall.h
@@ -193,6 +193,13 @@ hidden long __syscall_ret(unsigned long),
#define SYS_sendfile SYS_sendfile64
#endif
+#ifndef SYS_clock_gettime
+#define SYS_clock_gettime SYS_clock_gettime32
+#endif
+
+#ifndef SYS_gettimeofday
+#define SYS_gettimeofday SYS_gettimeofday_time32
+#endif
/* Ensure that the plain syscall names are defined even for "time64-only"
* archs. These facilitate callers passing null time arguments, and make
prev parent reply other threads:[~2020-01-21 18:50 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-19 16:36 [musl] [RFC] " Rich Felker
2020-01-19 17:51 ` Szabolcs Nagy
2020-01-19 18:16 ` Rich Felker
2020-01-19 18:42 ` Szabolcs Nagy
2020-01-19 18:53 ` Rich Felker
2020-01-19 19:30 ` Szabolcs Nagy
2020-01-21 18:49 ` Rich Felker [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200121184950.GT30412@brightrain.aerifal.cx \
--to=dalias@libc.org \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).