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 commit 1dd783fafdbc30bd82e078ccab42b9539d3274a5 Author: H.J. Lu Date: Tue Feb 15 06:57:11 2022 -0800 elf: Check invalid hole in PT_LOAD segments [BZ #28838] Changes in v2: 1. Update commit log. commit 163f625cf9becbb82dfec63a29e566324129c0cd Author: H.J. Lu Date: Tue Dec 21 12:35:47 2021 -0800 elf: Remove excessive p_align check on PT_LOAD segments [BZ #28688] removed the p_align check against the page size. It caused the loader error or crash on elf/tst-p_align3 when loading elf/tst-p_alignmod3.so, which has the invalid p_align in PT_LOAD segments, added by commit d8d94863ef125a392b929732b37e07dc927fbcd1 Author: H.J. Lu Date: Tue Dec 21 13:42:28 2021 -0800 The loader failure caused by a negative length passed to __mprotect is random, depending on architecture and toolchain. Update _dl_map_segments to detect invalid holes. This fixes BZ #28838. Reviewed-by: Florian Weimer (cherry picked from commit 2c0915cbf570cb9c8a65f1d20a55c5a7238e5b63) diff --git a/elf/dl-map-segments.h b/elf/dl-map-segments.h index 172692b120..fd24cf5d01 100644 --- a/elf/dl-map-segments.h +++ b/elf/dl-map-segments.h @@ -113,6 +113,9 @@ _dl_map_segments (struct link_map *l, int fd, unallocated. Then jump into the normal segment-mapping loop to handle the portion of the segment past the end of the file mapping. */ + if (__glibc_unlikely (loadcmds[nloadcmds - 1].mapstart < + c->mapend)) + return N_("ELF load command address/offset not page-aligned"); if (__glibc_unlikely (__mprotect ((caddr_t) (l->l_addr + c->mapend), loadcmds[nloadcmds - 1].mapstart - c->mapend, commit e247a3b1188f6c4b623bbfbe19bb415153c66637 Author: H.J. Lu Date: Sun Feb 6 11:12:24 2022 -0800 elf: Replace tst-audit24bmod2.so with tst-audit24bmod2 Replace tst-audit24bmod2.so with tst-audit24bmod2 to silence: make[2]: Entering directory '/export/gnu/import/git/gitlab/x86-glibc/elf' Makefile:2201: warning: overriding recipe for target '/export/build/gnu/tools-build/glibc-gitlab/build-x86_64-linux/elf/tst-audit24bmod2.so' ../Makerules:765: warning: ignoring old recipe for target '/export/build/gnu/tools-build/glibc-gitlab/build-x86_64-linux/elf/tst-audit24bmod2.so' (cherry picked from commit fa7ad1df1915c8a62f50e3a5b7e10f9c7118cd7f) diff --git a/elf/Makefile b/elf/Makefile index 5bdf0a383d..ac37159b89 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -943,7 +943,7 @@ extra-test-objs += $(addsuffix .os,$(strip $(modules-names))) # filtmod1.so, tst-big-note-lib.so, tst-ro-dynamic-mod.so have special # rules. modules-names-nobuild := filtmod1 tst-big-note-lib tst-ro-dynamic-mod \ - tst-audit24bmod1 tst-audit24bmod2.so + tst-audit24bmod1 tst-audit24bmod2 tests += $(tests-static) commit 264ad5d7d66c0f18587860d62498b8f2a9001400 Author: Stafford Horne Date: Sat Feb 12 08:17:55 2022 +0900 resolv: Fix tst-resolv tests for 2.35 ABIs and later The commit 737e873b30 ("resolv: Do not build libanl.so for ABIs starting at 2.35") disabled building libanl for ports supporting only 2.35 and later like OpenRISC. However, the if statement was not updated quite correctly and the change ends up disabling many tst-resolv* tests. This was not supposed to be done and it causes test dependency errors like: make: Entering directory 'gnu-home/glibc/resolv' make: *** No rule to make target 'gnu-home/build-glibc/resolv/tst-resolv-res_ninit.out', needed by 'gnu-home/build-glibc/resolv/mtrace-tst-resolv-res_ninit.out'. Stop. make: Leaving directory 'gnu-home/glibc/resolv' This patch move the extra-libs += libanl definition and condition down to be closer to other libanl definitions. The $(have-GLIBC_2.34) condition now includes libanl-routines and libanl-shared-only-routines as well. Also, I have added a comment to endif of $(have-thread-library) to help show the bondary of the have-thread-library definitions. Reviewed-by: Adhemerval Zanella (cherry picked from commit ee5d27bea53626c0187f77feec2c883f2c6ac4b3) diff --git a/resolv/Makefile b/resolv/Makefile index c465479e8b..438672786f 100644 --- a/resolv/Makefile +++ b/resolv/Makefile @@ -79,11 +79,6 @@ generate := mtrace-tst-leaks.out tst-leaks.mtrace tst-leaks2.mtrace extra-libs := libresolv libnss_dns ifeq ($(have-thread-library),yes) routines += gai_sigqueue -endif - -ifeq ($(have-GLIBC_2.34)$(have-thread-library),yesyes) -# Empty compatibility library for old binaries. -extra-libs += libanl tests += \ tst-bug18665 \ @@ -144,7 +139,8 @@ xtests += tst-resolv-qtypes # This test has dropped packet tests and runs for a long time. xtests += tst-resolv-rotate -endif +endif # $(have-thread-library) + extra-libs-others = $(extra-libs) libresolv-routines := \ base64 \ @@ -168,6 +164,13 @@ libresolv-routines := \ resolv-deprecated \ # libresolv-routines +ifeq ($(have-GLIBC_2.34)$(have-thread-library),yesyes) +# Empty compatibility library for old binaries. +extra-libs += libanl +libanl-routines += libanl-compat +libanl-shared-only-routines += libanl-compat +endif + $(libanl-routines-var) += \ gai_cancel \ gai_error \ @@ -177,9 +180,6 @@ $(libanl-routines-var) += \ getaddrinfo_a \ # $(libanl-routines-var) -libanl-routines += libanl-compat -libanl-shared-only-routines += libanl-compat - # Pretend that libanl.so is a linker script, so that the symbolic link # is not installed. install-lib-ldscripts = libanl.so commit a787325e8316830f8d9a118aac5afee3c0e75617 Author: H.J. Lu Date: Thu Feb 24 07:58:36 2022 -0800 NEWS: Add a bug fix entry for BZ #28688 diff --git a/NEWS b/NEWS index 008941555d..094a979afb 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,7 @@ Version 2.35.1 The following bugs are resolved with this release: + [28838] FAIL: elf/tst-p_align3 [28850] linux: __get_nprocs_sched reads uninitialized memory from the stack [28853] libc: tst-spawn6 changes current foreground process group (breaks test isolation) commit 3feecd80013c822a12d4b01c5c25e155dfbc6e2f Author: Carlos O'Donell Date: Thu Feb 3 16:51:59 2022 -0500 localedef: Update LC_MONETARY handling (Bug 28845) ISO C17, POSIX Issue 7, and ISO 30112 all allow the char* types to be empty strings i.e. "", integer or char values to be -1 or CHAR_MAX respectively, with the exception of decimal_point which must be non-empty in ISO C. Note that the defaults for mon_grouping vary, but are functionaly equivalent e.g. "\177" (no further grouping reuqired) vs. "" (no grouping defined for all groups). We include a broad comment talking about harmonizing ISO C, POSIX, ISO 30112, and the default C/POSIX locale for glibc. We reorder all setting based on locale/categories.def order. We soften all missing definitions from errors to warnings when defaults exist. Given that ISO C, POSIX and ISO 30112 allow the empty string we change LC_MONETARY handling of mon_decimal_point to allow the empty string. If mon_decimal_point is not defined at all then we pick the existing legacy glibc default value of i.e. ".". We also set the default for mon_thousands_sep_wc at the same time as mon_thousands_sep, but this is not a change in behaviour, it is always either a matching value or L'\0', but if in the future we change the default to a non-empty string we would need to update both at the same time. Tested on x86_64 and i686 without regressions. Tested with install-locale-archive target. Tested with install-locale-files target. Reviewed-by: DJ Delorie (cherry picked from commit 2ab8b74567dc0a9a3c98696e6444881997dd6c49) diff --git a/locale/programs/ld-monetary.c b/locale/programs/ld-monetary.c index 3b0412b405..18698bbe94 100644 --- a/locale/programs/ld-monetary.c +++ b/locale/programs/ld-monetary.c @@ -196,21 +196,105 @@ No definition for %s category found"), "LC_MONETARY"); } } + /* Generally speaking there are 3 standards the define the default, + warning, and error behaviour of LC_MONETARY. They are ISO/IEC TR 30112, + ISO/IEC 9899:2018 (ISO C17), and POSIX.1-2017. Within 30112 we have the + definition of a standard i18n FDCC-set, which for LC_MONETARY has the + following default values: + int_curr_symbol "" + currency_symbol "" + mon_decimal_point "" i.e. "," + mon_thousand_sep "" + mon_grouping "\177" i.e. CHAR_MAX + positive_sign "" + negative_sign "" i.e. "." + int_frac_digits -1 + frac_digits -1 + p_cs_precedes -1 + p_sep_by_space -1 + n_cs_precedes -1 + n_sep_by_space -1 + p_sign_posn -1 + n_sign_posn -1 + Under 30112 a keyword that is not provided implies an empty string "" + for string values or a -1 for integer values, and indicates the value + is unspecified with no default implied. No errors are considered. + The exception is mon_grouping which is a string with a terminating + CHAR_MAX. + For POSIX Issue 7 we have: + https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap07.html + and again values not provided default to "" or -1, and indicate the value + is not available to the locale. The exception is mon_grouping which is + a string with a terminating CHAR_MAX. For the POSIX locale the values of + LC_MONETARY should be: + int_curr_symbol "" + currency_symbol "" + mon_decimal_point "" + mon_thousands_sep "" + mon_grouping "\177" i.e. CHAR_MAX + positive_sign "" + negative_sign "" + int_frac_digits -1 + frac_digits -1 + p_cs_precedes -1 + p_sep_by_space -1 + n_cs_precedes -1 + n_sep_by_space -1 + p_sign_posn -1 + n_sign_posn -1 + int_p_cs_precedes -1 + int_p_sep_by_space -1 + int_n_cs_precedes -1 + int_n_sep_by_space -1 + int_p_sign_posn -1 + int_n_sign_posn -1 + Like with 30112, POSIX also considers no error if the keywords are + missing, only that if the cateory as a whole is missing the referencing + of the category results in unspecified behaviour. + For ISO C17 there is no default value provided, but the localeconv + specification in 7.11.2.1 admits that members of char * type may point + to "" to indicate a value is not available or is of length zero. + The exception is decimal_point (not mon_decimal_point) which must be a + defined non-empty string. The values of char, which are generally + mapped to integer values in 30112 and POSIX, must be non-negative + numbers that map to CHAR_MAX when a value is not available in the + locale. + In ISO C17 for the "C" locale all values are empty strings "", or + CHAR_MAX, with the exception of decimal_point which is "." (defined + in LC_NUMERIC). ISO C17 makes no exception for mon_grouping like + 30112 and POSIX, but a value of "" is functionally equivalent to + "\177" since neither defines a grouping (though the latter terminates + the grouping). + + Lastly, we must consider the legacy C/POSIX locale that implemented + as a builtin in glibc and wether a default value mapping to the + C/POSIX locale may benefit the user from a compatibility perspective. + + Thus given 30112, POSIX, ISO C, and the builtin C/POSIX locale we + need to pick appropriate defaults below. */ + + /* The members of LC_MONETARY are handled in the order of their definition + in locale/categories.def. Please keep them in that order. */ + + /* The purpose of TEST_ELEM is to define a default value for the fields + in the category if the field was not defined in the cateory. If the + category was present but we didn't see a definition for the field then + we also issue a warning, otherwise the only warning you get is the one + earlier when a default category is created (completely missing category). + This missing field warning is glibc-specific since no standard requires + this warning, but we consider it valuable to print a warning for all + missing fields in the category. */ #define TEST_ELEM(cat, initval) \ if (monetary->cat == NULL) \ { \ if (! nothing) \ - record_error (0, 0, _("%s: field `%s' not defined"), \ - "LC_MONETARY", #cat); \ + record_warning (_("%s: field `%s' not defined"), \ + "LC_MONETARY", #cat); \ monetary->cat = initval; \ } + /* Keyword: int_curr_symbol. */ TEST_ELEM (int_curr_symbol, ""); - TEST_ELEM (currency_symbol, ""); - TEST_ELEM (mon_thousands_sep, ""); - TEST_ELEM (positive_sign, ""); - TEST_ELEM (negative_sign, ""); - /* The international currency symbol must come from ISO 4217. */ if (monetary->int_curr_symbol != NULL) { @@ -247,41 +331,63 @@ not correspond to a valid name in ISO 4217 [--no-warnings=intcurrsym]"), } } - /* The decimal point must not be empty. This is not said explicitly - in POSIX but ANSI C (ISO/IEC 9899) says in 4.4.2.1 it has to be - != "". */ + /* Keyword: currency_symbol */ + TEST_ELEM (currency_symbol, ""); + + /* Keyword: mon_decimal_point */ + /* ISO C17 7.11.2.1.3 explicitly allows mon_decimal_point to be the + empty string e.g. "". This indicates the value is not available in the + current locale or is of zero length. However, if the value was never + defined then we issue a warning and use a glibc-specific default. ISO + 30112 in the i18n FDCC-Set uses ",", and POSIX Issue 7 in the + POSIX locale uses "". It is specific to glibc that the default is + "."; we retain this existing behaviour for backwards compatibility. */ if (monetary->mon_decimal_point == NULL) { if (! nothing) - record_error (0, 0, _("%s: field `%s' not defined"), - "LC_MONETARY", "mon_decimal_point"); + record_warning (_("%s: field `%s' not defined, using defaults"), + "LC_MONETARY", "mon_decimal_point"); monetary->mon_decimal_point = "."; monetary->mon_decimal_point_wc = L'.'; } - else if (monetary->mon_decimal_point[0] == '\0' && ! be_quiet && ! nothing) + + /* Keyword: mon_thousands_sep */ + if (monetary->mon_thousands_sep == NULL) { - record_error (0, 0, _("\ -%s: value for field `%s' must not be an empty string"), - "LC_MONETARY", "mon_decimal_point"); + if (! nothing) + record_warning (_("%s: field `%s' not defined, using defaults"), + "LC_MONETARY", "mon_thousands_sep"); + monetary->mon_thousands_sep = ""; + monetary->mon_thousands_sep_wc = L'\0'; } + /* Keyword: mon_grouping */ if (monetary->mon_grouping_len == 0) { if (! nothing) - record_error (0, 0, _("%s: field `%s' not defined"), - "LC_MONETARY", "mon_grouping"); - + record_warning (_("%s: field `%s' not defined"), + "LC_MONETARY", "mon_grouping"); + /* Missing entries are given 1 element in their bytearray with + a value of CHAR_MAX which indicates that "No further grouping + is to be performed" (functionally equivalent to ISO C's "C" + locale default of ""). */ monetary->mon_grouping = (char *) "\177"; monetary->mon_grouping_len = 1; } + /* Keyword: positive_sign */ + TEST_ELEM (positive_sign, ""); + + /* Keyword: negative_sign */ + TEST_ELEM (negative_sign, ""); + #undef TEST_ELEM #define TEST_ELEM(cat, min, max, initval) \ if (monetary->cat == -2) \ { \ if (! nothing) \ - record_error (0, 0, _("%s: field `%s' not defined"), \ - "LC_MONETARY", #cat); \ + record_warning (_("%s: field `%s' not defined"), \ + "LC_MONETARY", #cat); \ monetary->cat = initval; \ } \ else if ((monetary->cat < min || monetary->cat > max) \ @@ -300,16 +406,11 @@ not correspond to a valid name in ISO 4217 [--no-warnings=intcurrsym]"), TEST_ELEM (p_sign_posn, -1, 4, -1); TEST_ELEM (n_sign_posn, -1, 4, -1); - /* The non-POSIX.2 extensions are optional. */ - if (monetary->duo_int_curr_symbol == NULL) - monetary->duo_int_curr_symbol = monetary->int_curr_symbol; - if (monetary->duo_currency_symbol == NULL) - monetary->duo_currency_symbol = monetary->currency_symbol; - - if (monetary->duo_int_frac_digits == -2) - monetary->duo_int_frac_digits = monetary->int_frac_digits; - if (monetary->duo_frac_digits == -2) - monetary->duo_frac_digits = monetary->frac_digits; + /* Keyword: crncystr */ + monetary->crncystr = (char *) xmalloc (strlen (monetary->currency_symbol) + + 2); + monetary->crncystr[0] = monetary->p_cs_precedes ? '-' : '+'; + strcpy (&monetary->crncystr[1], monetary->currency_symbol); #undef TEST_ELEM #define TEST_ELEM(cat, alt, min, max) \ @@ -327,6 +428,17 @@ not correspond to a valid name in ISO 4217 [--no-warnings=intcurrsym]"), TEST_ELEM (int_p_sign_posn, p_sign_posn, -1, 4); TEST_ELEM (int_n_sign_posn, n_sign_posn, -1, 4); + /* The non-POSIX.2 extensions are optional. */ + if (monetary->duo_int_curr_symbol == NULL) + monetary->duo_int_curr_symbol = monetary->int_curr_symbol; + if (monetary->duo_currency_symbol == NULL) + monetary->duo_currency_symbol = monetary->currency_symbol; + + if (monetary->duo_int_frac_digits == -2) + monetary->duo_int_frac_digits = monetary->int_frac_digits; + if (monetary->duo_frac_digits == -2) + monetary->duo_frac_digits = monetary->frac_digits; + TEST_ELEM (duo_p_cs_precedes, p_cs_precedes, -1, 1); TEST_ELEM (duo_p_sep_by_space, p_sep_by_space, -1, 2); TEST_ELEM (duo_n_cs_precedes, n_cs_precedes, -1, 1); @@ -349,17 +461,15 @@ not correspond to a valid name in ISO 4217 [--no-warnings=intcurrsym]"), if (monetary->duo_valid_to == 0) monetary->duo_valid_to = 99991231; + /* Keyword: conversion_rate */ if (monetary->conversion_rate[0] == 0) { monetary->conversion_rate[0] = 1; monetary->conversion_rate[1] = 1; } - /* Create the crncystr entry. */ - monetary->crncystr = (char *) xmalloc (strlen (monetary->currency_symbol) - + 2); - monetary->crncystr[0] = monetary->p_cs_precedes ? '-' : '+'; - strcpy (&monetary->crncystr[1], monetary->currency_symbol); + /* A value for monetary-decimal-point-wc was set when + monetary_decimal_point was set, likewise for monetary-thousands-sep-wc. */ } commit 732dd3a63d39c7ca77e817b462285c14551c8b49 Author: Carlos O'Donell Date: Thu Feb 3 16:01:52 2022 -0500 localedata: Do not generate output if warnings were present. With LC_MONETARY parsing fixed we can now generate locales without forcing output with '-c'. Removing '-c' from localedef invocation is the equivalent of using -Werror for localedef. The glibc locale sources should always be clean and free from warnings. We remove '-c' from both test locale generation and the targets used for installing locales e.g. install-locale-archive, and install-locale-files. Tested on x86_64 and i686 without regressions. Tested with install-locale-archive target. Tested with install-locale-files target. Reviewed-by: DJ Delorie (cherry picked from commit 1c7a34567d21fbd3b706c77cd794956b43daefe7) diff --git a/localedata/Makefile b/localedata/Makefile index 9ae2e5c161..7741ac3b5e 100644 --- a/localedata/Makefile +++ b/localedata/Makefile @@ -468,11 +468,11 @@ define build-one-locale endef $(INSTALL-SUPPORTED-LOCALE-ARCHIVE): install-locales-dir - @flags="-c"; \ + @flags=""; \ $(build-one-locale) $(INSTALL-SUPPORTED-LOCALE-FILES): install-locales-dir - @flags="-c --no-archive --no-hard-links"; \ + @flags="--no-archive --no-hard-links"; \ $(build-one-locale) tst-setlocale-ENV = LC_ALL=ja_JP.EUC-JP diff --git a/localedata/gen-locale.sh b/localedata/gen-locale.sh index 7fce35f212..8053c816a6 100644 --- a/localedata/gen-locale.sh +++ b/localedata/gen-locale.sh @@ -54,8 +54,14 @@ modifier=`echo $locfile|sed 's|[^.]*[.]\([^@ ]*\)\(@[^ ]*\)\?/LC_CTYPE|\2|'` echo "Generating locale $locale.$charmap: this might take a while..." -# Run quietly and force output. -flags="--quiet -c" +# Do not force output with '-c', all locales should compile without +# warning or errors. There is likewise no need to run quietly with +# '--quiet' since all locales should compile without additional +# diagnostics. If there are messages printed then we want to see +# them, fix them, and the associated error or warning. During +# development it may be beneficialy to put '--quiet -c' here to allow +# you to develop in-progress locales. +flags="" # For SJIS the charmap is SHIFT_JIS. We just want the locale to have # a slightly nicer name instead of using "*.SHIFT_SJIS", but that commit 90797f49722b69818780b1111c0ecc9dbbbf0bdf Author: Arjun Shankar Date: Thu Feb 24 21:43:09 2022 +0100 localedef: Handle symbolic links when generating locale-archive Whenever locale data for any locale included symbolic links, localedef would throw the error "incomplete set of locale files" and exclude it from the generated locale archive. This commit fixes that. Co-authored-by: Florian Weimer Reviewed-by: Carlos O'Donell (cherry picked from commit ea89d5bbd9e5e514b606045d909e6ab87d851c88) diff --git a/locale/programs/locarchive.c b/locale/programs/locarchive.c index 45408c26c1..eeb2fa6ffe 100644 --- a/locale/programs/locarchive.c +++ b/locale/programs/locarchive.c @@ -1397,7 +1397,7 @@ add_locales_to_archive (size_t nlist, char *list[], bool replace) { char fullname[fnamelen + 2 * strlen (d->d_name) + 7]; - if (d_type == DT_UNKNOWN) + if (d_type == DT_UNKNOWN || d_type == DT_LNK) { strcpy (stpcpy (stpcpy (fullname, fname), "/"), d->d_name); commit c60e6a458b8e2efc39c81d372a88d258009eb1b7 Author: Adhemerval Zanella Date: Fri Feb 4 15:54:59 2022 -0300 hppa: Fix bind-now audit (BZ #28857) On hppa, a function pointer returned by la_symbind is actually a function descriptor has the plabel bit set (bit 30). This must be cleared to get the actual address of the descriptor. If the descriptor has been bound, the first word of the descriptor is the physical address of theA function, otherwise, the first word of the descriptor points to a trampoline in the PLT. This patch also adds a workaround on tests because on hppa (and it seems to be the only ABI I have see it), some shared library adds a dynamic PLT relocation to am empty symbol name: $ readelf -r elf/tst-audit25mod1.so [...] Relocation section '.rela.plt' at offset 0x464 contains 6 entries: Offset Info Type Sym.Value Sym. Name + Addend 00002008 00000081 R_PARISC_IPLT 508 [...] It breaks some assumptions on the test, where a symbol with an empty name ("") is passed on la_symbind. Checked on x86_64-linux-gnu and hppa-linux-gnu. (Cherry-pick picked from 9e94f57484a2aba0fe67ea2059b5843f651887c2) diff --git a/NEWS b/NEWS index 094a979afb..d11e2d9d31 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,7 @@ 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) + [28857] libc: FAIL: elf/tst-audit24a [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 diff --git a/elf/Makefile b/elf/Makefile index ac37159b89..b2bd03a9f6 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -2210,7 +2210,7 @@ $(objpfx)tst-audit24c.out: $(objpfx)tst-auditmod24c.so $(objpfx)tst-audit24c: $(objpfx)tst-audit24amod1.so \ $(objpfx)tst-audit24amod2.so tst-audit24c-ENV = LD_BIND_NOW=1 LD_AUDIT=$(objpfx)tst-auditmod24c.so -LDFLAGS-tst-audit24b = -Wl,-z,lazy +LDFLAGS-tst-audit24c = -Wl,-z,lazy $(objpfx)tst-audit24d.out: $(objpfx)tst-auditmod24d.so $(objpfx)tst-audit24d: $(objpfx)tst-audit24dmod1.so \ diff --git a/elf/dl-audit.c b/elf/dl-audit.c index 794bfd45cd..efc0492474 100644 --- a/elf/dl-audit.c +++ b/elf/dl-audit.c @@ -257,7 +257,8 @@ _dl_audit_symbind (struct link_map *l, struct reloc_result *reloc_result, reloc_result->flags = flags; } - DL_FIXUP_BINDNOW_RELOC (value, new_value, sym.st_value); + if (flags & LA_SYMB_ALTVALUE) + DL_FIXUP_BINDNOW_RELOC (value, new_value, sym.st_value); } void diff --git a/elf/tst-auditmod24a.c b/elf/tst-auditmod24a.c index d8e88f3984..3075dfae2f 100644 --- a/elf/tst-auditmod24a.c +++ b/elf/tst-auditmod24a.c @@ -110,5 +110,7 @@ la_symbind32 (Elf32_Sym *sym, unsigned int ndx, return sym->st_value; } - abort (); + if (symname[0] != '\0') + abort (); + return sym->st_value; } diff --git a/elf/tst-auditmod24d.c b/elf/tst-auditmod24d.c index 8c803ecc0a..badc6be451 100644 --- a/elf/tst-auditmod24d.c +++ b/elf/tst-auditmod24d.c @@ -116,5 +116,7 @@ la_symbind32 (Elf32_Sym *sym, unsigned int ndx, } } - abort (); + if (symname[0] != '\0') + abort (); + return sym->st_value; } diff --git a/elf/tst-auditmod25.c b/elf/tst-auditmod25.c index 526f5c54bc..20640a8daf 100644 --- a/elf/tst-auditmod25.c +++ b/elf/tst-auditmod25.c @@ -72,7 +72,7 @@ la_symbind32 (Elf32_Sym *sym, unsigned int ndx, unsigned int *flags, const char *symname) #endif { - if (*refcook != -1 && *defcook != -1) + if (*refcook != -1 && *defcook != -1 && symname[0] != '\0') fprintf (stderr, "la_symbind: %s %u\n", symname, *flags & (LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT) ? 1 : 0); return sym->st_value; diff --git a/sysdeps/hppa/dl-lookupcfg.h b/sysdeps/hppa/dl-lookupcfg.h index 8da2412fea..27d2cd5e0e 100644 --- a/sysdeps/hppa/dl-lookupcfg.h +++ b/sysdeps/hppa/dl-lookupcfg.h @@ -79,7 +79,9 @@ void attribute_hidden _dl_unmap (struct link_map *map); /* Extract the code address from a fixup value */ #define DL_FIXUP_VALUE_CODE_ADDR(value) ((value).ip) #define DL_FIXUP_VALUE_ADDR(value) ((uintptr_t) &(value)) -#define DL_FIXUP_ADDR_VALUE(addr) (*(struct fdesc *) (addr)) +/* Clear the plabel bit to get the actual address of the descriptor. */ +#define DL_FIXUP_ADDR_VALUE(addr) \ + (*(DL_FIXUP_VALUE_TYPE *) ((uintptr_t) (addr) & ~2)) #define DL_FIXUP_BINDNOW_ADDR_VALUE(addr) (addr) -#define DL_FIXUP_BINDNOW_RELOC(value, new_value, st_value) \ - (*value) = *(struct fdesc *) (st_value) +#define DL_FIXUP_BINDNOW_RELOC(value, new_value, st_value) \ + *(value) = *(DL_FIXUP_VALUE_TYPE *) ((uintptr_t) (new_value) & ~2) commit 1f770811785e6c79db995b0390d1ef4e67e87d44 Author: John David Anglin Date: Mon Feb 14 15:14:49 2022 +0000 Fix elf/tst-audit2 on hppa The test elf/tst-audit2 fails on hppa with a segmentation fault in the long branch stub used to call malloc from calloc. This occurs because the test is not a PIC executable and calloc is called from the dynamic linker before the dp register is initialized in _dl_start_user. The fix is to move the dp register initialization into elf_machine_runtime_setup. Since the address of $global$ can't be loaded directly, we continue to use the DT_PLTGOT value from the the main_map to initialize dp. (cherry picked from commit 2e20cd63c96555d650c525ad5633475e8f11bed4) diff --git a/sysdeps/hppa/dl-machine.h b/sysdeps/hppa/dl-machine.h index da4d57d2e4..7b7a697cbb 100644 --- a/sysdeps/hppa/dl-machine.h +++ b/sysdeps/hppa/dl-machine.h @@ -176,6 +176,15 @@ elf_machine_runtime_setup (struct link_map *l, struct r_scope_elem *scope[], Elf32_Addr i[2]; } sig = {{0x00,0xc0,0xff,0xee, 0xde,0xad,0xbe,0xef}}; + /* Initialize dp register for main executable. */ + if (l->l_main_map) + { + register Elf32_Addr dp asm ("%r27"); + + dp = D_PTR (l, l_info[DT_PLTGOT]); + asm volatile ("" : : "r" (dp)); + } + /* If we don't have a PLT we can just skip all this... */ if (__builtin_expect (l->l_info[DT_JMPREL] == NULL,0)) return lazy; @@ -338,16 +347,6 @@ elf_machine_runtime_setup (struct link_map *l, struct r_scope_elem *scope[], its return value is the user program's entry point. */ #define RTLD_START \ -/* Set up dp for any non-PIC lib constructors that may be called. */ \ -static struct link_map * __attribute__((used)) \ -set_dp (struct link_map *map) \ -{ \ - register Elf32_Addr dp asm ("%r27"); \ - dp = D_PTR (map, l_info[DT_PLTGOT]); \ - asm volatile ("" : : "r" (dp)); \ - return map; \ -} \ - \ asm ( \ " .text\n" \ " .globl _start\n" \ @@ -447,14 +446,11 @@ asm ( \ " stw %r24,-44(%sp)\n" \ \ ".Lnofix:\n" \ + /* Call _dl_init(main_map, argc, argv, envp). */ \ " addil LT'_rtld_local,%r19\n" \ " ldw RT'_rtld_local(%r1),%r26\n" \ -" bl set_dp, %r2\n" \ " ldw 0(%r26),%r26\n" \ \ - /* Call _dl_init(_dl_loaded, argc, argv, envp). */ \ -" copy %r28,%r26\n" \ - \ /* envp = argv + argc + 1 */ \ " sh2add %r25,%r24,%r23\n" \ " bl _dl_init,%r2\n" \ commit 2631d3b3a68108661deca311c3fc159a4ce62983 Author: John David Anglin Date: Fri Feb 18 20:38:25 2022 +0000 hppa: Fix swapcontext This change fixes the failure of stdlib/tst-setcontext2 and stdlib/tst-setcontext7 on hppa. The implementation of swapcontext in C is broken. C saves the return pointer (rp) and any non call-clobbered registers (in this case r3, r4 and r5) on the stack. However, the setcontext call in swapcontext pops the stack and subsequent calls clobber the saved registers. When the context in oucp is restored, both tests fault. Here we rewrite swapcontext in assembly code to avoid using the stack for register values that need to be used after restoration. The getcontext and setcontext routines are revised to save and restore register ret1 for normal returns. We copy the oucp pointer to ret1. This allows access to the old context after calling getcontext and setcontext. (cherry picked from commit 71b108d7eb33b2bf3e61d5e92d2a47f74c1f7d96) diff --git a/sysdeps/unix/sysv/linux/hppa/getcontext.S b/sysdeps/unix/sysv/linux/hppa/getcontext.S index 1e73587f13..6470d73de5 100644 --- a/sysdeps/unix/sysv/linux/hppa/getcontext.S +++ b/sysdeps/unix/sysv/linux/hppa/getcontext.S @@ -137,6 +137,8 @@ ENTRY(__getcontext) stw %r19, -32(%sp) .cfi_offset 19, 32 #endif + stw %ret1, -60(%sp) + .cfi_offset 29, 4 /* Set up the trampoline registers. r20, r23, r24, r25, r26 and r2 are clobbered @@ -167,6 +169,7 @@ ENTRY(__getcontext) #ifdef PIC ldw -32(%sp), %r19 #endif + ldw -60(%sp), %ret1 bv %r0(%r2) ldwm -64(%sp), %r4 END(__getcontext) diff --git a/sysdeps/unix/sysv/linux/hppa/setcontext.S b/sysdeps/unix/sysv/linux/hppa/setcontext.S index bc4872c8e2..5da01c2f35 100644 --- a/sysdeps/unix/sysv/linux/hppa/setcontext.S +++ b/sysdeps/unix/sysv/linux/hppa/setcontext.S @@ -33,6 +33,8 @@ ENTRY(__setcontext) stw %r19, -32(%sp) .cfi_offset 19, 32 #endif + stw %ret1, -60(%sp) + .cfi_offset 29, 4 /* Save ucp. */ copy %r26, %r3 @@ -154,6 +156,7 @@ ENTRY(__setcontext) #ifdef PIC ldw -32(%r30), %r19 #endif + ldw -60(%r30), %ret1 bv %r0(%r2) ldwm -64(%r30), %r3 L(pseudo_end): diff --git a/sysdeps/unix/sysv/linux/hppa/swapcontext.c b/sysdeps/unix/sysv/linux/hppa/swapcontext.c index 5cbe00f1e9..64adb9ee62 100644 --- a/sysdeps/unix/sysv/linux/hppa/swapcontext.c +++ b/sysdeps/unix/sysv/linux/hppa/swapcontext.c @@ -17,6 +17,7 @@ . */ #include +#include "ucontext_i.h" extern int __getcontext (ucontext_t *ucp); extern int __setcontext (const ucontext_t *ucp); @@ -24,17 +25,61 @@ extern int __setcontext (const ucontext_t *ucp); int __swapcontext (ucontext_t *oucp, const ucontext_t *ucp) { + /* Save ucp in stack argument slot. */ + asm ("stw %r25,-40(%sp)"); + asm (".cfi_offset 25, -40"); + + /* Save rp for debugger. */ + asm ("stw %rp,-20(%sp)"); + asm (".cfi_offset 2, -20"); + + /* Copy rp to ret0 (r28). */ + asm ("copy %rp,%ret0"); + + /* Create a frame. */ + asm ("ldo 64(%sp),%sp"); + asm (".cfi_def_cfa_offset -64"); + /* Save the current machine context to oucp. */ - __getcontext (oucp); + asm ("bl __getcontext,%rp"); + + /* Copy oucp to register ret1 (r29). __getcontext saves and restores it + on a normal return. It is restored from oR29 on reactivation. */ + asm ("copy %r26,%ret1"); + + /* Pop frame. */ + asm ("ldo -64(%sp),%sp"); + asm (".cfi_def_cfa_offset 0"); + + /* Load return pointer from oR28. */ + asm ("ldw %0(%%ret1),%%rp" : : "i" (oR28)); + + /* Return if error. */ + asm ("or,= %r0,%ret0,%r0"); + asm ("bv,n %r0(%rp)"); + + /* Load sc_sar flag. */ + asm ("ldw %0(%%ret1),%%r20" : : "i" (oSAR)); + + /* Return if oucp context has been reactivated. */ + asm ("or,= %r0,%r20,%r0"); + asm ("bv,n %r0(%rp)"); + + /* Mark sc_sar flag. */ + asm ("1: ldi 1,%r20"); + asm ("stw %%r20,%0(%%ret1)" : : "i" (oSAR)); + + /* Activate the machine context in ucp. */ + asm ("bl __setcontext,%rp"); + asm ("ldw -40(%sp),%r26"); - /* mark sc_sar flag to skip the setcontext call on reactivation. */ - if (oucp->uc_mcontext.sc_sar == 0) { - oucp->uc_mcontext.sc_sar++; + /* Load return pointer. */ + asm ("ldw %0(%%ret1),%%rp" : : "i" (oR28)); - /* Restore the machine context in ucp. */ - __setcontext (ucp); - } + /* A successful call to setcontext does not return. */ + asm ("bv,n %r0(%rp)"); + /* Make gcc happy. */ return 0; } commit d82d9cdff40492d46f75d5d12b3c9e2ac0c422fe Author: John David Anglin Date: Tue Feb 22 17:28:46 2022 +0000 hppa: Revise gettext trampoline design The current getcontext return trampoline is overly complex and it unnecessarily clobbers several registers. By saving the context pointer (r26) in the context, __getcontext_ret can restore any registers not restored by setcontext. This allows getcontext to save and restore the entire register context present when getcontext is entered. We use the unused oR0 context slot for the return from __getcontext_ret. While this is not directly useful in C, it can be exploited in assembly code. Registers r20, r23, r24 and r25 are not clobbered in the call path to getcontext. This allows a small simplification of swapcontext. It also allows saving and restoring the 6-bit SAR register in the LSB of the oSAR context slot. The getcontext flag value can be stored in the MSB of the oSAR slot. (cherry picked from commit 9e7e5fda38471e00d1190479ea91d7b08ae3e304) diff --git a/sysdeps/unix/sysv/linux/hppa/getcontext.S b/sysdeps/unix/sysv/linux/hppa/getcontext.S index 6470d73de5..dcdf986f2d 100644 --- a/sysdeps/unix/sysv/linux/hppa/getcontext.S +++ b/sysdeps/unix/sysv/linux/hppa/getcontext.S @@ -21,22 +21,28 @@ #include "ucontext_i.h" - /* Trampoline function. Non-standard calling ABI. */ + /* Trampoline function. Non-standard calling ABI. */ /* Can not use ENTRY(__getcontext_ret) here. */ .type __getcontext_ret, @function .hidden __getcontext_ret __getcontext_ret: .proc .callinfo FRAME=0,NO_CALLS - /* r26-r23 contain original r3-r6, but because setcontext - does not reload r3-r6 (it's using them as temporaries) - we must save them elsewhere and swap them back in. */ - copy %r23, %r3 - copy %r24, %r4 - copy %r25, %r5 - copy %r26, %r6 - /* r20 contains original return pointer. */ - bv 0(%r20) + /* Because setcontext does not reload r3-r6 (it's using them + as temporaries), we must load them ourself. */ + ldw oR3(%r26), %r3 + ldw oR4(%r26), %r4 + ldw oR5(%r26), %r5 + ldw oR6(%r26), %r6 + + /* Also reload registers clobbered by $$dyncall. */ + ldw oR21(%r26), %r21 + ldw oR22(%r26), %r22 + ldw oR31(%r26), %r31 + + /* oR0 contains original return pointer. */ + ldw oR0(%r26), %rp + bv 0(%rp) copy %r0, %ret0 .procend .size __getcontext_ret, .-__getcontext_ret @@ -64,13 +70,13 @@ ENTRY(__getcontext) stw %r17, oR17(%r26) stw %r18, oR18(%r26) stw %r19, oR19(%r26) - /* stw %r20, oR20(%r26) - used for trampoline. */ + stw %r20, oR20(%r26) stw %r21, oR21(%r26) stw %r22, oR22(%r26) - /* stw %r23, oR23(%r26) - used for trampoline. */ - /* stw %r24, oR24(%r26) - used for trampoline. */ - /* stw %r25, oR25(%r26) - used for trampoline. */ - /* stw %r26, oR26(%r26) - used for trampoline. */ + stw %r23, oR23(%r26) + stw %r24, oR24(%r26) + stw %r25, oR25(%r26) + stw %r26, oR26(%r26) stw %r27, oR27(%r26) stw %r28, oR28(%r26) stw %r29, oR29(%r26) @@ -89,7 +95,10 @@ ENTRY(__getcontext) stw %r0, oIASQ1(%r26) stw %r0, oIAOQ0(%r26) stw %r0, oIAOQ1(%r26) - stw %r0, oSAR(%r26) /* used as flag in swapcontext(). */ + + /* Save SAR register. */ + mfctl %sar, %r1 + stw %r1, oSAR(%r26) /* MSB used as flag in swapcontext(). */ /* Store floating-point regs. */ @@ -141,13 +150,8 @@ ENTRY(__getcontext) .cfi_offset 29, 4 /* Set up the trampoline registers. - r20, r23, r24, r25, r26 and r2 are clobbered - by call to getcontext() anyway. Reuse them. */ - stw %r2, oR20(%r26) - stw %r3, oR23(%r26) - stw %r4, oR24(%r26) - stw %r5, oR25(%r26) - stw %r6, oR26(%r26) + Use oR0 context slot to save return value. */ + stw %r2, oR0(%r26) #ifdef PIC addil LT%__getcontext_ret, %r19 ldw RT%__getcontext_ret(%r1), %r1 diff --git a/sysdeps/unix/sysv/linux/hppa/setcontext.S b/sysdeps/unix/sysv/linux/hppa/setcontext.S index 5da01c2f35..dfa794ad5c 100644 --- a/sysdeps/unix/sysv/linux/hppa/setcontext.S +++ b/sysdeps/unix/sysv/linux/hppa/setcontext.S @@ -75,7 +75,7 @@ ENTRY(__setcontext) ldw oR18(%r3), %r18 ldw oR19(%r3), %r19 ldw oR20(%r3), %r20 - ldw oR21(%r3), %r21 + ldw oR21(%r3), %r21 /* maybe clobbered by dyncall */ /* ldw oR22(%r3), %r22 - dyncall arg. */ ldw oR23(%r3), %r23 ldw oR24(%r3), %r24 @@ -87,6 +87,10 @@ ENTRY(__setcontext) ldw oR30(%r3), %sp /* ldw oR31(%r3), %r31 - dyncall scratch register */ + /* Restore SAR register. */ + ldw oSAR(%r3), %r22 + mtsar %r22 + /* Restore floating-point registers. */ ldo oFPREGS31(%r3), %r22 fldds 0(%r22), %fr31 diff --git a/sysdeps/unix/sysv/linux/hppa/swapcontext.c b/sysdeps/unix/sysv/linux/hppa/swapcontext.c index 64adb9ee62..e5bf6c9933 100644 --- a/sysdeps/unix/sysv/linux/hppa/swapcontext.c +++ b/sysdeps/unix/sysv/linux/hppa/swapcontext.c @@ -25,10 +25,6 @@ extern int __setcontext (const ucontext_t *ucp); int __swapcontext (ucontext_t *oucp, const ucontext_t *ucp) { - /* Save ucp in stack argument slot. */ - asm ("stw %r25,-40(%sp)"); - asm (".cfi_offset 25, -40"); - /* Save rp for debugger. */ asm ("stw %rp,-20(%sp)"); asm (".cfi_offset 2, -20"); @@ -59,7 +55,7 @@ __swapcontext (ucontext_t *oucp, const ucontext_t *ucp) asm ("bv,n %r0(%rp)"); /* Load sc_sar flag. */ - asm ("ldw %0(%%ret1),%%r20" : : "i" (oSAR)); + asm ("ldb %0(%%ret1),%%r20" : : "i" (oSAR)); /* Return if oucp context has been reactivated. */ asm ("or,= %r0,%r20,%r0"); @@ -67,11 +63,11 @@ __swapcontext (ucontext_t *oucp, const ucontext_t *ucp) /* Mark sc_sar flag. */ asm ("1: ldi 1,%r20"); - asm ("stw %%r20,%0(%%ret1)" : : "i" (oSAR)); + asm ("stb %%r20,%0(%%ret1)" : : "i" (oSAR)); /* Activate the machine context in ucp. */ asm ("bl __setcontext,%rp"); - asm ("ldw -40(%sp),%r26"); + asm ("ldw %0(%%ret1),%%r26" : : "i" (oR25)); /* Load return pointer. */ asm ("ldw %0(%%ret1),%%rp" : : "i" (oR28)); commit ca0570fee323349bac834cf3bf3aef712f09cdc1 Author: John David Anglin Date: Tue Feb 22 18:51:35 2022 +0000 hppa: Fix warnings from _dl_lookup_address This change fixes two warnings from _dl_lookup_address. The first warning comes from dropping the volatile keyword from desc in the call to _dl_read_access_allowed. We now have a full atomic barrier between loading desc[0] and the access check, so desc no longer needs to be declared as volatile. The second warning comes from the implicit declaration of _dl_fix_reloc_arg. This is fixed by including dl-runtime.h and declaring _dl_fix_reloc_arg in dl-runtime.h. (cherry picked from commit d2224ffbddc9d25ed5b0e34c212018c32d1e5a95) diff --git a/sysdeps/hppa/dl-fptr.c b/sysdeps/hppa/dl-fptr.c index 2584557c4f..9ed21602d6 100644 --- a/sysdeps/hppa/dl-fptr.c +++ b/sysdeps/hppa/dl-fptr.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -351,21 +352,20 @@ _dl_lookup_address (const void *address) { ElfW(Addr) addr = (ElfW(Addr)) address; ElfW(Word) reloc_arg; - volatile unsigned int *desc; - unsigned int *gptr; + unsigned int *desc, *gptr; /* Return ADDR if the least-significant two bits of ADDR are not consistent with ADDR being a linker defined function pointer. The normal value for a code address in a backtrace is 3. */ - if (((unsigned int) addr & 3) != 2) + if (((uintptr_t) addr & 3) != 2) return addr; /* Handle special case where ADDR points to page 0. */ - if ((unsigned int) addr < 4096) + if ((uintptr_t) addr < 4096) return addr; /* Clear least-significant two bits from descriptor address. */ - desc = (unsigned int *) ((unsigned int) addr & ~3); + desc = (unsigned int *) ((uintptr_t) addr & ~3); if (!_dl_read_access_allowed (desc)) return addr; @@ -376,7 +376,7 @@ _dl_lookup_address (const void *address) /* Then load first word of candidate descriptor. It should be a pointer with word alignment and point to memory that can be read. */ gptr = (unsigned int *) desc[0]; - if (((unsigned int) gptr & 3) != 0 + if (((uintptr_t) gptr & 3) != 0 || !_dl_read_access_allowed (gptr)) return addr; @@ -400,10 +400,11 @@ _dl_lookup_address (const void *address) /* If gp has been resolved, we need to hunt for relocation offset. */ if (!(reloc_arg & PA_GP_RELOC)) - reloc_arg = _dl_fix_reloc_arg (addr, l); + reloc_arg = _dl_fix_reloc_arg ((struct fdesc *) addr, l); _dl_fixup (l, reloc_arg); } return (ElfW(Addr)) desc[0]; } +rtld_hidden_def (_dl_lookup_address) diff --git a/sysdeps/hppa/dl-lookupcfg.h b/sysdeps/hppa/dl-lookupcfg.h index 27d2cd5e0e..de0a3b78e8 100644 --- a/sysdeps/hppa/dl-lookupcfg.h +++ b/sysdeps/hppa/dl-lookupcfg.h @@ -30,6 +30,7 @@ rtld_hidden_proto (_dl_symbol_address) #define DL_SYMBOL_ADDRESS(map, ref) _dl_symbol_address(map, ref) Elf32_Addr _dl_lookup_address (const void *address); +rtld_hidden_proto (_dl_lookup_address) #define DL_LOOKUP_ADDRESS(addr) _dl_lookup_address ((const void *) addr) diff --git a/sysdeps/hppa/dl-runtime.c b/sysdeps/hppa/dl-runtime.c index 8b2ee58e37..192a6bee03 100644 --- a/sysdeps/hppa/dl-runtime.c +++ b/sysdeps/hppa/dl-runtime.c @@ -25,8 +25,7 @@ return that to the caller. The caller will continue on to call _dl_fixup with the relocation offset. */ -ElfW(Word) -attribute_hidden __attribute ((noinline)) DL_ARCH_FIXUP_ATTRIBUTE +ElfW(Word) __attribute ((noinline)) DL_ARCH_FIXUP_ATTRIBUTE _dl_fix_reloc_arg (struct fdesc *fptr, struct link_map *l) { Elf32_Addr l_addr, iplt, jmprel, end_jmprel, r_type; @@ -52,3 +51,4 @@ _dl_fix_reloc_arg (struct fdesc *fptr, struct link_map *l) ABORT_INSTRUCTION; return 0; } +rtld_hidden_def (_dl_fix_reloc_arg) diff --git a/sysdeps/hppa/dl-runtime.h b/sysdeps/hppa/dl-runtime.h index d4da46079b..5ced8e14e9 100644 --- a/sysdeps/hppa/dl-runtime.h +++ b/sysdeps/hppa/dl-runtime.h @@ -17,6 +17,9 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +ElfW(Word) _dl_fix_reloc_arg (struct fdesc *, struct link_map *); +rtld_hidden_proto (_dl_fix_reloc_arg) + /* Clear PA_GP_RELOC bit in relocation offset. */ static inline uintptr_t reloc_offset (uintptr_t plt0, uintptr_t pltn) commit e30c1c73da3f220f5bf0063a1d0344f8280311e7 Author: John David Anglin Date: Mon Feb 28 15:47:38 2022 +0000 nptl: Fix cleanups for stack grows up [BZ# 28899] _STACK_GROWS_DOWN is defined to 0 when the stack grows up. The code in unwind.c used `#ifdef _STACK_GROWS_DOWN' to selct the stack grows down define for FRAME_LEFT. As a result, the _STACK_GROWS_DOWN define was always selected and cleanups were incorrectly sequenced when the stack grows up. (cherry picked from commit 2bbc694df279020a6620096d31c1e05c93966f9b) diff --git a/nptl/unwind.c b/nptl/unwind.c index c3563e3467..33b0d87579 100644 --- a/nptl/unwind.c +++ b/nptl/unwind.c @@ -25,7 +25,7 @@ #include #include -#ifdef _STACK_GROWS_DOWN +#if _STACK_GROWS_DOWN # define FRAME_LEFT(frame, other, adj) \ ((uintptr_t) frame - adj >= (uintptr_t) other - adj) #elif _STACK_GROWS_UP