commit 9e8281add35dde70478464389fab6f0f7e75b880 Author: Andreas Schwab Date: Thu Feb 3 09:37:42 2022 +0100 Regenerate configure diff --git a/configure b/configure index 00dc638388..8e5bee775a 100755 --- a/configure +++ b/configure @@ -730,7 +730,6 @@ infodir docdir oldincludedir includedir -runstatedir localstatedir sharedstatedir sysconfdir @@ -845,7 +844,6 @@ datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' -runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' @@ -1098,15 +1096,6 @@ do | -silent | --silent | --silen | --sile | --sil) silent=yes ;; - -runstatedir | --runstatedir | --runstatedi | --runstated \ - | --runstate | --runstat | --runsta | --runst | --runs \ - | --run | --ru | --r) - ac_prev=runstatedir ;; - -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ - | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ - | --run=* | --ru=* | --r=*) - runstatedir=$ac_optarg ;; - -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ @@ -1244,7 +1233,7 @@ fi for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ - libdir localedir mandir runstatedir + libdir localedir mandir do eval ac_val=\$$ac_var # Remove trailing slashes. @@ -1397,7 +1386,6 @@ Fine tuning of the installation directories: --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] - --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] commit d2e4d2a38e4e7bc3ca407607e717b7f50b20c63f Author: Adhemerval Zanella Date: Wed Feb 2 18:31:59 2022 -0300 posix: Fix tst-spawn6 terminal handling (BZ #28853) The test changes the current foreground process group, which might break testing depending of how the make check is issued. For instance: nohup make -j1 test t=posix/tst-spawn6 | less Will set 'make' and 'less' to be in the foreground process group in the current session. When tst-spawn6 new child takes over it becomes the foreground process and 'less' is stopped and backgrounded which interrupts the 'make check' command. To fix it a pseudo-terminal is allocated, the test starts in new session (so there is no controlling terminal associated), and the pseudo-terminal is set as the controlling one (similar to what login_tty does). Checked on x86_64-linux-gnu. Tested-by: Carlos O'Donell Reviewed-by: Carlos O'Donell (cherry picked from a9d35765728cbc5b66af5eeda5428298bccf9b69) diff --git a/NEWS b/NEWS index faa7ec1871..b1aae94cfb 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,14 @@ See the end for copying conditions. Please send GNU C library bug reports via using `glibc' in the "product" field. + +Version 2.35.1 + +The following bugs are resolved with this release: + + [28853] libc: tst-spawn6 changes current foreground process group + (breaks test isolation) + Version 2.35 diff --git a/posix/tst-spawn6.c b/posix/tst-spawn6.c index 911e90a461..044abd8535 100644 --- a/posix/tst-spawn6.c +++ b/posix/tst-spawn6.c @@ -29,7 +29,14 @@ #include #include #include +#include #include +#include + +#ifndef PATH_MAX +# define PATH_MAX 1024 +#endif +static char ptmxpath[PATH_MAX]; static int handle_restart (const char *argv1, const char *argv2) @@ -115,7 +122,7 @@ run_subprogram (int argc, char *argv[], const posix_spawnattr_t *attr, } static int -do_test (int argc, char *argv[]) +run_test (int argc, char *argv[]) { /* We must have either: - four parameters left if called initially: @@ -127,16 +134,7 @@ do_test (int argc, char *argv[]) + --setgrpr optional */ - if (restart) - return handle_restart (argv[1], argv[2]); - - int tcfd = open64 (_PATH_TTY, O_RDONLY, 0600); - if (tcfd == -1) - { - if (errno == ENXIO) - FAIL_UNSUPPORTED ("terminal not available, skipping test"); - FAIL_EXIT1 ("open64 (\"%s\", 0x%x, 0600): %m", _PATH_TTY, O_RDONLY); - } + int tcfd = xopen (ptmxpath, O_RDONLY, 0600); /* Check setting the controlling terminal without changing the group. */ { @@ -198,5 +196,47 @@ do_test (int argc, char *argv[]) return 0; } +static int +do_test (int argc, char *argv[]) +{ + if (restart) + return handle_restart (argv[1], argv[2]); + + pid_t pid = xfork (); + if (pid == 0) + { + /* Create a pseudo-terminal to avoid interfering with the one using by + test itself, creates a new session (so there is no controlling + terminal), and set the pseudo-terminal as the controlling one. */ + int ptmx = posix_openpt (0); + if (ptmx == -1) + { + if (errno == ENXIO) + FAIL_UNSUPPORTED ("terminal not available, skipping test"); + FAIL_EXIT1 ("posix_openpt (0): %m"); + } + TEST_VERIFY_EXIT (grantpt (ptmx) == 0); + TEST_VERIFY_EXIT (unlockpt (ptmx) == 0); + + TEST_VERIFY_EXIT (setsid () != -1); + TEST_VERIFY_EXIT (ioctl (ptmx, TIOCSCTTY, NULL) == 0); + while (dup2 (ptmx, STDIN_FILENO) == -1 && errno == EBUSY) + ; + while (dup2 (ptmx, STDOUT_FILENO) == -1 && errno == EBUSY) + ; + while (dup2 (ptmx, STDERR_FILENO) == -1 && errno == EBUSY) + ; + TEST_VERIFY_EXIT (ptsname_r (ptmx, ptmxpath, sizeof ptmxpath) == 0); + xclose (ptmx); + + run_test (argc, argv); + _exit (0); + } + int status; + xwaitpid (pid, &status, 0); + TEST_VERIFY (WIFEXITED (status)); + exit (0); +} + #define TEST_FUNCTION_ARGV do_test #include commit a2f1675634b3513c09c38e55e6766e8c05768b1f Author: Gleb Fotengauer-Malinovskiy Date: Tue Feb 1 22:39:02 2022 +0000 linux: __get_nprocs_sched: do not feed CPU_COUNT_S with garbage [BZ #28850] Pass the actual number of bytes returned by the kernel. Fixes: 33099d72e41c ("linux: Simplify get_nprocs") Reviewed-by: Dmitry V. Levin (cherry picked from commit 97ba273b505763325efd802dc3a9562dbba79579) diff --git a/NEWS b/NEWS index b1aae94cfb..d1602051d1 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,7 @@ Version 2.35.1 The following bugs are resolved with this release: + [28850] linux: __get_nprocs_sched reads uninitialized memory from the stack [28853] libc: tst-spawn6 changes current foreground process group (breaks test isolation) diff --git a/sysdeps/unix/sysv/linux/getsysstats.c b/sysdeps/unix/sysv/linux/getsysstats.c index 4798cc337e..c98c8ce3d4 100644 --- a/sysdeps/unix/sysv/linux/getsysstats.c +++ b/sysdeps/unix/sysv/linux/getsysstats.c @@ -44,7 +44,7 @@ __get_nprocs_sched (void) int r = INTERNAL_SYSCALL_CALL (sched_getaffinity, 0, cpu_bits_size, cpu_bits); if (r > 0) - return CPU_COUNT_S (cpu_bits_size, (cpu_set_t*) cpu_bits); + return CPU_COUNT_S (r, (cpu_set_t*) cpu_bits); else if (r == -EINVAL) /* The input buffer is still not enough to store the number of cpus. This is an arbitrary values assuming such systems should be rare and there commit 7001c1e38b46d5f5a90f7915b1211782341ab6a8 Author: Adhemerval Zanella Date: Thu Feb 3 16:52:52 2022 -0300 linux: Fix missing __convert_scm_timestamps (BZ #28860) Commit 948ce73b31 made recvmsg/recvmmsg to always call __convert_scm_timestamps for 64 bit time_t symbol, so adjust it to always build it for __TIMESIZE != 64. It fixes build for architecture with 32 bit time_t support when configured with minimum kernel of 5.1. (cherry picked from 798d716df71fb23dc89d1d5dba1fc26a1b5c0024) diff --git a/sysdeps/unix/sysv/linux/convert_scm_timestamps.c b/sysdeps/unix/sysv/linux/convert_scm_timestamps.c index 82171bf325..dfc8c2beff 100644 --- a/sysdeps/unix/sysv/linux/convert_scm_timestamps.c +++ b/sysdeps/unix/sysv/linux/convert_scm_timestamps.c @@ -16,9 +16,9 @@ License along with the GNU C Library; if not, see . */ -#include +#include -#ifndef __ASSUME_TIME64_SYSCALLS +#if __TIMESIZE != 64 # include # include # include commit 24962427071fa532c3c48c918e9d64d719cc8a6c Author: Adhemerval Zanella Date: Thu Feb 3 17:50:13 2022 -0300 Add BZ#28860 reference on NEWS diff --git a/NEWS b/NEWS index d1602051d1..6b8db4e947 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,8 @@ The following bugs are resolved with this release: [28850] linux: __get_nprocs_sched reads uninitialized memory from the stack [28853] libc: tst-spawn6 changes current foreground process group (breaks test isolation) + [28860] build: --enable-kernel=5.1.0 build fails because of missing + __convert_scm_timestamps Version 2.35 commit 491f2ef1f0ff849490f374917957018d07ee0586 Author: Dmitry V. Levin Date: Sat Feb 5 08:00:00 2022 +0000 linux: fix accuracy of get_nprocs and get_nprocs_conf [BZ #28865] get_nprocs() and get_nprocs_conf() use various methods to obtain an accurate number of processors. Re-introduce __get_nprocs_sched() as a source of information, and fix the order in which these methods are used to return the most accurate information. The primary source of information used in both functions remains unchanged. This also changes __get_nprocs_sched() error return value from 2 to 0, but all its users are already prepared to handle that. Old fallback order: get_nprocs: /sys/devices/system/cpu/online -> /proc/stat -> 2 get_nprocs_conf: /sys/devices/system/cpu/ -> /proc/stat -> 2 New fallback order: get_nprocs: /sys/devices/system/cpu/online -> /proc/stat -> sched_getaffinity -> 2 get_nprocs_conf: /sys/devices/system/cpu/ -> /proc/stat -> sched_getaffinity -> 2 Fixes: 342298278e ("linux: Revert the use of sched_getaffinity on get_nproc") Closes: BZ #28865 Reviewed-by: Adhemerval Zanella (cherry picked from commit e1d32b836410767270a3adf1f82b1a47e6e4cd51) diff --git a/NEWS b/NEWS index 6b8db4e947..04df0f4e8a 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,8 @@ The following bugs are resolved with this release: (breaks test isolation) [28860] build: --enable-kernel=5.1.0 build fails because of missing __convert_scm_timestamps + [28865] linux: _SC_NPROCESSORS_CONF and _SC_NPROCESSORS_ONLN are inaccurate + without /sys and /proc Version 2.35 diff --git a/sysdeps/unix/sysv/linux/getsysstats.c b/sysdeps/unix/sysv/linux/getsysstats.c index c98c8ce3d4..d1ea074f0d 100644 --- a/sysdeps/unix/sysv/linux/getsysstats.c +++ b/sysdeps/unix/sysv/linux/getsysstats.c @@ -50,9 +50,8 @@ __get_nprocs_sched (void) is an arbitrary values assuming such systems should be rare and there is no offline cpus. */ return max_num_cpus; - /* Some other error. 2 is conservative (not a uniprocessor system, so - atomics are needed). */ - return 2; + /* Some other error. */ + return 0; } static char * @@ -108,22 +107,19 @@ next_line (int fd, char *const buffer, char **cp, char **re, } static int -get_nproc_stat (char *buffer, size_t buffer_size) +get_nproc_stat (void) { + enum { buffer_size = 1024 }; + char buffer[buffer_size]; char *buffer_end = buffer + buffer_size; char *cp = buffer_end; char *re = buffer_end; - - /* Default to an SMP system in case we cannot obtain an accurate - number. */ - int result = 2; + int result = 0; const int flags = O_RDONLY | O_CLOEXEC; int fd = __open_nocancel ("/proc/stat", flags); if (fd != -1) { - result = 0; - char *l; while ((l = next_line (fd, buffer, &cp, &re, buffer_end)) != NULL) /* The current format of /proc/stat has all the cpu* entries @@ -139,8 +135,8 @@ get_nproc_stat (char *buffer, size_t buffer_size) return result; } -int -__get_nprocs (void) +static int +get_nprocs_cpu_online (void) { enum { buffer_size = 1024 }; char buffer[buffer_size]; @@ -179,7 +175,8 @@ __get_nprocs (void) } } - result += m - n + 1; + if (m >= n) + result += m - n + 1; l = endp; if (l < re && *l == ',') @@ -188,28 +185,18 @@ __get_nprocs (void) while (l < re && *l != '\n'); __close_nocancel_nostatus (fd); - - if (result > 0) - return result; } - return get_nproc_stat (buffer, buffer_size); + return result; } -libc_hidden_def (__get_nprocs) -weak_alias (__get_nprocs, get_nprocs) - -/* On some architectures it is possible to distinguish between configured - and active cpus. */ -int -__get_nprocs_conf (void) +static int +get_nprocs_cpu (void) { - /* Try to use the sysfs filesystem. It has actual information about - online processors. */ + int count = 0; DIR *dir = __opendir ("/sys/devices/system/cpu"); if (dir != NULL) { - int count = 0; struct dirent64 *d; while ((d = __readdir64 (dir)) != NULL) @@ -224,12 +211,57 @@ __get_nprocs_conf (void) __closedir (dir); - return count; } + return count; +} - enum { buffer_size = 1024 }; - char buffer[buffer_size]; - return get_nproc_stat (buffer, buffer_size); +static int +get_nprocs_fallback (void) +{ + int result; + + /* Try /proc/stat first. */ + result = get_nproc_stat (); + if (result != 0) + return result; + + /* Try sched_getaffinity. */ + result = __get_nprocs_sched (); + if (result != 0) + return result; + + /* We failed to obtain an accurate number. Be conservative: return + the smallest number meaning that this is not a uniprocessor system, + so atomics are needed. */ + return 2; +} + +int +__get_nprocs (void) +{ + /* Try /sys/devices/system/cpu/online first. */ + int result = get_nprocs_cpu_online (); + if (result != 0) + return result; + + /* Fall back to /proc/stat and sched_getaffinity. */ + return get_nprocs_fallback (); +} +libc_hidden_def (__get_nprocs) +weak_alias (__get_nprocs, get_nprocs) + +/* On some architectures it is possible to distinguish between configured + and active cpus. */ +int +__get_nprocs_conf (void) +{ + /* Try /sys/devices/system/cpu/ first. */ + int result = get_nprocs_cpu (); + if (result != 0) + return result; + + /* Fall back to /proc/stat and sched_getaffinity. */ + return get_nprocs_fallback (); } libc_hidden_def (__get_nprocs_conf) weak_alias (__get_nprocs_conf, get_nprocs_conf) commit f055faf801cbffd9a0311774589de1cc745ccbe4 Author: Adhemerval Zanella Date: Mon Feb 14 10:35:30 2022 -0300 linux: Use socket-constants-time64.h on tst-socket-timestamp-compat The kernel header might not define the SO_TIMESTAMP{NS}_OLD or SO_TIMESTAMP{NS}_NEW if it older than v5.1. Reviewed-by: Carlos O'Donell Reviewed-by: Tulio Magno Quites Machado Filho (cherry picked from commit fee62d6c6285548027e222c8dae597fec6577f23) diff --git a/sysdeps/unix/sysv/linux/tst-socket-timestamp-compat.c b/sysdeps/unix/sysv/linux/tst-socket-timestamp-compat.c index 0ff1a214e6..2b1feb4766 100644 --- a/sysdeps/unix/sysv/linux/tst-socket-timestamp-compat.c +++ b/sysdeps/unix/sysv/linux/tst-socket-timestamp-compat.c @@ -22,6 +22,7 @@ #include #include #include +#include /* AF_INET socket and address used to receive data. */ static int srv; @@ -88,7 +89,7 @@ do_test_large_buffer (bool mc) /* Enable 32 bit timeval precision and check if no 64 bit timeval stamp is created. */ { - int r = setsockopt (srv, SOL_SOCKET, SO_TIMESTAMP_OLD, &(int){1}, + int r = setsockopt (srv, SOL_SOCKET, COMPAT_SO_TIMESTAMP_OLD, &(int){1}, sizeof (int)); TEST_VERIFY_EXIT (r != -1); @@ -103,10 +104,10 @@ do_test_large_buffer (bool mc) if (cmsg->cmsg_level != SOL_SOCKET) continue; - if (sizeof (time_t) > 4 && cmsg->cmsg_type == SO_TIMESTAMP_NEW) + if (sizeof (time_t) > 4 && cmsg->cmsg_type == COMPAT_SO_TIMESTAMP_NEW) found_timestamp = true; else - TEST_VERIFY (cmsg->cmsg_type != SO_TIMESTAMP_NEW); + TEST_VERIFY (cmsg->cmsg_type != COMPAT_SO_TIMESTAMP_NEW); } TEST_COMPARE (found_timestamp, sizeof (time_t) > 4); @@ -114,7 +115,7 @@ do_test_large_buffer (bool mc) /* Same as before, but for timespec. */ { - int r = setsockopt (srv, SOL_SOCKET, SO_TIMESTAMPNS_OLD, &(int){1}, + int r = setsockopt (srv, SOL_SOCKET, COMPAT_SO_TIMESTAMPNS_OLD, &(int){1}, sizeof (int)); TEST_VERIFY_EXIT (r != -1); @@ -129,10 +130,10 @@ do_test_large_buffer (bool mc) if (cmsg->cmsg_level != SOL_SOCKET) continue; - if (sizeof (time_t) > 4 && cmsg->cmsg_type == SO_TIMESTAMPNS_NEW) + if (sizeof (time_t) > 4 && cmsg->cmsg_type == COMPAT_SO_TIMESTAMPNS_NEW) found_timestamp = true; else - TEST_VERIFY (cmsg->cmsg_type != SO_TIMESTAMPNS_NEW); + TEST_VERIFY (cmsg->cmsg_type != COMPAT_SO_TIMESTAMPNS_NEW); } TEST_COMPARE (found_timestamp, sizeof (time_t) > 4); @@ -151,7 +152,7 @@ do_test_small_buffer (bool mc) /* Enable 32 bit timeval precision and check if no 64 bit timeval stamp is created. */ { - int r = setsockopt (srv, SOL_SOCKET, SO_TIMESTAMP_OLD, &(int){1}, + int r = setsockopt (srv, SOL_SOCKET, COMPAT_SO_TIMESTAMP_OLD, &(int){1}, sizeof (int)); TEST_VERIFY_EXIT (r != -1); @@ -172,10 +173,10 @@ do_test_small_buffer (bool mc) if (cmsg->cmsg_level != SOL_SOCKET) continue; - if (sizeof (time_t) > 4 && cmsg->cmsg_type == SO_TIMESTAMP_NEW) + if (sizeof (time_t) > 4 && cmsg->cmsg_type == COMPAT_SO_TIMESTAMP_NEW) found_timestamp = true; else - TEST_VERIFY (cmsg->cmsg_type != SO_TIMESTAMP_NEW); + TEST_VERIFY (cmsg->cmsg_type != COMPAT_SO_TIMESTAMP_NEW); } if (sizeof (time_t) > 4) @@ -192,7 +193,7 @@ do_test_small_buffer (bool mc) /* Same as before, but for timespec. */ { - int r = setsockopt (srv, SOL_SOCKET, SO_TIMESTAMPNS_OLD, &(int){1}, + int r = setsockopt (srv, SOL_SOCKET, COMPAT_SO_TIMESTAMPNS_OLD, &(int){1}, sizeof (int)); TEST_VERIFY_EXIT (r != -1); @@ -213,10 +214,10 @@ do_test_small_buffer (bool mc) if (cmsg->cmsg_level != SOL_SOCKET) continue; - if (sizeof (time_t) > 4 && cmsg->cmsg_type == SO_TIMESTAMPNS_NEW) + if (sizeof (time_t) > 4 && cmsg->cmsg_type == COMPAT_SO_TIMESTAMPNS_NEW) found_timestamp = true; else - TEST_VERIFY (cmsg->cmsg_type != SO_TIMESTAMPNS_NEW); + TEST_VERIFY (cmsg->cmsg_type != COMPAT_SO_TIMESTAMPNS_NEW); } if (sizeof (time_t) > 4) commit a30807b7db924d31681e9c6e98e78f2f46a2640c Author: H.J. Lu Date: Thu Feb 17 08:10:35 2022 -0800 string: Add a testcase for wcsncmp with SIZE_MAX [BZ #28755] Verify that wcsncmp (L("abc"), L("abd"), SIZE_MAX) == 0. The new test fails without commit ddf0992cf57a93200e0c782e2a94d0733a5a0b87 Author: Noah Goldstein Date: Sun Jan 9 16:02:21 2022 -0600 x86: Fix __wcsncmp_avx2 in strcmp-avx2.S [BZ# 28755] and commit 7e08db3359c86c94918feb33a1182cd0ff3bb10b Author: Noah Goldstein Date: Sun Jan 9 16:02:28 2022 -0600 x86: Fix __wcsncmp_evex in strcmp-evex.S [BZ# 28755] This is for BZ #28755. Reviewed-by: Sunil K Pandey (cherry picked from commit aa5a720056d37cf24924c138a3dbe6dace98e97c) diff --git a/string/test-strncmp.c b/string/test-strncmp.c index e7d5edea39..22b7dfa73b 100644 --- a/string/test-strncmp.c +++ b/string/test-strncmp.c @@ -434,6 +434,18 @@ check3 (void) } } +static void +check4 (void) +{ + const CHAR *s1 = L ("abc"); + CHAR *s2 = STRDUP (s1); + + FOR_EACH_IMPL (impl, 0) + check_result (impl, s1, s2, SIZE_MAX, 0); + + free (s2); +} + int test_main (void) { @@ -444,6 +456,7 @@ test_main (void) check1 (); check2 (); check3 (); + check4 (); printf ("%23s", ""); FOR_EACH_IMPL (impl, 0) commit fd412fff6d2bd322ec24ebd13fab196efc6c5506 Author: Noah Goldstein Date: Tue Feb 15 08:18:15 2022 -0600 x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896] In the overflow fallback strncmp-avx2-rtm and wcsncmp-avx2-rtm would call strcmp-avx2 and wcscmp-avx2 respectively. This would have not checks around vzeroupper and would trigger spurious aborts. This commit fixes that. test-strcmp, test-strncmp, test-wcscmp, and test-wcsncmp all pass on AVX2 machines with and without RTM. Co-authored-by: H.J. Lu (cherry picked from commit c6272098323153db373f2986c67786ea8c85f1cf) diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile index 6cf708335c..d110f7b7f2 100644 --- a/sysdeps/x86/Makefile +++ b/sysdeps/x86/Makefile @@ -109,7 +109,7 @@ CFLAGS-tst-memset-rtm.c += -mrtm CFLAGS-tst-strchr-rtm.c += -mrtm CFLAGS-tst-strcpy-rtm.c += -mrtm CFLAGS-tst-strlen-rtm.c += -mrtm -CFLAGS-tst-strncmp-rtm.c += -mrtm +CFLAGS-tst-strncmp-rtm.c += -mrtm -Wno-error CFLAGS-tst-strrchr-rtm.c += -mrtm endif diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c index 09ed6fa0d6..9e20abaacc 100644 --- a/sysdeps/x86/tst-strncmp-rtm.c +++ b/sysdeps/x86/tst-strncmp-rtm.c @@ -16,6 +16,7 @@ License along with the GNU C Library; if not, see . */ +#include #include #define LOOP 3000 @@ -45,8 +46,22 @@ function (void) return 1; } +__attribute__ ((noinline, noclone)) +static int +function_overflow (void) +{ + if (strncmp (string1, string2, SIZE_MAX) == 0) + return 0; + else + return 1; +} + static int do_test (void) { - return do_test_1 ("strncmp", LOOP, prepare, function); + int status = do_test_1 ("strncmp", LOOP, prepare, function); + if (status != EXIT_SUCCESS) + return status; + status = do_test_1 ("strncmp", LOOP, prepare, function_overflow); + return status; } diff --git a/sysdeps/x86_64/multiarch/strcmp-avx2.S b/sysdeps/x86_64/multiarch/strcmp-avx2.S index 9c73b5899d..cdcb3c5a26 100644 --- a/sysdeps/x86_64/multiarch/strcmp-avx2.S +++ b/sysdeps/x86_64/multiarch/strcmp-avx2.S @@ -95,7 +95,7 @@ ENTRY (STRCMP) length to bound a valid memory region. In these cases just use 'wcscmp'. */ shrq $56, %rcx - jnz __wcscmp_avx2 + jnz OVERFLOW_STRCMP # endif /* Convert units: from wide to byte char. */ shl $2, %RDX_LP diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S index 37d1224bb9..68bad365ba 100644 --- a/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S +++ b/sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S @@ -1,3 +1,4 @@ #define STRCMP __strncmp_avx2_rtm #define USE_AS_STRNCMP 1 +#define OVERFLOW_STRCMP __strcmp_avx2_rtm #include "strcmp-avx2-rtm.S" diff --git a/sysdeps/x86_64/multiarch/strncmp-avx2.S b/sysdeps/x86_64/multiarch/strncmp-avx2.S index 1678bcc235..f138e9f1fd 100644 --- a/sysdeps/x86_64/multiarch/strncmp-avx2.S +++ b/sysdeps/x86_64/multiarch/strncmp-avx2.S @@ -1,3 +1,4 @@ #define STRCMP __strncmp_avx2 #define USE_AS_STRNCMP 1 +#define OVERFLOW_STRCMP __strcmp_avx2 #include "strcmp-avx2.S" diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S index 4e88c70cc6..f467582cbe 100644 --- a/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S +++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S @@ -1,5 +1,5 @@ #define STRCMP __wcsncmp_avx2_rtm #define USE_AS_STRNCMP 1 #define USE_AS_WCSCMP 1 - +#define OVERFLOW_STRCMP __wcscmp_avx2_rtm #include "strcmp-avx2-rtm.S" diff --git a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S index 4fa1de4d3f..e9ede522b8 100644 --- a/sysdeps/x86_64/multiarch/wcsncmp-avx2.S +++ b/sysdeps/x86_64/multiarch/wcsncmp-avx2.S @@ -1,5 +1,5 @@ #define STRCMP __wcsncmp_avx2 #define USE_AS_STRNCMP 1 #define USE_AS_WCSCMP 1 - +#define OVERFLOW_STRCMP __wcscmp_avx2 #include "strcmp-avx2.S" commit d001088e221ab3f89d78ce3e914e97206a27c94b Author: Noah Goldstein Date: Fri Feb 18 14:19:15 2022 -0600 x86: Test wcscmp RTM in the wcsncmp overflow case [BZ #28896] In the overflow fallback strncmp-avx2-rtm and wcsncmp-avx2-rtm would call strcmp-avx2 and wcscmp-avx2 respectively. This would have not checks around vzeroupper and would trigger spurious aborts. This commit fixes that. test-strcmp, test-strncmp, test-wcscmp, and test-wcsncmp all pass on AVX2 machines with and without RTM. Reviewed-by: H.J. Lu (cherry picked from commit 7835d611af0854e69a0c71e3806f8fe379282d6f) diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile index d110f7b7f2..c6bee981f8 100644 --- a/sysdeps/x86/Makefile +++ b/sysdeps/x86/Makefile @@ -99,7 +99,9 @@ tests += \ tst-strcpy-rtm \ tst-strlen-rtm \ tst-strncmp-rtm \ - tst-strrchr-rtm + tst-strrchr-rtm \ + tst-wcsncmp-rtm \ +# tests CFLAGS-tst-memchr-rtm.c += -mrtm CFLAGS-tst-memcmp-rtm.c += -mrtm @@ -111,6 +113,7 @@ CFLAGS-tst-strcpy-rtm.c += -mrtm CFLAGS-tst-strlen-rtm.c += -mrtm CFLAGS-tst-strncmp-rtm.c += -mrtm -Wno-error CFLAGS-tst-strrchr-rtm.c += -mrtm +CFLAGS-tst-wcsncmp-rtm.c += -mrtm -Wno-error endif ifneq ($(enable-cet),no) diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c index 9e20abaacc..b50c11e8d4 100644 --- a/sysdeps/x86/tst-strncmp-rtm.c +++ b/sysdeps/x86/tst-strncmp-rtm.c @@ -19,18 +19,32 @@ #include #include +#ifdef WIDE +# define CHAR wchar_t +# define MEMSET wmemset +# define STRNCMP wcsncmp +# define TEST_NAME wcsncmp +#else /* !WIDE */ +# define CHAR char +# define MEMSET memset +# define STRNCMP strncmp +# define TEST_NAME strncmp +#endif /* !WIDE */ + + + #define LOOP 3000 #define STRING_SIZE 1024 -char string1[STRING_SIZE]; -char string2[STRING_SIZE]; +CHAR string1[STRING_SIZE]; +CHAR string2[STRING_SIZE]; __attribute__ ((noinline, noclone)) static int prepare (void) { - memset (string1, 'a', STRING_SIZE - 1); - memset (string2, 'a', STRING_SIZE - 1); - if (strncmp (string1, string2, STRING_SIZE) == 0) + MEMSET (string1, 'a', STRING_SIZE - 1); + MEMSET (string2, 'a', STRING_SIZE - 1); + if (STRNCMP (string1, string2, STRING_SIZE) == 0) return EXIT_SUCCESS; else return EXIT_FAILURE; @@ -40,7 +54,7 @@ __attribute__ ((noinline, noclone)) static int function (void) { - if (strncmp (string1, string2, STRING_SIZE) == 0) + if (STRNCMP (string1, string2, STRING_SIZE) == 0) return 0; else return 1; @@ -50,7 +64,7 @@ __attribute__ ((noinline, noclone)) static int function_overflow (void) { - if (strncmp (string1, string2, SIZE_MAX) == 0) + if (STRNCMP (string1, string2, SIZE_MAX) == 0) return 0; else return 1; @@ -59,9 +73,9 @@ function_overflow (void) static int do_test (void) { - int status = do_test_1 ("strncmp", LOOP, prepare, function); + int status = do_test_1 (TEST_NAME, LOOP, prepare, function); if (status != EXIT_SUCCESS) return status; - status = do_test_1 ("strncmp", LOOP, prepare, function_overflow); + status = do_test_1 (TEST_NAME, LOOP, prepare, function_overflow); return status; } diff --git a/sysdeps/x86/tst-wcsncmp-rtm.c b/sysdeps/x86/tst-wcsncmp-rtm.c new file mode 100644 index 0000000000..bad3b86378 --- /dev/null +++ b/sysdeps/x86/tst-wcsncmp-rtm.c @@ -0,0 +1,21 @@ +/* Test case for wcsncmp inside a transactionally executing RTM region. + Copyright (C) 2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#define WIDE 1 +#include +#include "tst-strncmp-rtm.c" commit 676f85759c5cd1eeb081e8b1c1c05a4f0fa3b92b Author: Noah Goldstein Date: Fri Feb 18 17:00:25 2022 -0600 x86: Fix TEST_NAME to make it a string in tst-strncmp-rtm.c Previously TEST_NAME was passing a function pointer. This didn't fail because of the -Wno-error flag (to allow for overflow sizes passed to strncmp/wcsncmp) Reviewed-by: H.J. Lu (cherry picked from commit b98d0bbf747f39770e0caba7e984ce9f8f900330) diff --git a/sysdeps/x86/tst-strncmp-rtm.c b/sysdeps/x86/tst-strncmp-rtm.c index b50c11e8d4..300bc8c281 100644 --- a/sysdeps/x86/tst-strncmp-rtm.c +++ b/sysdeps/x86/tst-strncmp-rtm.c @@ -23,12 +23,12 @@ # define CHAR wchar_t # define MEMSET wmemset # define STRNCMP wcsncmp -# define TEST_NAME wcsncmp +# define TEST_NAME "wcsncmp" #else /* !WIDE */ # define CHAR char # define MEMSET memset # define STRNCMP strncmp -# define TEST_NAME strncmp +# define TEST_NAME "strncmp" #endif /* !WIDE */ commit 3226ffde07ae2bef3c2f57ad018829320f2922ee Author: H.J. Lu Date: Fri Feb 18 19:07:11 2022 -0800 NEWS: Add a bug fix entry for BZ #28896 diff --git a/NEWS b/NEWS index 04df0f4e8a..008941555d 100644 --- a/NEWS +++ b/NEWS @@ -16,6 +16,8 @@ The following bugs are resolved with this release: __convert_scm_timestamps [28865] linux: _SC_NPROCESSORS_CONF and _SC_NPROCESSORS_ONLN are inaccurate without /sys and /proc + [28896] strncmp-avx2-rtm and wcsncmp-avx2-rtm fallback on non-rtm + variants when avoiding overflow Version 2.35