summaryrefslogtreecommitdiff
path: root/glibc/glibc-2.32-6.patch
blob: 5d4a58d22eaf56775e1791d10849098945c21ac4 (plain)
    1 diff --git a/NEWS b/NEWS
    2 index 485b8ddffa..b29826f4f5 100644
    3 --- a/NEWS
    4 +++ b/NEWS
    5 @@ -5,6 +5,27 @@ See the end for copying conditions.
    6  Please send GNU C library bug reports via <https://sourceware.org/bugzilla/>
    7  using `glibc' in the "product" field.
    8  
    9 +The following bugs are resolved with this release:
   10 +
   11 +  [20019] NULL pointer dereference in libc.so.6 IFUNC due to uninitialized GOT
   12 +  [26224] iconv hangs when converting some invalid inputs from several IBM
   13 +    character sets (CVE-2020-27618)
   14 +  [26534] libm.so 2.32 SIGILL in pow() due to FMA4 instruction on non-FMA4
   15 +    system
   16 +  [26555] string: strerrorname_np does not return the documented value
   17 +  [26600] Transaction ID collisions cause slow DNS lookups in getaddrinfo
   18 +  [26636] libc: 32-bit shmctl(IPC_INFO) crashes when shminfo struct is
   19 +    at the end of a memory mapping
   20 +  [26637] libc: semctl SEM_STAT_ANY fails to pass the buffer specified
   21 +    by the caller to the kernel
   22 +  [26639] libc: msgctl IPC_INFO and MSG_INFO return garbage
   23 +  [26853] aarch64: Missing unwind information in statically linked startup code
   24 +  [26932] libc: sh: Multiple floating point functions defined as stubs only
   25 +  [27130] "rep movsb" performance issue
   26 +  [27177] GLIBC_TUNABLES=glibc.cpu.x86_ibt=on:glibc.cpu.x86_shstk=on doesn't work
   27 +  [28524] Conversion from ISO-2022-JP-3 with iconv may emit spurious NULs
   28 +  [28607] Masked signals are delivered on thread exit
   29 +
   30  Version 2.32
   31  
   32  Major new features:
   33 @@ -185,6 +206,14 @@ Security related changes:
   34    Dytrych of the Cisco Security Assessment and Penetration Team (See
   35    TALOS-2020-1019).
   36  
   37 +  CVE-2020-27618: An infinite loop has been fixed in the iconv program when
   38 +  invoked with input containing redundant shift sequences in the IBM1364,
   39 +  IBM1371, IBM1388, IBM1390, or IBM1399 character sets.
   40 +
   41 +  CVE-2021-33574: The mq_notify function has a potential use-after-free
   42 +  issue when using a notification type of SIGEV_THREAD and a thread
   43 +  attribute with a non-default affinity mask.
   44 +
   45  The following bugs are resolved with this release:
   46  
   47    [9809] localedata: ckb_IQ: new Kurdish Sorani locale
   48 diff --git a/Rules b/Rules
   49 index 8b771f6095..beab969fde 100644
   50 --- a/Rules
   51 +++ b/Rules
   52 @@ -155,6 +155,7 @@ xtests: tests $(xtests-special)
   53  else
   54  tests: $(tests:%=$(objpfx)%.out) $(tests-internal:%=$(objpfx)%.out) \
   55         $(tests-container:%=$(objpfx)%.out) \
   56 +       $(tests-mcheck:%=$(objpfx)%-mcheck.out) \
   57         $(tests-special) $(tests-printers-out)
   58  xtests: tests $(xtests:%=$(objpfx)%.out) $(xtests-special)
   59  endif
   60 @@ -165,7 +166,7 @@ ifeq ($(run-built-tests),no)
   61  tests-expected =
   62  else
   63  tests-expected = $(tests) $(tests-internal) $(tests-printers) \
   64 -	$(tests-container)
   65 +	$(tests-container) $(tests-mcheck:%=%-mcheck)
   66  endif
   67  tests:
   68  	$(..)scripts/merge-test-results.sh -s $(objpfx) $(subdir) \
   69 @@ -191,6 +192,7 @@ else
   70  binaries-pie-tests =
   71  binaries-pie-notests =
   72  endif
   73 +binaries-mcheck-tests = $(tests-mcheck:%=%-mcheck)
   74  else
   75  binaries-all-notests =
   76  binaries-all-tests = $(tests) $(tests-internal) $(xtests) $(test-srcs)
   77 @@ -200,6 +202,7 @@ binaries-static-tests =
   78  binaries-static =
   79  binaries-pie-tests =
   80  binaries-pie-notests =
   81 +binaries-mcheck-tests =
   82  endif
   83  
   84  binaries-pie = $(binaries-pie-tests) $(binaries-pie-notests)
   85 @@ -223,6 +226,14 @@ $(addprefix $(objpfx),$(binaries-shared-tests)): %: %.o \
   86  	$(+link-tests)
   87  endif
   88  
   89 +ifneq "$(strip $(binaries-mcheck-tests))" ""
   90 +$(addprefix $(objpfx),$(binaries-mcheck-tests)): %-mcheck: %.o \
   91 +  $(link-extra-libs-tests) \
   92 +  $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \
   93 +  $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
   94 +	$(+link-tests)
   95 +endif
   96 +
   97  ifneq "$(strip $(binaries-pie-tests))" ""
   98  $(addprefix $(objpfx),$(binaries-pie-tests)): %: %.o \
   99    $(link-extra-libs-tests) \
  100 @@ -253,6 +264,12 @@ $(addprefix $(objpfx),$(binaries-static-tests)): %: %.o \
  101  	$(+link-static-tests)
  102  endif
  103  
  104 +# All mcheck tests will be run with MALLOC_CHECK_=3
  105 +define mcheck-ENVS
  106 +$(1)-mcheck-ENV = MALLOC_CHECK_=3
  107 +endef
  108 +$(foreach t,$(tests-mcheck),$(eval $(call mcheck-ENVS,$(t))))
  109 +
  110  ifneq "$(strip $(tests) $(tests-internal) $(xtests) $(test-srcs))" ""
  111  # These are the implicit rules for making test outputs
  112  # from the test programs and whatever input files are present.
  113 diff --git a/debug/Makefile b/debug/Makefile
  114 index 3a60d7af7a..0036edd187 100644
  115 --- a/debug/Makefile
  116 +++ b/debug/Makefile
  117 @@ -51,7 +51,7 @@ routines  = backtrace backtracesyms backtracesymsfd noophooks \
  118  	    explicit_bzero_chk \
  119  	    stack_chk_fail fortify_fail \
  120  	    $(static-only-routines)
  121 -static-only-routines := warning-nop stack_chk_fail_local
  122 +static-only-routines := stack_chk_fail_local
  123  
  124  # Don't add stack_chk_fail_local.o to libc.a since __stack_chk_fail_local
  125  # is an alias of __stack_chk_fail in stack_chk_fail.o.
  126 diff --git a/debug/warning-nop.c b/debug/warning-nop.c
  127 deleted file mode 100644
  128 index 4ab7e182b7..0000000000
  129 --- a/debug/warning-nop.c
  130 +++ /dev/null
  131 @@ -1,70 +0,0 @@
  132 -/* Dummy nop functions to elicit link-time warnings.
  133 -   Copyright (C) 2005-2020 Free Software Foundation, Inc.
  134 -   This file is part of the GNU C Library.
  135 -
  136 -   The GNU C Library is free software; you can redistribute it and/or
  137 -   modify it under the terms of the GNU Lesser General Public
  138 -   License as published by the Free Software Foundation; either
  139 -   version 2.1 of the License, or (at your option) any later version.
  140 -
  141 -   In addition to the permissions in the GNU Lesser General Public
  142 -   License, the Free Software Foundation gives you unlimited
  143 -   permission to link the compiled version of this file with other
  144 -   programs, and to distribute those programs without any restriction
  145 -   coming from the use of this file. (The GNU Lesser General Public
  146 -   License restrictions do apply in other respects; for example, they
  147 -   cover modification of the file, and distribution when not linked
  148 -   into another program.)
  149 -
  150 -   Note that people who make modified versions of this file are not
  151 -   obligated to grant this special exception for their modified
  152 -   versions; it is their choice whether to do so. The GNU Lesser
  153 -   General Public License gives permission to release a modified
  154 -   version without this exception; this exception also makes it
  155 -   possible to release a modified version which carries forward this
  156 -   exception.
  157 -
  158 -   The GNU C Library is distributed in the hope that it will be useful,
  159 -   but WITHOUT ANY WARRANTY; without even the implied warranty of
  160 -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  161 -   Lesser General Public License for more details.
  162 -
  163 -   You should have received a copy of the GNU Lesser General Public
  164 -   License along with the GNU C Library; if not, see
  165 -   <https://www.gnu.org/licenses/>.  */
  166 -
  167 -#include <sys/cdefs.h>
  168 -
  169 -static void
  170 -__attribute__ ((used))
  171 -nop (void)
  172 -{
  173 -}
  174 -
  175 -/* Don't insert any other #include's before this #undef!  */
  176 -
  177 -#undef __warndecl
  178 -#define __warndecl(name, msg) \
  179 -  extern void name (void) __attribute__ ((alias ("nop"))) attribute_hidden; \
  180 -  link_warning (name, msg)
  181 -
  182 -#undef	__USE_FORTIFY_LEVEL
  183 -#define __USE_FORTIFY_LEVEL 99
  184 -
  185 -/* Following here we need an #include for each public header file
  186 -   that uses __warndecl.  */
  187 -
  188 -/* Define away to avoid warnings with compilers that do not have these
  189 -   builtins.  */
  190 -#define __builtin___memcpy_chk(dest, src, len, bos) NULL
  191 -#define __builtin___memmove_chk(dest, src, len, bos) NULL
  192 -#define __builtin___mempcpy_chk(dest, src, len, bos) NULL
  193 -#define __builtin___memset_chk(dest, ch, len, bos) NULL
  194 -#define __builtin___stpcpy_chk(dest, src, bos) NULL
  195 -#define __builtin___strcat_chk(dest, src, bos) NULL
  196 -#define __builtin___strcpy_chk(dest, src, bos) NULL
  197 -#define __builtin___strncat_chk(dest, src, len, bos) NULL
  198 -#define __builtin___strncpy_chk(dest, src, len, bos) NULL
  199 -#define __builtin_object_size(bos, level) 0
  200 -
  201 -#include <string.h>
  202 diff --git a/elf/Makefile b/elf/Makefile
  203 index 0b78721848..3ba7f4ecfc 100644
  204 --- a/elf/Makefile
  205 +++ b/elf/Makefile
  206 @@ -1381,6 +1381,8 @@ CFLAGS-ifuncmain7pie.c += $(pie-ccflag)
  207  CFLAGS-ifuncmain9pie.c += $(pie-ccflag)
  208  CFLAGS-tst-ifunc-textrel.c += $(pic-ccflag)
  209  
  210 +LDFLAGS-ifuncmain6pie = -Wl,-z,lazy
  211 +
  212  $(objpfx)ifuncmain1pie: $(objpfx)ifuncmod1.so
  213  $(objpfx)ifuncmain1staticpie: $(objpfx)ifuncdep1pic.o
  214  $(objpfx)ifuncmain1vispie: $(objpfx)ifuncmod1.so
  215 @@ -1630,8 +1632,6 @@ $(objpfx)tst-nodelete-dlclose.out: $(objpfx)tst-nodelete-dlclose-dso.so \
  216  
  217  tst-env-setuid-ENV = MALLOC_CHECK_=2 MALLOC_MMAP_THRESHOLD_=4096 \
  218  		     LD_HWCAP_MASK=0x1
  219 -tst-env-setuid-tunables-ENV = \
  220 -	GLIBC_TUNABLES=glibc.malloc.check=2:glibc.malloc.mmap_threshold=4096
  221  
  222  $(objpfx)tst-debug1: $(libdl)
  223  $(objpfx)tst-debug1.out: $(objpfx)tst-debug1mod1.so
  224 diff --git a/elf/dl-load.c b/elf/dl-load.c
  225 index e39980fb19..71867e7c1a 100644
  226 --- a/elf/dl-load.c
  227 +++ b/elf/dl-load.c
  228 @@ -855,10 +855,12 @@ lose (int code, int fd, const char *name, char *realname, struct link_map *l,
  229  
  230  /* Process PT_GNU_PROPERTY program header PH in module L after
  231     PT_LOAD segments are mapped.  Only one NT_GNU_PROPERTY_TYPE_0
  232 -   note is handled which contains processor specific properties.  */
  233 +   note is handled which contains processor specific properties.
  234 +   FD is -1 for the kernel mapped main executable otherwise it is
  235 +   the fd used for loading module L.  */
  236  
  237  void
  238 -_dl_process_pt_gnu_property (struct link_map *l, const ElfW(Phdr) *ph)
  239 +_dl_process_pt_gnu_property (struct link_map *l, int fd, const ElfW(Phdr) *ph)
  240  {
  241    const ElfW(Nhdr) *note = (const void *) (ph->p_vaddr + l->l_addr);
  242    const ElfW(Addr) size = ph->p_memsz;
  243 @@ -905,7 +907,7 @@ _dl_process_pt_gnu_property (struct link_map *l, const ElfW(Phdr) *ph)
  244  	      last_type = type;
  245  
  246  	      /* Target specific property processing.  */
  247 -	      if (_dl_process_gnu_property (l, type, datasz, ptr) == 0)
  248 +	      if (_dl_process_gnu_property (l, fd, type, datasz, ptr) == 0)
  249  		return;
  250  
  251  	      /* Check the next property item.  */
  252 @@ -1251,21 +1253,6 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
  253  				  maplength, has_holes, loader);
  254      if (__glibc_unlikely (errstring != NULL))
  255        goto call_lose;
  256 -
  257 -    /* Process program headers again after load segments are mapped in
  258 -       case processing requires accessing those segments.  Scan program
  259 -       headers backward so that PT_NOTE can be skipped if PT_GNU_PROPERTY
  260 -       exits.  */
  261 -    for (ph = &phdr[l->l_phnum]; ph != phdr; --ph)
  262 -      switch (ph[-1].p_type)
  263 -	{
  264 -	case PT_NOTE:
  265 -	  _dl_process_pt_note (l, &ph[-1]);
  266 -	  break;
  267 -	case PT_GNU_PROPERTY:
  268 -	  _dl_process_pt_gnu_property (l, &ph[-1]);
  269 -	  break;
  270 -	}
  271    }
  272  
  273    if (l->l_ld == 0)
  274 @@ -1377,6 +1364,21 @@ cannot enable executable stack as shared object requires");
  275    if (l->l_tls_initimage != NULL)
  276      l->l_tls_initimage = (char *) l->l_tls_initimage + l->l_addr;
  277  
  278 +  /* Process program headers again after load segments are mapped in
  279 +     case processing requires accessing those segments.  Scan program
  280 +     headers backward so that PT_NOTE can be skipped if PT_GNU_PROPERTY
  281 +     exits.  */
  282 +  for (ph = &l->l_phdr[l->l_phnum]; ph != l->l_phdr; --ph)
  283 +    switch (ph[-1].p_type)
  284 +      {
  285 +      case PT_NOTE:
  286 +	_dl_process_pt_note (l, fd, &ph[-1]);
  287 +	break;
  288 +      case PT_GNU_PROPERTY:
  289 +	_dl_process_pt_gnu_property (l, fd, &ph[-1]);
  290 +	break;
  291 +      }
  292 +
  293    /* We are done mapping in the file.  We no longer need the descriptor.  */
  294    if (__glibc_unlikely (__close_nocancel (fd) != 0))
  295      {
  296 diff --git a/elf/dl-open.c b/elf/dl-open.c
  297 index 8769e47051..55b39e1bbe 100644
  298 --- a/elf/dl-open.c
  299 +++ b/elf/dl-open.c
  300 @@ -887,7 +887,7 @@ no more namespaces available for dlmopen()"));
  301        /* Avoid keeping around a dangling reference to the libc.so link
  302  	 map in case it has been cached in libc_map.  */
  303        if (!args.libc_already_loaded)
  304 -	GL(dl_ns)[nsid].libc_map = NULL;
  305 +	GL(dl_ns)[args.nsid].libc_map = NULL;
  306  
  307        /* Remove the object from memory.  It may be in an inconsistent
  308  	 state if relocation failed, for example.  */
  309 diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c
  310 index 26e6e26612..15b29bcb90 100644
  311 --- a/elf/dl-tunables.c
  312 +++ b/elf/dl-tunables.c
  313 @@ -177,6 +177,7 @@ parse_tunables (char *tunestr, char *valstring)
  314      return;
  315  
  316    char *p = tunestr;
  317 +  size_t off = 0;
  318  
  319    while (true)
  320      {
  321 @@ -190,7 +191,11 @@ parse_tunables (char *tunestr, char *valstring)
  322        /* If we reach the end of the string before getting a valid name-value
  323  	 pair, bail out.  */
  324        if (p[len] == '\0')
  325 -	return;
  326 +	{
  327 +	  if (__libc_enable_secure)
  328 +	    tunestr[off] = '\0';
  329 +	  return;
  330 +	}
  331  
  332        /* We did not find a valid name-value pair before encountering the
  333  	 colon.  */
  334 @@ -216,35 +221,28 @@ parse_tunables (char *tunestr, char *valstring)
  335  
  336  	  if (tunable_is_name (cur->name, name))
  337  	    {
  338 -	      /* If we are in a secure context (AT_SECURE) then ignore the tunable
  339 -		 unless it is explicitly marked as secure.  Tunable values take
  340 -		 precedence over their envvar aliases.  */
  341 +	      /* If we are in a secure context (AT_SECURE) then ignore the
  342 +		 tunable unless it is explicitly marked as secure.  Tunable
  343 +		 values take precedence over their envvar aliases.  We write
  344 +		 the tunables that are not SXID_ERASE back to TUNESTR, thus
  345 +		 dropping all SXID_ERASE tunables and any invalid or
  346 +		 unrecognized tunables.  */
  347  	      if (__libc_enable_secure)
  348  		{
  349 -		  if (cur->security_level == TUNABLE_SECLEVEL_SXID_ERASE)
  350 +		  if (cur->security_level != TUNABLE_SECLEVEL_SXID_ERASE)
  351  		    {
  352 -		      if (p[len] == '\0')
  353 -			{
  354 -			  /* Last tunable in the valstring.  Null-terminate and
  355 -			     return.  */
  356 -			  *name = '\0';
  357 -			  return;
  358 -			}
  359 -		      else
  360 -			{
  361 -			  /* Remove the current tunable from the string.  We do
  362 -			     this by overwriting the string starting from NAME
  363 -			     (which is where the current tunable begins) with
  364 -			     the remainder of the string.  We then have P point
  365 -			     to NAME so that we continue in the correct
  366 -			     position in the valstring.  */
  367 -			  char *q = &p[len + 1];
  368 -			  p = name;
  369 -			  while (*q != '\0')
  370 -			    *name++ = *q++;
  371 -			  name[0] = '\0';
  372 -			  len = 0;
  373 -			}
  374 +		      if (off > 0)
  375 +			tunestr[off++] = ':';
  376 +
  377 +		      const char *n = cur->name;
  378 +
  379 +		      while (*n != '\0')
  380 +			tunestr[off++] = *n++;
  381 +
  382 +		      tunestr[off++] = '=';
  383 +
  384 +		      for (size_t j = 0; j < len; j++)
  385 +			tunestr[off++] = value[j];
  386  		    }
  387  
  388  		  if (cur->security_level != TUNABLE_SECLEVEL_NONE)
  389 @@ -257,9 +255,7 @@ parse_tunables (char *tunestr, char *valstring)
  390  	    }
  391  	}
  392  
  393 -      if (p[len] == '\0')
  394 -	return;
  395 -      else
  396 +      if (p[len] != '\0')
  397  	p += len + 1;
  398      }
  399  }
  400 diff --git a/elf/ifuncmain6pie.c b/elf/ifuncmain6pie.c
  401 index 04faeb86ef..4a01906836 100644
  402 --- a/elf/ifuncmain6pie.c
  403 +++ b/elf/ifuncmain6pie.c
  404 @@ -9,7 +9,6 @@
  405  #include "ifunc-sel.h"
  406  
  407  typedef int (*foo_p) (void);
  408 -extern foo_p foo_ptr;
  409  
  410  static int
  411  one (void)
  412 @@ -28,20 +27,17 @@ foo_ifunc (void)
  413  }
  414  
  415  extern int foo (void);
  416 -extern foo_p get_foo (void);
  417 +extern int call_foo (void);
  418  extern foo_p get_foo_p (void);
  419  
  420 -foo_p my_foo_ptr = foo;
  421 +foo_p foo_ptr = foo;
  422  
  423  int
  424  main (void)
  425  {
  426    foo_p p;
  427  
  428 -  p = get_foo ();
  429 -  if (p != foo)
  430 -    abort ();
  431 -  if ((*p) () != -30)
  432 +  if (call_foo () != -30)
  433      abort ();
  434  
  435    p = get_foo_p ();
  436 @@ -52,12 +48,8 @@ main (void)
  437  
  438    if (foo_ptr != foo)
  439      abort ();
  440 -  if (my_foo_ptr != foo)
  441 -    abort ();
  442    if ((*foo_ptr) () != -30)
  443      abort ();
  444 -  if ((*my_foo_ptr) () != -30)
  445 -    abort ();
  446    if (foo () != -30)
  447      abort ();
  448  
  449 diff --git a/elf/ifuncmod6.c b/elf/ifuncmod6.c
  450 index 2e16c1d06d..2f6d0715e6 100644
  451 --- a/elf/ifuncmod6.c
  452 +++ b/elf/ifuncmod6.c
  453 @@ -4,7 +4,7 @@ extern int foo (void);
  454  
  455  typedef int (*foo_p) (void);
  456  
  457 -foo_p foo_ptr = foo;
  458 +extern foo_p foo_ptr;
  459  
  460  foo_p
  461  get_foo_p (void)
  462 @@ -12,8 +12,8 @@ get_foo_p (void)
  463    return foo_ptr;
  464  }
  465  
  466 -foo_p
  467 -get_foo (void)
  468 +int
  469 +call_foo (void)
  470  {
  471 -  return foo;
  472 +  return foo ();
  473  }
  474 diff --git a/elf/rtld.c b/elf/rtld.c
  475 index 5b882163fa..14a42ed00a 100644
  476 --- a/elf/rtld.c
  477 +++ b/elf/rtld.c
  478 @@ -1534,10 +1534,10 @@ of this helper program; chances are you did not intend to run this program.\n\
  479      switch (ph[-1].p_type)
  480        {
  481        case PT_NOTE:
  482 -	_dl_process_pt_note (main_map, &ph[-1]);
  483 +	_dl_process_pt_note (main_map, -1, &ph[-1]);
  484  	break;
  485        case PT_GNU_PROPERTY:
  486 -	_dl_process_pt_gnu_property (main_map, &ph[-1]);
  487 +	_dl_process_pt_gnu_property (main_map, -1, &ph[-1]);
  488  	break;
  489        }
  490  
  491 diff --git a/elf/tst-env-setuid-tunables.c b/elf/tst-env-setuid-tunables.c
  492 index 971d5892b1..ca0c8c245c 100644
  493 --- a/elf/tst-env-setuid-tunables.c
  494 +++ b/elf/tst-env-setuid-tunables.c
  495 @@ -25,35 +25,76 @@
  496  #include "config.h"
  497  #undef _LIBC
  498  
  499 -#define test_parent test_parent_tunables
  500 -#define test_child test_child_tunables
  501 -
  502 -static int test_child_tunables (void);
  503 -static int test_parent_tunables (void);
  504 -
  505 -#include "tst-env-setuid.c"
  506 -
  507 -#define CHILD_VALSTRING_VALUE "glibc.malloc.mmap_threshold=4096"
  508 -#define PARENT_VALSTRING_VALUE \
  509 -  "glibc.malloc.check=2:glibc.malloc.mmap_threshold=4096"
  510 +#include <errno.h>
  511 +#include <fcntl.h>
  512 +#include <stdlib.h>
  513 +#include <stdint.h>
  514 +#include <stdio.h>
  515 +#include <string.h>
  516 +#include <sys/stat.h>
  517 +#include <sys/wait.h>
  518 +#include <unistd.h>
  519 +#include <intprops.h>
  520 +#include <array_length.h>
  521 +
  522 +#include <support/check.h>
  523 +#include <support/support.h>
  524 +#include <support/test-driver.h>
  525 +#include <support/capture_subprocess.h>
  526 +
  527 +const char *teststrings[] =
  528 +{
  529 +  "glibc.malloc.check=2:glibc.malloc.mmap_threshold=4096",
  530 +  "glibc.malloc.check=2:glibc.malloc.check=2:glibc.malloc.mmap_threshold=4096",
  531 +  "glibc.malloc.check=2:glibc.malloc.mmap_threshold=4096:glibc.malloc.check=2",
  532 +  "glibc.malloc.perturb=0x800",
  533 +  "glibc.malloc.perturb=0x800:glibc.malloc.mmap_threshold=4096",
  534 +  "glibc.malloc.perturb=0x800:not_valid.malloc.check=2:glibc.malloc.mmap_threshold=4096",
  535 +  "glibc.not_valid.check=2:glibc.malloc.mmap_threshold=4096",
  536 +  "not_valid.malloc.check=2:glibc.malloc.mmap_threshold=4096",
  537 +  "glibc.malloc.garbage=2:glibc.maoc.mmap_threshold=4096:glibc.malloc.check=2",
  538 +  "glibc.malloc.check=4:glibc.malloc.garbage=2:glibc.maoc.mmap_threshold=4096",
  539 +  ":glibc.malloc.garbage=2:glibc.malloc.check=1",
  540 +  "glibc.malloc.check=1:glibc.malloc.check=2",
  541 +  "not_valid.malloc.check=2",
  542 +  "glibc.not_valid.check=2",
  543 +};
  544 +
  545 +const char *resultstrings[] =
  546 +{
  547 +  "glibc.malloc.mmap_threshold=4096",
  548 +  "glibc.malloc.mmap_threshold=4096",
  549 +  "glibc.malloc.mmap_threshold=4096",
  550 +  "glibc.malloc.perturb=0x800",
  551 +  "glibc.malloc.perturb=0x800:glibc.malloc.mmap_threshold=4096",
  552 +  "glibc.malloc.perturb=0x800:glibc.malloc.mmap_threshold=4096",
  553 +  "glibc.malloc.mmap_threshold=4096",
  554 +  "glibc.malloc.mmap_threshold=4096",
  555 +  "",
  556 +  "",
  557 +  "",
  558 +  "",
  559 +  "",
  560 +  "",
  561 +};
  562  
  563  static int
  564 -test_child_tunables (void)
  565 +test_child (int off)
  566  {
  567    const char *val = getenv ("GLIBC_TUNABLES");
  568  
  569  #if HAVE_TUNABLES
  570 -  if (val != NULL && strcmp (val, CHILD_VALSTRING_VALUE) == 0)
  571 +  if (val != NULL && strcmp (val, resultstrings[off]) == 0)
  572      return 0;
  573  
  574    if (val != NULL)
  575 -    printf ("Unexpected GLIBC_TUNABLES VALUE %s\n", val);
  576 +    printf ("[%d] Unexpected GLIBC_TUNABLES VALUE %s\n", off, val);
  577  
  578    return 1;
  579  #else
  580    if (val != NULL)
  581      {
  582 -      printf ("GLIBC_TUNABLES not cleared\n");
  583 +      printf ("[%d] GLIBC_TUNABLES not cleared\n", off);
  584        return 1;
  585      }
  586    return 0;
  587 @@ -61,15 +102,48 @@ test_child_tunables (void)
  588  }
  589  
  590  static int
  591 -test_parent_tunables (void)
  592 +do_test (int argc, char **argv)
  593  {
  594 -  const char *val = getenv ("GLIBC_TUNABLES");
  595 +  /* Setgid child process.  */
  596 +  if (argc == 2)
  597 +    {
  598 +      if (getgid () == getegid ())
  599 +	/* This can happen if the file system is mounted nosuid.  */
  600 +	FAIL_UNSUPPORTED ("SGID failed: GID and EGID match (%jd)\n",
  601 +			  (intmax_t) getgid ());
  602  
  603 -  if (val != NULL && strcmp (val, PARENT_VALSTRING_VALUE) == 0)
  604 -    return 0;
  605 +      int ret = test_child (atoi (argv[1]));
  606  
  607 -  if (val != NULL)
  608 -    printf ("Unexpected GLIBC_TUNABLES VALUE %s\n", val);
  609 +      if (ret != 0)
  610 +	exit (1);
  611  
  612 -  return 1;
  613 +      exit (EXIT_SUCCESS);
  614 +    }
  615 +  else
  616 +    {
  617 +      int ret = 0;
  618 +
  619 +      /* Spawn tests.  */
  620 +      for (int i = 0; i < array_length (teststrings); i++)
  621 +	{
  622 +	  char buf[INT_BUFSIZE_BOUND (int)];
  623 +
  624 +	  printf ("Spawned test for %s (%d)\n", teststrings[i], i);
  625 +	  snprintf (buf, sizeof (buf), "%d\n", i);
  626 +	  if (setenv ("GLIBC_TUNABLES", teststrings[i], 1) != 0)
  627 +	    exit (1);
  628 +
  629 +	  int status = support_capture_subprogram_self_sgid (buf);
  630 +
  631 +	  /* Bail out early if unsupported.  */
  632 +	  if (WEXITSTATUS (status) == EXIT_UNSUPPORTED)
  633 +	    return EXIT_UNSUPPORTED;
  634 +
  635 +	  ret |= status;
  636 +	}
  637 +      return ret;
  638 +    }
  639  }
  640 +
  641 +#define TEST_FUNCTION_ARGV do_test
  642 +#include <support/test-driver.c>
  643 diff --git a/elf/tst-env-setuid.c b/elf/tst-env-setuid.c
  644 index 41dc79e83a..2dbccdb69e 100644
  645 --- a/elf/tst-env-setuid.c
  646 +++ b/elf/tst-env-setuid.c
  647 @@ -29,173 +29,12 @@
  648  #include <sys/wait.h>
  649  #include <unistd.h>
  650  
  651 +#include <support/check.h>
  652  #include <support/support.h>
  653  #include <support/test-driver.h>
  654 +#include <support/capture_subprocess.h>
  655  
  656  static char SETGID_CHILD[] = "setgid-child";
  657 -#define CHILD_STATUS 42
  658 -
  659 -/* Return a GID which is not our current GID, but is present in the
  660 -   supplementary group list.  */
  661 -static gid_t
  662 -choose_gid (void)
  663 -{
  664 -  const int count = 64;
  665 -  gid_t groups[count];
  666 -  int ret = getgroups (count, groups);
  667 -  if (ret < 0)
  668 -    {
  669 -      printf ("getgroups: %m\n");
  670 -      exit (1);
  671 -    }
  672 -  gid_t current = getgid ();
  673 -  for (int i = 0; i < ret; ++i)
  674 -    {
  675 -      if (groups[i] != current)
  676 -	return groups[i];
  677 -    }
  678 -  return 0;
  679 -}
  680 -
  681 -/* Spawn and execute a program and verify that it returns the CHILD_STATUS.  */
  682 -static pid_t
  683 -do_execve (char **args)
  684 -{
  685 -  pid_t kid = vfork ();
  686 -
  687 -  if (kid < 0)
  688 -    {
  689 -      printf ("vfork: %m\n");
  690 -      return -1;
  691 -    }
  692 -
  693 -  if (kid == 0)
  694 -    {
  695 -      /* Child process.  */
  696 -      execve (args[0], args, environ);
  697 -      _exit (-errno);
  698 -    }
  699 -
  700 -  if (kid < 0)
  701 -    return 1;
  702 -
  703 -  int status;
  704 -
  705 -  if (waitpid (kid, &status, 0) < 0)
  706 -    {
  707 -      printf ("waitpid: %m\n");
  708 -      return 1;
  709 -    }
  710 -
  711 -  if (WEXITSTATUS (status) == EXIT_UNSUPPORTED)
  712 -    return EXIT_UNSUPPORTED;
  713 -
  714 -  if (!WIFEXITED (status) || WEXITSTATUS (status) != CHILD_STATUS)
  715 -    {
  716 -      printf ("Unexpected exit status %d from child process\n",
  717 -	      WEXITSTATUS (status));
  718 -      return 1;
  719 -    }
  720 -  return 0;
  721 -}
  722 -
  723 -/* Copies the executable into a restricted directory, so that we can
  724 -   safely make it SGID with the TARGET group ID.  Then runs the
  725 -   executable.  */
  726 -static int
  727 -run_executable_sgid (gid_t target)
  728 -{
  729 -  char *dirname = xasprintf ("%s/tst-tunables-setuid.%jd",
  730 -			     test_dir, (intmax_t) getpid ());
  731 -  char *execname = xasprintf ("%s/bin", dirname);
  732 -  int infd = -1;
  733 -  int outfd = -1;
  734 -  int ret = 0;
  735 -  if (mkdir (dirname, 0700) < 0)
  736 -    {
  737 -      printf ("mkdir: %m\n");
  738 -      goto err;
  739 -    }
  740 -  infd = open ("/proc/self/exe", O_RDONLY);
  741 -  if (infd < 0)
  742 -    {
  743 -      printf ("open (/proc/self/exe): %m\n");
  744 -      goto err;
  745 -    }
  746 -  outfd = open (execname, O_WRONLY | O_CREAT | O_EXCL, 0700);
  747 -  if (outfd < 0)
  748 -    {
  749 -      printf ("open (%s): %m\n", execname);
  750 -      goto err;
  751 -    }
  752 -  char buf[4096];
  753 -  for (;;)
  754 -    {
  755 -      ssize_t rdcount = read (infd, buf, sizeof (buf));
  756 -      if (rdcount < 0)
  757 -	{
  758 -	  printf ("read: %m\n");
  759 -	  goto err;
  760 -	}
  761 -      if (rdcount == 0)
  762 -	break;
  763 -      char *p = buf;
  764 -      char *end = buf + rdcount;
  765 -      while (p != end)
  766 -	{
  767 -	  ssize_t wrcount = write (outfd, buf, end - p);
  768 -	  if (wrcount == 0)
  769 -	    errno = ENOSPC;
  770 -	  if (wrcount <= 0)
  771 -	    {
  772 -	      printf ("write: %m\n");
  773 -	      goto err;
  774 -	    }
  775 -	  p += wrcount;
  776 -	}
  777 -    }
  778 -  if (fchown (outfd, getuid (), target) < 0)
  779 -    {
  780 -      printf ("fchown (%s): %m\n", execname);
  781 -      goto err;
  782 -    }
  783 -  if (fchmod (outfd, 02750) < 0)
  784 -    {
  785 -      printf ("fchmod (%s): %m\n", execname);
  786 -      goto err;
  787 -    }
  788 -  if (close (outfd) < 0)
  789 -    {
  790 -      printf ("close (outfd): %m\n");
  791 -      goto err;
  792 -    }
  793 -  if (close (infd) < 0)
  794 -    {
  795 -      printf ("close (infd): %m\n");
  796 -      goto err;
  797 -    }
  798 -
  799 -  char *args[] = {execname, SETGID_CHILD, NULL};
  800 -
  801 -  ret = do_execve (args);
  802 -
  803 -err:
  804 -  if (outfd >= 0)
  805 -    close (outfd);
  806 -  if (infd >= 0)
  807 -    close (infd);
  808 -  if (execname)
  809 -    {
  810 -      unlink (execname);
  811 -      free (execname);
  812 -    }
  813 -  if (dirname)
  814 -    {
  815 -      rmdir (dirname);
  816 -      free (dirname);
  817 -    }
  818 -  return ret;
  819 -}
  820  
  821  #ifndef test_child
  822  static int
  823 @@ -256,40 +95,32 @@ do_test (int argc, char **argv)
  824    if (argc == 2 && strcmp (argv[1], SETGID_CHILD) == 0)
  825      {
  826        if (getgid () == getegid ())
  827 -	{
  828 -	  /* This can happen if the file system is mounted nosuid.  */
  829 -	  fprintf (stderr, "SGID failed: GID and EGID match (%jd)\n",
  830 -		   (intmax_t) getgid ());
  831 -	  exit (EXIT_UNSUPPORTED);
  832 -	}
  833 +	/* This can happen if the file system is mounted nosuid.  */
  834 +	FAIL_UNSUPPORTED ("SGID failed: GID and EGID match (%jd)\n",
  835 +			  (intmax_t) getgid ());
  836  
  837        int ret = test_child ();
  838  
  839        if (ret != 0)
  840  	exit (1);
  841  
  842 -      exit (CHILD_STATUS);
  843 +      exit (EXIT_SUCCESS);
  844      }
  845    else
  846      {
  847        if (test_parent () != 0)
  848  	exit (1);
  849  
  850 -      /* Try running a setgid program.  */
  851 -      gid_t target = choose_gid ();
  852 -      if (target == 0)
  853 -	{
  854 -	  fprintf (stderr,
  855 -		   "Could not find a suitable GID for user %jd, skipping test\n",
  856 -		   (intmax_t) getuid ());
  857 -	  exit (0);
  858 -	}
  859 +      int status = support_capture_subprogram_self_sgid (SETGID_CHILD);
  860  
  861 -      return run_executable_sgid (target);
  862 -    }
  863 +      if (WEXITSTATUS (status) == EXIT_UNSUPPORTED)
  864 +	return EXIT_UNSUPPORTED;
  865 +
  866 +      if (!WIFEXITED (status))
  867 +	FAIL_EXIT1 ("Unexpected exit status %d from child process\n", status);
  868  
  869 -  /* Something went wrong and our argv was corrupted.  */
  870 -  _exit (1);
  871 +      return 0;
  872 +    }
  873  }
  874  
  875  #define TEST_FUNCTION_ARGV do_test
  876 diff --git a/iconv/Versions b/iconv/Versions
  877 index 8a5f4cf780..d51af52fa3 100644
  878 --- a/iconv/Versions
  879 +++ b/iconv/Versions
  880 @@ -6,7 +6,9 @@ libc {
  881    GLIBC_PRIVATE {
  882      # functions shared with iconv program
  883      __gconv_get_alias_db; __gconv_get_cache; __gconv_get_modules_db;
  884 -    __gconv_open; __gconv_create_spec;
  885 +
  886 +    # functions used elsewhere in glibc
  887 +    __gconv_open; __gconv_create_spec; __gconv_destroy_spec;
  888  
  889      # function used by the gconv modules
  890      __gconv_transliterate;
  891 diff --git a/iconv/gconv_charset.c b/iconv/gconv_charset.c
  892 index 6ccd0773cc..4ba0aa99f5 100644
  893 --- a/iconv/gconv_charset.c
  894 +++ b/iconv/gconv_charset.c
  895 @@ -216,3 +216,13 @@ out:
  896    return ret;
  897  }
  898  libc_hidden_def (__gconv_create_spec)
  899 +
  900 +
  901 +void
  902 +__gconv_destroy_spec (struct gconv_spec *conv_spec)
  903 +{
  904 +  free (conv_spec->fromcode);
  905 +  free (conv_spec->tocode);
  906 +  return;
  907 +}
  908 +libc_hidden_def (__gconv_destroy_spec)
  909 diff --git a/iconv/gconv_charset.h b/iconv/gconv_charset.h
  910 index b39b09aea1..e9c122cf7e 100644
  911 --- a/iconv/gconv_charset.h
  912 +++ b/iconv/gconv_charset.h
  913 @@ -48,33 +48,6 @@
  914  #define GCONV_IGNORE_ERRORS_SUFFIX "IGNORE"
  915  
  916  
  917 -/* This function accepts the charset names of the source and destination of the
  918 -   conversion and populates *conv_spec with an equivalent conversion
  919 -   specification that may later be used by __gconv_open.  The charset names
  920 -   might contain options in the form of suffixes that alter the conversion,
  921 -   e.g. "ISO-10646/UTF-8/TRANSLIT".  It processes the charset names, ignoring
  922 -   and truncating any suffix options in fromcode, and processing and truncating
  923 -   any suffix options in tocode.  Supported suffix options ("TRANSLIT" or
  924 -   "IGNORE") when found in tocode lead to the corresponding flag in *conv_spec
  925 -   to be set to true.  Unrecognized suffix options are silently discarded.  If
  926 -   the function succeeds, it returns conv_spec back to the caller.  It returns
  927 -   NULL upon failure.  */
  928 -struct gconv_spec *
  929 -__gconv_create_spec (struct gconv_spec *conv_spec, const char *fromcode,
  930 -                     const char *tocode);
  931 -libc_hidden_proto (__gconv_create_spec)
  932 -
  933 -
  934 -/* This function frees all heap memory allocated by __gconv_create_spec.  */
  935 -static void __attribute__ ((unused))
  936 -gconv_destroy_spec (struct gconv_spec *conv_spec)
  937 -{
  938 -  free (conv_spec->fromcode);
  939 -  free (conv_spec->tocode);
  940 -  return;
  941 -}
  942 -
  943 -
  944  /* This function copies in-order, characters from the source 's' that are
  945     either alpha-numeric or one in one of these: "_-.,:/" - into the destination
  946     'wp' while dropping all other characters.  In the process, it converts all
  947 diff --git a/iconv/gconv_int.h b/iconv/gconv_int.h
  948 index e86938dae7..f721ce30ff 100644
  949 --- a/iconv/gconv_int.h
  950 +++ b/iconv/gconv_int.h
  951 @@ -152,6 +152,27 @@ extern int __gconv_open (struct gconv_spec *conv_spec,
  952                           __gconv_t *handle, int flags);
  953  libc_hidden_proto (__gconv_open)
  954  
  955 +/* This function accepts the charset names of the source and destination of the
  956 +   conversion and populates *conv_spec with an equivalent conversion
  957 +   specification that may later be used by __gconv_open.  The charset names
  958 +   might contain options in the form of suffixes that alter the conversion,
  959 +   e.g. "ISO-10646/UTF-8/TRANSLIT".  It processes the charset names, ignoring
  960 +   and truncating any suffix options in fromcode, and processing and truncating
  961 +   any suffix options in tocode.  Supported suffix options ("TRANSLIT" or
  962 +   "IGNORE") when found in tocode lead to the corresponding flag in *conv_spec
  963 +   to be set to true.  Unrecognized suffix options are silently discarded.  If
  964 +   the function succeeds, it returns conv_spec back to the caller.  It returns
  965 +   NULL upon failure.  */
  966 +extern struct gconv_spec *
  967 +__gconv_create_spec (struct gconv_spec *conv_spec, const char *fromcode,
  968 +                     const char *tocode);
  969 +libc_hidden_proto (__gconv_create_spec)
  970 +
  971 +/* This function frees all heap memory allocated by __gconv_create_spec.  */
  972 +extern void
  973 +__gconv_destroy_spec (struct gconv_spec *conv_spec);
  974 +libc_hidden_proto (__gconv_destroy_spec)
  975 +
  976  /* Free resources associated with transformation descriptor CD.  */
  977  extern int __gconv_close (__gconv_t cd)
  978       attribute_hidden;
  979 diff --git a/iconv/iconv_open.c b/iconv/iconv_open.c
  980 index dd54bc12e0..5b30055c04 100644
  981 --- a/iconv/iconv_open.c
  982 +++ b/iconv/iconv_open.c
  983 @@ -39,7 +39,7 @@ iconv_open (const char *tocode, const char *fromcode)
  984  
  985    int res = __gconv_open (&conv_spec, &cd, 0);
  986  
  987 -  gconv_destroy_spec (&conv_spec);
  988 +  __gconv_destroy_spec (&conv_spec);
  989  
  990    if (__builtin_expect (res, __GCONV_OK) != __GCONV_OK)
  991      {
  992 diff --git a/iconv/iconv_prog.c b/iconv/iconv_prog.c
  993 index b4334faa57..d59979759c 100644
  994 --- a/iconv/iconv_prog.c
  995 +++ b/iconv/iconv_prog.c
  996 @@ -184,7 +184,7 @@ main (int argc, char *argv[])
  997        /* Let's see whether we have these coded character sets.  */
  998        res = __gconv_open (&conv_spec, &cd, 0);
  999  
 1000 -      gconv_destroy_spec (&conv_spec);
 1001 +      __gconv_destroy_spec (&conv_spec);
 1002  
 1003        if (res != __GCONV_OK)
 1004  	{
 1005 diff --git a/iconv/tst-iconv_prog.sh b/iconv/tst-iconv_prog.sh
 1006 index 8298136b7f..d8db7b335c 100644
 1007 --- a/iconv/tst-iconv_prog.sh
 1008 +++ b/iconv/tst-iconv_prog.sh
 1009 @@ -102,12 +102,16 @@ hangarray=(
 1010  "\x00\x80;-c;IBM1161;UTF-8//TRANSLIT//IGNORE"
 1011  "\x00\xdb;-c;IBM1162;UTF-8//TRANSLIT//IGNORE"
 1012  "\x00\x70;-c;IBM12712;UTF-8//TRANSLIT//IGNORE"
 1013 -# These are known hangs that are yet to be fixed:
 1014 -# "\x00\x0f;-c;IBM1364;UTF-8"
 1015 -# "\x00\x0f;-c;IBM1371;UTF-8"
 1016 -# "\x00\x0f;-c;IBM1388;UTF-8"
 1017 -# "\x00\x0f;-c;IBM1390;UTF-8"
 1018 -# "\x00\x0f;-c;IBM1399;UTF-8"
 1019 +"\x00\x0f;-c;IBM1364;UTF-8"
 1020 +"\x0e\x0e;-c;IBM1364;UTF-8"
 1021 +"\x00\x0f;-c;IBM1371;UTF-8"
 1022 +"\x0e\x0e;-c;IBM1371;UTF-8"
 1023 +"\x00\x0f;-c;IBM1388;UTF-8"
 1024 +"\x0e\x0e;-c;IBM1388;UTF-8"
 1025 +"\x00\x0f;-c;IBM1390;UTF-8"
 1026 +"\x0e\x0e;-c;IBM1390;UTF-8"
 1027 +"\x00\x0f;-c;IBM1399;UTF-8"
 1028 +"\x0e\x0e;-c;IBM1399;UTF-8"
 1029  "\x00\x53;-c;IBM16804;UTF-8//TRANSLIT//IGNORE"
 1030  "\x00\x41;-c;IBM274;UTF-8//TRANSLIT//IGNORE"
 1031  "\x00\x41;-c;IBM275;UTF-8//TRANSLIT//IGNORE"
 1032 diff --git a/iconvdata/Makefile b/iconvdata/Makefile
 1033 index 4ec2741cdc..b67b4feeb4 100644
 1034 --- a/iconvdata/Makefile
 1035 +++ b/iconvdata/Makefile
 1036 @@ -1,4 +1,5 @@
 1037  # Copyright (C) 1997-2020 Free Software Foundation, Inc.
 1038 +# Copyright (C) The GNU Toolchain Authors.
 1039  # This file is part of the GNU C Library.
 1040  
 1041  # The GNU C Library is free software; you can redistribute it and/or
 1042 @@ -73,7 +74,8 @@ modules.so := $(addsuffix .so, $(modules))
 1043  ifeq (yes,$(build-shared))
 1044  tests = bug-iconv1 bug-iconv2 tst-loading tst-e2big tst-iconv4 bug-iconv4 \
 1045  	tst-iconv6 bug-iconv5 bug-iconv6 tst-iconv7 bug-iconv8 bug-iconv9 \
 1046 -	bug-iconv10 bug-iconv11 bug-iconv12 tst-iconv-big5-hkscs-to-2ucs4
 1047 +	bug-iconv10 bug-iconv11 bug-iconv12 tst-iconv-big5-hkscs-to-2ucs4 \
 1048 +	bug-iconv13 bug-iconv14 bug-iconv15
 1049  ifeq ($(have-thread-library),yes)
 1050  tests += bug-iconv3
 1051  endif
 1052 @@ -321,6 +323,10 @@ $(objpfx)bug-iconv10.out: $(objpfx)gconv-modules \
 1053  			  $(addprefix $(objpfx),$(modules.so))
 1054  $(objpfx)bug-iconv12.out: $(objpfx)gconv-modules \
 1055  			  $(addprefix $(objpfx),$(modules.so))
 1056 +$(objpfx)bug-iconv14.out: $(objpfx)gconv-modules \
 1057 +			  $(addprefix $(objpfx),$(modules.so))
 1058 +$(objpfx)bug-iconv15.out: $(addprefix $(objpfx), $(gconv-modules)) \
 1059 +			  $(addprefix $(objpfx),$(modules.so))
 1060  
 1061  $(objpfx)iconv-test.out: run-iconv-test.sh $(objpfx)gconv-modules \
 1062  			 $(addprefix $(objpfx),$(modules.so)) \
 1063 diff --git a/iconvdata/bug-iconv13.c b/iconvdata/bug-iconv13.c
 1064 new file mode 100644
 1065 index 0000000000..87aaff398e
 1066 --- /dev/null
 1067 +++ b/iconvdata/bug-iconv13.c
 1068 @@ -0,0 +1,53 @@
 1069 +/* bug 24973: Test EUC-KR module
 1070 +   Copyright (C) 2020 Free Software Foundation, Inc.
 1071 +   This file is part of the GNU C Library.
 1072 +
 1073 +   The GNU C Library is free software; you can redistribute it and/or
 1074 +   modify it under the terms of the GNU Lesser General Public
 1075 +   License as published by the Free Software Foundation; either
 1076 +   version 2.1 of the License, or (at your option) any later version.
 1077 +
 1078 +   The GNU C Library is distributed in the hope that it will be useful,
 1079 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
 1080 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 1081 +   Lesser General Public License for more details.
 1082 +
 1083 +   You should have received a copy of the GNU Lesser General Public
 1084 +   License along with the GNU C Library; if not, see
 1085 +   <https://www.gnu.org/licenses/>.  */
 1086 +
 1087 +#include <errno.h>
 1088 +#include <iconv.h>
 1089 +#include <stdio.h>
 1090 +#include <support/check.h>
 1091 +
 1092 +static int
 1093 +do_test (void)
 1094 +{
 1095 +  iconv_t cd = iconv_open ("UTF-8//IGNORE", "EUC-KR");
 1096 +  TEST_VERIFY_EXIT (cd != (iconv_t) -1);
 1097 +
 1098 +  /* 0xfe (->0x7e : row 94) and 0xc9 (->0x49 : row 41) are user-defined
 1099 +     areas, which are not allowed and should be skipped over due to
 1100 +     //IGNORE.  The trailing 0xfe also is an incomplete sequence, which
 1101 +     should be checked first.  */
 1102 +  char input[4] = { '\xc9', '\xa1', '\0', '\xfe' };
 1103 +  char *inptr = input;
 1104 +  size_t insize = sizeof (input);
 1105 +  char output[4];
 1106 +  char *outptr = output;
 1107 +  size_t outsize = sizeof (output);
 1108 +
 1109 +  /* This used to crash due to buffer overrun.  */
 1110 +  TEST_VERIFY (iconv (cd, &inptr, &insize, &outptr, &outsize) == (size_t) -1);
 1111 +  TEST_VERIFY (errno == EINVAL);
 1112 +  /* The conversion should produce one character, the converted null
 1113 +     character.  */
 1114 +  TEST_VERIFY (sizeof (output) - outsize == 1);
 1115 +
 1116 +  TEST_VERIFY_EXIT (iconv_close (cd) != -1);
 1117 +
 1118 +  return 0;
 1119 +}
 1120 +
 1121 +#include <support/test-driver.c>
 1122 diff --git a/iconvdata/bug-iconv14.c b/iconvdata/bug-iconv14.c
 1123 new file mode 100644
 1124 index 0000000000..902f140fa9
 1125 --- /dev/null
 1126 +++ b/iconvdata/bug-iconv14.c
 1127 @@ -0,0 +1,127 @@
 1128 +/* Assertion in ISO-2022-JP-3 due to two-character sequence (bug 27256).
 1129 +   Copyright (C) 2021 Free Software Foundation, Inc.
 1130 +   This file is part of the GNU C Library.
 1131 +
 1132 +   The GNU C Library is free software; you can redistribute it and/or
 1133 +   modify it under the terms of the GNU Lesser General Public
 1134 +   License as published by the Free Software Foundation; either
 1135 +   version 2.1 of the License, or (at your option) any later version.
 1136 +
 1137 +   The GNU C Library is distributed in the hope that it will be useful,
 1138 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
 1139 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 1140 +   Lesser General Public License for more details.
 1141 +
 1142 +   You should have received a copy of the GNU Lesser General Public
 1143 +   License along with the GNU C Library; if not, see
 1144 +   <https://www.gnu.org/licenses/>.  */
 1145 +
 1146 +#include <iconv.h>
 1147 +#include <string.h>
 1148 +#include <errno.h>
 1149 +#include <support/check.h>
 1150 +
 1151 +/* Use an escape sequence to return to the initial state.  */
 1152 +static void
 1153 +with_escape_sequence (void)
 1154 +{
 1155 +  iconv_t c = iconv_open ("UTF-8", "ISO-2022-JP-3");
 1156 +  TEST_VERIFY_EXIT (c != (iconv_t) -1);
 1157 +
 1158 +  char in[] = "\e$(O+D\e(B";
 1159 +  char *inbuf = in;
 1160 +  size_t inleft = strlen (in);
 1161 +  char out[3];                  /* Space for one output character.  */
 1162 +  char *outbuf;
 1163 +  size_t outleft;
 1164 +
 1165 +  outbuf = out;
 1166 +  outleft = sizeof (out);
 1167 +  TEST_COMPARE (iconv (c, &inbuf, &inleft, &outbuf, &outleft), (size_t) -1);
 1168 +  TEST_COMPARE (errno, E2BIG);
 1169 +  TEST_COMPARE (inleft, 3);
 1170 +  TEST_COMPARE (inbuf - in, strlen (in) - 3);
 1171 +  TEST_COMPARE (outleft, sizeof (out) - 2);
 1172 +  TEST_COMPARE (outbuf - out, 2);
 1173 +  TEST_COMPARE (out[0] & 0xff, 0xc3);
 1174 +  TEST_COMPARE (out[1] & 0xff, 0xa6);
 1175 +
 1176 +  /* Return to the initial shift state, producing the pending
 1177 +     character.  */
 1178 +  outbuf = out;
 1179 +  outleft = sizeof (out);
 1180 +  TEST_COMPARE (iconv (c, &inbuf, &inleft, &outbuf, &outleft), 0);
 1181 +  TEST_COMPARE (inleft, 0);
 1182 +  TEST_COMPARE (inbuf - in, strlen (in));
 1183 +  TEST_COMPARE (outleft, sizeof (out) - 2);
 1184 +  TEST_COMPARE (outbuf - out, 2);
 1185 +  TEST_COMPARE (out[0] & 0xff, 0xcc);
 1186 +  TEST_COMPARE (out[1] & 0xff, 0x80);
 1187 +
 1188 +  /* Nothing should be flushed the second time.  */
 1189 +  outbuf = out;
 1190 +  outleft = sizeof (out);
 1191 +  TEST_COMPARE (iconv (c, NULL, 0, &outbuf, &outleft), 0);
 1192 +  TEST_COMPARE (outleft, sizeof (out));
 1193 +  TEST_COMPARE (outbuf - out, 0);
 1194 +  TEST_COMPARE (out[0] & 0xff, 0xcc);
 1195 +  TEST_COMPARE (out[1] & 0xff, 0x80);
 1196 +
 1197 +  TEST_COMPARE (iconv_close (c), 0);
 1198 +}
 1199 +
 1200 +/* Use an explicit flush to return to the initial state.  */
 1201 +static void
 1202 +with_flush (void)
 1203 +{
 1204 +  iconv_t c = iconv_open ("UTF-8", "ISO-2022-JP-3");
 1205 +  TEST_VERIFY_EXIT (c != (iconv_t) -1);
 1206 +
 1207 +  char in[] = "\e$(O+D";
 1208 +  char *inbuf = in;
 1209 +  size_t inleft = strlen (in);
 1210 +  char out[3];                  /* Space for one output character.  */
 1211 +  char *outbuf;
 1212 +  size_t outleft;
 1213 +
 1214 +  outbuf = out;
 1215 +  outleft = sizeof (out);
 1216 +  TEST_COMPARE (iconv (c, &inbuf, &inleft, &outbuf, &outleft), (size_t) -1);
 1217 +  TEST_COMPARE (errno, E2BIG);
 1218 +  TEST_COMPARE (inleft, 0);
 1219 +  TEST_COMPARE (inbuf - in, strlen (in));
 1220 +  TEST_COMPARE (outleft, sizeof (out) - 2);
 1221 +  TEST_COMPARE (outbuf - out, 2);
 1222 +  TEST_COMPARE (out[0] & 0xff, 0xc3);
 1223 +  TEST_COMPARE (out[1] & 0xff, 0xa6);
 1224 +
 1225 +  /* Flush the pending character.  */
 1226 +  outbuf = out;
 1227 +  outleft = sizeof (out);
 1228 +  TEST_COMPARE (iconv (c, NULL, 0, &outbuf, &outleft), 0);
 1229 +  TEST_COMPARE (outleft, sizeof (out) - 2);
 1230 +  TEST_COMPARE (outbuf - out, 2);
 1231 +  TEST_COMPARE (out[0] & 0xff, 0xcc);
 1232 +  TEST_COMPARE (out[1] & 0xff, 0x80);
 1233 +
 1234 +  /* Nothing should be flushed the second time.  */
 1235 +  outbuf = out;
 1236 +  outleft = sizeof (out);
 1237 +  TEST_COMPARE (iconv (c, NULL, 0, &outbuf, &outleft), 0);
 1238 +  TEST_COMPARE (outleft, sizeof (out));
 1239 +  TEST_COMPARE (outbuf - out, 0);
 1240 +  TEST_COMPARE (out[0] & 0xff, 0xcc);
 1241 +  TEST_COMPARE (out[1] & 0xff, 0x80);
 1242 +
 1243 +  TEST_COMPARE (iconv_close (c), 0);
 1244 +}
 1245 +
 1246 +static int
 1247 +do_test (void)
 1248 +{
 1249 +  with_escape_sequence ();
 1250 +  with_flush ();
 1251 +  return 0;
 1252 +}
 1253 +
 1254 +#include <support/test-driver.c>
 1255 diff --git a/iconvdata/bug-iconv15.c b/iconvdata/bug-iconv15.c
 1256 new file mode 100644
 1257 index 0000000000..cc04bd0313
 1258 --- /dev/null
 1259 +++ b/iconvdata/bug-iconv15.c
 1260 @@ -0,0 +1,60 @@
 1261 +/* Bug 28524: Conversion from ISO-2022-JP-3 with iconv
 1262 +   may emit spurious NUL character on state reset.
 1263 +   Copyright (C) The GNU Toolchain Authors.
 1264 +   This file is part of the GNU C Library.
 1265 +
 1266 +   The GNU C Library is free software; you can redistribute it and/or
 1267 +   modify it under the terms of the GNU Lesser General Public
 1268 +   License as published by the Free Software Foundation; either
 1269 +   version 2.1 of the License, or (at your option) any later version.
 1270 +
 1271 +   The GNU C Library is distributed in the hope that it will be useful,
 1272 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
 1273 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 1274 +   Lesser General Public License for more details.
 1275 +
 1276 +   You should have received a copy of the GNU Lesser General Public
 1277 +   License along with the GNU C Library; if not, see
 1278 +   <https://www.gnu.org/licenses/>.  */
 1279 +
 1280 +#include <stddef.h>
 1281 +#include <iconv.h>
 1282 +#include <support/check.h>
 1283 +
 1284 +static int
 1285 +do_test (void)
 1286 +{
 1287 +  char in[] = "\x1b(I";
 1288 +  char *inbuf = in;
 1289 +  size_t inleft = sizeof (in) - 1;
 1290 +  char out[1];
 1291 +  char *outbuf = out;
 1292 +  size_t outleft = sizeof (out);
 1293 +  iconv_t cd;
 1294 +
 1295 +  cd = iconv_open ("UTF8", "ISO-2022-JP-3");
 1296 +  TEST_VERIFY_EXIT (cd != (iconv_t) -1);
 1297 +
 1298 +  /* First call to iconv should alter internal state.
 1299 +     Now, JISX0201_Kana_set is selected and
 1300 +     state value != ASCII_set.  */
 1301 +  TEST_VERIFY (iconv (cd, &inbuf, &inleft, &outbuf, &outleft) != (size_t) -1);
 1302 +
 1303 +  /* No bytes should have been added to
 1304 +     the output buffer at this point.  */
 1305 +  TEST_VERIFY (outbuf == out);
 1306 +  TEST_VERIFY (outleft == sizeof (out));
 1307 +
 1308 +  /* Second call shall emit spurious NUL character in unpatched glibc.  */
 1309 +  TEST_VERIFY (iconv (cd, NULL, NULL, &outbuf, &outleft) != (size_t) -1);
 1310 +
 1311 +  /* No characters are expected to be produced.  */
 1312 +  TEST_VERIFY (outbuf == out);
 1313 +  TEST_VERIFY (outleft == sizeof (out));
 1314 +
 1315 +  TEST_VERIFY_EXIT (iconv_close (cd) != -1);
 1316 +
 1317 +  return 0;
 1318 +}
 1319 +
 1320 +#include <support/test-driver.c>
 1321 diff --git a/iconvdata/euc-kr.c b/iconvdata/euc-kr.c
 1322 index b0d56cf3ee..1045bae926 100644
 1323 --- a/iconvdata/euc-kr.c
 1324 +++ b/iconvdata/euc-kr.c
 1325 @@ -80,11 +80,7 @@ euckr_from_ucs4 (uint32_t ch, unsigned char *cp)
 1326  									      \
 1327      if (ch <= 0x9f)							      \
 1328        ++inptr;								      \
 1329 -    /* 0xfe(->0x7e : row 94) and 0xc9(->0x59 : row 41) are		      \
 1330 -       user-defined areas.  */						      \
 1331 -    else if (__builtin_expect (ch == 0xa0, 0)				      \
 1332 -	     || __builtin_expect (ch > 0xfe, 0)				      \
 1333 -	     || __builtin_expect (ch == 0xc9, 0))			      \
 1334 +    else if (__glibc_unlikely (ch == 0xa0))				      \
 1335        {									      \
 1336  	/* This is illegal.  */						      \
 1337  	STANDARD_FROM_LOOP_ERR_HANDLER (1);				      \
 1338 diff --git a/iconvdata/ibm1364.c b/iconvdata/ibm1364.c
 1339 index 49e7267ab4..521f0825b7 100644
 1340 --- a/iconvdata/ibm1364.c
 1341 +++ b/iconvdata/ibm1364.c
 1342 @@ -158,24 +158,14 @@ enum
 1343  									      \
 1344      if (__builtin_expect (ch, 0) == SO)					      \
 1345        {									      \
 1346 -	/* Shift OUT, change to DBCS converter.  */			      \
 1347 -	if (curcs == db)						      \
 1348 -	  {								      \
 1349 -	    result = __GCONV_ILLEGAL_INPUT;				      \
 1350 -	    break;							      \
 1351 -	  }								      \
 1352 +	/* Shift OUT, change to DBCS converter (redundant escape okay).  */   \
 1353  	curcs = db;							      \
 1354  	++inptr;							      \
 1355  	continue;							      \
 1356        }									      \
 1357      if (__builtin_expect (ch, 0) == SI)					      \
 1358        {									      \
 1359 -	/* Shift IN, change to SBCS converter.  */			      \
 1360 -	if (curcs == sb)						      \
 1361 -	  {								      \
 1362 -	    result = __GCONV_ILLEGAL_INPUT;				      \
 1363 -	    break;							      \
 1364 -	  }								      \
 1365 +	/* Shift IN, change to SBCS converter (redundant escape okay).  */    \
 1366  	curcs = sb;							      \
 1367  	++inptr;							      \
 1368  	continue;							      \
 1369 diff --git a/iconvdata/iso-2022-jp-3.c b/iconvdata/iso-2022-jp-3.c
 1370 index 8c3b7e627e..c7b470db61 100644
 1371 --- a/iconvdata/iso-2022-jp-3.c
 1372 +++ b/iconvdata/iso-2022-jp-3.c
 1373 @@ -1,5 +1,6 @@
 1374  /* Conversion module for ISO-2022-JP-3.
 1375     Copyright (C) 1998-2020 Free Software Foundation, Inc.
 1376 +   Copyright (C) The GNU Toolchain Authors.
 1377     This file is part of the GNU C Library.
 1378     Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998,
 1379     and Bruno Haible <bruno@clisp.org>, 2002.
 1380 @@ -67,10 +68,15 @@ enum
 1381    CURRENT_SEL_MASK = 7 << 3
 1382  };
 1383  
 1384 -/* During UCS-4 to ISO-2022-JP-3 conversion, the COUNT element of the state
 1385 -   also contains the last two bytes to be output, shifted by 6 bits, and a
 1386 -   one-bit indicator whether they must be preceded by the shift sequence,
 1387 -   in bit 22.  */
 1388 +/* During UCS-4 to ISO-2022-JP-3 conversion, the COUNT element of the
 1389 +   state also contains the last two bytes to be output, shifted by 6
 1390 +   bits, and a one-bit indicator whether they must be preceded by the
 1391 +   shift sequence, in bit 22.  During ISO-2022-JP-3 to UCS-4
 1392 +   conversion, COUNT may also contain a non-zero pending wide
 1393 +   character, shifted by six bits.  This happens for certain inputs in
 1394 +   JISX0213_1_2004_set and JISX0213_2_set if the second wide character
 1395 +   in a combining sequence cannot be written because the buffer is
 1396 +   full.  */
 1397  
 1398  /* Since this is a stateful encoding we have to provide code which resets
 1399     the output state to the initial state.  This has to be done during the
 1400 @@ -80,10 +86,27 @@ enum
 1401      {									      \
 1402        if (FROM_DIRECTION)						      \
 1403  	{								      \
 1404 -	  /* It's easy, we don't have to emit anything, we just reset the     \
 1405 -	     state for the input.  */					      \
 1406 -	  data->__statep->__count &= 7;					      \
 1407 -	  data->__statep->__count |= ASCII_set;				      \
 1408 +	  uint32_t ch = data->__statep->__count >> 6;			      \
 1409 +									      \
 1410 +	  if (__glibc_unlikely (ch != 0))				      \
 1411 +	    {								      \
 1412 +	      if (__glibc_likely (outbuf + 4 <= outend))		      \
 1413 +		{							      \
 1414 +		  /* Write out the last character.  */			      \
 1415 +		  put32u (outbuf, ch);					      \
 1416 +		  outbuf += 4;						      \
 1417 +		  data->__statep->__count &= 7;				      \
 1418 +		  data->__statep->__count |= ASCII_set;			      \
 1419 +		}							      \
 1420 +	      else							      \
 1421 +		/* We don't have enough room in the output buffer.  */	      \
 1422 +		status = __GCONV_FULL_OUTPUT;				      \
 1423 +	    }								      \
 1424 +	  else								      \
 1425 +	    {								      \
 1426 +	      data->__statep->__count &= 7;				      \
 1427 +	      data->__statep->__count |= ASCII_set;			      \
 1428 +	    }								      \
 1429  	}								      \
 1430        else								      \
 1431  	{								      \
 1432 @@ -151,7 +174,21 @@ enum
 1433  #define LOOPFCT			FROM_LOOP
 1434  #define BODY \
 1435    {									      \
 1436 -    uint32_t ch = *inptr;						      \
 1437 +    uint32_t ch;							      \
 1438 +									      \
 1439 +    /* Output any pending character.  */				      \
 1440 +    ch = set >> 6;							      \
 1441 +    if (__glibc_unlikely (ch != 0))					      \
 1442 +      {									      \
 1443 +	put32 (outptr, ch);						      \
 1444 +	outptr += 4;							      \
 1445 +	/* Remove the pending character, but preserve state bits.  */	      \
 1446 +	set &= (1 << 6) - 1;						      \
 1447 +	continue;							      \
 1448 +      }									      \
 1449 +									      \
 1450 +    /* Otherwise read the next input byte.  */				      \
 1451 +    ch = *inptr;							      \
 1452  									      \
 1453      /* Recognize escape sequences.  */					      \
 1454      if (__glibc_unlikely (ch == ESC))					      \
 1455 @@ -297,21 +334,25 @@ enum
 1456  	    uint32_t u1 = __jisx0213_to_ucs_combining[ch - 1][0];	      \
 1457  	    uint32_t u2 = __jisx0213_to_ucs_combining[ch - 1][1];	      \
 1458  									      \
 1459 +	    inptr += 2;							      \
 1460 +									      \
 1461 +	    put32 (outptr, u1);						      \
 1462 +	    outptr += 4;						      \
 1463 +									      \
 1464  	    /* See whether we have room for two characters.  */		      \
 1465 -	    if (outptr + 8 <= outend)					      \
 1466 +	    if (outptr + 4 <= outend)					      \
 1467  	      {								      \
 1468 -		inptr += 2;						      \
 1469 -		put32 (outptr, u1);					      \
 1470 -		outptr += 4;						      \
 1471  		put32 (outptr, u2);					      \
 1472  		outptr += 4;						      \
 1473  		continue;						      \
 1474  	      }								      \
 1475 -	    else							      \
 1476 -	      {								      \
 1477 -		result = __GCONV_FULL_OUTPUT;				      \
 1478 -		break;							      \
 1479 -	      }								      \
 1480 +									      \
 1481 +	    /* Otherwise store only the first character now, and	      \
 1482 +	       put the second one into the queue.  */			      \
 1483 +	    set |= u2 << 6;						      \
 1484 +	    /* Tell the caller why we terminate the loop.  */		      \
 1485 +	    result = __GCONV_FULL_OUTPUT;				      \
 1486 +	    break;							      \
 1487  	  }								      \
 1488  									      \
 1489  	inptr += 2;							      \
 1490 diff --git a/iconvdata/ksc5601.h b/iconvdata/ksc5601.h
 1491 index d3eb3a4ff8..f5cdc72797 100644
 1492 --- a/iconvdata/ksc5601.h
 1493 +++ b/iconvdata/ksc5601.h
 1494 @@ -50,15 +50,15 @@ ksc5601_to_ucs4 (const unsigned char **s, size_t avail, unsigned char offset)
 1495    unsigned char ch2;
 1496    int idx;
 1497  
 1498 +  if (avail < 2)
 1499 +    return 0;
 1500 +
 1501    /* row 94(0x7e) and row 41(0x49) are user-defined area in KS C 5601 */
 1502  
 1503    if (ch < offset || (ch - offset) <= 0x20 || (ch - offset) >= 0x7e
 1504        || (ch - offset) == 0x49)
 1505      return __UNKNOWN_10646_CHAR;
 1506  
 1507 -  if (avail < 2)
 1508 -    return 0;
 1509 -
 1510    ch2 = (*s)[1];
 1511    if (ch2 < offset || (ch2 - offset) <= 0x20 || (ch2 - offset) >= 0x7f)
 1512      return __UNKNOWN_10646_CHAR;
 1513 diff --git a/intl/dcigettext.c b/intl/dcigettext.c
 1514 index 2e7c662bc7..bd332e71da 100644
 1515 --- a/intl/dcigettext.c
 1516 +++ b/intl/dcigettext.c
 1517 @@ -1120,15 +1120,18 @@ _nl_find_msg (struct loaded_l10nfile *domain_file,
 1518  
 1519  # ifdef _LIBC
 1520  
 1521 -		      struct gconv_spec conv_spec
 1522 -		        = { .fromcode = norm_add_slashes (charset, ""),
 1523 -		            .tocode = norm_add_slashes (outcharset, ""),
 1524 -		            /* We always want to use transliteration.  */
 1525 -		            .translit = true,
 1526 -		            .ignore = false
 1527 -		          };
 1528 +		      struct gconv_spec conv_spec;
 1529 +
 1530 +                      __gconv_create_spec (&conv_spec, charset, outcharset);
 1531 +
 1532 +		      /* We always want to use transliteration.  */
 1533 +                      conv_spec.translit = true;
 1534 +
 1535  		      int r = __gconv_open (&conv_spec, &convd->conv,
 1536  		                            GCONV_AVOID_NOCONV);
 1537 +
 1538 +                      __gconv_destroy_spec (&conv_spec);
 1539 +
 1540  		      if (__builtin_expect (r != __GCONV_OK, 0))
 1541  			{
 1542  			  /* If the output encoding is the same there is
 1543 diff --git a/intl/tst-codeset.c b/intl/tst-codeset.c
 1544 index fd70432eca..e9f6e5e09f 100644
 1545 --- a/intl/tst-codeset.c
 1546 +++ b/intl/tst-codeset.c
 1547 @@ -22,13 +22,11 @@
 1548  #include <stdio.h>
 1549  #include <stdlib.h>
 1550  #include <string.h>
 1551 +#include <support/check.h>
 1552  
 1553  static int
 1554  do_test (void)
 1555  {
 1556 -  char *s;
 1557 -  int result = 0;
 1558 -
 1559    unsetenv ("LANGUAGE");
 1560    unsetenv ("OUTPUT_CHARSET");
 1561    setlocale (LC_ALL, "de_DE.ISO-8859-1");
 1562 @@ -36,25 +34,21 @@ do_test (void)
 1563    bindtextdomain ("codeset", OBJPFX "domaindir");
 1564  
 1565    /* Here we expect output in ISO-8859-1.  */
 1566 -  s = gettext ("cheese");
 1567 -  if (strcmp (s, "K\344se"))
 1568 -    {
 1569 -      printf ("call 1 returned: %s\n", s);
 1570 -      result = 1;
 1571 -    }
 1572 +  TEST_COMPARE_STRING (gettext ("cheese"), "K\344se");
 1573  
 1574 +  /* Here we expect output in UTF-8.  */
 1575    bind_textdomain_codeset ("codeset", "UTF-8");
 1576 +  TEST_COMPARE_STRING (gettext ("cheese"), "K\303\244se");
 1577  
 1578 -  /* Here we expect output in UTF-8.  */
 1579 -  s = gettext ("cheese");
 1580 -  if (strcmp (s, "K\303\244se"))
 1581 -    {
 1582 -      printf ("call 2 returned: %s\n", s);
 1583 -      result = 1;
 1584 -    }
 1585 -
 1586 -  return result;
 1587 +  /* `a with umlaut' is transliterated to `ae'.  */
 1588 +  bind_textdomain_codeset ("codeset", "ASCII//TRANSLIT");
 1589 +  TEST_COMPARE_STRING (gettext ("cheese"), "Kaese");
 1590 +
 1591 +  /* Transliteration also works by default even if not set.  */
 1592 +  bind_textdomain_codeset ("codeset", "ASCII");
 1593 +  TEST_COMPARE_STRING (gettext ("cheese"), "Kaese");
 1594 +
 1595 +  return 0;
 1596  }
 1597  
 1598 -#define TEST_FUNCTION do_test ()
 1599 -#include "../test-skeleton.c"
 1600 +#include <support/test-driver.c>
 1601 diff --git a/malloc/Makefile b/malloc/Makefile
 1602 index e22cbde22d..5093e8730e 100644
 1603 --- a/malloc/Makefile
 1604 +++ b/malloc/Makefile
 1605 @@ -62,6 +62,16 @@ endif
 1606  tests += $(tests-static)
 1607  test-srcs = tst-mtrace
 1608  
 1609 +# These tests either are run with MALLOC_CHECK_=3 by default or do not work
 1610 +# with MALLOC_CHECK_=3 because they expect a specific failure.
 1611 +tests-exclude-mcheck = tst-mcheck tst-malloc-usable \
 1612 +	tst-interpose-nothread tst-interpose-static-nothread \
 1613 +	tst-interpose-static-thread tst-malloc-too-large \
 1614 +	tst-mxfast tst-safe-linking
 1615 +
 1616 +# Run all tests with MALLOC_CHECK_=3
 1617 +tests-mcheck = $(filter-out $(tests-exclude-mcheck),$(tests))
 1618 +
 1619  routines = malloc morecore mcheck mtrace obstack reallocarray \
 1620    scratch_buffer_grow scratch_buffer_grow_preserve \
 1621    scratch_buffer_set_array_size \
 1622 @@ -100,6 +110,11 @@ $(objpfx)tst-malloc-thread-exit: $(shared-thread-library)
 1623  $(objpfx)tst-malloc-thread-fail: $(shared-thread-library)
 1624  $(objpfx)tst-malloc-fork-deadlock: $(shared-thread-library)
 1625  $(objpfx)tst-malloc-stats-cancellation: $(shared-thread-library)
 1626 +$(objpfx)tst-malloc-backtrace-mcheck: $(shared-thread-library)
 1627 +$(objpfx)tst-malloc-thread-exit-mcheck: $(shared-thread-library)
 1628 +$(objpfx)tst-malloc-thread-fail-mcheck: $(shared-thread-library)
 1629 +$(objpfx)tst-malloc-fork-deadlock-mcheck: $(shared-thread-library)
 1630 +$(objpfx)tst-malloc-stats-cancellation-mcheck: $(shared-thread-library)
 1631  
 1632  # Export the __malloc_initialize_hook variable to libc.so.
 1633  LDFLAGS-tst-mallocstate = -rdynamic
 1634 @@ -239,6 +254,8 @@ $(tests:%=$(objpfx)%.o): CPPFLAGS += -DTEST_NO_MALLOPT
 1635  $(objpfx)tst-interpose-nothread: $(objpfx)tst-interpose-aux-nothread.o
 1636  $(objpfx)tst-interpose-thread: \
 1637    $(objpfx)tst-interpose-aux-thread.o $(shared-thread-library)
 1638 +$(objpfx)tst-interpose-thread-mcheck: \
 1639 +  $(objpfx)tst-interpose-aux-thread.o $(shared-thread-library)
 1640  $(objpfx)tst-interpose-static-nothread: $(objpfx)tst-interpose-aux-nothread.o
 1641  $(objpfx)tst-interpose-static-thread: \
 1642    $(objpfx)tst-interpose-aux-thread.o $(static-thread-library)
 1643 @@ -256,3 +273,6 @@ $(objpfx)tst-dynarray-fail-mem.out: $(objpfx)tst-dynarray-fail.out
 1644  $(objpfx)tst-malloc-tcache-leak: $(shared-thread-library)
 1645  $(objpfx)tst-malloc_info: $(shared-thread-library)
 1646  $(objpfx)tst-mallocfork2: $(shared-thread-library)
 1647 +$(objpfx)tst-malloc-tcache-leak-mcheck: $(shared-thread-library)
 1648 +$(objpfx)tst-malloc_info-mcheck: $(shared-thread-library)
 1649 +$(objpfx)tst-mallocfork2-mcheck: $(shared-thread-library)
 1650 diff --git a/manual/tunables.texi b/manual/tunables.texi
 1651 index 23ef0d40e7..d72d7a5ec0 100644
 1652 --- a/manual/tunables.texi
 1653 +++ b/manual/tunables.texi
 1654 @@ -432,7 +432,11 @@ set shared cache size in bytes for use in memory and string routines.
 1655  
 1656  @deftp Tunable glibc.cpu.x86_non_temporal_threshold
 1657  The @code{glibc.cpu.x86_non_temporal_threshold} tunable allows the user
 1658 -to set threshold in bytes for non temporal store.
 1659 +to set threshold in bytes for non temporal store. Non temporal stores
 1660 +give a hint to the hardware to move data directly to memory without
 1661 +displacing other data from the cache. This tunable is used by some
 1662 +platforms to determine when to use non temporal stores in operations
 1663 +like memmove and memcpy.
 1664  
 1665  This tunable is specific to i386 and x86-64.
 1666  @end deftp
 1667 diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h
 1668 index 19d9cc5cfe..38221d0b2a 100644
 1669 --- a/misc/sys/cdefs.h
 1670 +++ b/misc/sys/cdefs.h
 1671 @@ -124,13 +124,10 @@
 1672  #define __bos0(ptr) __builtin_object_size (ptr, 0)
 1673  
 1674  #if __GNUC_PREREQ (4,3)
 1675 -# define __warndecl(name, msg) \
 1676 -  extern void name (void) __attribute__((__warning__ (msg)))
 1677  # define __warnattr(msg) __attribute__((__warning__ (msg)))
 1678  # define __errordecl(name, msg) \
 1679    extern void name (void) __attribute__((__error__ (msg)))
 1680  #else
 1681 -# define __warndecl(name, msg) extern void name (void)
 1682  # define __warnattr(msg)
 1683  # define __errordecl(name, msg) extern void name (void)
 1684  #endif
 1685 diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
 1686 index 2cba3da38c..c217cda608 100644
 1687 --- a/nptl/pthread_create.c
 1688 +++ b/nptl/pthread_create.c
 1689 @@ -416,8 +416,6 @@ START_THREAD_DEFN
 1690    unwind_buf.priv.data.prev = NULL;
 1691    unwind_buf.priv.data.cleanup = NULL;
 1692  
 1693 -  __libc_signal_restore_set (&pd->sigmask);
 1694 -
 1695    /* Allow setxid from now onwards.  */
 1696    if (__glibc_unlikely (atomic_exchange_acq (&pd->setxid_futex, 0) == -2))
 1697      futex_wake (&pd->setxid_futex, 1, FUTEX_PRIVATE);
 1698 @@ -427,6 +425,8 @@ START_THREAD_DEFN
 1699        /* Store the new cleanup handler info.  */
 1700        THREAD_SETMEM (pd, cleanup_jmp_buf, &unwind_buf);
 1701  
 1702 +      __libc_signal_restore_set (&pd->sigmask);
 1703 +
 1704        /* We are either in (a) or (b), and in either case we either own
 1705           PD already (2) or are about to own PD (1), and so our only
 1706  	 restriction would be that we can't free PD until we know we
 1707 diff --git a/nscd/netgroupcache.c b/nscd/netgroupcache.c
 1708 index 88c69d1e9c..381aa721ef 100644
 1709 --- a/nscd/netgroupcache.c
 1710 +++ b/nscd/netgroupcache.c
 1711 @@ -248,7 +248,7 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,
 1712  					     : NULL);
 1713  				    ndomain = (ndomain ? newbuf + ndomaindiff
 1714  					       : NULL);
 1715 -				    buffer = newbuf;
 1716 +				    *tofreep = buffer = newbuf;
 1717  				  }
 1718  
 1719  				nhost = memcpy (buffer + bufused,
 1720 @@ -319,7 +319,7 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,
 1721  		    else if (status == NSS_STATUS_TRYAGAIN && e == ERANGE)
 1722  		      {
 1723  			buflen *= 2;
 1724 -			buffer = xrealloc (buffer, buflen);
 1725 +			*tofreep = buffer = xrealloc (buffer, buflen);
 1726  		      }
 1727  		    else if (status == NSS_STATUS_RETURN
 1728  			     || status == NSS_STATUS_NOTFOUND
 1729 diff --git a/nss/tst-nss-files-hosts-long.root/etc/nsswitch.conf b/nss/tst-nss-files-hosts-long.root/etc/nsswitch.conf
 1730 new file mode 100644
 1731 index 0000000000..5b0c6a4199
 1732 --- /dev/null
 1733 +++ b/nss/tst-nss-files-hosts-long.root/etc/nsswitch.conf
 1734 @@ -0,0 +1 @@
 1735 +hosts: files
 1736 diff --git a/posix/bits/unistd.h b/posix/bits/unistd.h
 1737 index 725a83eb0d..7e5bb6fb1e 100644
 1738 --- a/posix/bits/unistd.h
 1739 +++ b/posix/bits/unistd.h
 1740 @@ -193,10 +193,9 @@ __NTH (readlinkat (int __fd, const char *__restrict __path,
 1741  #endif
 1742  
 1743  extern char *__getcwd_chk (char *__buf, size_t __size, size_t __buflen)
 1744 -     __THROW __wur __attr_access ((__write_only__, 1, 2));
 1745 +     __THROW __wur;
 1746  extern char *__REDIRECT_NTH (__getcwd_alias,
 1747 -			     (char *__buf, size_t __size), getcwd)
 1748 -  __wur __attr_access ((__write_only__, 1, 2));
 1749 +			     (char *__buf, size_t __size), getcwd) __wur;
 1750  extern char *__REDIRECT_NTH (__getcwd_chk_warn,
 1751  			     (char *__buf, size_t __size, size_t __buflen),
 1752  			     __getcwd_chk)
 1753 diff --git a/posix/unistd.h b/posix/unistd.h
 1754 index 32b8161619..acf9ee7e79 100644
 1755 --- a/posix/unistd.h
 1756 +++ b/posix/unistd.h
 1757 @@ -517,8 +517,7 @@ extern int fchdir (int __fd) __THROW __wur;
 1758     an array is allocated with `malloc'; the array is SIZE
 1759     bytes long, unless SIZE == 0, in which case it is as
 1760     big as necessary.  */
 1761 -extern char *getcwd (char *__buf, size_t __size) __THROW __wur
 1762 -    __attr_access ((__write_only__, 1, 2));
 1763 +extern char *getcwd (char *__buf, size_t __size) __THROW __wur;
 1764  
 1765  #ifdef	__USE_GNU
 1766  /* Return a malloc'd string containing the current directory name.
 1767 @@ -831,7 +830,7 @@ extern int symlinkat (const char *__from, int __tofd,
 1768  /* Like readlink but a relative PATH is interpreted relative to FD.  */
 1769  extern ssize_t readlinkat (int __fd, const char *__restrict __path,
 1770  			   char *__restrict __buf, size_t __len)
 1771 -     __THROW __nonnull ((2, 3)) __wur __attr_access ((__read_only__, 3, 4));
 1772 +     __THROW __nonnull ((2, 3)) __wur __attr_access ((__write_only__, 3, 4));
 1773  #endif
 1774  
 1775  /* Remove the link NAME.  */
 1776 diff --git a/posix/wordexp-test.c b/posix/wordexp-test.c
 1777 index ed1b22308e..cb3f989cba 100644
 1778 --- a/posix/wordexp-test.c
 1779 +++ b/posix/wordexp-test.c
 1780 @@ -183,6 +183,7 @@ struct test_case_struct
 1781      { 0, NULL, "$var", 0, 0, { NULL, }, IFS },
 1782      { 0, NULL, "\"\\n\"", 0, 1, { "\\n", }, IFS },
 1783      { 0, NULL, "", 0, 0, { NULL, }, IFS },
 1784 +    { 0, NULL, "${1234567890123456789012}", 0, 0, { NULL, }, IFS },
 1785  
 1786      /* Flags not already covered (testit() has special handling for these) */
 1787      { 0, NULL, "one two", WRDE_DOOFFS, 2, { "one", "two", }, IFS },
 1788 diff --git a/posix/wordexp.c b/posix/wordexp.c
 1789 index e082d94895..56289503a1 100644
 1790 --- a/posix/wordexp.c
 1791 +++ b/posix/wordexp.c
 1792 @@ -1399,7 +1399,7 @@ envsubst:
 1793    /* Is it a numeric parameter? */
 1794    else if (isdigit (env[0]))
 1795      {
 1796 -      int n = atoi (env);
 1797 +      unsigned long n = strtoul (env, NULL, 10);
 1798  
 1799        if (n >= __libc_argc)
 1800  	/* Substitute NULL. */
 1801 diff --git a/resolv/Makefile b/resolv/Makefile
 1802 index b61c0c3e0c..dbd8f8bf4f 100644
 1803 --- a/resolv/Makefile
 1804 +++ b/resolv/Makefile
 1805 @@ -61,6 +61,11 @@ tests += \
 1806    tst-resolv-search \
 1807    tst-resolv-trailing \
 1808  
 1809 +# This test calls __res_context_send directly, which is not exported
 1810 +# from libresolv.
 1811 +tests-internal += tst-resolv-txnid-collision
 1812 +tests-static += tst-resolv-txnid-collision
 1813 +
 1814  # These tests need libdl.
 1815  ifeq (yes,$(build-shared))
 1816  tests += \
 1817 @@ -191,6 +196,8 @@ $(objpfx)tst-resolv-search: $(objpfx)libresolv.so $(shared-thread-library)
 1818  $(objpfx)tst-resolv-trailing: $(objpfx)libresolv.so $(shared-thread-library)
 1819  $(objpfx)tst-resolv-threads: \
 1820    $(libdl) $(objpfx)libresolv.so $(shared-thread-library)
 1821 +$(objpfx)tst-resolv-txnid-collision: $(objpfx)libresolv.a \
 1822 +  $(static-thread-library)
 1823  $(objpfx)tst-resolv-canonname: \
 1824    $(libdl) $(objpfx)libresolv.so $(shared-thread-library)
 1825  $(objpfx)tst-resolv-trustad: $(objpfx)libresolv.so $(shared-thread-library)
 1826 diff --git a/resolv/res_send.c b/resolv/res_send.c
 1827 index 7e5fec6646..70e5066031 100644
 1828 --- a/resolv/res_send.c
 1829 +++ b/resolv/res_send.c
 1830 @@ -1342,15 +1342,6 @@ send_dg(res_state statp,
 1831  			*terrno = EMSGSIZE;
 1832  			return close_and_return_error (statp, resplen2);
 1833  		}
 1834 -		if ((recvresp1 || hp->id != anhp->id)
 1835 -		    && (recvresp2 || hp2->id != anhp->id)) {
 1836 -			/*
 1837 -			 * response from old query, ignore it.
 1838 -			 * XXX - potential security hazard could
 1839 -			 *	 be detected here.
 1840 -			 */
 1841 -			goto wait;
 1842 -		}
 1843  
 1844  		/* Paranoia check.  Due to the connected UDP socket,
 1845  		   the kernel has already filtered invalid addresses
 1846 @@ -1360,15 +1351,24 @@ send_dg(res_state statp,
 1847  
 1848  		/* Check for the correct header layout and a matching
 1849  		   question.  */
 1850 -		if ((recvresp1 || !res_queriesmatch(buf, buf + buflen,
 1851 -						       *thisansp,
 1852 -						       *thisansp
 1853 -						       + *thisanssizp))
 1854 -		    && (recvresp2 || !res_queriesmatch(buf2, buf2 + buflen2,
 1855 -						       *thisansp,
 1856 -						       *thisansp
 1857 -						       + *thisanssizp)))
 1858 -		  goto wait;
 1859 +		int matching_query = 0; /* Default to no matching query.  */
 1860 +		if (!recvresp1
 1861 +		    && anhp->id == hp->id
 1862 +		    && res_queriesmatch (buf, buf + buflen,
 1863 +					 *thisansp, *thisansp + *thisanssizp))
 1864 +		  matching_query = 1;
 1865 +		if (!recvresp2
 1866 +		    && anhp->id == hp2->id
 1867 +		    && res_queriesmatch (buf2, buf2 + buflen2,
 1868 +					 *thisansp, *thisansp + *thisanssizp))
 1869 +		  matching_query = 2;
 1870 +		if (matching_query == 0)
 1871 +		  /* Spurious UDP packet.  Drop it and continue
 1872 +		     waiting.  */
 1873 +		  {
 1874 +		    need_recompute = 1;
 1875 +		    goto wait;
 1876 +		  }
 1877  
 1878  		if (anhp->rcode == SERVFAIL ||
 1879  		    anhp->rcode == NOTIMP ||
 1880 @@ -1383,7 +1383,7 @@ send_dg(res_state statp,
 1881  			    /* No data from the first reply.  */
 1882  			    resplen = 0;
 1883  			    /* We are waiting for a possible second reply.  */
 1884 -			    if (hp->id == anhp->id)
 1885 +			    if (matching_query == 1)
 1886  			      recvresp1 = 1;
 1887  			    else
 1888  			      recvresp2 = 1;
 1889 @@ -1414,7 +1414,7 @@ send_dg(res_state statp,
 1890  			return (1);
 1891  		}
 1892  		/* Mark which reply we received.  */
 1893 -		if (recvresp1 == 0 && hp->id == anhp->id)
 1894 +		if (matching_query == 1)
 1895  			recvresp1 = 1;
 1896  		else
 1897  			recvresp2 = 1;
 1898 diff --git a/resolv/tst-resolv-txnid-collision.c b/resolv/tst-resolv-txnid-collision.c
 1899 new file mode 100644
 1900 index 0000000000..189b76f126
 1901 --- /dev/null
 1902 +++ b/resolv/tst-resolv-txnid-collision.c
 1903 @@ -0,0 +1,334 @@
 1904 +/* Test parallel queries with transaction ID collisions.
 1905 +   Copyright (C) 2020 Free Software Foundation, Inc.
 1906 +   This file is part of the GNU C Library.
 1907 +
 1908 +   The GNU C Library is free software; you can redistribute it and/or
 1909 +   modify it under the terms of the GNU Lesser General Public
 1910 +   License as published by the Free Software Foundation; either
 1911 +   version 2.1 of the License, or (at your option) any later version.
 1912 +
 1913 +   The GNU C Library is distributed in the hope that it will be useful,
 1914 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
 1915 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 1916 +   Lesser General Public License for more details.
 1917 +
 1918 +   You should have received a copy of the GNU Lesser General Public
 1919 +   License along with the GNU C Library; if not, see
 1920 +   <https://www.gnu.org/licenses/>.  */
 1921 +
 1922 +#include <arpa/nameser.h>
 1923 +#include <array_length.h>
 1924 +#include <resolv-internal.h>
 1925 +#include <resolv_context.h>
 1926 +#include <stdbool.h>
 1927 +#include <stdio.h>
 1928 +#include <string.h>
 1929 +#include <support/check.h>
 1930 +#include <support/check_nss.h>
 1931 +#include <support/resolv_test.h>
 1932 +#include <support/support.h>
 1933 +#include <support/test-driver.h>
 1934 +
 1935 +/* Result of parsing a DNS question name.
 1936 +
 1937 +   A question name has the form reorder-N-M-rcode-C.example.net, where
 1938 +   N and M are either 0 and 1, corresponding to the reorder member,
 1939 +   and C is a number that will be stored in the rcode field.
 1940 +
 1941 +   Also see parse_qname below.  */
 1942 +struct parsed_qname
 1943 +{
 1944 +  /* The DNS response code requested from the first server.  The
 1945 +     second server always responds with RCODE zero.  */
 1946 +  int rcode;
 1947 +
 1948 +  /* Indicates whether to perform reordering in the responses from the
 1949 +     respective server.  */
 1950 +  bool reorder[2];
 1951 +};
 1952 +
 1953 +/* Fills *PARSED based on QNAME.  */
 1954 +static void
 1955 +parse_qname (struct parsed_qname *parsed, const char *qname)
 1956 +{
 1957 +  int reorder0;
 1958 +  int reorder1;
 1959 +  int rcode;
 1960 +  char *suffix;
 1961 +  if (sscanf (qname, "reorder-%d-%d.rcode-%d.%ms",
 1962 +              &reorder0, &reorder1, &rcode, &suffix) == 4)
 1963 +    {
 1964 +      if (reorder0 != 0)
 1965 +        TEST_COMPARE (reorder0, 1);
 1966 +      if (reorder1 != 0)
 1967 +        TEST_COMPARE (reorder1, 1);
 1968 +      TEST_VERIFY (rcode >= 0 && rcode <= 15);
 1969 +      TEST_COMPARE_STRING (suffix, "example.net");
 1970 +      free (suffix);
 1971 +
 1972 +      parsed->rcode = rcode;
 1973 +      parsed->reorder[0] = reorder0;
 1974 +      parsed->reorder[1] = reorder1;
 1975 +    }
 1976 +  else
 1977 +    FAIL_EXIT1 ("unexpected query: %s", qname);
 1978 +}
 1979 +
 1980 +/* Used to construct a response. The first server responds with an
 1981 +   error, the second server succeeds.  */
 1982 +static void
 1983 +build_response (const struct resolv_response_context *ctx,
 1984 +                struct resolv_response_builder *b,
 1985 +                const char *qname, uint16_t qclass, uint16_t qtype)
 1986 +{
 1987 +  struct parsed_qname parsed;
 1988 +  parse_qname (&parsed, qname);
 1989 +
 1990 +  switch (ctx->server_index)
 1991 +    {
 1992 +    case 0:
 1993 +      {
 1994 +        struct resolv_response_flags flags = { 0 };
 1995 +        if (parsed.rcode == 0)
 1996 +          /* Simulate a delegation in case a NODATA (RCODE zero)
 1997 +             response is requested.  */
 1998 +          flags.clear_ra = true;
 1999 +        else
 2000 +          flags.rcode = parsed.rcode;
 2001 +
 2002 +        resolv_response_init (b, flags);
 2003 +        resolv_response_add_question (b, qname, qclass, qtype);
 2004 +      }
 2005 +      break;
 2006 +
 2007 +    case 1:
 2008 +      {
 2009 +        struct resolv_response_flags flags = { 0, };
 2010 +        resolv_response_init (b, flags);
 2011 +        resolv_response_add_question (b, qname, qclass, qtype);
 2012 +
 2013 +        resolv_response_section (b, ns_s_an);
 2014 +        resolv_response_open_record (b, qname, qclass, qtype, 0);
 2015 +        if (qtype == T_A)
 2016 +          {
 2017 +            char ipv4[4] = { 192, 0, 2, 1 };
 2018 +            resolv_response_add_data (b, &ipv4, sizeof (ipv4));
 2019 +          }
 2020 +        else
 2021 +          {
 2022 +            char ipv6[16]
 2023 +              = { 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
 2024 +            resolv_response_add_data (b, &ipv6, sizeof (ipv6));
 2025 +          }
 2026 +        resolv_response_close_record (b);
 2027 +      }
 2028 +      break;
 2029 +    }
 2030 +}
 2031 +
 2032 +/* Used to reorder responses.  */
 2033 +struct resolv_response_context *previous_query;
 2034 +
 2035 +/* Used to keep track of the queries received.  */
 2036 +static int previous_server_index = -1;
 2037 +static uint16_t previous_qtype;
 2038 +
 2039 +/* For each server, buffer the first query and then send both answers
 2040 +   to the second query, reordered if requested.  */
 2041 +static void
 2042 +response (const struct resolv_response_context *ctx,
 2043 +          struct resolv_response_builder *b,
 2044 +          const char *qname, uint16_t qclass, uint16_t qtype)
 2045 +{
 2046 +  TEST_VERIFY (qtype == T_A || qtype == T_AAAA);
 2047 +  if (ctx->server_index != 0)
 2048 +    TEST_COMPARE (ctx->server_index, 1);
 2049 +
 2050 +  struct parsed_qname parsed;
 2051 +  parse_qname (&parsed, qname);
 2052 +
 2053 +  if (previous_query == NULL)
 2054 +    {
 2055 +      /* No buffered query.  Record this query and do not send a
 2056 +         response.  */
 2057 +      TEST_COMPARE (previous_qtype, 0);
 2058 +      previous_query = resolv_response_context_duplicate (ctx);
 2059 +      previous_qtype = qtype;
 2060 +      resolv_response_drop (b);
 2061 +      previous_server_index = ctx->server_index;
 2062 +
 2063 +      if (test_verbose)
 2064 +        printf ("info: buffering first query for: %s\n", qname);
 2065 +    }
 2066 +  else
 2067 +    {
 2068 +      TEST_VERIFY (previous_query != 0);
 2069 +      TEST_COMPARE (ctx->server_index, previous_server_index);
 2070 +      TEST_VERIFY (previous_qtype != qtype); /* Not a duplicate.  */
 2071 +
 2072 +      /* If reordering, send a response for this query explicitly, and
 2073 +         then skip the implicit send.  */
 2074 +      if (parsed.reorder[ctx->server_index])
 2075 +        {
 2076 +          if (test_verbose)
 2077 +            printf ("info: sending reordered second response for: %s\n",
 2078 +                    qname);
 2079 +          build_response (ctx, b, qname, qclass, qtype);
 2080 +          resolv_response_send_udp (ctx, b);
 2081 +          resolv_response_drop (b);
 2082 +        }
 2083 +
 2084 +      /* Build a response for the previous query and send it, thus
 2085 +         reordering the two responses.  */
 2086 +      {
 2087 +        if (test_verbose)
 2088 +          printf ("info: sending first response for: %s\n", qname);
 2089 +        struct resolv_response_builder *btmp
 2090 +          = resolv_response_builder_allocate (previous_query->query_buffer,
 2091 +                                              previous_query->query_length);
 2092 +        build_response (ctx, btmp, qname, qclass, previous_qtype);
 2093 +        resolv_response_send_udp (ctx, btmp);
 2094 +        resolv_response_builder_free (btmp);
 2095 +      }
 2096 +
 2097 +      /* If not reordering, send the reply as usual.  */
 2098 +      if (!parsed.reorder[ctx->server_index])
 2099 +        {
 2100 +          if (test_verbose)
 2101 +            printf ("info: sending non-reordered second response for: %s\n",
 2102 +                    qname);
 2103 +          build_response (ctx, b, qname, qclass, qtype);
 2104 +        }
 2105 +
 2106 +      /* Unbuffer the response and prepare for the next query.  */
 2107 +      resolv_response_context_free (previous_query);
 2108 +      previous_query = NULL;
 2109 +      previous_qtype = 0;
 2110 +      previous_server_index = -1;
 2111 +    }
 2112 +}
 2113 +
 2114 +/* Runs a query for QNAME and checks for the expected reply.  See
 2115 +   struct parsed_qname for the expected format for QNAME.  */
 2116 +static void
 2117 +test_qname (const char *qname, int rcode)
 2118 +{
 2119 +  struct resolv_context *ctx = __resolv_context_get ();
 2120 +  TEST_VERIFY_EXIT (ctx != NULL);
 2121 +
 2122 +  unsigned char q1[512];
 2123 +  int q1len = res_mkquery (QUERY, qname, C_IN, T_A, NULL, 0, NULL,
 2124 +                           q1, sizeof (q1));
 2125 +  TEST_VERIFY_EXIT (q1len > 12);
 2126 +
 2127 +  unsigned char q2[512];
 2128 +  int q2len = res_mkquery (QUERY, qname, C_IN, T_AAAA, NULL, 0, NULL,
 2129 +                           q2, sizeof (q2));
 2130 +  TEST_VERIFY_EXIT (q2len > 12);
 2131 +
 2132 +  /* Produce a transaction ID collision.  */
 2133 +  memcpy (q2, q1, 2);
 2134 +
 2135 +  unsigned char ans1[512];
 2136 +  unsigned char *ans1p = ans1;
 2137 +  unsigned char *ans2p = NULL;
 2138 +  int nans2p = 0;
 2139 +  int resplen2 = 0;
 2140 +  int ans2p_malloced = 0;
 2141 +
 2142 +  /* Perform a parallel A/AAAA query.  */
 2143 +  int resplen1 = __res_context_send (ctx, q1, q1len, q2, q2len,
 2144 +                                     ans1, sizeof (ans1), &ans1p,
 2145 +                                     &ans2p, &nans2p,
 2146 +                                     &resplen2, &ans2p_malloced);
 2147 +
 2148 +  TEST_VERIFY (resplen1 > 12);
 2149 +  TEST_VERIFY (resplen2 > 12);
 2150 +  if (resplen1 <= 12 || resplen2 <= 12)
 2151 +    return;
 2152 +
 2153 +  if (rcode == 1 || rcode == 3)
 2154 +    {
 2155 +      /* Format Error and Name Error responses does not trigger
 2156 +         switching to the next server.  */
 2157 +      TEST_COMPARE (ans1p[3] & 0x0f, rcode);
 2158 +      TEST_COMPARE (ans2p[3] & 0x0f, rcode);
 2159 +      return;
 2160 +    }
 2161 +
 2162 +  /* The response should be successful.  */
 2163 +  TEST_COMPARE (ans1p[3] & 0x0f, 0);
 2164 +  TEST_COMPARE (ans2p[3] & 0x0f, 0);
 2165 +
 2166 +  /* Due to bug 19691, the answer may not be in the slot matching the
 2167 +     query.  Assume that the AAAA response is the longer one.  */
 2168 +  unsigned char *a_answer;
 2169 +  int a_answer_length;
 2170 +  unsigned char *aaaa_answer;
 2171 +  int aaaa_answer_length;
 2172 +  if (resplen2 > resplen1)
 2173 +    {
 2174 +      a_answer = ans1p;
 2175 +      a_answer_length = resplen1;
 2176 +      aaaa_answer = ans2p;
 2177 +      aaaa_answer_length = resplen2;
 2178 +    }
 2179 +  else
 2180 +    {
 2181 +      a_answer = ans2p;
 2182 +      a_answer_length = resplen2;
 2183 +      aaaa_answer = ans1p;
 2184 +      aaaa_answer_length = resplen1;
 2185 +    }
 2186 +
 2187 +  {
 2188 +    char *expected = xasprintf ("name: %s\n"
 2189 +                                "address: 192.0.2.1\n",
 2190 +                                qname);
 2191 +    check_dns_packet (qname, a_answer, a_answer_length, expected);
 2192 +    free (expected);
 2193 +  }
 2194 +  {
 2195 +    char *expected = xasprintf ("name: %s\n"
 2196 +                                "address: 2001:db8::1\n",
 2197 +                                qname);
 2198 +    check_dns_packet (qname, aaaa_answer, aaaa_answer_length, expected);
 2199 +    free (expected);
 2200 +  }
 2201 +
 2202 +  if (ans2p_malloced)
 2203 +    free (ans2p);
 2204 +
 2205 +  __resolv_context_put (ctx);
 2206 +}
 2207 +
 2208 +static int
 2209 +do_test (void)
 2210 +{
 2211 +  struct resolv_test *aux = resolv_test_start
 2212 +    ((struct resolv_redirect_config)
 2213 +     {
 2214 +       .response_callback = response,
 2215 +
 2216 +       /* The response callback use global state (the previous_*
 2217 +          variables), and query processing must therefore be
 2218 +          serialized.  */
 2219 +       .single_thread_udp = true,
 2220 +     });
 2221 +
 2222 +  for (int rcode = 0; rcode <= 5; ++rcode)
 2223 +    for (int do_reorder_0 = 0; do_reorder_0 < 2; ++do_reorder_0)
 2224 +      for (int do_reorder_1 = 0; do_reorder_1 < 2; ++do_reorder_1)
 2225 +        {
 2226 +          char *qname = xasprintf ("reorder-%d-%d.rcode-%d.example.net",
 2227 +                                   do_reorder_0, do_reorder_1, rcode);
 2228 +          test_qname (qname, rcode);
 2229 +          free (qname);
 2230 +        }
 2231 +
 2232 +  resolv_test_end (aux);
 2233 +
 2234 +  return 0;
 2235 +}
 2236 +
 2237 +#include <support/test-driver.c>
 2238 diff --git a/rt/Makefile b/rt/Makefile
 2239 index dab5d62a57..93502cfaa7 100644
 2240 --- a/rt/Makefile
 2241 +++ b/rt/Makefile
 2242 @@ -44,6 +44,7 @@ tests := tst-shm tst-timer tst-timer2 \
 2243  	 tst-aio7 tst-aio8 tst-aio9 tst-aio10 \
 2244  	 tst-mqueue1 tst-mqueue2 tst-mqueue3 tst-mqueue4 \
 2245  	 tst-mqueue5 tst-mqueue6 tst-mqueue7 tst-mqueue8 tst-mqueue9 \
 2246 +	 tst-bz28213 \
 2247  	 tst-timer3 tst-timer4 tst-timer5 \
 2248  	 tst-cpuclock2 tst-cputimer1 tst-cputimer2 tst-cputimer3 \
 2249  	 tst-shm-cancel
 2250 diff --git a/rt/tst-bz28213.c b/rt/tst-bz28213.c
 2251 new file mode 100644
 2252 index 0000000000..0c096b5a0a
 2253 --- /dev/null
 2254 +++ b/rt/tst-bz28213.c
 2255 @@ -0,0 +1,101 @@
 2256 +/* Bug 28213: test for NULL pointer dereference in mq_notify.
 2257 +   Copyright (C) The GNU Toolchain Authors.
 2258 +   This file is part of the GNU C Library.
 2259 +
 2260 +   The GNU C Library is free software; you can redistribute it and/or
 2261 +   modify it under the terms of the GNU Lesser General Public
 2262 +   License as published by the Free Software Foundation; either
 2263 +   version 2.1 of the License, or (at your option) any later version.
 2264 +
 2265 +   The GNU C Library is distributed in the hope that it will be useful,
 2266 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
 2267 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 2268 +   Lesser General Public License for more details.
 2269 +
 2270 +   You should have received a copy of the GNU Lesser General Public
 2271 +   License along with the GNU C Library; if not, see
 2272 +   <https://www.gnu.org/licenses/>.  */
 2273 +
 2274 +#include <errno.h>
 2275 +#include <sys/types.h>
 2276 +#include <sys/stat.h>
 2277 +#include <fcntl.h>
 2278 +#include <unistd.h>
 2279 +#include <mqueue.h>
 2280 +#include <signal.h>
 2281 +#include <stdlib.h>
 2282 +#include <string.h>
 2283 +#include <support/check.h>
 2284 +
 2285 +static mqd_t m = -1;
 2286 +static const char msg[] = "hello";
 2287 +
 2288 +static void
 2289 +check_bz28213_cb (union sigval sv)
 2290 +{
 2291 +  char buf[sizeof (msg)];
 2292 +
 2293 +  (void) sv;
 2294 +
 2295 +  TEST_VERIFY_EXIT ((size_t) mq_receive (m, buf, sizeof (buf), NULL)
 2296 +		    == sizeof (buf));
 2297 +  TEST_VERIFY_EXIT (memcmp (buf, msg, sizeof (buf)) == 0);
 2298 +
 2299 +  exit (0);
 2300 +}
 2301 +
 2302 +static void
 2303 +check_bz28213 (void)
 2304 +{
 2305 +  struct sigevent sev;
 2306 +
 2307 +  memset (&sev, '\0', sizeof (sev));
 2308 +  sev.sigev_notify = SIGEV_THREAD;
 2309 +  sev.sigev_notify_function = check_bz28213_cb;
 2310 +
 2311 +  /* Step 1: Register & unregister notifier.
 2312 +     Helper thread should receive NOTIFY_REMOVED notification.
 2313 +     In a vulnerable version of glibc, NULL pointer dereference follows. */
 2314 +  TEST_VERIFY_EXIT (mq_notify (m, &sev) == 0);
 2315 +  TEST_VERIFY_EXIT (mq_notify (m, NULL) == 0);
 2316 +
 2317 +  /* Step 2: Once again, register notification.
 2318 +     Try to send one message.
 2319 +     Test is considered successful, if the callback does exit (0). */
 2320 +  TEST_VERIFY_EXIT (mq_notify (m, &sev) == 0);
 2321 +  TEST_VERIFY_EXIT (mq_send (m, msg, sizeof (msg), 1) == 0);
 2322 +
 2323 +  /* Wait... */
 2324 +  pause ();
 2325 +}
 2326 +
 2327 +static int
 2328 +do_test (void)
 2329 +{
 2330 +  static const char m_name[] = "/bz28213_queue";
 2331 +  struct mq_attr m_attr;
 2332 +
 2333 +  memset (&m_attr, '\0', sizeof (m_attr));
 2334 +  m_attr.mq_maxmsg = 1;
 2335 +  m_attr.mq_msgsize = sizeof (msg);
 2336 +
 2337 +  m = mq_open (m_name,
 2338 +               O_RDWR | O_CREAT | O_EXCL,
 2339 +               0600,
 2340 +               &m_attr);
 2341 +
 2342 +  if (m < 0)
 2343 +    {
 2344 +      if (errno == ENOSYS)
 2345 +        FAIL_UNSUPPORTED ("POSIX message queues are not implemented\n");
 2346 +      FAIL_EXIT1 ("Failed to create POSIX message queue: %m\n");
 2347 +    }
 2348 +
 2349 +  TEST_VERIFY_EXIT (mq_unlink (m_name) == 0);
 2350 +
 2351 +  check_bz28213 ();
 2352 +
 2353 +  return 0;
 2354 +}
 2355 +
 2356 +#include <support/test-driver.c>
 2357 diff --git a/stdio-common/Makefile b/stdio-common/Makefile
 2358 index 8475fd1f09..eff0c98d82 100644
 2359 --- a/stdio-common/Makefile
 2360 +++ b/stdio-common/Makefile
 2361 @@ -69,7 +69,8 @@ tests := tstscanf test_rdwr test-popen tstgetln test-fseek \
 2362  	 tst-printf-bz25691 \
 2363  	 tst-vfprintf-width-prec-alloc \
 2364  	 tst-printf-fp-free \
 2365 -	 tst-printf-fp-leak
 2366 +	 tst-printf-fp-leak \
 2367 +	 test-strerr
 2368  
 2369  
 2370  test-srcs = tst-unbputc tst-printf tst-printfsz-islongdouble
 2371 diff --git a/stdio-common/errlist.c b/stdio-common/errlist.c
 2372 index d15f13a22a..2ecf121674 100644
 2373 --- a/stdio-common/errlist.c
 2374 +++ b/stdio-common/errlist.c
 2375 @@ -20,9 +20,13 @@
 2376  #include <libintl.h>
 2377  #include <array_length.h>
 2378  
 2379 +#ifndef ERR_MAP
 2380 +# define ERR_MAP(n) n
 2381 +#endif
 2382 +
 2383  const char *const _sys_errlist_internal[] =
 2384    {
 2385 -#define _S(n, str)         [n] = str,
 2386 +#define _S(n, str)         [ERR_MAP(n)] = str,
 2387  #include <errlist.h>
 2388  #undef _S
 2389    };
 2390 @@ -41,20 +45,21 @@ static const union sys_errname_t
 2391    {
 2392  #define MSGSTRFIELD1(line) str##line
 2393  #define MSGSTRFIELD(line)  MSGSTRFIELD1(line)
 2394 -#define _S(n, str)         char MSGSTRFIELD(__LINE__)[sizeof(str)];
 2395 +#define _S(n, str)         char MSGSTRFIELD(__LINE__)[sizeof(#n)];
 2396  #include <errlist.h>
 2397  #undef _S
 2398    };
 2399    char str[0];
 2400  } _sys_errname = { {
 2401 -#define _S(n, s) s,
 2402 +#define _S(n, s) #n,
 2403  #include <errlist.h>
 2404  #undef _S
 2405  } };
 2406  
 2407  static const unsigned short _sys_errnameidx[] =
 2408  {
 2409 -#define _S(n, s) [n] = offsetof(union sys_errname_t, MSGSTRFIELD(__LINE__)),
 2410 +#define _S(n, s) \
 2411 +  [ERR_MAP(n)] = offsetof(union sys_errname_t, MSGSTRFIELD(__LINE__)),
 2412  #include <errlist.h>
 2413  #undef _S
 2414  };
 2415 diff --git a/stdio-common/test-strerr.c b/stdio-common/test-strerr.c
 2416 index fded208118..d77b81d507 100644
 2417 --- a/stdio-common/test-strerr.c
 2418 +++ b/stdio-common/test-strerr.c
 2419 @@ -18,46 +18,672 @@
 2420  
 2421  #include <string.h>
 2422  #include <errno.h>
 2423 -#include <array_length.h>
 2424  
 2425  #include <support/support.h>
 2426  #include <support/check.h>
 2427  
 2428 -#define N_(name)      name
 2429 -
 2430 -static const char *const errlist[] =
 2431 -  {
 2432 -/* This file is auto-generated from errlist.def.  */
 2433 -#include <errlist.h>
 2434 -  };
 2435 -
 2436 -#define MSGSTR_T errname_t
 2437 -#define MSGSTR   errname
 2438 -#define MSGIDX   errnameidx
 2439 -#include <errlist-name.h>
 2440 -#undef MSGSTR
 2441 -#undef MSGIDX
 2442 -
 2443  static int
 2444  do_test (void)
 2445  {
 2446 -  TEST_VERIFY (strerrordesc_np (-1) == NULL);
 2447 -  TEST_VERIFY (strerrordesc_np (array_length (errlist)) == NULL);
 2448 -  for (size_t i = 0; i < array_length (errlist); i++)
 2449 -    {
 2450 -      if (errlist[i] == NULL)
 2451 -        continue;
 2452 -      TEST_COMPARE_STRING (strerrordesc_np (i), errlist[i]);
 2453 -    }
 2454 +  TEST_COMPARE_STRING (strerrordesc_np (0), "Success");
 2455 +  TEST_COMPARE_STRING (strerrorname_np (0), "0");
 2456  
 2457 -  TEST_VERIFY (strerrorname_np (-1) == NULL);
 2458 -  TEST_VERIFY (strerrorname_np (array_length (errlist)) == NULL);
 2459 -  for (size_t i = 0; i < array_length (errlist); i++)
 2460 -    {
 2461 -      if (errlist[i] == NULL)
 2462 -        continue;
 2463 -      TEST_COMPARE_STRING (strerrorname_np (i), errname.str + errnameidx[i]);
 2464 -    }
 2465 +#ifdef EPERM
 2466 +  TEST_COMPARE_STRING (strerrordesc_np (EPERM), "Operation not permitted");
 2467 +  TEST_COMPARE_STRING (strerrorname_np (EPERM), "EPERM");
 2468 +#endif
 2469 +#ifdef ENOENT
 2470 +  TEST_COMPARE_STRING (strerrordesc_np (ENOENT),
 2471 +		       "No such file or directory");
 2472 +  TEST_COMPARE_STRING (strerrorname_np (ENOENT), "ENOENT");
 2473 +#endif
 2474 +#ifdef ESRCH
 2475 +  TEST_COMPARE_STRING (strerrordesc_np (ESRCH), "No such process");
 2476 +  TEST_COMPARE_STRING (strerrorname_np (ESRCH), "ESRCH");
 2477 +#endif
 2478 +#ifdef EINTR
 2479 +  TEST_COMPARE_STRING (strerrordesc_np (EINTR), "Interrupted system call");
 2480 +  TEST_COMPARE_STRING (strerrorname_np (EINTR), "EINTR");
 2481 +#endif
 2482 +#ifdef EIO
 2483 +  TEST_COMPARE_STRING (strerrordesc_np (EIO), "Input/output error");
 2484 +  TEST_COMPARE_STRING (strerrorname_np (EIO), "EIO");
 2485 +#endif
 2486 +#ifdef ENXIO
 2487 +  TEST_COMPARE_STRING (strerrordesc_np (ENXIO), "No such device or address");
 2488 +  TEST_COMPARE_STRING (strerrorname_np (ENXIO), "ENXIO");
 2489 +#endif
 2490 +#ifdef E2BIG
 2491 +  TEST_COMPARE_STRING (strerrordesc_np (E2BIG), "Argument list too long");
 2492 +  TEST_COMPARE_STRING (strerrorname_np (E2BIG), "E2BIG");
 2493 +#endif
 2494 +#ifdef ENOEXEC
 2495 +  TEST_COMPARE_STRING (strerrordesc_np (ENOEXEC), "Exec format error");
 2496 +  TEST_COMPARE_STRING (strerrorname_np (ENOEXEC), "ENOEXEC");
 2497 +#endif
 2498 +#ifdef EBADF
 2499 +  TEST_COMPARE_STRING (strerrordesc_np (EBADF), "Bad file descriptor");
 2500 +  TEST_COMPARE_STRING (strerrorname_np (EBADF), "EBADF");
 2501 +#endif
 2502 +#ifdef ECHILD
 2503 +  TEST_COMPARE_STRING (strerrordesc_np (ECHILD), "No child processes");
 2504 +  TEST_COMPARE_STRING (strerrorname_np (ECHILD), "ECHILD");
 2505 +#endif
 2506 +#ifdef EDEADLK
 2507 +  TEST_COMPARE_STRING (strerrordesc_np (EDEADLK),
 2508 +		       "Resource deadlock avoided");
 2509 +  TEST_COMPARE_STRING (strerrorname_np (EDEADLK), "EDEADLK");
 2510 +#endif
 2511 +#ifdef ENOMEM
 2512 +  TEST_COMPARE_STRING (strerrordesc_np (ENOMEM), "Cannot allocate memory");
 2513 +  TEST_COMPARE_STRING (strerrorname_np (ENOMEM), "ENOMEM");
 2514 +#endif
 2515 +#ifdef EACCES
 2516 +  TEST_COMPARE_STRING (strerrordesc_np (EACCES), "Permission denied");
 2517 +  TEST_COMPARE_STRING (strerrorname_np (EACCES), "EACCES");
 2518 +#endif
 2519 +#ifdef EFAULT
 2520 +  TEST_COMPARE_STRING (strerrordesc_np (EFAULT), "Bad address");
 2521 +  TEST_COMPARE_STRING (strerrorname_np (EFAULT), "EFAULT");
 2522 +#endif
 2523 +#ifdef ENOTBLK
 2524 +  TEST_COMPARE_STRING (strerrordesc_np (ENOTBLK), "Block device required");
 2525 +  TEST_COMPARE_STRING (strerrorname_np (ENOTBLK), "ENOTBLK");
 2526 +#endif
 2527 +#ifdef EBUSY
 2528 +  TEST_COMPARE_STRING (strerrordesc_np (EBUSY), "Device or resource busy");
 2529 +  TEST_COMPARE_STRING (strerrorname_np (EBUSY), "EBUSY");
 2530 +#endif
 2531 +#ifdef EEXIST
 2532 +  TEST_COMPARE_STRING (strerrordesc_np (EEXIST), "File exists");
 2533 +  TEST_COMPARE_STRING (strerrorname_np (EEXIST), "EEXIST");
 2534 +#endif
 2535 +#ifdef EXDEV
 2536 +  TEST_COMPARE_STRING (strerrordesc_np (EXDEV), "Invalid cross-device link");
 2537 +  TEST_COMPARE_STRING (strerrorname_np (EXDEV), "EXDEV");
 2538 +#endif
 2539 +#ifdef ENODEV
 2540 +  TEST_COMPARE_STRING (strerrordesc_np (ENODEV), "No such device");
 2541 +  TEST_COMPARE_STRING (strerrorname_np (ENODEV), "ENODEV");
 2542 +#endif
 2543 +#ifdef ENOTDIR
 2544 +  TEST_COMPARE_STRING (strerrordesc_np (ENOTDIR), "Not a directory");
 2545 +  TEST_COMPARE_STRING (strerrorname_np (ENOTDIR), "ENOTDIR");
 2546 +#endif
 2547 +#ifdef EISDIR
 2548 +  TEST_COMPARE_STRING (strerrordesc_np (EISDIR), "Is a directory");
 2549 +  TEST_COMPARE_STRING (strerrorname_np (EISDIR), "EISDIR");
 2550 +#endif
 2551 +#ifdef EINVAL
 2552 +  TEST_COMPARE_STRING (strerrordesc_np (EINVAL), "Invalid argument");
 2553 +  TEST_COMPARE_STRING (strerrorname_np (EINVAL), "EINVAL");
 2554 +#endif
 2555 +#ifdef EMFILE
 2556 +  TEST_COMPARE_STRING (strerrordesc_np (EMFILE), "Too many open files");
 2557 +  TEST_COMPARE_STRING (strerrorname_np (EMFILE), "EMFILE");
 2558 +#endif
 2559 +#ifdef ENFILE
 2560 +  TEST_COMPARE_STRING (strerrordesc_np (ENFILE),
 2561 +		       "Too many open files in system");
 2562 +  TEST_COMPARE_STRING (strerrorname_np (ENFILE), "ENFILE");
 2563 +#endif
 2564 +#ifdef ENOTTY
 2565 +  TEST_COMPARE_STRING (strerrordesc_np (ENOTTY),
 2566 +		       "Inappropriate ioctl for device");
 2567 +  TEST_COMPARE_STRING (strerrorname_np (ENOTTY), "ENOTTY");
 2568 +#endif
 2569 +#ifdef ETXTBSY
 2570 +  TEST_COMPARE_STRING (strerrordesc_np (ETXTBSY), "Text file busy");
 2571 +  TEST_COMPARE_STRING (strerrorname_np (ETXTBSY), "ETXTBSY");
 2572 +#endif
 2573 +#ifdef EFBIG
 2574 +  TEST_COMPARE_STRING (strerrordesc_np (EFBIG), "File too large");
 2575 +  TEST_COMPARE_STRING (strerrorname_np (EFBIG), "EFBIG");
 2576 +#endif
 2577 +#ifdef ENOSPC
 2578 +  TEST_COMPARE_STRING (strerrordesc_np (ENOSPC), "No space left on device");
 2579 +  TEST_COMPARE_STRING (strerrorname_np (ENOSPC), "ENOSPC");
 2580 +#endif
 2581 +#ifdef ESPIPE
 2582 +  TEST_COMPARE_STRING (strerrordesc_np (ESPIPE), "Illegal seek");
 2583 +  TEST_COMPARE_STRING (strerrorname_np (ESPIPE), "ESPIPE");
 2584 +#endif
 2585 +#ifdef EROFS
 2586 +  TEST_COMPARE_STRING (strerrordesc_np (EROFS), "Read-only file system");
 2587 +  TEST_COMPARE_STRING (strerrorname_np (EROFS), "EROFS");
 2588 +#endif
 2589 +#ifdef EMLINK
 2590 +  TEST_COMPARE_STRING (strerrordesc_np (EMLINK), "Too many links");
 2591 +  TEST_COMPARE_STRING (strerrorname_np (EMLINK), "EMLINK");
 2592 +#endif
 2593 +#ifdef EPIPE
 2594 +  TEST_COMPARE_STRING (strerrordesc_np (EPIPE), "Broken pipe");
 2595 +  TEST_COMPARE_STRING (strerrorname_np (EPIPE), "EPIPE");
 2596 +#endif
 2597 +#ifdef EDOM
 2598 +  TEST_COMPARE_STRING (strerrordesc_np (EDOM),
 2599 +		       "Numerical argument out of domain");
 2600 +  TEST_COMPARE_STRING (strerrorname_np (EDOM), "EDOM");
 2601 +#endif
 2602 +#ifdef ERANGE
 2603 +  TEST_COMPARE_STRING (strerrordesc_np (ERANGE),
 2604 +		       "Numerical result out of range");
 2605 +  TEST_COMPARE_STRING (strerrorname_np (ERANGE), "ERANGE");
 2606 +#endif
 2607 +#ifdef EAGAIN
 2608 +  TEST_COMPARE_STRING (strerrordesc_np (EAGAIN),
 2609 +		       "Resource temporarily unavailable");
 2610 +  TEST_COMPARE_STRING (strerrorname_np (EAGAIN), "EAGAIN");
 2611 +#endif
 2612 +#ifdef EINPROGRESS
 2613 +  TEST_COMPARE_STRING (strerrordesc_np (EINPROGRESS),
 2614 +		       "Operation now in progress");
 2615 +  TEST_COMPARE_STRING (strerrorname_np (EINPROGRESS), "EINPROGRESS");
 2616 +#endif
 2617 +#ifdef EALREADY
 2618 +  TEST_COMPARE_STRING (strerrordesc_np (EALREADY),
 2619 +		       "Operation already in progress");
 2620 +  TEST_COMPARE_STRING (strerrorname_np (EALREADY), "EALREADY");
 2621 +#endif
 2622 +#ifdef ENOTSOCK
 2623 +  TEST_COMPARE_STRING (strerrordesc_np (ENOTSOCK),
 2624 +		       "Socket operation on non-socket");
 2625 +  TEST_COMPARE_STRING (strerrorname_np (ENOTSOCK), "ENOTSOCK");
 2626 +#endif
 2627 +#ifdef EMSGSIZE
 2628 +  TEST_COMPARE_STRING (strerrordesc_np (EMSGSIZE), "Message too long");
 2629 +  TEST_COMPARE_STRING (strerrorname_np (EMSGSIZE), "EMSGSIZE");
 2630 +#endif
 2631 +#ifdef EPROTOTYPE
 2632 +  TEST_COMPARE_STRING (strerrordesc_np (EPROTOTYPE),
 2633 +		       "Protocol wrong type for socket");
 2634 +  TEST_COMPARE_STRING (strerrorname_np (EPROTOTYPE), "EPROTOTYPE");
 2635 +#endif
 2636 +#ifdef ENOPROTOOPT
 2637 +  TEST_COMPARE_STRING (strerrordesc_np (ENOPROTOOPT),
 2638 +		       "Protocol not available");
 2639 +  TEST_COMPARE_STRING (strerrorname_np (ENOPROTOOPT), "ENOPROTOOPT");
 2640 +#endif
 2641 +#ifdef EPROTONOSUPPORT
 2642 +  TEST_COMPARE_STRING (strerrordesc_np (EPROTONOSUPPORT),
 2643 +		       "Protocol not supported");
 2644 +  TEST_COMPARE_STRING (strerrorname_np (EPROTONOSUPPORT), "EPROTONOSUPPORT");
 2645 +#endif
 2646 +#ifdef ESOCKTNOSUPPORT
 2647 +  TEST_COMPARE_STRING (strerrordesc_np (ESOCKTNOSUPPORT),
 2648 +		       "Socket type not supported");
 2649 +  TEST_COMPARE_STRING (strerrorname_np (ESOCKTNOSUPPORT), "ESOCKTNOSUPPORT");
 2650 +#endif
 2651 +#ifdef EOPNOTSUPP
 2652 +  TEST_COMPARE_STRING (strerrordesc_np (EOPNOTSUPP),
 2653 +		       "Operation not supported");
 2654 +  TEST_COMPARE_STRING (strerrorname_np (EOPNOTSUPP), "EOPNOTSUPP");
 2655 +#endif
 2656 +#ifdef EPFNOSUPPORT
 2657 +  TEST_COMPARE_STRING (strerrordesc_np (EPFNOSUPPORT),
 2658 +		       "Protocol family not supported");
 2659 +  TEST_COMPARE_STRING (strerrorname_np (EPFNOSUPPORT), "EPFNOSUPPORT");
 2660 +#endif
 2661 +#ifdef EAFNOSUPPORT
 2662 +  TEST_COMPARE_STRING (strerrordesc_np (EAFNOSUPPORT),
 2663 +		       "Address family not supported by protocol");
 2664 +  TEST_COMPARE_STRING (strerrorname_np (EAFNOSUPPORT), "EAFNOSUPPORT");
 2665 +#endif
 2666 +#ifdef EADDRINUSE
 2667 +  TEST_COMPARE_STRING (strerrordesc_np (EADDRINUSE),
 2668 +		       "Address already in use");
 2669 +  TEST_COMPARE_STRING (strerrorname_np (EADDRINUSE), "EADDRINUSE");
 2670 +#endif
 2671 +#ifdef EADDRNOTAVAIL
 2672 +  TEST_COMPARE_STRING (strerrordesc_np (EADDRNOTAVAIL),
 2673 +		       "Cannot assign requested address");
 2674 +  TEST_COMPARE_STRING (strerrorname_np (EADDRNOTAVAIL), "EADDRNOTAVAIL");
 2675 +#endif
 2676 +#ifdef ENETDOWN
 2677 +  TEST_COMPARE_STRING (strerrordesc_np (ENETDOWN), "Network is down");
 2678 +  TEST_COMPARE_STRING (strerrorname_np (ENETDOWN), "ENETDOWN");
 2679 +#endif
 2680 +#ifdef ENETUNREACH
 2681 +  TEST_COMPARE_STRING (strerrordesc_np (ENETUNREACH),
 2682 +		       "Network is unreachable");
 2683 +  TEST_COMPARE_STRING (strerrorname_np (ENETUNREACH), "ENETUNREACH");
 2684 +#endif
 2685 +#ifdef ENETRESET
 2686 +  TEST_COMPARE_STRING (strerrordesc_np (ENETRESET),
 2687 +		       "Network dropped connection on reset");
 2688 +  TEST_COMPARE_STRING (strerrorname_np (ENETRESET), "ENETRESET");
 2689 +#endif
 2690 +#ifdef ECONNABORTED
 2691 +  TEST_COMPARE_STRING (strerrordesc_np (ECONNABORTED),
 2692 +		       "Software caused connection abort");
 2693 +  TEST_COMPARE_STRING (strerrorname_np (ECONNABORTED), "ECONNABORTED");
 2694 +#endif
 2695 +#ifdef ECONNRESET
 2696 +  TEST_COMPARE_STRING (strerrordesc_np (ECONNRESET),
 2697 +		       "Connection reset by peer");
 2698 +  TEST_COMPARE_STRING (strerrorname_np (ECONNRESET), "ECONNRESET");
 2699 +#endif
 2700 +#ifdef ENOBUFS
 2701 +  TEST_COMPARE_STRING (strerrordesc_np (ENOBUFS),
 2702 +		       "No buffer space available");
 2703 +  TEST_COMPARE_STRING (strerrorname_np (ENOBUFS), "ENOBUFS");
 2704 +#endif
 2705 +#ifdef EISCONN
 2706 +  TEST_COMPARE_STRING (strerrordesc_np (EISCONN),
 2707 +		       "Transport endpoint is already connected");
 2708 +  TEST_COMPARE_STRING (strerrorname_np (EISCONN), "EISCONN");
 2709 +#endif
 2710 +#ifdef ENOTCONN
 2711 +  TEST_COMPARE_STRING (strerrordesc_np (ENOTCONN),
 2712 +		       "Transport endpoint is not connected");
 2713 +  TEST_COMPARE_STRING (strerrorname_np (ENOTCONN), "ENOTCONN");
 2714 +#endif
 2715 +#ifdef EDESTADDRREQ
 2716 +  TEST_COMPARE_STRING (strerrordesc_np (EDESTADDRREQ),
 2717 +		       "Destination address required");
 2718 +  TEST_COMPARE_STRING (strerrorname_np (EDESTADDRREQ), "EDESTADDRREQ");
 2719 +#endif
 2720 +#ifdef ESHUTDOWN
 2721 +  TEST_COMPARE_STRING (strerrordesc_np (ESHUTDOWN),
 2722 +		       "Cannot send after transport endpoint shutdown");
 2723 +  TEST_COMPARE_STRING (strerrorname_np (ESHUTDOWN), "ESHUTDOWN");
 2724 +#endif
 2725 +#ifdef ETOOMANYREFS
 2726 +  TEST_COMPARE_STRING (strerrordesc_np (ETOOMANYREFS),
 2727 +		       "Too many references: cannot splice");
 2728 +  TEST_COMPARE_STRING (strerrorname_np (ETOOMANYREFS), "ETOOMANYREFS");
 2729 +#endif
 2730 +#ifdef ETIMEDOUT
 2731 +  TEST_COMPARE_STRING (strerrordesc_np (ETIMEDOUT), "Connection timed out");
 2732 +  TEST_COMPARE_STRING (strerrorname_np (ETIMEDOUT), "ETIMEDOUT");
 2733 +#endif
 2734 +#ifdef ECONNREFUSED
 2735 +  TEST_COMPARE_STRING (strerrordesc_np (ECONNREFUSED), "Connection refused");
 2736 +  TEST_COMPARE_STRING (strerrorname_np (ECONNREFUSED), "ECONNREFUSED");
 2737 +#endif
 2738 +#ifdef ELOOP
 2739 +  TEST_COMPARE_STRING (strerrordesc_np (ELOOP),
 2740 +		       "Too many levels of symbolic links");
 2741 +  TEST_COMPARE_STRING (strerrorname_np (ELOOP), "ELOOP");
 2742 +#endif
 2743 +#ifdef ENAMETOOLONG
 2744 +  TEST_COMPARE_STRING (strerrordesc_np (ENAMETOOLONG), "File name too long");
 2745 +  TEST_COMPARE_STRING (strerrorname_np (ENAMETOOLONG), "ENAMETOOLONG");
 2746 +#endif
 2747 +#ifdef EHOSTDOWN
 2748 +  TEST_COMPARE_STRING (strerrordesc_np (EHOSTDOWN), "Host is down");
 2749 +  TEST_COMPARE_STRING (strerrorname_np (EHOSTDOWN), "EHOSTDOWN");
 2750 +#endif
 2751 +#ifdef EHOSTUNREACH
 2752 +  TEST_COMPARE_STRING (strerrordesc_np (EHOSTUNREACH), "No route to host");
 2753 +  TEST_COMPARE_STRING (strerrorname_np (EHOSTUNREACH), "EHOSTUNREACH");
 2754 +#endif
 2755 +#ifdef ENOTEMPTY
 2756 +  TEST_COMPARE_STRING (strerrordesc_np (ENOTEMPTY), "Directory not empty");
 2757 +  TEST_COMPARE_STRING (strerrorname_np (ENOTEMPTY), "ENOTEMPTY");
 2758 +#endif
 2759 +#ifdef EUSERS
 2760 +  TEST_COMPARE_STRING (strerrordesc_np (EUSERS), "Too many users");
 2761 +  TEST_COMPARE_STRING (strerrorname_np (EUSERS), "EUSERS");
 2762 +#endif
 2763 +#ifdef EDQUOT
 2764 +  TEST_COMPARE_STRING (strerrordesc_np (EDQUOT), "Disk quota exceeded");
 2765 +  TEST_COMPARE_STRING (strerrorname_np (EDQUOT), "EDQUOT");
 2766 +#endif
 2767 +#ifdef ESTALE
 2768 +  TEST_COMPARE_STRING (strerrordesc_np (ESTALE), "Stale file handle");
 2769 +  TEST_COMPARE_STRING (strerrorname_np (ESTALE), "ESTALE");
 2770 +#endif
 2771 +#ifdef EREMOTE
 2772 +  TEST_COMPARE_STRING (strerrordesc_np (EREMOTE), "Object is remote");
 2773 +  TEST_COMPARE_STRING (strerrorname_np (EREMOTE), "EREMOTE");
 2774 +#endif
 2775 +#ifdef ENOLCK
 2776 +  TEST_COMPARE_STRING (strerrordesc_np (ENOLCK), "No locks available");
 2777 +  TEST_COMPARE_STRING (strerrorname_np (ENOLCK), "ENOLCK");
 2778 +#endif
 2779 +#ifdef ENOSYS
 2780 +  TEST_COMPARE_STRING (strerrordesc_np (ENOSYS), "Function not implemented");
 2781 +  TEST_COMPARE_STRING (strerrorname_np (ENOSYS), "ENOSYS");
 2782 +#endif
 2783 +#ifdef EILSEQ
 2784 +  TEST_COMPARE_STRING (strerrordesc_np (EILSEQ),
 2785 +		       "Invalid or incomplete multibyte or wide character");
 2786 +  TEST_COMPARE_STRING (strerrorname_np (EILSEQ), "EILSEQ");
 2787 +#endif
 2788 +#ifdef EBADMSG
 2789 +  TEST_COMPARE_STRING (strerrordesc_np (EBADMSG), "Bad message");
 2790 +  TEST_COMPARE_STRING (strerrorname_np (EBADMSG), "EBADMSG");
 2791 +#endif
 2792 +#ifdef EIDRM
 2793 +  TEST_COMPARE_STRING (strerrordesc_np (EIDRM), "Identifier removed");
 2794 +  TEST_COMPARE_STRING (strerrorname_np (EIDRM), "EIDRM");
 2795 +#endif
 2796 +#ifdef EMULTIHOP
 2797 +  TEST_COMPARE_STRING (strerrordesc_np (EMULTIHOP), "Multihop attempted");
 2798 +  TEST_COMPARE_STRING (strerrorname_np (EMULTIHOP), "EMULTIHOP");
 2799 +#endif
 2800 +#ifdef ENODATA
 2801 +  TEST_COMPARE_STRING (strerrordesc_np (ENODATA), "No data available");
 2802 +  TEST_COMPARE_STRING (strerrorname_np (ENODATA), "ENODATA");
 2803 +#endif
 2804 +#ifdef ENOLINK
 2805 +  TEST_COMPARE_STRING (strerrordesc_np (ENOLINK), "Link has been severed");
 2806 +  TEST_COMPARE_STRING (strerrorname_np (ENOLINK), "ENOLINK");
 2807 +#endif
 2808 +#ifdef ENOMSG
 2809 +  TEST_COMPARE_STRING (strerrordesc_np (ENOMSG),
 2810 +		       "No message of desired type");
 2811 +  TEST_COMPARE_STRING (strerrorname_np (ENOMSG), "ENOMSG");
 2812 +#endif
 2813 +#ifdef ENOSR
 2814 +  TEST_COMPARE_STRING (strerrordesc_np (ENOSR), "Out of streams resources");
 2815 +  TEST_COMPARE_STRING (strerrorname_np (ENOSR), "ENOSR");
 2816 +#endif
 2817 +#ifdef ENOSTR
 2818 +  TEST_COMPARE_STRING (strerrordesc_np (ENOSTR), "Device not a stream");
 2819 +  TEST_COMPARE_STRING (strerrorname_np (ENOSTR), "ENOSTR");
 2820 +#endif
 2821 +#ifdef EOVERFLOW
 2822 +  TEST_COMPARE_STRING (strerrordesc_np (EOVERFLOW),
 2823 +		       "Value too large for defined data type");
 2824 +  TEST_COMPARE_STRING (strerrorname_np (EOVERFLOW), "EOVERFLOW");
 2825 +#endif
 2826 +#ifdef EPROTO
 2827 +  TEST_COMPARE_STRING (strerrordesc_np (EPROTO), "Protocol error");
 2828 +  TEST_COMPARE_STRING (strerrorname_np (EPROTO), "EPROTO");
 2829 +#endif
 2830 +#ifdef ETIME
 2831 +  TEST_COMPARE_STRING (strerrordesc_np (ETIME), "Timer expired");
 2832 +  TEST_COMPARE_STRING (strerrorname_np (ETIME), "ETIME");
 2833 +#endif
 2834 +#ifdef ECANCELED
 2835 +  TEST_COMPARE_STRING (strerrordesc_np (ECANCELED), "Operation canceled");
 2836 +  TEST_COMPARE_STRING (strerrorname_np (ECANCELED), "ECANCELED");
 2837 +#endif
 2838 +#ifdef EOWNERDEAD
 2839 +  TEST_COMPARE_STRING (strerrordesc_np (EOWNERDEAD), "Owner died");
 2840 +  TEST_COMPARE_STRING (strerrorname_np (EOWNERDEAD), "EOWNERDEAD");
 2841 +#endif
 2842 +#ifdef ENOTRECOVERABLE
 2843 +  TEST_COMPARE_STRING (strerrordesc_np (ENOTRECOVERABLE),
 2844 +		       "State not recoverable");
 2845 +  TEST_COMPARE_STRING (strerrorname_np (ENOTRECOVERABLE), "ENOTRECOVERABLE");
 2846 +#endif
 2847 +#ifdef ERESTART
 2848 +  TEST_COMPARE_STRING (strerrordesc_np (ERESTART),
 2849 +		       "Interrupted system call should be restarted");
 2850 +  TEST_COMPARE_STRING (strerrorname_np (ERESTART), "ERESTART");
 2851 +#endif
 2852 +#ifdef ECHRNG
 2853 +  TEST_COMPARE_STRING (strerrordesc_np (ECHRNG),
 2854 +		       "Channel number out of range");
 2855 +  TEST_COMPARE_STRING (strerrorname_np (ECHRNG), "ECHRNG");
 2856 +#endif
 2857 +#ifdef EL2NSYNC
 2858 +  TEST_COMPARE_STRING (strerrordesc_np (EL2NSYNC),
 2859 +		       "Level 2 not synchronized");
 2860 +  TEST_COMPARE_STRING (strerrorname_np (EL2NSYNC), "EL2NSYNC");
 2861 +#endif
 2862 +#ifdef EL3HLT
 2863 +  TEST_COMPARE_STRING (strerrordesc_np (EL3HLT), "Level 3 halted");
 2864 +  TEST_COMPARE_STRING (strerrorname_np (EL3HLT), "EL3HLT");
 2865 +#endif
 2866 +#ifdef EL3RST
 2867 +  TEST_COMPARE_STRING (strerrordesc_np (EL3RST), "Level 3 reset");
 2868 +  TEST_COMPARE_STRING (strerrorname_np (EL3RST), "EL3RST");
 2869 +#endif
 2870 +#ifdef ELNRNG
 2871 +  TEST_COMPARE_STRING (strerrordesc_np (ELNRNG), "Link number out of range");
 2872 +  TEST_COMPARE_STRING (strerrorname_np (ELNRNG), "ELNRNG");
 2873 +#endif
 2874 +#ifdef EUNATCH
 2875 +  TEST_COMPARE_STRING (strerrordesc_np (EUNATCH),
 2876 +		       "Protocol driver not attached");
 2877 +  TEST_COMPARE_STRING (strerrorname_np (EUNATCH), "EUNATCH");
 2878 +#endif
 2879 +#ifdef ENOCSI
 2880 +  TEST_COMPARE_STRING (strerrordesc_np (ENOCSI),
 2881 +		       "No CSI structure available");
 2882 +  TEST_COMPARE_STRING (strerrorname_np (ENOCSI), "ENOCSI");
 2883 +#endif
 2884 +#ifdef EL2HLT
 2885 +  TEST_COMPARE_STRING (strerrordesc_np (EL2HLT), "Level 2 halted");
 2886 +  TEST_COMPARE_STRING (strerrorname_np (EL2HLT), "EL2HLT");
 2887 +#endif
 2888 +#ifdef EBADE
 2889 +  TEST_COMPARE_STRING (strerrordesc_np (EBADE), "Invalid exchange");
 2890 +  TEST_COMPARE_STRING (strerrorname_np (EBADE), "EBADE");
 2891 +#endif
 2892 +#ifdef EBADR
 2893 +  TEST_COMPARE_STRING (strerrordesc_np (EBADR),
 2894 +		       "Invalid request descriptor");
 2895 +  TEST_COMPARE_STRING (strerrorname_np (EBADR), "EBADR");
 2896 +#endif
 2897 +#ifdef EXFULL
 2898 +  TEST_COMPARE_STRING (strerrordesc_np (EXFULL), "Exchange full");
 2899 +  TEST_COMPARE_STRING (strerrorname_np (EXFULL), "EXFULL");
 2900 +#endif
 2901 +#ifdef ENOANO
 2902 +  TEST_COMPARE_STRING (strerrordesc_np (ENOANO), "No anode");
 2903 +  TEST_COMPARE_STRING (strerrorname_np (ENOANO), "ENOANO");
 2904 +#endif
 2905 +#ifdef EBADRQC
 2906 +  TEST_COMPARE_STRING (strerrordesc_np (EBADRQC), "Invalid request code");
 2907 +  TEST_COMPARE_STRING (strerrorname_np (EBADRQC), "EBADRQC");
 2908 +#endif
 2909 +#ifdef EBADSLT
 2910 +  TEST_COMPARE_STRING (strerrordesc_np (EBADSLT), "Invalid slot");
 2911 +  TEST_COMPARE_STRING (strerrorname_np (EBADSLT), "EBADSLT");
 2912 +#endif
 2913 +#ifdef EBFONT
 2914 +  TEST_COMPARE_STRING (strerrordesc_np (EBFONT), "Bad font file format");
 2915 +  TEST_COMPARE_STRING (strerrorname_np (EBFONT), "EBFONT");
 2916 +#endif
 2917 +#ifdef ENONET
 2918 +  TEST_COMPARE_STRING (strerrordesc_np (ENONET),
 2919 +		       "Machine is not on the network");
 2920 +  TEST_COMPARE_STRING (strerrorname_np (ENONET), "ENONET");
 2921 +#endif
 2922 +#ifdef ENOPKG
 2923 +  TEST_COMPARE_STRING (strerrordesc_np (ENOPKG), "Package not installed");
 2924 +  TEST_COMPARE_STRING (strerrorname_np (ENOPKG), "ENOPKG");
 2925 +#endif
 2926 +#ifdef EADV
 2927 +  TEST_COMPARE_STRING (strerrordesc_np (EADV), "Advertise error");
 2928 +  TEST_COMPARE_STRING (strerrorname_np (EADV), "EADV");
 2929 +#endif
 2930 +#ifdef ESRMNT
 2931 +  TEST_COMPARE_STRING (strerrordesc_np (ESRMNT), "Srmount error");
 2932 +  TEST_COMPARE_STRING (strerrorname_np (ESRMNT), "ESRMNT");
 2933 +#endif
 2934 +#ifdef ECOMM
 2935 +  TEST_COMPARE_STRING (strerrordesc_np (ECOMM),
 2936 +		       "Communication error on send");
 2937 +  TEST_COMPARE_STRING (strerrorname_np (ECOMM), "ECOMM");
 2938 +#endif
 2939 +#ifdef EDOTDOT
 2940 +  TEST_COMPARE_STRING (strerrordesc_np (EDOTDOT), "RFS specific error");
 2941 +  TEST_COMPARE_STRING (strerrorname_np (EDOTDOT), "EDOTDOT");
 2942 +#endif
 2943 +#ifdef ENOTUNIQ
 2944 +  TEST_COMPARE_STRING (strerrordesc_np (ENOTUNIQ),
 2945 +		       "Name not unique on network");
 2946 +  TEST_COMPARE_STRING (strerrorname_np (ENOTUNIQ), "ENOTUNIQ");
 2947 +#endif
 2948 +#ifdef EBADFD
 2949 +  TEST_COMPARE_STRING (strerrordesc_np (EBADFD),
 2950 +		       "File descriptor in bad state");
 2951 +  TEST_COMPARE_STRING (strerrorname_np (EBADFD), "EBADFD");
 2952 +#endif
 2953 +#ifdef EREMCHG
 2954 +  TEST_COMPARE_STRING (strerrordesc_np (EREMCHG), "Remote address changed");
 2955 +  TEST_COMPARE_STRING (strerrorname_np (EREMCHG), "EREMCHG");
 2956 +#endif
 2957 +#ifdef ELIBACC
 2958 +  TEST_COMPARE_STRING (strerrordesc_np (ELIBACC),
 2959 +		       "Can not access a needed shared library");
 2960 +  TEST_COMPARE_STRING (strerrorname_np (ELIBACC), "ELIBACC");
 2961 +#endif
 2962 +#ifdef ELIBBAD
 2963 +  TEST_COMPARE_STRING (strerrordesc_np (ELIBBAD),
 2964 +		       "Accessing a corrupted shared library");
 2965 +  TEST_COMPARE_STRING (strerrorname_np (ELIBBAD), "ELIBBAD");
 2966 +#endif
 2967 +#ifdef ELIBSCN
 2968 +  TEST_COMPARE_STRING (strerrordesc_np (ELIBSCN),
 2969 +		       ".lib section in a.out corrupted");
 2970 +  TEST_COMPARE_STRING (strerrorname_np (ELIBSCN), "ELIBSCN");
 2971 +#endif
 2972 +#ifdef ELIBMAX
 2973 +  TEST_COMPARE_STRING (strerrordesc_np (ELIBMAX),
 2974 +		       "Attempting to link in too many shared libraries");
 2975 +  TEST_COMPARE_STRING (strerrorname_np (ELIBMAX), "ELIBMAX");
 2976 +#endif
 2977 +#ifdef ELIBEXEC
 2978 +  TEST_COMPARE_STRING (strerrordesc_np (ELIBEXEC),
 2979 +		       "Cannot exec a shared library directly");
 2980 +  TEST_COMPARE_STRING (strerrorname_np (ELIBEXEC), "ELIBEXEC");
 2981 +#endif
 2982 +#ifdef ESTRPIPE
 2983 +  TEST_COMPARE_STRING (strerrordesc_np (ESTRPIPE), "Streams pipe error");
 2984 +  TEST_COMPARE_STRING (strerrorname_np (ESTRPIPE), "ESTRPIPE");
 2985 +#endif
 2986 +#ifdef EUCLEAN
 2987 +  TEST_COMPARE_STRING (strerrordesc_np (EUCLEAN),
 2988 +		       "Structure needs cleaning");
 2989 +  TEST_COMPARE_STRING (strerrorname_np (EUCLEAN), "EUCLEAN");
 2990 +#endif
 2991 +#ifdef ENOTNAM
 2992 +  TEST_COMPARE_STRING (strerrordesc_np (ENOTNAM),
 2993 +		       "Not a XENIX named type file");
 2994 +  TEST_COMPARE_STRING (strerrorname_np (ENOTNAM), "ENOTNAM");
 2995 +#endif
 2996 +#ifdef ENAVAIL
 2997 +  TEST_COMPARE_STRING (strerrordesc_np (ENAVAIL),
 2998 +		       "No XENIX semaphores available");
 2999 +  TEST_COMPARE_STRING (strerrorname_np (ENAVAIL), "ENAVAIL");
 3000 +#endif
 3001 +#ifdef EISNAM
 3002 +  TEST_COMPARE_STRING (strerrordesc_np (EISNAM), "Is a named type file");
 3003 +  TEST_COMPARE_STRING (strerrorname_np (EISNAM), "EISNAM");
 3004 +#endif
 3005 +#ifdef EREMOTEIO
 3006 +  TEST_COMPARE_STRING (strerrordesc_np (EREMOTEIO), "Remote I/O error");
 3007 +  TEST_COMPARE_STRING (strerrorname_np (EREMOTEIO), "EREMOTEIO");
 3008 +#endif
 3009 +#ifdef ENOMEDIUM
 3010 +  TEST_COMPARE_STRING (strerrordesc_np (ENOMEDIUM), "No medium found");
 3011 +  TEST_COMPARE_STRING (strerrorname_np (ENOMEDIUM), "ENOMEDIUM");
 3012 +#endif
 3013 +#ifdef EMEDIUMTYPE
 3014 +  TEST_COMPARE_STRING (strerrordesc_np (EMEDIUMTYPE), "Wrong medium type");
 3015 +  TEST_COMPARE_STRING (strerrorname_np (EMEDIUMTYPE), "EMEDIUMTYPE");
 3016 +#endif
 3017 +#ifdef ENOKEY
 3018 +  TEST_COMPARE_STRING (strerrordesc_np (ENOKEY),
 3019 +		       "Required key not available");
 3020 +  TEST_COMPARE_STRING (strerrorname_np (ENOKEY), "ENOKEY");
 3021 +#endif
 3022 +#ifdef EKEYEXPIRED
 3023 +  TEST_COMPARE_STRING (strerrordesc_np (EKEYEXPIRED), "Key has expired");
 3024 +  TEST_COMPARE_STRING (strerrorname_np (EKEYEXPIRED), "EKEYEXPIRED");
 3025 +#endif
 3026 +#ifdef EKEYREVOKED
 3027 +  TEST_COMPARE_STRING (strerrordesc_np (EKEYREVOKED),
 3028 +		       "Key has been revoked");
 3029 +  TEST_COMPARE_STRING (strerrorname_np (EKEYREVOKED), "EKEYREVOKED");
 3030 +#endif
 3031 +#ifdef EKEYREJECTED
 3032 +  TEST_COMPARE_STRING (strerrordesc_np (EKEYREJECTED),
 3033 +		       "Key was rejected by service");
 3034 +  TEST_COMPARE_STRING (strerrorname_np (EKEYREJECTED), "EKEYREJECTED");
 3035 +#endif
 3036 +#ifdef ERFKILL
 3037 +  TEST_COMPARE_STRING (strerrordesc_np (ERFKILL),
 3038 +		       "Operation not possible due to RF-kill");
 3039 +  TEST_COMPARE_STRING (strerrorname_np (ERFKILL), "ERFKILL");
 3040 +#endif
 3041 +#ifdef EHWPOISON
 3042 +  TEST_COMPARE_STRING (strerrordesc_np (EHWPOISON),
 3043 +		       "Memory page has hardware error");
 3044 +  TEST_COMPARE_STRING (strerrorname_np (EHWPOISON), "EHWPOISON");
 3045 +#endif
 3046 +#ifdef EBADRPC
 3047 +  TEST_COMPARE_STRING (strerrordesc_np (EBADRPC), "RPC struct is bad");
 3048 +  TEST_COMPARE_STRING (strerrorname_np (EBADRPC), "EBADRPC");
 3049 +#endif
 3050 +#ifdef EFTYPE
 3051 +  TEST_COMPARE_STRING (strerrordesc_np (EFTYPE),
 3052 +		       "Inappropriate file type or format");
 3053 +  TEST_COMPARE_STRING (strerrorname_np (EFTYPE), "EFTYPE");
 3054 +#endif
 3055 +#ifdef EPROCUNAVAIL
 3056 +  TEST_COMPARE_STRING (strerrordesc_np (EPROCUNAVAIL),
 3057 +		       "RPC bad procedure for program");
 3058 +  TEST_COMPARE_STRING (strerrorname_np (EPROCUNAVAIL), "EPROCUNAVAIL");
 3059 +#endif
 3060 +#ifdef EAUTH
 3061 +  TEST_COMPARE_STRING (strerrordesc_np (EAUTH), "Authentication error");
 3062 +  TEST_COMPARE_STRING (strerrorname_np (EAUTH), "EAUTH");
 3063 +#endif
 3064 +#ifdef EDIED
 3065 +  TEST_COMPARE_STRING (strerrordesc_np (EDIED), "Translator died");
 3066 +  TEST_COMPARE_STRING (strerrorname_np (EDIED), "EDIED");
 3067 +#endif
 3068 +#ifdef ERPCMISMATCH
 3069 +  TEST_COMPARE_STRING (strerrordesc_np (ERPCMISMATCH), "RPC version wrong");
 3070 +  TEST_COMPARE_STRING (strerrorname_np (ERPCMISMATCH), "ERPCMISMATCH");
 3071 +#endif
 3072 +#ifdef EGREGIOUS
 3073 +  TEST_COMPARE_STRING (strerrordesc_np (EGREGIOUS),
 3074 +		       "You really blew it this time");
 3075 +  TEST_COMPARE_STRING (strerrorname_np (EGREGIOUS), "EGREGIOUS");
 3076 +#endif
 3077 +#ifdef EPROCLIM
 3078 +  TEST_COMPARE_STRING (strerrordesc_np (EPROCLIM), "Too many processes");
 3079 +  TEST_COMPARE_STRING (strerrorname_np (EPROCLIM), "EPROCLIM");
 3080 +#endif
 3081 +#ifdef EGRATUITOUS
 3082 +  TEST_COMPARE_STRING (strerrordesc_np (EGRATUITOUS), "Gratuitous error");
 3083 +  TEST_COMPARE_STRING (strerrorname_np (EGRATUITOUS), "EGRATUITOUS");
 3084 +#endif
 3085 +#if defined (ENOTSUP) && ENOTSUP != EOPNOTSUPP
 3086 +  TEST_COMPARE_STRING (strerrordesc_np (ENOTSUP), "Not supported");
 3087 +  TEST_COMPARE_STRING (strerrorname_np (ENOTSUP), "ENOTSUP");
 3088 +#endif
 3089 +#ifdef EPROGMISMATCH
 3090 +  TEST_COMPARE_STRING (strerrordesc_np (EPROGMISMATCH),
 3091 +		       "RPC program version wrong");
 3092 +  TEST_COMPARE_STRING (strerrorname_np (EPROGMISMATCH), "EPROGMISMATCH");
 3093 +#endif
 3094 +#ifdef EBACKGROUND
 3095 +  TEST_COMPARE_STRING (strerrordesc_np (EBACKGROUND),
 3096 +		       "Inappropriate operation for background process");
 3097 +  TEST_COMPARE_STRING (strerrorname_np (EBACKGROUND), "EBACKGROUND");
 3098 +#endif
 3099 +#ifdef EIEIO
 3100 +  TEST_COMPARE_STRING (strerrordesc_np (EIEIO), "Computer bought the farm");
 3101 +  TEST_COMPARE_STRING (strerrorname_np (EIEIO), "EIEIO");
 3102 +#endif
 3103 +#if defined (EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
 3104 +  TEST_COMPARE_STRING (strerrordesc_np (EWOULDBLOCK),
 3105 +		       "Operation would block");
 3106 +  TEST_COMPARE_STRING (strerrorname_np (EWOULDBLOCK), "EWOULDBLOCK");
 3107 +#endif
 3108 +#ifdef ENEEDAUTH
 3109 +  TEST_COMPARE_STRING (strerrordesc_np (ENEEDAUTH), "Need authenticator");
 3110 +  TEST_COMPARE_STRING (strerrorname_np (ENEEDAUTH), "ENEEDAUTH");
 3111 +#endif
 3112 +#ifdef ED
 3113 +  TEST_COMPARE_STRING (strerrordesc_np (ED), "?");
 3114 +  TEST_COMPARE_STRING (strerrorname_np (ED), "ED");
 3115 +#endif
 3116 +#ifdef EPROGUNAVAIL
 3117 +  TEST_COMPARE_STRING (strerrordesc_np (EPROGUNAVAIL),
 3118 +		       "RPC program not available");
 3119 +  TEST_COMPARE_STRING (strerrorname_np (EPROGUNAVAIL), "EPROGUNAVAIL");
 3120 +#endif
 3121  
 3122    return 0;
 3123  }
 3124 diff --git a/stdio-common/vfscanf-internal.c b/stdio-common/vfscanf-internal.c
 3125 index 95b46dcbeb..3a323547f9 100644
 3126 --- a/stdio-common/vfscanf-internal.c
 3127 +++ b/stdio-common/vfscanf-internal.c
 3128 @@ -277,7 +277,7 @@ __vfscanf_internal (FILE *s, const char *format, va_list argptr,
 3129  #endif
 3130  {
 3131    va_list arg;
 3132 -  const CHAR_T *f = format;
 3133 +  const UCHAR_T *f = (const UCHAR_T *) format;
 3134    UCHAR_T fc;	/* Current character of the format.  */
 3135    WINT_T done = 0;	/* Assignments done.  */
 3136    size_t read_in = 0;	/* Chars read in.  */
 3137 @@ -415,10 +415,11 @@ __vfscanf_internal (FILE *s, const char *format, va_list argptr,
 3138  #endif
 3139  
 3140  #ifndef COMPILE_WSCANF
 3141 -      if (!isascii ((unsigned char) *f))
 3142 +      if (!isascii (*f))
 3143  	{
 3144  	  /* Non-ASCII, may be a multibyte.  */
 3145 -	  int len = __mbrlen (f, strlen (f), &state);
 3146 +	  int len = __mbrlen ((const char *) f, strlen ((const char *) f),
 3147 +			      &state);
 3148  	  if (len > 0)
 3149  	    {
 3150  	      do
 3151 @@ -426,7 +427,7 @@ __vfscanf_internal (FILE *s, const char *format, va_list argptr,
 3152  		  c = inchar ();
 3153  		  if (__glibc_unlikely (c == EOF))
 3154  		    input_error ();
 3155 -		  else if (c != (unsigned char) *f++)
 3156 +		  else if (c != *f++)
 3157  		    {
 3158  		      ungetc_not_eof (c, s);
 3159  		      conv_error ();
 3160 @@ -484,9 +485,9 @@ __vfscanf_internal (FILE *s, const char *format, va_list argptr,
 3161        char_buffer_rewind (&charbuf);
 3162  
 3163        /* Check for a positional parameter specification.  */
 3164 -      if (ISDIGIT ((UCHAR_T) *f))
 3165 +      if (ISDIGIT (*f))
 3166  	{
 3167 -	  argpos = read_int ((const UCHAR_T **) &f);
 3168 +	  argpos = read_int (&f);
 3169  	  if (*f == L_('$'))
 3170  	    ++f;
 3171  	  else
 3172 @@ -521,8 +522,8 @@ __vfscanf_internal (FILE *s, const char *format, va_list argptr,
 3173  
 3174        /* Find the maximum field width.  */
 3175        width = 0;
 3176 -      if (ISDIGIT ((UCHAR_T) *f))
 3177 -	width = read_int ((const UCHAR_T **) &f);
 3178 +      if (ISDIGIT (*f))
 3179 +	width = read_int (&f);
 3180      got_width:
 3181        if (width == 0)
 3182  	width = -1;
 3183 @@ -2522,12 +2523,11 @@ __vfscanf_internal (FILE *s, const char *format, va_list argptr,
 3184  	    }
 3185  
 3186  	  while ((fc = *f++) != '\0' && fc != ']')
 3187 -	    if (fc == '-' && *f != '\0' && *f != ']'
 3188 -		&& (unsigned char) f[-2] <= (unsigned char) *f)
 3189 +	    if (fc == '-' && *f != '\0' && *f != ']' && f[-2] <= *f)
 3190  	      {
 3191  		/* Add all characters from the one before the '-'
 3192  		   up to (but not including) the next format char.  */
 3193 -		for (fc = (unsigned char) f[-2]; fc < (unsigned char) *f; ++fc)
 3194 +		for (fc = f[-2]; fc < *f; ++fc)
 3195  		  ((char *)charbuf.scratch.data)[fc] = 1;
 3196  	      }
 3197  	    else
 3198 diff --git a/stdlib/tst-secure-getenv.c b/stdlib/tst-secure-getenv.c
 3199 index 3cfe9a05c3..d4b1139c5e 100644
 3200 --- a/stdlib/tst-secure-getenv.c
 3201 +++ b/stdlib/tst-secure-getenv.c
 3202 @@ -30,167 +30,12 @@
 3203  #include <sys/wait.h>
 3204  #include <unistd.h>
 3205  
 3206 +#include <support/check.h>
 3207  #include <support/support.h>
 3208 +#include <support/capture_subprocess.h>
 3209  #include <support/test-driver.h>
 3210  
 3211  static char MAGIC_ARGUMENT[] = "run-actual-test";
 3212 -#define MAGIC_STATUS 19
 3213 -
 3214 -/* Return a GID which is not our current GID, but is present in the
 3215 -   supplementary group list.  */
 3216 -static gid_t
 3217 -choose_gid (void)
 3218 -{
 3219 -  int count = getgroups (0, NULL);
 3220 -  if (count < 0)
 3221 -    {
 3222 -      printf ("getgroups: %m\n");
 3223 -      exit (1);
 3224 -    }
 3225 -  gid_t *groups;
 3226 -  groups = xcalloc (count, sizeof (*groups));
 3227 -  int ret = getgroups (count, groups);
 3228 -  if (ret < 0)
 3229 -    {
 3230 -      printf ("getgroups: %m\n");
 3231 -      exit (1);
 3232 -    }
 3233 -  gid_t current = getgid ();
 3234 -  gid_t not_current = 0;
 3235 -  for (int i = 0; i < ret; ++i)
 3236 -    {
 3237 -      if (groups[i] != current)
 3238 -        {
 3239 -          not_current = groups[i];
 3240 -          break;
 3241 -        }
 3242 -    }
 3243 -  free (groups);
 3244 -  return not_current;
 3245 -}
 3246 -
 3247 -
 3248 -/* Copies the executable into a restricted directory, so that we can
 3249 -   safely make it SGID with the TARGET group ID.  Then runs the
 3250 -   executable.  */
 3251 -static int
 3252 -run_executable_sgid (gid_t target)
 3253 -{
 3254 -  char *dirname = xasprintf ("%s/secure-getenv.%jd",
 3255 -			     test_dir, (intmax_t) getpid ());
 3256 -  char *execname = xasprintf ("%s/bin", dirname);
 3257 -  int infd = -1;
 3258 -  int outfd = -1;
 3259 -  int ret = -1;
 3260 -  if (mkdir (dirname, 0700) < 0)
 3261 -    {
 3262 -      printf ("mkdir: %m\n");
 3263 -      goto err;
 3264 -    }
 3265 -  infd = open ("/proc/self/exe", O_RDONLY);
 3266 -  if (infd < 0)
 3267 -    {
 3268 -      printf ("open (/proc/self/exe): %m\n");
 3269 -      goto err;
 3270 -    }
 3271 -  outfd = open (execname, O_WRONLY | O_CREAT | O_EXCL, 0700);
 3272 -  if (outfd < 0)
 3273 -    {
 3274 -      printf ("open (%s): %m\n", execname);
 3275 -      goto err;
 3276 -    }
 3277 -  char buf[4096];
 3278 -  for (;;)
 3279 -    {
 3280 -      ssize_t rdcount = read (infd, buf, sizeof (buf));
 3281 -      if (rdcount < 0)
 3282 -	{
 3283 -	  printf ("read: %m\n");
 3284 -	  goto err;
 3285 -	}
 3286 -      if (rdcount == 0)
 3287 -	break;
 3288 -      char *p = buf;
 3289 -      char *end = buf + rdcount;
 3290 -      while (p != end)
 3291 -	{
 3292 -	  ssize_t wrcount = write (outfd, buf, end - p);
 3293 -	  if (wrcount == 0)
 3294 -	    errno = ENOSPC;
 3295 -	  if (wrcount <= 0)
 3296 -	    {
 3297 -	      printf ("write: %m\n");
 3298 -	      goto err;
 3299 -	    }
 3300 -	  p += wrcount;
 3301 -	}
 3302 -    }
 3303 -  if (fchown (outfd, getuid (), target) < 0)
 3304 -    {
 3305 -      printf ("fchown (%s): %m\n", execname);
 3306 -      goto err;
 3307 -    }
 3308 -  if (fchmod (outfd, 02750) < 0)
 3309 -    {
 3310 -      printf ("fchmod (%s): %m\n", execname);
 3311 -      goto err;
 3312 -    }
 3313 -  if (close (outfd) < 0)
 3314 -    {
 3315 -      printf ("close (outfd): %m\n");
 3316 -      goto err;
 3317 -    }
 3318 -  if (close (infd) < 0)
 3319 -    {
 3320 -      printf ("close (infd): %m\n");
 3321 -      goto err;
 3322 -    }
 3323 -
 3324 -  int kid = fork ();
 3325 -  if (kid < 0)
 3326 -    {
 3327 -      printf ("fork: %m\n");
 3328 -      goto err;
 3329 -    }
 3330 -  if (kid == 0)
 3331 -    {
 3332 -      /* Child process.  */
 3333 -      char *args[] = { execname, MAGIC_ARGUMENT, NULL };
 3334 -      execve (execname, args, environ);
 3335 -      printf ("execve (%s): %m\n", execname);
 3336 -      _exit (1);
 3337 -    }
 3338 -  int status;
 3339 -  if (waitpid (kid, &status, 0) < 0)
 3340 -    {
 3341 -      printf ("waitpid: %m\n");
 3342 -      goto err;
 3343 -    }
 3344 -  if (!WIFEXITED (status) || WEXITSTATUS (status) != MAGIC_STATUS)
 3345 -    {
 3346 -      printf ("Unexpected exit status %d from child process\n",
 3347 -	      status);
 3348 -      goto err;
 3349 -    }
 3350 -  ret = 0;
 3351 -
 3352 -err:
 3353 -  if (outfd >= 0)
 3354 -    close (outfd);
 3355 -  if (infd >= 0)
 3356 -    close (infd);
 3357 -  if (execname)
 3358 -    {
 3359 -      unlink (execname);
 3360 -      free (execname);
 3361 -    }
 3362 -  if (dirname)
 3363 -    {
 3364 -      rmdir (dirname);
 3365 -      free (dirname);
 3366 -    }
 3367 -  return ret;
 3368 -}
 3369  
 3370  static int
 3371  do_test (void)
 3372 @@ -212,15 +57,15 @@ do_test (void)
 3373        exit (1);
 3374      }
 3375  
 3376 -  gid_t target = choose_gid ();
 3377 -  if (target == 0)
 3378 -    {
 3379 -      fprintf (stderr,
 3380 -	       "Could not find a suitable GID for user %jd, skipping test\n",
 3381 -	       (intmax_t) getuid ());
 3382 -      exit (0);
 3383 -    }
 3384 -  return run_executable_sgid (target);
 3385 +  int status = support_capture_subprogram_self_sgid (MAGIC_ARGUMENT);
 3386 +
 3387 +  if (WEXITSTATUS (status) == EXIT_UNSUPPORTED)
 3388 +    return EXIT_UNSUPPORTED;
 3389 +
 3390 +  if (!WIFEXITED (status))
 3391 +    FAIL_EXIT1 ("Unexpected exit status %d from child process\n", status);
 3392 +
 3393 +  return 0;
 3394  }
 3395  
 3396  static void
 3397 @@ -229,23 +74,15 @@ alternative_main (int argc, char **argv)
 3398    if (argc == 2 && strcmp (argv[1], MAGIC_ARGUMENT) == 0)
 3399      {
 3400        if (getgid () == getegid ())
 3401 -	{
 3402 -	  /* This can happen if the file system is mounted nosuid.  */
 3403 -	  fprintf (stderr, "SGID failed: GID and EGID match (%jd)\n",
 3404 -		  (intmax_t) getgid ());
 3405 -	  exit (MAGIC_STATUS);
 3406 -	}
 3407 +	/* This can happen if the file system is mounted nosuid.  */
 3408 +	FAIL_UNSUPPORTED ("SGID failed: GID and EGID match (%jd)\n",
 3409 +		   (intmax_t) getgid ());
 3410        if (getenv ("PATH") == NULL)
 3411 -	{
 3412 -	  printf ("PATH variable not present\n");
 3413 -	  exit (3);
 3414 -	}
 3415 +	FAIL_EXIT (3, "PATH variable not present\n");
 3416        if (secure_getenv ("PATH") != NULL)
 3417 -	{
 3418 -	  printf ("PATH variable not filtered out\n");
 3419 -	  exit (4);
 3420 -	}
 3421 -      exit (MAGIC_STATUS);
 3422 +	FAIL_EXIT (4, "PATH variable not filtered out\n");
 3423 +
 3424 +      exit (EXIT_SUCCESS);
 3425      }
 3426  }
 3427  
 3428 diff --git a/string/bits/string_fortified.h b/string/bits/string_fortified.h
 3429 index 309d0f39b2..c8d3051af8 100644
 3430 --- a/string/bits/string_fortified.h
 3431 +++ b/string/bits/string_fortified.h
 3432 @@ -22,11 +22,6 @@
 3433  # error "Never use <bits/string_fortified.h> directly; include <string.h> instead."
 3434  #endif
 3435  
 3436 -#if !__GNUC_PREREQ (5,0)
 3437 -__warndecl (__warn_memset_zero_len,
 3438 -	    "memset used with constant zero length parameter; this could be due to transposed parameters");
 3439 -#endif
 3440 -
 3441  __fortify_function void *
 3442  __NTH (memcpy (void *__restrict __dest, const void *__restrict __src,
 3443  	       size_t __len))
 3444 @@ -58,16 +53,6 @@ __NTH (mempcpy (void *__restrict __dest, const void *__restrict __src,
 3445  __fortify_function void *
 3446  __NTH (memset (void *__dest, int __ch, size_t __len))
 3447  {
 3448 -  /* GCC-5.0 and newer implements these checks in the compiler, so we don't
 3449 -     need them here.  */
 3450 -#if !__GNUC_PREREQ (5,0)
 3451 -  if (__builtin_constant_p (__len) && __len == 0
 3452 -      && (!__builtin_constant_p (__ch) || __ch != 0))
 3453 -    {
 3454 -      __warn_memset_zero_len ();
 3455 -      return __dest;
 3456 -    }
 3457 -#endif
 3458    return __builtin___memset_chk (__dest, __ch, __len, __bos0 (__dest));
 3459  }
 3460  
 3461 diff --git a/support/Makefile b/support/Makefile
 3462 index 93faafddf9..3d3aff5ff9 100644
 3463 --- a/support/Makefile
 3464 +++ b/support/Makefile
 3465 @@ -35,6 +35,8 @@ libsupport-routines = \
 3466    ignore_stderr \
 3467    next_to_fault \
 3468    oom_error \
 3469 +  resolv_response_context_duplicate \
 3470 +  resolv_response_context_free \
 3471    resolv_test \
 3472    set_fortify_handler \
 3473    support-xfstat \
 3474 @@ -133,6 +135,7 @@ libsupport-routines = \
 3475    xpthread_join \
 3476    xpthread_key_create \
 3477    xpthread_key_delete \
 3478 +  xpthread_kill \
 3479    xpthread_mutex_consistent \
 3480    xpthread_mutex_destroy \
 3481    xpthread_mutex_init \
 3482 diff --git a/support/capture_subprocess.h b/support/capture_subprocess.h
 3483 index 9808750f80..421f657678 100644
 3484 --- a/support/capture_subprocess.h
 3485 +++ b/support/capture_subprocess.h
 3486 @@ -41,6 +41,12 @@ struct support_capture_subprocess support_capture_subprocess
 3487  struct support_capture_subprocess support_capture_subprogram
 3488    (const char *file, char *const argv[]);
 3489  
 3490 +/* Copy the running program into a setgid binary and run it with CHILD_ID
 3491 +   argument.  If execution is successful, return the exit status of the child
 3492 +   program, otherwise return a non-zero failure exit code.  */
 3493 +int support_capture_subprogram_self_sgid
 3494 +  (char *child_id);
 3495 +
 3496  /* Deallocate the subprocess data captured by
 3497     support_capture_subprocess.  */
 3498  void support_capture_subprocess_free (struct support_capture_subprocess *);
 3499 diff --git a/support/resolv_response_context_duplicate.c b/support/resolv_response_context_duplicate.c
 3500 new file mode 100644
 3501 index 0000000000..f9c5c3462a
 3502 --- /dev/null
 3503 +++ b/support/resolv_response_context_duplicate.c
 3504 @@ -0,0 +1,37 @@
 3505 +/* Duplicate a response context used in DNS resolver tests.
 3506 +   Copyright (C) 2020 Free Software Foundation, Inc.
 3507 +   This file is part of the GNU C Library.
 3508 +
 3509 +   The GNU C Library is free software; you can redistribute it and/or
 3510 +   modify it under the terms of the GNU Lesser General Public
 3511 +   License as published by the Free Software Foundation; either
 3512 +   version 2.1 of the License, or (at your option) any later version.
 3513 +
 3514 +   The GNU C Library is distributed in the hope that it will be useful,
 3515 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
 3516 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 3517 +   Lesser General Public License for more details.
 3518 +
 3519 +   You should have received a copy of the GNU Lesser General Public
 3520 +   License along with the GNU C Library; if not, see
 3521 +   <https://www.gnu.org/licenses/>.  */
 3522 +
 3523 +#include <string.h>
 3524 +#include <support/resolv_test.h>
 3525 +#include <support/support.h>
 3526 +
 3527 +struct resolv_response_context *
 3528 +resolv_response_context_duplicate (const struct resolv_response_context *ctx)
 3529 +{
 3530 +  struct resolv_response_context *result = xmalloc (sizeof (*result));
 3531 +  memcpy (result, ctx, sizeof (*result));
 3532 +  if (result->client_address != NULL)
 3533 +    {
 3534 +      result->client_address = xmalloc (result->client_address_length);
 3535 +      memcpy (result->client_address, ctx->client_address,
 3536 +              result->client_address_length);
 3537 +    }
 3538 +  result->query_buffer = xmalloc (result->query_length);
 3539 +  memcpy (result->query_buffer, ctx->query_buffer, result->query_length);
 3540 +  return result;
 3541 +}
 3542 diff --git a/support/resolv_response_context_free.c b/support/resolv_response_context_free.c
 3543 new file mode 100644
 3544 index 0000000000..b88c05ffd4
 3545 --- /dev/null
 3546 +++ b/support/resolv_response_context_free.c
 3547 @@ -0,0 +1,28 @@
 3548 +/* Free a response context used in DNS resolver tests.
 3549 +   Copyright (C) 2020 Free Software Foundation, Inc.
 3550 +   This file is part of the GNU C Library.
 3551 +
 3552 +   The GNU C Library is free software; you can redistribute it and/or
 3553 +   modify it under the terms of the GNU Lesser General Public
 3554 +   License as published by the Free Software Foundation; either
 3555 +   version 2.1 of the License, or (at your option) any later version.
 3556 +
 3557 +   The GNU C Library is distributed in the hope that it will be useful,
 3558 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
 3559 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 3560 +   Lesser General Public License for more details.
 3561 +
 3562 +   You should have received a copy of the GNU Lesser General Public
 3563 +   License along with the GNU C Library; if not, see
 3564 +   <https://www.gnu.org/licenses/>.  */
 3565 +
 3566 +#include <stdlib.h>
 3567 +#include <support/resolv_test.h>
 3568 +
 3569 +void
 3570 +resolv_response_context_free (struct resolv_response_context *ctx)
 3571 +{
 3572 +  free (ctx->query_buffer);
 3573 +  free (ctx->client_address);
 3574 +  free (ctx);
 3575 +}
 3576 diff --git a/support/resolv_test.c b/support/resolv_test.c
 3577 index 53b7fc41ab..9878a040a3 100644
 3578 --- a/support/resolv_test.c
 3579 +++ b/support/resolv_test.c
 3580 @@ -181,7 +181,9 @@ resolv_response_init (struct resolv_response_builder *b,
 3581    b->buffer[2] |= b->query_buffer[2] & 0x01; /* Copy the RD bit.  */
 3582    if (flags.tc)
 3583      b->buffer[2] |= 0x02;
 3584 -  b->buffer[3] = 0x80 | flags.rcode; /* Always set RA.  */
 3585 +  b->buffer[3] = flags.rcode;
 3586 +  if (!flags.clear_ra)
 3587 +    b->buffer[3] |= 0x80;
 3588    if (flags.ad)
 3589      b->buffer[3] |= 0x20;
 3590  
 3591 @@ -434,9 +436,9 @@ resolv_response_buffer (const struct resolv_response_builder *b)
 3592    return result;
 3593  }
 3594  
 3595 -static struct resolv_response_builder *
 3596 -response_builder_allocate
 3597 -  (const unsigned char *query_buffer, size_t query_length)
 3598 +struct resolv_response_builder *
 3599 +resolv_response_builder_allocate (const unsigned char *query_buffer,
 3600 +                                  size_t query_length)
 3601  {
 3602    struct resolv_response_builder *b = xmalloc (sizeof (*b));
 3603    memset (b, 0, offsetof (struct resolv_response_builder, buffer));
 3604 @@ -445,8 +447,8 @@ response_builder_allocate
 3605    return b;
 3606  }
 3607  
 3608 -static void
 3609 -response_builder_free (struct resolv_response_builder *b)
 3610 +void
 3611 +resolv_response_builder_free (struct resolv_response_builder *b)
 3612  {
 3613    tdestroy (b->compression_offsets, free);
 3614    free (b);
 3615 @@ -661,13 +663,17 @@ server_thread_udp_process_one (struct resolv_test *obj, int server_index)
 3616  
 3617    struct resolv_response_context ctx =
 3618      {
 3619 +      .test = obj,
 3620 +      .client_address = &peer,
 3621 +      .client_address_length = peerlen,
 3622        .query_buffer = query,
 3623        .query_length = length,
 3624        .server_index = server_index,
 3625        .tcp = false,
 3626        .edns = qinfo.edns,
 3627      };
 3628 -  struct resolv_response_builder *b = response_builder_allocate (query, length);
 3629 +  struct resolv_response_builder *b
 3630 +    = resolv_response_builder_allocate (query, length);
 3631    obj->config.response_callback
 3632      (&ctx, b, qinfo.qname, qinfo.qclass, qinfo.qtype);
 3633  
 3634 @@ -684,7 +690,7 @@ server_thread_udp_process_one (struct resolv_test *obj, int server_index)
 3635            if (b->offset >= 12)
 3636              printf ("info: UDP server %d: sending response:"
 3637                      " %zu bytes, RCODE %d (for %s/%u/%u)\n",
 3638 -                    server_index, b->offset, b->buffer[3] & 0x0f,
 3639 +                    ctx.server_index, b->offset, b->buffer[3] & 0x0f,
 3640                      qinfo.qname, qinfo.qclass, qinfo.qtype);
 3641            else
 3642              printf ("info: UDP server %d: sending response: %zu bytes"
 3643 @@ -694,23 +700,31 @@ server_thread_udp_process_one (struct resolv_test *obj, int server_index)
 3644            if (b->truncate_bytes > 0)
 3645              printf ("info:    truncated by %u bytes\n", b->truncate_bytes);
 3646          }
 3647 -      size_t to_send = b->offset;
 3648 -      if (to_send < b->truncate_bytes)
 3649 -        to_send = 0;
 3650 -      else
 3651 -        to_send -= b->truncate_bytes;
 3652 -
 3653 -      /* Ignore most errors here because the other end may have closed
 3654 -         the socket. */
 3655 -      if (sendto (obj->servers[server_index].socket_udp,
 3656 -                  b->buffer, to_send, 0,
 3657 -                  (struct sockaddr *) &peer, peerlen) < 0)
 3658 -        TEST_VERIFY_EXIT (errno != EBADF);
 3659 +      resolv_response_send_udp (&ctx, b);
 3660      }
 3661 -  response_builder_free (b);
 3662 +  resolv_response_builder_free (b);
 3663    return true;
 3664  }
 3665  
 3666 +void
 3667 +resolv_response_send_udp (const struct resolv_response_context *ctx,
 3668 +                          struct resolv_response_builder *b)
 3669 +{
 3670 +  TEST_VERIFY_EXIT (!ctx->tcp);
 3671 +  size_t to_send = b->offset;
 3672 +  if (to_send < b->truncate_bytes)
 3673 +    to_send = 0;
 3674 +  else
 3675 +    to_send -= b->truncate_bytes;
 3676 +
 3677 +  /* Ignore most errors here because the other end may have closed
 3678 +     the socket.  */
 3679 +  if (sendto (ctx->test->servers[ctx->server_index].socket_udp,
 3680 +              b->buffer, to_send, 0,
 3681 +              ctx->client_address, ctx->client_address_length) < 0)
 3682 +    TEST_VERIFY_EXIT (errno != EBADF);
 3683 +}
 3684 +
 3685  /* UDP thread_callback function.  Variant for one thread per
 3686     server.  */
 3687  static void
 3688 @@ -897,14 +911,15 @@ server_thread_tcp_client (void *arg)
 3689  
 3690        struct resolv_response_context ctx =
 3691          {
 3692 +          .test = closure->obj,
 3693            .query_buffer = query_buffer,
 3694            .query_length = query_length,
 3695            .server_index = closure->server_index,
 3696            .tcp = true,
 3697            .edns = qinfo.edns,
 3698          };
 3699 -      struct resolv_response_builder *b = response_builder_allocate
 3700 -        (query_buffer, query_length);
 3701 +      struct resolv_response_builder *b
 3702 +        = resolv_response_builder_allocate (query_buffer, query_length);
 3703        closure->obj->config.response_callback
 3704          (&ctx, b, qinfo.qname, qinfo.qclass, qinfo.qtype);
 3705  
 3706 @@ -936,7 +951,7 @@ server_thread_tcp_client (void *arg)
 3707            writev_fully (closure->client_socket, buffers, 2);
 3708          }
 3709        bool close_flag = b->close;
 3710 -      response_builder_free (b);
 3711 +      resolv_response_builder_free (b);
 3712        free (query_buffer);
 3713        if (close_flag)
 3714          break;
 3715 diff --git a/support/resolv_test.h b/support/resolv_test.h
 3716 index 67819469a0..31a5c1c3e7 100644
 3717 --- a/support/resolv_test.h
 3718 +++ b/support/resolv_test.h
 3719 @@ -35,25 +35,36 @@ struct resolv_edns_info
 3720    uint16_t payload_size;
 3721  };
 3722  
 3723 +/* This opaque struct collects information about the resolver testing
 3724 +   currently in progress.  */
 3725 +struct resolv_test;
 3726 +
 3727  /* This struct provides context information when the response callback
 3728     specified in struct resolv_redirect_config is invoked. */
 3729  struct resolv_response_context
 3730  {
 3731 -  const unsigned char *query_buffer;
 3732 +  struct resolv_test *test;
 3733 +  void *client_address;
 3734 +  size_t client_address_length;
 3735 +  unsigned char *query_buffer;
 3736    size_t query_length;
 3737    int server_index;
 3738    bool tcp;
 3739    struct resolv_edns_info edns;
 3740  };
 3741  
 3742 +/* Produces a deep copy of the context.  */
 3743 +struct resolv_response_context *
 3744 +  resolv_response_context_duplicate (const struct resolv_response_context *);
 3745 +
 3746 +/* Frees the copy.  For the context passed to the response function,
 3747 +   this happens implicitly.  */
 3748 +void resolv_response_context_free (struct resolv_response_context *);
 3749 +
 3750  /* This opaque struct is used to construct responses from within the
 3751     response callback function.  */
 3752  struct resolv_response_builder;
 3753  
 3754 -/* This opaque struct collects information about the resolver testing
 3755 -   currently in progress.  */
 3756 -struct resolv_test;
 3757 -
 3758  enum
 3759    {
 3760      /* Maximum number of test servers supported by the framework.  */
 3761 @@ -137,6 +148,10 @@ struct resolv_response_flags
 3762    /* If true, the AD (authenticated data) flag will be set.  */
 3763    bool ad;
 3764  
 3765 +  /* If true, do not set the RA (recursion available) flag in the
 3766 +     response.  */
 3767 +  bool clear_ra;
 3768 +
 3769    /* Initial section count values.  Can be used to artificially
 3770       increase the counts, for malformed packet testing.*/
 3771    unsigned short qdcount;
 3772 @@ -188,6 +203,22 @@ void resolv_response_close (struct resolv_response_builder *);
 3773  /* The size of the response packet built so far.  */
 3774  size_t resolv_response_length (const struct resolv_response_builder *);
 3775  
 3776 +/* Allocates a response builder tied to a specific query packet,
 3777 +   starting at QUERY_BUFFER, containing QUERY_LENGTH bytes.  */
 3778 +struct resolv_response_builder *
 3779 +  resolv_response_builder_allocate (const unsigned char *query_buffer,
 3780 +                                    size_t query_length);
 3781 +
 3782 +/* Deallocates a response buffer.  */
 3783 +void resolv_response_builder_free (struct resolv_response_builder *);
 3784 +
 3785 +/* Sends a UDP response using a specific context.  This can be used to
 3786 +   reorder or duplicate responses, along with
 3787 +   resolv_response_context_duplicate and
 3788 +   response_builder_allocate.  */
 3789 +void resolv_response_send_udp (const struct resolv_response_context *,
 3790 +                               struct resolv_response_builder *);
 3791 +
 3792  __END_DECLS
 3793  
 3794  #endif /* SUPPORT_RESOLV_TEST_H */
 3795 diff --git a/support/subprocess.h b/support/subprocess.h
 3796 index 8b442fd5c0..34ffd02e8e 100644
 3797 --- a/support/subprocess.h
 3798 +++ b/support/subprocess.h
 3799 @@ -38,6 +38,11 @@ struct support_subprocess support_subprocess
 3800  struct support_subprocess support_subprogram
 3801    (const char *file, char *const argv[]);
 3802  
 3803 +/* Invoke program FILE with ARGV arguments by using posix_spawn and wait for it
 3804 +   to complete.  Return program exit status.  */
 3805 +int support_subprogram_wait
 3806 +  (const char *file, char *const argv[]);
 3807 +
 3808  /* Wait for the subprocess indicated by PROC::PID.  Return the status
 3809     indicate by waitpid call.  */
 3810  int support_process_wait (struct support_subprocess *proc);
 3811 diff --git a/support/support_capture_subprocess.c b/support/support_capture_subprocess.c
 3812 index eeed676e3d..28a37df67f 100644
 3813 --- a/support/support_capture_subprocess.c
 3814 +++ b/support/support_capture_subprocess.c
 3815 @@ -20,11 +20,14 @@
 3816  #include <support/capture_subprocess.h>
 3817  
 3818  #include <errno.h>
 3819 +#include <fcntl.h>
 3820  #include <stdlib.h>
 3821  #include <support/check.h>
 3822  #include <support/xunistd.h>
 3823  #include <support/xsocket.h>
 3824  #include <support/xspawn.h>
 3825 +#include <support/support.h>
 3826 +#include <support/test-driver.h>
 3827  
 3828  static void
 3829  transfer (const char *what, struct pollfd *pfd, struct xmemstream *stream)
 3830 @@ -36,7 +39,7 @@ transfer (const char *what, struct pollfd *pfd, struct xmemstream *stream)
 3831        if (ret < 0)
 3832          {
 3833            support_record_failure ();
 3834 -          printf ("error: reading from subprocess %s: %m", what);
 3835 +          printf ("error: reading from subprocess %s: %m\n", what);
 3836            pfd->events = 0;
 3837            pfd->revents = 0;
 3838          }
 3839 @@ -102,6 +105,129 @@ support_capture_subprogram (const char *file, char *const argv[])
 3840    return result;
 3841  }
 3842  
 3843 +/* Copies the executable into a restricted directory, so that we can
 3844 +   safely make it SGID with the TARGET group ID.  Then runs the
 3845 +   executable.  */
 3846 +static int
 3847 +copy_and_spawn_sgid (char *child_id, gid_t gid)
 3848 +{
 3849 +  char *dirname = xasprintf ("%s/tst-tunables-setuid.%jd",
 3850 +			     test_dir, (intmax_t) getpid ());
 3851 +  char *execname = xasprintf ("%s/bin", dirname);
 3852 +  int infd = -1;
 3853 +  int outfd = -1;
 3854 +  int ret = 1, status = 1;
 3855 +
 3856 +  TEST_VERIFY (mkdir (dirname, 0700) == 0);
 3857 +  if (support_record_failure_is_failed ())
 3858 +    goto err;
 3859 +
 3860 +  infd = open ("/proc/self/exe", O_RDONLY);
 3861 +  if (infd < 0)
 3862 +    FAIL_UNSUPPORTED ("unsupported: Cannot read binary from procfs\n");
 3863 +
 3864 +  outfd = open (execname, O_WRONLY | O_CREAT | O_EXCL, 0700);
 3865 +  TEST_VERIFY (outfd >= 0);
 3866 +  if (support_record_failure_is_failed ())
 3867 +    goto err;
 3868 +
 3869 +  char buf[4096];
 3870 +  for (;;)
 3871 +    {
 3872 +      ssize_t rdcount = read (infd, buf, sizeof (buf));
 3873 +      TEST_VERIFY (rdcount >= 0);
 3874 +      if (support_record_failure_is_failed ())
 3875 +	goto err;
 3876 +      if (rdcount == 0)
 3877 +	break;
 3878 +      char *p = buf;
 3879 +      char *end = buf + rdcount;
 3880 +      while (p != end)
 3881 +	{
 3882 +	  ssize_t wrcount = write (outfd, buf, end - p);
 3883 +	  if (wrcount == 0)
 3884 +	    errno = ENOSPC;
 3885 +	  TEST_VERIFY (wrcount > 0);
 3886 +	  if (support_record_failure_is_failed ())
 3887 +	    goto err;
 3888 +	  p += wrcount;
 3889 +	}
 3890 +    }
 3891 +  TEST_VERIFY (fchown (outfd, getuid (), gid) == 0);
 3892 +  if (support_record_failure_is_failed ())
 3893 +    goto err;
 3894 +  TEST_VERIFY (fchmod (outfd, 02750) == 0);
 3895 +  if (support_record_failure_is_failed ())
 3896 +    goto err;
 3897 +  TEST_VERIFY (close (outfd) == 0);
 3898 +  if (support_record_failure_is_failed ())
 3899 +    goto err;
 3900 +  TEST_VERIFY (close (infd) == 0);
 3901 +  if (support_record_failure_is_failed ())
 3902 +    goto err;
 3903 +
 3904 +  /* We have the binary, now spawn the subprocess.  Avoid using
 3905 +     support_subprogram because we only want the program exit status, not the
 3906 +     contents.  */
 3907 +  ret = 0;
 3908 +
 3909 +  char * const args[] = {execname, child_id, NULL};
 3910 +
 3911 +  status = support_subprogram_wait (args[0], args);
 3912 +
 3913 +err:
 3914 +  if (outfd >= 0)
 3915 +    close (outfd);
 3916 +  if (infd >= 0)
 3917 +    close (infd);
 3918 +  if (execname != NULL)
 3919 +    {
 3920 +      unlink (execname);
 3921 +      free (execname);
 3922 +    }
 3923 +  if (dirname != NULL)
 3924 +    {
 3925 +      rmdir (dirname);
 3926 +      free (dirname);
 3927 +    }
 3928 +
 3929 +  if (ret != 0)
 3930 +    FAIL_EXIT1("Failed to make sgid executable for test\n");
 3931 +
 3932 +  return status;
 3933 +}
 3934 +
 3935 +int
 3936 +support_capture_subprogram_self_sgid (char *child_id)
 3937 +{
 3938 +  gid_t target = 0;
 3939 +  const int count = 64;
 3940 +  gid_t groups[count];
 3941 +
 3942 +  /* Get a GID which is not our current GID, but is present in the
 3943 +     supplementary group list.  */
 3944 +  int ret = getgroups (count, groups);
 3945 +  if (ret < 0)
 3946 +    FAIL_UNSUPPORTED("Could not get group list for user %jd\n",
 3947 +		     (intmax_t) getuid ());
 3948 +
 3949 +  gid_t current = getgid ();
 3950 +  for (int i = 0; i < ret; ++i)
 3951 +    {
 3952 +      if (groups[i] != current)
 3953 +	{
 3954 +	  target = groups[i];
 3955 +	  break;
 3956 +	}
 3957 +    }
 3958 +
 3959 +  if (target == 0)
 3960 +    FAIL_UNSUPPORTED("Could not find a suitable GID for user %jd\n",
 3961 +		     (intmax_t) getuid ());
 3962 +
 3963 +  return copy_and_spawn_sgid (child_id, target);
 3964 +}
 3965 +
 3966  void
 3967  support_capture_subprocess_free (struct support_capture_subprocess *p)
 3968  {
 3969 diff --git a/support/support_subprocess.c b/support/support_subprocess.c
 3970 index 36e3a77af2..4a25828111 100644
 3971 --- a/support/support_subprocess.c
 3972 +++ b/support/support_subprocess.c
 3973 @@ -27,7 +27,7 @@
 3974  #include <support/subprocess.h>
 3975  
 3976  static struct support_subprocess
 3977 -support_suprocess_init (void)
 3978 +support_subprocess_init (void)
 3979  {
 3980    struct support_subprocess result;
 3981  
 3982 @@ -48,7 +48,7 @@ support_suprocess_init (void)
 3983  struct support_subprocess
 3984  support_subprocess (void (*callback) (void *), void *closure)
 3985  {
 3986 -  struct support_subprocess result = support_suprocess_init ();
 3987 +  struct support_subprocess result = support_subprocess_init ();
 3988  
 3989    result.pid = xfork ();
 3990    if (result.pid == 0)
 3991 @@ -71,7 +71,7 @@ support_subprocess (void (*callback) (void *), void *closure)
 3992  struct support_subprocess
 3993  support_subprogram (const char *file, char *const argv[])
 3994  {
 3995 -  struct support_subprocess result = support_suprocess_init ();
 3996 +  struct support_subprocess result = support_subprocess_init ();
 3997  
 3998    posix_spawn_file_actions_t fa;
 3999    /* posix_spawn_file_actions_init does not fail.  */
 4000 @@ -84,7 +84,7 @@ support_subprogram (const char *file, char *const argv[])
 4001    xposix_spawn_file_actions_addclose (&fa, result.stdout_pipe[1]);
 4002    xposix_spawn_file_actions_addclose (&fa, result.stderr_pipe[1]);
 4003  
 4004 -  result.pid = xposix_spawn (file, &fa, NULL, argv, NULL);
 4005 +  result.pid = xposix_spawn (file, &fa, NULL, argv, environ);
 4006  
 4007    xclose (result.stdout_pipe[1]);
 4008    xclose (result.stderr_pipe[1]);
 4009 @@ -92,6 +92,19 @@ support_subprogram (const char *file, char *const argv[])
 4010    return result;
 4011  }
 4012  
 4013 +int
 4014 +support_subprogram_wait (const char *file, char *const argv[])
 4015 +{
 4016 +  posix_spawn_file_actions_t fa;
 4017 +
 4018 +  posix_spawn_file_actions_init (&fa);
 4019 +  struct support_subprocess res = support_subprocess_init ();
 4020 +
 4021 +  res.pid = xposix_spawn (file, &fa, NULL, argv, environ);
 4022 +
 4023 +  return support_process_wait (&res);
 4024 +}
 4025 +
 4026  int
 4027  support_process_wait (struct support_subprocess *proc)
 4028  {
 4029 diff --git a/support/xpthread_kill.c b/support/xpthread_kill.c
 4030 new file mode 100644
 4031 index 0000000000..111a75d85e
 4032 --- /dev/null
 4033 +++ b/support/xpthread_kill.c
 4034 @@ -0,0 +1,26 @@
 4035 +/* pthread_kill with error checking.
 4036 +   Copyright (C) 2021 Free Software Foundation, Inc.
 4037 +   This file is part of the GNU C Library.
 4038 +
 4039 +   The GNU C Library is free software; you can redistribute it and/or
 4040 +   modify it under the terms of the GNU Lesser General Public
 4041 +   License as published by the Free Software Foundation; either
 4042 +   version 2.1 of the License, or (at your option) any later version.
 4043 +
 4044 +   The GNU C Library is distributed in the hope that it will be useful,
 4045 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
 4046 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 4047 +   Lesser General Public License for more details.
 4048 +
 4049 +   You should have received a copy of the GNU Lesser General Public
 4050 +   License along with the GNU C Library; if not, see
 4051 +   <https://www.gnu.org/licenses/>.  */
 4052 +
 4053 +#include <signal.h>
 4054 +#include <support/xthread.h>
 4055 +
 4056 +void
 4057 +xpthread_kill (pthread_t thr, int signo)
 4058 +{
 4059 +  xpthread_check_return ("pthread_kill", pthread_kill (thr, signo));
 4060 +}
 4061 diff --git a/support/xthread.h b/support/xthread.h
 4062 index 05f8d4a7d9..cb1fc30da0 100644
 4063 --- a/support/xthread.h
 4064 +++ b/support/xthread.h
 4065 @@ -75,6 +75,8 @@ void xpthread_attr_setstacksize (pthread_attr_t *attr,
 4066  void xpthread_attr_setguardsize (pthread_attr_t *attr,
 4067  				 size_t guardsize);
 4068  
 4069 +void xpthread_kill (pthread_t thr, int signo);
 4070 +
 4071  /* Set the stack size in ATTR to a small value, but still large enough
 4072     to cover most internal glibc stack usage.  */
 4073  void support_set_small_thread_stack_size (pthread_attr_t *attr);
 4074 diff --git a/sysdeps/aarch64/dl-bti.c b/sysdeps/aarch64/dl-bti.c
 4075 index 196e462520..cf7624aaa2 100644
 4076 --- a/sysdeps/aarch64/dl-bti.c
 4077 +++ b/sysdeps/aarch64/dl-bti.c
 4078 @@ -19,43 +19,76 @@
 4079  #include <errno.h>
 4080  #include <libintl.h>
 4081  #include <ldsodefs.h>
 4082 +#include <sys/mman.h>
 4083  
 4084 -static int
 4085 -enable_bti (struct link_map *map, const char *program)
 4086 +/* See elf/dl-load.h.  */
 4087 +#ifndef MAP_COPY
 4088 +# define MAP_COPY (MAP_PRIVATE | MAP_DENYWRITE)
 4089 +#endif
 4090 +
 4091 +/* Enable BTI protection for MAP.  */
 4092 +
 4093 +void
 4094 +_dl_bti_protect (struct link_map *map, int fd)
 4095  {
 4096 +  const size_t pagesz = GLRO(dl_pagesize);
 4097    const ElfW(Phdr) *phdr;
 4098 -  unsigned prot;
 4099  
 4100    for (phdr = map->l_phdr; phdr < &map->l_phdr[map->l_phnum]; ++phdr)
 4101      if (phdr->p_type == PT_LOAD && (phdr->p_flags & PF_X))
 4102        {
 4103 -	void *start = (void *) (phdr->p_vaddr + map->l_addr);
 4104 -	size_t len = phdr->p_memsz;
 4105 +	size_t vstart = ALIGN_DOWN (phdr->p_vaddr, pagesz);
 4106 +	size_t vend = ALIGN_UP (phdr->p_vaddr + phdr->p_filesz, pagesz);
 4107 +	off_t off = ALIGN_DOWN (phdr->p_offset, pagesz);
 4108 +	void *start = (void *) (vstart + map->l_addr);
 4109 +	size_t len = vend - vstart;
 4110  
 4111 -	prot = PROT_EXEC | PROT_BTI;
 4112 +	unsigned prot = PROT_EXEC | PROT_BTI;
 4113  	if (phdr->p_flags & PF_R)
 4114  	  prot |= PROT_READ;
 4115  	if (phdr->p_flags & PF_W)
 4116  	  prot |= PROT_WRITE;
 4117  
 4118 -	if (__mprotect (start, len, prot) < 0)
 4119 -	  {
 4120 -	    if (program)
 4121 -	      _dl_fatal_printf ("%s: mprotect failed to turn on BTI\n",
 4122 -				map->l_name);
 4123 -	    else
 4124 -	      _dl_signal_error (errno, map->l_name, "dlopen",
 4125 -				N_("mprotect failed to turn on BTI"));
 4126 -	  }
 4127 +	if (fd == -1)
 4128 +	  /* Ignore failures for kernel mapped binaries.  */
 4129 +	  __mprotect (start, len, prot);
 4130 +	else
 4131 +	  map->l_mach.bti_fail = __mmap (start, len, prot,
 4132 +					 MAP_FIXED|MAP_COPY|MAP_FILE,
 4133 +					 fd, off) == MAP_FAILED;
 4134        }
 4135 -  return 0;
 4136  }
 4137  
 4138 -/* Enable BTI for L if required.  */
 4139 +
 4140 +static void
 4141 +bti_failed (struct link_map *l, const char *program)
 4142 +{
 4143 +  if (program)
 4144 +    _dl_fatal_printf ("%s: %s: failed to turn on BTI protection\n",
 4145 +		      program, l->l_name);
 4146 +  else
 4147 +    /* Note: the errno value is not available any more.  */
 4148 +    _dl_signal_error (0, l->l_name, "dlopen",
 4149 +		      N_("failed to turn on BTI protection"));
 4150 +}
 4151 +
 4152 +
 4153 +/* Enable BTI for L and its dependencies.  */
 4154  
 4155  void
 4156  _dl_bti_check (struct link_map *l, const char *program)
 4157  {
 4158 -  if (GLRO(dl_aarch64_cpu_features).bti && l->l_mach.bti)
 4159 -    enable_bti (l, program);
 4160 +  if (!GLRO(dl_aarch64_cpu_features).bti)
 4161 +    return;
 4162 +
 4163 +  if (l->l_mach.bti_fail)
 4164 +    bti_failed (l, program);
 4165 +
 4166 +  unsigned int i = l->l_searchlist.r_nlist;
 4167 +  while (i-- > 0)
 4168 +    {
 4169 +      struct link_map *dep = l->l_initfini[i];
 4170 +      if (dep->l_mach.bti_fail)
 4171 +	bti_failed (dep, program);
 4172 +    }
 4173  }
 4174 diff --git a/sysdeps/aarch64/dl-machine.h b/sysdeps/aarch64/dl-machine.h
 4175 index 70b9ed3925..fde7cfd9e2 100644
 4176 --- a/sysdeps/aarch64/dl-machine.h
 4177 +++ b/sysdeps/aarch64/dl-machine.h
 4178 @@ -395,13 +395,6 @@ elf_machine_lazy_rel (struct link_map *map,
 4179    /* Check for unexpected PLT reloc type.  */
 4180    if (__builtin_expect (r_type == AARCH64_R(JUMP_SLOT), 1))
 4181      {
 4182 -      if (map->l_mach.plt == 0)
 4183 -	{
 4184 -	  /* Prelinking.  */
 4185 -	  *reloc_addr += l_addr;
 4186 -	  return;
 4187 -	}
 4188 -
 4189        if (__glibc_unlikely (map->l_info[DT_AARCH64 (VARIANT_PCS)] != NULL))
 4190  	{
 4191  	  /* Check the symbol table for variant PCS symbols.  */
 4192 @@ -425,7 +418,10 @@ elf_machine_lazy_rel (struct link_map *map,
 4193  	    }
 4194  	}
 4195  
 4196 -      *reloc_addr = map->l_mach.plt;
 4197 +      if (map->l_mach.plt == 0)
 4198 +	*reloc_addr += l_addr;
 4199 +      else
 4200 +	*reloc_addr = map->l_mach.plt;
 4201      }
 4202    else if (__builtin_expect (r_type == AARCH64_R(TLSDESC), 1))
 4203      {
 4204 diff --git a/sysdeps/aarch64/dl-prop.h b/sysdeps/aarch64/dl-prop.h
 4205 index b0785bda83..e926e54984 100644
 4206 --- a/sysdeps/aarch64/dl-prop.h
 4207 +++ b/sysdeps/aarch64/dl-prop.h
 4208 @@ -19,6 +19,8 @@
 4209  #ifndef _DL_PROP_H
 4210  #define _DL_PROP_H
 4211  
 4212 +extern void _dl_bti_protect (struct link_map *, int) attribute_hidden;
 4213 +
 4214  extern void _dl_bti_check (struct link_map *, const char *)
 4215      attribute_hidden;
 4216  
 4217 @@ -35,14 +37,18 @@ _dl_open_check (struct link_map *m)
 4218  }
 4219  
 4220  static inline void __attribute__ ((always_inline))
 4221 -_dl_process_pt_note (struct link_map *l, const ElfW(Phdr) *ph)
 4222 +_dl_process_pt_note (struct link_map *l, int fd, const ElfW(Phdr) *ph)
 4223  {
 4224  }
 4225  
 4226  static inline int
 4227 -_dl_process_gnu_property (struct link_map *l, uint32_t type, uint32_t datasz,
 4228 -			  void *data)
 4229 +_dl_process_gnu_property (struct link_map *l, int fd, uint32_t type,
 4230 +			  uint32_t datasz, void *data)
 4231  {
 4232 +  if (!GLRO(dl_aarch64_cpu_features).bti)
 4233 +    /* Skip note processing.  */
 4234 +    return 0;
 4235 +
 4236    if (type == GNU_PROPERTY_AARCH64_FEATURE_1_AND)
 4237      {
 4238        /* Stop if the property note is ill-formed.  */
 4239 @@ -51,7 +57,7 @@ _dl_process_gnu_property (struct link_map *l, uint32_t type, uint32_t datasz,
 4240  
 4241        unsigned int feature_1 = *(unsigned int *) data;
 4242        if (feature_1 & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)
 4243 -	l->l_mach.bti = true;
 4244 +	_dl_bti_protect (l, fd);
 4245  
 4246        /* Stop if we processed the property note.  */
 4247        return 0;
 4248 diff --git a/sysdeps/aarch64/linkmap.h b/sysdeps/aarch64/linkmap.h
 4249 index 847a03ace2..b3f7663b07 100644
 4250 --- a/sysdeps/aarch64/linkmap.h
 4251 +++ b/sysdeps/aarch64/linkmap.h
 4252 @@ -22,5 +22,5 @@ struct link_map_machine
 4253  {
 4254    ElfW(Addr) plt;	  /* Address of .plt */
 4255    void *tlsdesc_table;	  /* Address of TLS descriptor hash table.  */
 4256 -  bool bti;		  /* Branch Target Identification is enabled.  */
 4257 +  bool bti_fail;	  /* Failed to enable Branch Target Identification.  */
 4258  };
 4259 diff --git a/sysdeps/aarch64/multiarch/memcpy.c b/sysdeps/aarch64/multiarch/memcpy.c
 4260 index 7cf5f033e8..799d60c98c 100644
 4261 --- a/sysdeps/aarch64/multiarch/memcpy.c
 4262 +++ b/sysdeps/aarch64/multiarch/memcpy.c
 4263 @@ -41,7 +41,8 @@ libc_ifunc (__libc_memcpy,
 4264  		? __memcpy_falkor
 4265  		: (IS_THUNDERX2 (midr) || IS_THUNDERX2PA (midr)
 4266  		  ? __memcpy_thunderx2
 4267 -		  : (IS_NEOVERSE_N1 (midr)
 4268 +		  : (IS_NEOVERSE_N1 (midr) || IS_NEOVERSE_N2 (midr)
 4269 +		     || IS_NEOVERSE_V1 (midr)
 4270  		     ? __memcpy_simd
 4271  		     : __memcpy_generic)))));
 4272  
 4273 diff --git a/sysdeps/aarch64/multiarch/memcpy_advsimd.S b/sysdeps/aarch64/multiarch/memcpy_advsimd.S
 4274 index d4ba747777..48bb6d7ca4 100644
 4275 --- a/sysdeps/aarch64/multiarch/memcpy_advsimd.S
 4276 +++ b/sysdeps/aarch64/multiarch/memcpy_advsimd.S
 4277 @@ -223,12 +223,13 @@ L(copy_long_backwards):
 4278  	b.ls	L(copy64_from_start)
 4279  
 4280  L(loop64_backwards):
 4281 -	stp	A_q, B_q, [dstend, -32]
 4282 +	str	B_q, [dstend, -16]
 4283 +	str	A_q, [dstend, -32]
 4284  	ldp	A_q, B_q, [srcend, -96]
 4285 -	stp	C_q, D_q, [dstend, -64]
 4286 +	str	D_q, [dstend, -48]
 4287 +	str	C_q, [dstend, -64]!
 4288  	ldp	C_q, D_q, [srcend, -128]
 4289  	sub	srcend, srcend, 64
 4290 -	sub	dstend, dstend, 64
 4291  	subs	count, count, 64
 4292  	b.hi	L(loop64_backwards)
 4293  
 4294 diff --git a/sysdeps/aarch64/multiarch/memmove.c b/sysdeps/aarch64/multiarch/memmove.c
 4295 index ad10aa8ac6..46a4cb3a54 100644
 4296 --- a/sysdeps/aarch64/multiarch/memmove.c
 4297 +++ b/sysdeps/aarch64/multiarch/memmove.c
 4298 @@ -41,7 +41,8 @@ libc_ifunc (__libc_memmove,
 4299  		? __memmove_falkor
 4300  		: (IS_THUNDERX2 (midr) || IS_THUNDERX2PA (midr)
 4301  		  ? __memmove_thunderx2
 4302 -		  : (IS_NEOVERSE_N1 (midr)
 4303 +		  : (IS_NEOVERSE_N1 (midr) || IS_NEOVERSE_N2 (midr)
 4304 +		     || IS_NEOVERSE_V1 (midr)
 4305  		     ? __memmove_simd
 4306  		     : __memmove_generic)))));
 4307  
 4308 diff --git a/sysdeps/aarch64/start.S b/sysdeps/aarch64/start.S
 4309 index 75393e1c18..1998ea95d4 100644
 4310 --- a/sysdeps/aarch64/start.S
 4311 +++ b/sysdeps/aarch64/start.S
 4312 @@ -43,11 +43,9 @@
 4313   */
 4314  
 4315  	.text
 4316 -	.globl _start
 4317 -	.type _start,#function
 4318 -_start:
 4319 -	BTI_C
 4320 +ENTRY(_start)
 4321  	/* Create an initial frame with 0 LR and FP */
 4322 +	cfi_undefined (x30)
 4323  	mov	x29, #0
 4324  	mov	x30, #0
 4325  
 4326 @@ -101,8 +99,10 @@ _start:
 4327  	   because crt1.o and rcrt1.o share code and the later must avoid the
 4328  	   use of GOT relocations before __libc_start_main is called.  */
 4329  __wrap_main:
 4330 +	BTI_C
 4331  	b	main
 4332  #endif
 4333 +END(_start)
 4334  
 4335  	/* Define a symbol for the first piece of initialized data.  */
 4336  	.data
 4337 diff --git a/sysdeps/generic/dl-prop.h b/sysdeps/generic/dl-prop.h
 4338 index f1cf576fe3..df27ff8e6a 100644
 4339 --- a/sysdeps/generic/dl-prop.h
 4340 +++ b/sysdeps/generic/dl-prop.h
 4341 @@ -37,15 +37,15 @@ _dl_open_check (struct link_map *m)
 4342  }
 4343  
 4344  static inline void __attribute__ ((always_inline))
 4345 -_dl_process_pt_note (struct link_map *l, const ElfW(Phdr) *ph)
 4346 +_dl_process_pt_note (struct link_map *l, int fd, const ElfW(Phdr) *ph)
 4347  {
 4348  }
 4349  
 4350  /* Called for each property in the NT_GNU_PROPERTY_TYPE_0 note of L,
 4351     processing of the properties continues until this returns 0.  */
 4352  static inline int __attribute__ ((always_inline))
 4353 -_dl_process_gnu_property (struct link_map *l, uint32_t type, uint32_t datasz,
 4354 -			  void *data)
 4355 +_dl_process_gnu_property (struct link_map *l, int fd, uint32_t type,
 4356 +			  uint32_t datasz, void *data)
 4357  {
 4358    return 0;
 4359  }
 4360 diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
 4361 index ba114ab4b1..62ac40d81b 100644
 4362 --- a/sysdeps/generic/ldsodefs.h
 4363 +++ b/sysdeps/generic/ldsodefs.h
 4364 @@ -919,8 +919,9 @@ extern void _dl_rtld_di_serinfo (struct link_map *loader,
 4365  				 Dl_serinfo *si, bool counting);
 4366  
 4367  /* Process PT_GNU_PROPERTY program header PH in module L after
 4368 -   PT_LOAD segments are mapped.  */
 4369 -void _dl_process_pt_gnu_property (struct link_map *l, const ElfW(Phdr) *ph);
 4370 +   PT_LOAD segments are mapped from file FD.  */
 4371 +void _dl_process_pt_gnu_property (struct link_map *l, int fd,
 4372 +				  const ElfW(Phdr) *ph);
 4373  
 4374  
 4375  /* Search loaded objects' symbol tables for a definition of the symbol
 4376 diff --git a/sysdeps/generic/unwind.h b/sysdeps/generic/unwind.h
 4377 index b667a5b652..c229603af3 100644
 4378 --- a/sysdeps/generic/unwind.h
 4379 +++ b/sysdeps/generic/unwind.h
 4380 @@ -75,15 +75,21 @@ typedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code,
 4381  
 4382  struct _Unwind_Exception
 4383  {
 4384 -  _Unwind_Exception_Class exception_class;
 4385 -  _Unwind_Exception_Cleanup_Fn exception_cleanup;
 4386 -  _Unwind_Word private_1;
 4387 -  _Unwind_Word private_2;
 4388 -
 4389 -  /* @@@ The IA-64 ABI says that this structure must be double-word aligned.
 4390 -     Taking that literally does not make much sense generically.  Instead we
 4391 -     provide the maximum alignment required by any type for the machine.  */
 4392 -} __attribute__((__aligned__));
 4393 +  union
 4394 +  {
 4395 +    struct
 4396 +    {
 4397 +      _Unwind_Exception_Class exception_class;
 4398 +      _Unwind_Exception_Cleanup_Fn exception_cleanup;
 4399 +      _Unwind_Word private_1;
 4400 +      _Unwind_Word private_2;
 4401 +    };
 4402 +
 4403 +    /* The IA-64 ABI says that this structure must be double-word aligned.  */
 4404 +    _Unwind_Word unwind_exception_align[2]
 4405 +      __attribute__ ((__aligned__ (2 * sizeof (_Unwind_Word))));
 4406 +  };
 4407 +};
 4408  
 4409  
 4410  /* The ACTIONS argument to the personality routine is a bitwise OR of one
 4411 diff --git a/sysdeps/gnu/errlist.h b/sysdeps/gnu/errlist.h
 4412 index 5d11ed723d..6329e5f393 100644
 4413 --- a/sysdeps/gnu/errlist.h
 4414 +++ b/sysdeps/gnu/errlist.h
 4415 @@ -1,24 +1,21 @@
 4416 -#ifndef ERR_MAP
 4417 -#define ERR_MAP(value) value
 4418 -#endif
 4419 -_S(ERR_MAP(0), N_("Success"))
 4420 +_S(0, N_("Success"))
 4421  #ifdef EPERM
 4422  /*
 4423  TRANS Only the owner of the file (or other resource)
 4424  TRANS or processes with special privileges can perform the operation. */
 4425 -_S(ERR_MAP(EPERM), N_("Operation not permitted"))
 4426 +_S(EPERM, N_("Operation not permitted"))
 4427  #endif
 4428  #ifdef ENOENT
 4429  /*
 4430  TRANS This is a ``file doesn't exist'' error
 4431  TRANS for ordinary files that are referenced in contexts where they are
 4432  TRANS expected to already exist. */
 4433 -_S(ERR_MAP(ENOENT), N_("No such file or directory"))
 4434 +_S(ENOENT, N_("No such file or directory"))
 4435  #endif
 4436  #ifdef ESRCH
 4437  /*
 4438  TRANS No process matches the specified process ID. */
 4439 -_S(ERR_MAP(ESRCH), N_("No such process"))
 4440 +_S(ESRCH, N_("No such process"))
 4441  #endif
 4442  #ifdef EINTR
 4443  /*
 4444 @@ -29,12 +26,12 @@ TRANS
 4445  TRANS You can choose to have functions resume after a signal that is handled,
 4446  TRANS rather than failing with @code{EINTR}; see @ref{Interrupted
 4447  TRANS Primitives}. */
 4448 -_S(ERR_MAP(EINTR), N_("Interrupted system call"))
 4449 +_S(EINTR, N_("Interrupted system call"))
 4450  #endif
 4451  #ifdef EIO
 4452  /*
 4453  TRANS Usually used for physical read or write errors. */
 4454 -_S(ERR_MAP(EIO), N_("Input/output error"))
 4455 +_S(EIO, N_("Input/output error"))
 4456  #endif
 4457  #ifdef ENXIO
 4458  /*
 4459 @@ -43,7 +40,7 @@ TRANS represented by a file you specified, and it couldn't find the device.
 4460  TRANS This can mean that the device file was installed incorrectly, or that
 4461  TRANS the physical device is missing or not correctly attached to the
 4462  TRANS computer. */
 4463 -_S(ERR_MAP(ENXIO), N_("No such device or address"))
 4464 +_S(ENXIO, N_("No such device or address"))
 4465  #endif
 4466  #ifdef E2BIG
 4467  /*
 4468 @@ -51,27 +48,27 @@ TRANS Used when the arguments passed to a new program
 4469  TRANS being executed with one of the @code{exec} functions (@pxref{Executing a
 4470  TRANS File}) occupy too much memory space.  This condition never arises on
 4471  TRANS @gnuhurdsystems{}. */
 4472 -_S(ERR_MAP(E2BIG), N_("Argument list too long"))
 4473 +_S(E2BIG, N_("Argument list too long"))
 4474  #endif
 4475  #ifdef ENOEXEC
 4476  /*
 4477  TRANS Invalid executable file format.  This condition is detected by the
 4478  TRANS @code{exec} functions; see @ref{Executing a File}. */
 4479 -_S(ERR_MAP(ENOEXEC), N_("Exec format error"))
 4480 +_S(ENOEXEC, N_("Exec format error"))
 4481  #endif
 4482  #ifdef EBADF
 4483  /*
 4484  TRANS For example, I/O on a descriptor that has been
 4485  TRANS closed or reading from a descriptor open only for writing (or vice
 4486  TRANS versa). */
 4487 -_S(ERR_MAP(EBADF), N_("Bad file descriptor"))
 4488 +_S(EBADF, N_("Bad file descriptor"))
 4489  #endif
 4490  #ifdef ECHILD
 4491  /*
 4492  TRANS This error happens on operations that are
 4493  TRANS supposed to manipulate child processes, when there aren't any processes
 4494  TRANS to manipulate. */
 4495 -_S(ERR_MAP(ECHILD), N_("No child processes"))
 4496 +_S(ECHILD, N_("No child processes"))
 4497  #endif
 4498  #ifdef EDEADLK
 4499  /*
 4500 @@ -79,74 +76,74 @@ TRANS Allocating a system resource would have resulted in a
 4501  TRANS deadlock situation.  The system does not guarantee that it will notice
 4502  TRANS all such situations.  This error means you got lucky and the system
 4503  TRANS noticed; it might just hang.  @xref{File Locks}, for an example. */
 4504 -_S(ERR_MAP(EDEADLK), N_("Resource deadlock avoided"))
 4505 +_S(EDEADLK, N_("Resource deadlock avoided"))
 4506  #endif
 4507  #ifdef ENOMEM
 4508  /*
 4509  TRANS The system cannot allocate more virtual memory
 4510  TRANS because its capacity is full. */
 4511 -_S(ERR_MAP(ENOMEM), N_("Cannot allocate memory"))
 4512 +_S(ENOMEM, N_("Cannot allocate memory"))
 4513  #endif
 4514  #ifdef EACCES
 4515  /*
 4516  TRANS The file permissions do not allow the attempted operation. */
 4517 -_S(ERR_MAP(EACCES), N_("Permission denied"))
 4518 +_S(EACCES, N_("Permission denied"))
 4519  #endif
 4520  #ifdef EFAULT
 4521  /*
 4522  TRANS An invalid pointer was detected.
 4523  TRANS On @gnuhurdsystems{}, this error never happens; you get a signal instead. */
 4524 -_S(ERR_MAP(EFAULT), N_("Bad address"))
 4525 +_S(EFAULT, N_("Bad address"))
 4526  #endif
 4527  #ifdef ENOTBLK
 4528  /*
 4529  TRANS A file that isn't a block special file was given in a situation that
 4530  TRANS requires one.  For example, trying to mount an ordinary file as a file
 4531  TRANS system in Unix gives this error. */
 4532 -_S(ERR_MAP(ENOTBLK), N_("Block device required"))
 4533 +_S(ENOTBLK, N_("Block device required"))
 4534  #endif
 4535  #ifdef EBUSY
 4536  /*
 4537  TRANS A system resource that can't be shared is already in use.
 4538  TRANS For example, if you try to delete a file that is the root of a currently
 4539  TRANS mounted filesystem, you get this error. */
 4540 -_S(ERR_MAP(EBUSY), N_("Device or resource busy"))
 4541 +_S(EBUSY, N_("Device or resource busy"))
 4542  #endif
 4543  #ifdef EEXIST
 4544  /*
 4545  TRANS An existing file was specified in a context where it only
 4546  TRANS makes sense to specify a new file. */
 4547 -_S(ERR_MAP(EEXIST), N_("File exists"))
 4548 +_S(EEXIST, N_("File exists"))
 4549  #endif
 4550  #ifdef EXDEV
 4551  /*
 4552  TRANS An attempt to make an improper link across file systems was detected.
 4553  TRANS This happens not only when you use @code{link} (@pxref{Hard Links}) but
 4554  TRANS also when you rename a file with @code{rename} (@pxref{Renaming Files}). */
 4555 -_S(ERR_MAP(EXDEV), N_("Invalid cross-device link"))
 4556 +_S(EXDEV, N_("Invalid cross-device link"))
 4557  #endif
 4558  #ifdef ENODEV
 4559  /*
 4560  TRANS The wrong type of device was given to a function that expects a
 4561  TRANS particular sort of device. */
 4562 -_S(ERR_MAP(ENODEV), N_("No such device"))
 4563 +_S(ENODEV, N_("No such device"))
 4564  #endif
 4565  #ifdef ENOTDIR
 4566  /*
 4567  TRANS A file that isn't a directory was specified when a directory is required. */
 4568 -_S(ERR_MAP(ENOTDIR), N_("Not a directory"))
 4569 +_S(ENOTDIR, N_("Not a directory"))
 4570  #endif
 4571  #ifdef EISDIR
 4572  /*
 4573  TRANS You cannot open a directory for writing,
 4574  TRANS or create or remove hard links to it. */
 4575 -_S(ERR_MAP(EISDIR), N_("Is a directory"))
 4576 +_S(EISDIR, N_("Is a directory"))
 4577  #endif
 4578  #ifdef EINVAL
 4579  /*
 4580  TRANS This is used to indicate various kinds of problems
 4581  TRANS with passing the wrong argument to a library function. */
 4582 -_S(ERR_MAP(EINVAL), N_("Invalid argument"))
 4583 +_S(EINVAL, N_("Invalid argument"))
 4584  #endif
 4585  #ifdef EMFILE
 4586  /*
 4587 @@ -157,20 +154,20 @@ TRANS In BSD and GNU, the number of open files is controlled by a resource
 4588  TRANS limit that can usually be increased.  If you get this error, you might
 4589  TRANS want to increase the @code{RLIMIT_NOFILE} limit or make it unlimited;
 4590  TRANS @pxref{Limits on Resources}. */
 4591 -_S(ERR_MAP(EMFILE), N_("Too many open files"))
 4592 +_S(EMFILE, N_("Too many open files"))
 4593  #endif
 4594  #ifdef ENFILE
 4595  /*
 4596  TRANS There are too many distinct file openings in the entire system.  Note
 4597  TRANS that any number of linked channels count as just one file opening; see
 4598  TRANS @ref{Linked Channels}.  This error never occurs on @gnuhurdsystems{}. */
 4599 -_S(ERR_MAP(ENFILE), N_("Too many open files in system"))
 4600 +_S(ENFILE, N_("Too many open files in system"))
 4601  #endif
 4602  #ifdef ENOTTY
 4603  /*
 4604  TRANS Inappropriate I/O control operation, such as trying to set terminal
 4605  TRANS modes on an ordinary file. */
 4606 -_S(ERR_MAP(ENOTTY), N_("Inappropriate ioctl for device"))
 4607 +_S(ENOTTY, N_("Inappropriate ioctl for device"))
 4608  #endif
 4609  #ifdef ETXTBSY
 4610  /*
 4611 @@ -179,35 +176,35 @@ TRANS write to a file that is currently being executed.  Often using a
 4612  TRANS debugger to run a program is considered having it open for writing and
 4613  TRANS will cause this error.  (The name stands for ``text file busy''.)  This
 4614  TRANS is not an error on @gnuhurdsystems{}; the text is copied as necessary. */
 4615 -_S(ERR_MAP(ETXTBSY), N_("Text file busy"))
 4616 +_S(ETXTBSY, N_("Text file busy"))
 4617  #endif
 4618  #ifdef EFBIG
 4619  /*
 4620  TRANS The size of a file would be larger than allowed by the system. */
 4621 -_S(ERR_MAP(EFBIG), N_("File too large"))
 4622 +_S(EFBIG, N_("File too large"))
 4623  #endif
 4624  #ifdef ENOSPC
 4625  /*
 4626  TRANS Write operation on a file failed because the
 4627  TRANS disk is full. */
 4628 -_S(ERR_MAP(ENOSPC), N_("No space left on device"))
 4629 +_S(ENOSPC, N_("No space left on device"))
 4630  #endif
 4631  #ifdef ESPIPE
 4632  /*
 4633  TRANS Invalid seek operation (such as on a pipe). */
 4634 -_S(ERR_MAP(ESPIPE), N_("Illegal seek"))
 4635 +_S(ESPIPE, N_("Illegal seek"))
 4636  #endif
 4637  #ifdef EROFS
 4638  /*
 4639  TRANS An attempt was made to modify something on a read-only file system. */
 4640 -_S(ERR_MAP(EROFS), N_("Read-only file system"))
 4641 +_S(EROFS, N_("Read-only file system"))
 4642  #endif
 4643  #ifdef EMLINK
 4644  /*
 4645  TRANS The link count of a single file would become too large.
 4646  TRANS @code{rename} can cause this error if the file being renamed already has
 4647  TRANS as many links as it can take (@pxref{Renaming Files}). */
 4648 -_S(ERR_MAP(EMLINK), N_("Too many links"))
 4649 +_S(EMLINK, N_("Too many links"))
 4650  #endif
 4651  #ifdef EPIPE
 4652  /*
 4653 @@ -216,19 +213,19 @@ TRANS Every library function that returns this error code also generates a
 4654  TRANS @code{SIGPIPE} signal; this signal terminates the program if not handled
 4655  TRANS or blocked.  Thus, your program will never actually see @code{EPIPE}
 4656  TRANS unless it has handled or blocked @code{SIGPIPE}. */
 4657 -_S(ERR_MAP(EPIPE), N_("Broken pipe"))
 4658 +_S(EPIPE, N_("Broken pipe"))
 4659  #endif
 4660  #ifdef EDOM
 4661  /*
 4662  TRANS Used by mathematical functions when an argument value does
 4663  TRANS not fall into the domain over which the function is defined. */
 4664 -_S(ERR_MAP(EDOM), N_("Numerical argument out of domain"))
 4665 +_S(EDOM, N_("Numerical argument out of domain"))
 4666  #endif
 4667  #ifdef ERANGE
 4668  /*
 4669  TRANS Used by mathematical functions when the result value is
 4670  TRANS not representable because of overflow or underflow. */
 4671 -_S(ERR_MAP(ERANGE), N_("Numerical result out of range"))
 4672 +_S(ERANGE, N_("Numerical result out of range"))
 4673  #endif
 4674  #ifdef EAGAIN
 4675  /*
 4676 @@ -261,7 +258,7 @@ TRANS Such shortages are usually fairly serious and affect the whole system,
 4677  TRANS so usually an interactive program should report the error to the user
 4678  TRANS and return to its command loop.
 4679  TRANS @end itemize */
 4680 -_S(ERR_MAP(EAGAIN), N_("Resource temporarily unavailable"))
 4681 +_S(EAGAIN, N_("Resource temporarily unavailable"))
 4682  #endif
 4683  #ifdef EINPROGRESS
 4684  /*
 4685 @@ -273,47 +270,47 @@ TRANS the operation has begun and will take some time.  Attempts to manipulate
 4686  TRANS the object before the call completes return @code{EALREADY}.  You can
 4687  TRANS use the @code{select} function to find out when the pending operation
 4688  TRANS has completed; @pxref{Waiting for I/O}. */
 4689 -_S(ERR_MAP(EINPROGRESS), N_("Operation now in progress"))
 4690 +_S(EINPROGRESS, N_("Operation now in progress"))
 4691  #endif
 4692  #ifdef EALREADY
 4693  /*
 4694  TRANS An operation is already in progress on an object that has non-blocking
 4695  TRANS mode selected. */
 4696 -_S(ERR_MAP(EALREADY), N_("Operation already in progress"))
 4697 +_S(EALREADY, N_("Operation already in progress"))
 4698  #endif
 4699  #ifdef ENOTSOCK
 4700  /*
 4701  TRANS A file that isn't a socket was specified when a socket is required. */
 4702 -_S(ERR_MAP(ENOTSOCK), N_("Socket operation on non-socket"))
 4703 +_S(ENOTSOCK, N_("Socket operation on non-socket"))
 4704  #endif
 4705  #ifdef EMSGSIZE
 4706  /*
 4707  TRANS The size of a message sent on a socket was larger than the supported
 4708  TRANS maximum size. */
 4709 -_S(ERR_MAP(EMSGSIZE), N_("Message too long"))
 4710 +_S(EMSGSIZE, N_("Message too long"))
 4711  #endif
 4712  #ifdef EPROTOTYPE
 4713  /*
 4714  TRANS The socket type does not support the requested communications protocol. */
 4715 -_S(ERR_MAP(EPROTOTYPE), N_("Protocol wrong type for socket"))
 4716 +_S(EPROTOTYPE, N_("Protocol wrong type for socket"))
 4717  #endif
 4718  #ifdef ENOPROTOOPT
 4719  /*
 4720  TRANS You specified a socket option that doesn't make sense for the
 4721  TRANS particular protocol being used by the socket.  @xref{Socket Options}. */
 4722 -_S(ERR_MAP(ENOPROTOOPT), N_("Protocol not available"))
 4723 +_S(ENOPROTOOPT, N_("Protocol not available"))
 4724  #endif
 4725  #ifdef EPROTONOSUPPORT
 4726  /*
 4727  TRANS The socket domain does not support the requested communications protocol
 4728  TRANS (perhaps because the requested protocol is completely invalid).
 4729  TRANS @xref{Creating a Socket}. */
 4730 -_S(ERR_MAP(EPROTONOSUPPORT), N_("Protocol not supported"))
 4731 +_S(EPROTONOSUPPORT, N_("Protocol not supported"))
 4732  #endif
 4733  #ifdef ESOCKTNOSUPPORT
 4734  /*
 4735  TRANS The socket type is not supported. */
 4736 -_S(ERR_MAP(ESOCKTNOSUPPORT), N_("Socket type not supported"))
 4737 +_S(ESOCKTNOSUPPORT, N_("Socket type not supported"))
 4738  #endif
 4739  #ifdef EOPNOTSUPP
 4740  /*
 4741 @@ -323,71 +320,71 @@ TRANS implemented for all communications protocols.  On @gnuhurdsystems{}, this
 4742  TRANS error can happen for many calls when the object does not support the
 4743  TRANS particular operation; it is a generic indication that the server knows
 4744  TRANS nothing to do for that call. */
 4745 -_S(ERR_MAP(EOPNOTSUPP), N_("Operation not supported"))
 4746 +_S(EOPNOTSUPP, N_("Operation not supported"))
 4747  #endif
 4748  #ifdef EPFNOSUPPORT
 4749  /*
 4750  TRANS The socket communications protocol family you requested is not supported. */
 4751 -_S(ERR_MAP(EPFNOSUPPORT), N_("Protocol family not supported"))
 4752 +_S(EPFNOSUPPORT, N_("Protocol family not supported"))
 4753  #endif
 4754  #ifdef EAFNOSUPPORT
 4755  /*
 4756  TRANS The address family specified for a socket is not supported; it is
 4757  TRANS inconsistent with the protocol being used on the socket.  @xref{Sockets}. */
 4758 -_S(ERR_MAP(EAFNOSUPPORT), N_("Address family not supported by protocol"))
 4759 +_S(EAFNOSUPPORT, N_("Address family not supported by protocol"))
 4760  #endif
 4761  #ifdef EADDRINUSE
 4762  /*
 4763  TRANS The requested socket address is already in use.  @xref{Socket Addresses}. */
 4764 -_S(ERR_MAP(EADDRINUSE), N_("Address already in use"))
 4765 +_S(EADDRINUSE, N_("Address already in use"))
 4766  #endif
 4767  #ifdef EADDRNOTAVAIL
 4768  /*
 4769  TRANS The requested socket address is not available; for example, you tried
 4770  TRANS to give a socket a name that doesn't match the local host name.
 4771  TRANS @xref{Socket Addresses}. */
 4772 -_S(ERR_MAP(EADDRNOTAVAIL), N_("Cannot assign requested address"))
 4773 +_S(EADDRNOTAVAIL, N_("Cannot assign requested address"))
 4774  #endif
 4775  #ifdef ENETDOWN
 4776  /*
 4777  TRANS A socket operation failed because the network was down. */
 4778 -_S(ERR_MAP(ENETDOWN), N_("Network is down"))
 4779 +_S(ENETDOWN, N_("Network is down"))
 4780  #endif
 4781  #ifdef ENETUNREACH
 4782  /*
 4783  TRANS A socket operation failed because the subnet containing the remote host
 4784  TRANS was unreachable. */
 4785 -_S(ERR_MAP(ENETUNREACH), N_("Network is unreachable"))
 4786 +_S(ENETUNREACH, N_("Network is unreachable"))
 4787  #endif
 4788  #ifdef ENETRESET
 4789  /*
 4790  TRANS A network connection was reset because the remote host crashed. */
 4791 -_S(ERR_MAP(ENETRESET), N_("Network dropped connection on reset"))
 4792 +_S(ENETRESET, N_("Network dropped connection on reset"))
 4793  #endif
 4794  #ifdef ECONNABORTED
 4795  /*
 4796  TRANS A network connection was aborted locally. */
 4797 -_S(ERR_MAP(ECONNABORTED), N_("Software caused connection abort"))
 4798 +_S(ECONNABORTED, N_("Software caused connection abort"))
 4799  #endif
 4800  #ifdef ECONNRESET
 4801  /*
 4802  TRANS A network connection was closed for reasons outside the control of the
 4803  TRANS local host, such as by the remote machine rebooting or an unrecoverable
 4804  TRANS protocol violation. */
 4805 -_S(ERR_MAP(ECONNRESET), N_("Connection reset by peer"))
 4806 +_S(ECONNRESET, N_("Connection reset by peer"))
 4807  #endif
 4808  #ifdef ENOBUFS
 4809  /*
 4810  TRANS The kernel's buffers for I/O operations are all in use.  In GNU, this
 4811  TRANS error is always synonymous with @code{ENOMEM}; you may get one or the
 4812  TRANS other from network operations. */
 4813 -_S(ERR_MAP(ENOBUFS), N_("No buffer space available"))
 4814 +_S(ENOBUFS, N_("No buffer space available"))
 4815  #endif
 4816  #ifdef EISCONN
 4817  /*
 4818  TRANS You tried to connect a socket that is already connected.
 4819  TRANS @xref{Connecting}. */
 4820 -_S(ERR_MAP(EISCONN), N_("Transport endpoint is already connected"))
 4821 +_S(EISCONN, N_("Transport endpoint is already connected"))
 4822  #endif
 4823  #ifdef ENOTCONN
 4824  /*
 4825 @@ -395,74 +392,74 @@ TRANS The socket is not connected to anything.  You get this error when you
 4826  TRANS try to transmit data over a socket, without first specifying a
 4827  TRANS destination for the data.  For a connectionless socket (for datagram
 4828  TRANS protocols, such as UDP), you get @code{EDESTADDRREQ} instead. */
 4829 -_S(ERR_MAP(ENOTCONN), N_("Transport endpoint is not connected"))
 4830 +_S(ENOTCONN, N_("Transport endpoint is not connected"))
 4831  #endif
 4832  #ifdef EDESTADDRREQ
 4833  /*
 4834  TRANS No default destination address was set for the socket.  You get this
 4835  TRANS error when you try to transmit data over a connectionless socket,
 4836  TRANS without first specifying a destination for the data with @code{connect}. */
 4837 -_S(ERR_MAP(EDESTADDRREQ), N_("Destination address required"))
 4838 +_S(EDESTADDRREQ, N_("Destination address required"))
 4839  #endif
 4840  #ifdef ESHUTDOWN
 4841  /*
 4842  TRANS The socket has already been shut down. */
 4843 -_S(ERR_MAP(ESHUTDOWN), N_("Cannot send after transport endpoint shutdown"))
 4844 +_S(ESHUTDOWN, N_("Cannot send after transport endpoint shutdown"))
 4845  #endif
 4846  #ifdef ETOOMANYREFS
 4847 -_S(ERR_MAP(ETOOMANYREFS), N_("Too many references: cannot splice"))
 4848 +_S(ETOOMANYREFS, N_("Too many references: cannot splice"))
 4849  #endif
 4850  #ifdef ETIMEDOUT
 4851  /*
 4852  TRANS A socket operation with a specified timeout received no response during
 4853  TRANS the timeout period. */
 4854 -_S(ERR_MAP(ETIMEDOUT), N_("Connection timed out"))
 4855 +_S(ETIMEDOUT, N_("Connection timed out"))
 4856  #endif
 4857  #ifdef ECONNREFUSED
 4858  /*
 4859  TRANS A remote host refused to allow the network connection (typically because
 4860  TRANS it is not running the requested service). */
 4861 -_S(ERR_MAP(ECONNREFUSED), N_("Connection refused"))
 4862 +_S(ECONNREFUSED, N_("Connection refused"))
 4863  #endif
 4864  #ifdef ELOOP
 4865  /*
 4866  TRANS Too many levels of symbolic links were encountered in looking up a file name.
 4867  TRANS This often indicates a cycle of symbolic links. */
 4868 -_S(ERR_MAP(ELOOP), N_("Too many levels of symbolic links"))
 4869 +_S(ELOOP, N_("Too many levels of symbolic links"))
 4870  #endif
 4871  #ifdef ENAMETOOLONG
 4872  /*
 4873  TRANS Filename too long (longer than @code{PATH_MAX}; @pxref{Limits for
 4874  TRANS Files}) or host name too long (in @code{gethostname} or
 4875  TRANS @code{sethostname}; @pxref{Host Identification}). */
 4876 -_S(ERR_MAP(ENAMETOOLONG), N_("File name too long"))
 4877 +_S(ENAMETOOLONG, N_("File name too long"))
 4878  #endif
 4879  #ifdef EHOSTDOWN
 4880  /*
 4881  TRANS The remote host for a requested network connection is down. */
 4882 -_S(ERR_MAP(EHOSTDOWN), N_("Host is down"))
 4883 +_S(EHOSTDOWN, N_("Host is down"))
 4884  #endif
 4885  /*
 4886  TRANS The remote host for a requested network connection is not reachable. */
 4887  #ifdef EHOSTUNREACH
 4888 -_S(ERR_MAP(EHOSTUNREACH), N_("No route to host"))
 4889 +_S(EHOSTUNREACH, N_("No route to host"))
 4890  #endif
 4891  #ifdef ENOTEMPTY
 4892  /*
 4893  TRANS Directory not empty, where an empty directory was expected.  Typically,
 4894  TRANS this error occurs when you are trying to delete a directory. */
 4895 -_S(ERR_MAP(ENOTEMPTY), N_("Directory not empty"))
 4896 +_S(ENOTEMPTY, N_("Directory not empty"))
 4897  #endif
 4898  #ifdef EUSERS
 4899  /*
 4900  TRANS The file quota system is confused because there are too many users.
 4901  TRANS @c This can probably happen in a GNU system when using NFS. */
 4902 -_S(ERR_MAP(EUSERS), N_("Too many users"))
 4903 +_S(EUSERS, N_("Too many users"))
 4904  #endif
 4905  #ifdef EDQUOT
 4906  /*
 4907  TRANS The user's disk quota was exceeded. */
 4908 -_S(ERR_MAP(EDQUOT), N_("Disk quota exceeded"))
 4909 +_S(EDQUOT, N_("Disk quota exceeded"))
 4910  #endif
 4911  #ifdef ESTALE
 4912  /*
 4913 @@ -471,7 +468,7 @@ TRANS file system which is due to file system rearrangements on the server host
 4914  TRANS for NFS file systems or corruption in other file systems.
 4915  TRANS Repairing this condition usually requires unmounting, possibly repairing
 4916  TRANS and remounting the file system. */
 4917 -_S(ERR_MAP(ESTALE), N_("Stale file handle"))
 4918 +_S(ESTALE, N_("Stale file handle"))
 4919  #endif
 4920  #ifdef EREMOTE
 4921  /*
 4922 @@ -479,7 +476,7 @@ TRANS An attempt was made to NFS-mount a remote file system with a file name tha
 4923  TRANS already specifies an NFS-mounted file.
 4924  TRANS (This is an error on some operating systems, but we expect it to work
 4925  TRANS properly on @gnuhurdsystems{}, making this error code impossible.) */
 4926 -_S(ERR_MAP(EREMOTE), N_("Object is remote"))
 4927 +_S(EREMOTE, N_("Object is remote"))
 4928  #endif
 4929  #ifdef ENOLCK
 4930  /*
 4931 @@ -487,7 +484,7 @@ TRANS This is used by the file locking facilities; see
 4932  TRANS @ref{File Locks}.  This error is never generated by @gnuhurdsystems{}, but
 4933  TRANS it can result from an operation to an NFS server running another
 4934  TRANS operating system. */
 4935 -_S(ERR_MAP(ENOLCK), N_("No locks available"))
 4936 +_S(ENOLCK, N_("No locks available"))
 4937  #endif
 4938  #ifdef ENOSYS
 4939  /*
 4940 @@ -496,46 +493,46 @@ TRANS not implemented at all, either in the C library itself or in the
 4941  TRANS operating system.  When you get this error, you can be sure that this
 4942  TRANS particular function will always fail with @code{ENOSYS} unless you
 4943  TRANS install a new version of the C library or the operating system. */
 4944 -_S(ERR_MAP(ENOSYS), N_("Function not implemented"))
 4945 +_S(ENOSYS, N_("Function not implemented"))
 4946  #endif
 4947  #ifdef EILSEQ
 4948  /*
 4949  TRANS While decoding a multibyte character the function came along an invalid
 4950  TRANS or an incomplete sequence of bytes or the given wide character is invalid. */
 4951 -_S(ERR_MAP(EILSEQ), N_("Invalid or incomplete multibyte or wide character"))
 4952 +_S(EILSEQ, N_("Invalid or incomplete multibyte or wide character"))
 4953  #endif
 4954  #ifdef EBADMSG
 4955 -_S(ERR_MAP(EBADMSG), N_("Bad message"))
 4956 +_S(EBADMSG, N_("Bad message"))
 4957  #endif
 4958  #ifdef EIDRM
 4959 -_S(ERR_MAP(EIDRM), N_("Identifier removed"))
 4960 +_S(EIDRM, N_("Identifier removed"))
 4961  #endif
 4962  #ifdef EMULTIHOP
 4963 -_S(ERR_MAP(EMULTIHOP), N_("Multihop attempted"))
 4964 +_S(EMULTIHOP, N_("Multihop attempted"))
 4965  #endif
 4966  #ifdef ENODATA
 4967 -_S(ERR_MAP(ENODATA), N_("No data available"))
 4968 +_S(ENODATA, N_("No data available"))
 4969  #endif
 4970  #ifdef ENOLINK
 4971 -_S(ERR_MAP(ENOLINK), N_("Link has been severed"))
 4972 +_S(ENOLINK, N_("Link has been severed"))
 4973  #endif
 4974  #ifdef ENOMSG
 4975 -_S(ERR_MAP(ENOMSG), N_("No message of desired type"))
 4976 +_S(ENOMSG, N_("No message of desired type"))
 4977  #endif
 4978  #ifdef ENOSR
 4979 -_S(ERR_MAP(ENOSR), N_("Out of streams resources"))
 4980 +_S(ENOSR, N_("Out of streams resources"))
 4981  #endif
 4982  #ifdef ENOSTR
 4983 -_S(ERR_MAP(ENOSTR), N_("Device not a stream"))
 4984 +_S(ENOSTR, N_("Device not a stream"))
 4985  #endif
 4986  #ifdef EOVERFLOW
 4987 -_S(ERR_MAP(EOVERFLOW), N_("Value too large for defined data type"))
 4988 +_S(EOVERFLOW, N_("Value too large for defined data type"))
 4989  #endif
 4990  #ifdef EPROTO
 4991 -_S(ERR_MAP(EPROTO), N_("Protocol error"))
 4992 +_S(EPROTO, N_("Protocol error"))
 4993  #endif
 4994  #ifdef ETIME
 4995 -_S(ERR_MAP(ETIME), N_("Timer expired"))
 4996 +_S(ETIME, N_("Timer expired"))
 4997  #endif
 4998  #ifdef ECANCELED
 4999  /*
 5000 @@ -543,148 +540,148 @@ TRANS An asynchronous operation was canceled before it
 5001  TRANS completed.  @xref{Asynchronous I/O}.  When you call @code{aio_cancel},
 5002  TRANS the normal result is for the operations affected to complete with this
 5003  TRANS error; @pxref{Cancel AIO Operations}. */
 5004 -_S(ERR_MAP(ECANCELED), N_("Operation canceled"))
 5005 +_S(ECANCELED, N_("Operation canceled"))
 5006  #endif
 5007  #ifdef EOWNERDEAD
 5008 -_S(ERR_MAP(EOWNERDEAD), N_("Owner died"))
 5009 +_S(EOWNERDEAD, N_("Owner died"))
 5010  #endif
 5011  #ifdef ENOTRECOVERABLE
 5012 -_S(ERR_MAP(ENOTRECOVERABLE), N_("State not recoverable"))
 5013 +_S(ENOTRECOVERABLE, N_("State not recoverable"))
 5014  #endif
 5015  #ifdef ERESTART
 5016 -_S(ERR_MAP(ERESTART), N_("Interrupted system call should be restarted"))
 5017 +_S(ERESTART, N_("Interrupted system call should be restarted"))
 5018  #endif
 5019  #ifdef ECHRNG
 5020 -_S(ERR_MAP(ECHRNG), N_("Channel number out of range"))
 5021 +_S(ECHRNG, N_("Channel number out of range"))
 5022  #endif
 5023  #ifdef EL2NSYNC
 5024 -_S(ERR_MAP(EL2NSYNC), N_("Level 2 not synchronized"))
 5025 +_S(EL2NSYNC, N_("Level 2 not synchronized"))
 5026  #endif
 5027  #ifdef EL3HLT
 5028 -_S(ERR_MAP(EL3HLT), N_("Level 3 halted"))
 5029 +_S(EL3HLT, N_("Level 3 halted"))
 5030  #endif
 5031  #ifdef EL3RST
 5032 -_S(ERR_MAP(EL3RST), N_("Level 3 reset"))
 5033 +_S(EL3RST, N_("Level 3 reset"))
 5034  #endif
 5035  #ifdef ELNRNG
 5036 -_S(ERR_MAP(ELNRNG), N_("Link number out of range"))
 5037 +_S(ELNRNG, N_("Link number out of range"))
 5038  #endif
 5039  #ifdef EUNATCH
 5040 -_S(ERR_MAP(EUNATCH), N_("Protocol driver not attached"))
 5041 +_S(EUNATCH, N_("Protocol driver not attached"))
 5042  #endif
 5043  #ifdef ENOCSI
 5044 -_S(ERR_MAP(ENOCSI), N_("No CSI structure available"))
 5045 +_S(ENOCSI, N_("No CSI structure available"))
 5046  #endif
 5047  #ifdef EL2HLT
 5048 -_S(ERR_MAP(EL2HLT), N_("Level 2 halted"))
 5049 +_S(EL2HLT, N_("Level 2 halted"))
 5050  #endif
 5051  #ifdef EBADE
 5052 -_S(ERR_MAP(EBADE), N_("Invalid exchange"))
 5053 +_S(EBADE, N_("Invalid exchange"))
 5054  #endif
 5055  #ifdef EBADR
 5056 -_S(ERR_MAP(EBADR), N_("Invalid request descriptor"))
 5057 +_S(EBADR, N_("Invalid request descriptor"))
 5058  #endif
 5059  #ifdef EXFULL
 5060 -_S(ERR_MAP(EXFULL), N_("Exchange full"))
 5061 +_S(EXFULL, N_("Exchange full"))
 5062  #endif
 5063  #ifdef ENOANO
 5064 -_S(ERR_MAP(ENOANO), N_("No anode"))
 5065 +_S(ENOANO, N_("No anode"))
 5066  #endif
 5067  #ifdef EBADRQC
 5068 -_S(ERR_MAP(EBADRQC), N_("Invalid request code"))
 5069 +_S(EBADRQC, N_("Invalid request code"))
 5070  #endif
 5071  #ifdef EBADSLT
 5072 -_S(ERR_MAP(EBADSLT), N_("Invalid slot"))
 5073 +_S(EBADSLT, N_("Invalid slot"))
 5074  #endif
 5075  #ifdef EBFONT
 5076 -_S(ERR_MAP(EBFONT), N_("Bad font file format"))
 5077 +_S(EBFONT, N_("Bad font file format"))
 5078  #endif
 5079  #ifdef ENONET
 5080 -_S(ERR_MAP(ENONET), N_("Machine is not on the network"))
 5081 +_S(ENONET, N_("Machine is not on the network"))
 5082  #endif
 5083  #ifdef ENOPKG
 5084 -_S(ERR_MAP(ENOPKG), N_("Package not installed"))
 5085 +_S(ENOPKG, N_("Package not installed"))
 5086  #endif
 5087  #ifdef EADV
 5088 -_S(ERR_MAP(EADV), N_("Advertise error"))
 5089 +_S(EADV, N_("Advertise error"))
 5090  #endif
 5091  #ifdef ESRMNT
 5092 -_S(ERR_MAP(ESRMNT), N_("Srmount error"))
 5093 +_S(ESRMNT, N_("Srmount error"))
 5094  #endif
 5095  #ifdef ECOMM
 5096 -_S(ERR_MAP(ECOMM), N_("Communication error on send"))
 5097 +_S(ECOMM, N_("Communication error on send"))
 5098  #endif
 5099  #ifdef EDOTDOT
 5100 -_S(ERR_MAP(EDOTDOT), N_("RFS specific error"))
 5101 +_S(EDOTDOT, N_("RFS specific error"))
 5102  #endif
 5103  #ifdef ENOTUNIQ
 5104 -_S(ERR_MAP(ENOTUNIQ), N_("Name not unique on network"))
 5105 +_S(ENOTUNIQ, N_("Name not unique on network"))
 5106  #endif
 5107  #ifdef EBADFD
 5108 -_S(ERR_MAP(EBADFD), N_("File descriptor in bad state"))
 5109 +_S(EBADFD, N_("File descriptor in bad state"))
 5110  #endif
 5111  #ifdef EREMCHG
 5112 -_S(ERR_MAP(EREMCHG), N_("Remote address changed"))
 5113 +_S(EREMCHG, N_("Remote address changed"))
 5114  #endif
 5115  #ifdef ELIBACC
 5116 -_S(ERR_MAP(ELIBACC), N_("Can not access a needed shared library"))
 5117 +_S(ELIBACC, N_("Can not access a needed shared library"))
 5118  #endif
 5119  #ifdef ELIBBAD
 5120 -_S(ERR_MAP(ELIBBAD), N_("Accessing a corrupted shared library"))
 5121 +_S(ELIBBAD, N_("Accessing a corrupted shared library"))
 5122  #endif
 5123  #ifdef ELIBSCN
 5124 -_S(ERR_MAP(ELIBSCN), N_(".lib section in a.out corrupted"))
 5125 +_S(ELIBSCN, N_(".lib section in a.out corrupted"))
 5126  #endif
 5127  #ifdef ELIBMAX
 5128 -_S(ERR_MAP(ELIBMAX), N_("Attempting to link in too many shared libraries"))
 5129 +_S(ELIBMAX, N_("Attempting to link in too many shared libraries"))
 5130  #endif
 5131  #ifdef ELIBEXEC
 5132 -_S(ERR_MAP(ELIBEXEC), N_("Cannot exec a shared library directly"))
 5133 +_S(ELIBEXEC, N_("Cannot exec a shared library directly"))
 5134  #endif
 5135  #ifdef ESTRPIPE
 5136 -_S(ERR_MAP(ESTRPIPE), N_("Streams pipe error"))
 5137 +_S(ESTRPIPE, N_("Streams pipe error"))
 5138  #endif
 5139  #ifdef EUCLEAN
 5140 -_S(ERR_MAP(EUCLEAN), N_("Structure needs cleaning"))
 5141 +_S(EUCLEAN, N_("Structure needs cleaning"))
 5142  #endif
 5143  #ifdef ENOTNAM
 5144 -_S(ERR_MAP(ENOTNAM), N_("Not a XENIX named type file"))
 5145 +_S(ENOTNAM, N_("Not a XENIX named type file"))
 5146  #endif
 5147  #ifdef ENAVAIL
 5148 -_S(ERR_MAP(ENAVAIL), N_("No XENIX semaphores available"))
 5149 +_S(ENAVAIL, N_("No XENIX semaphores available"))
 5150  #endif
 5151  #ifdef EISNAM
 5152 -_S(ERR_MAP(EISNAM), N_("Is a named type file"))
 5153 +_S(EISNAM, N_("Is a named type file"))
 5154  #endif
 5155  #ifdef EREMOTEIO
 5156 -_S(ERR_MAP(EREMOTEIO), N_("Remote I/O error"))
 5157 +_S(EREMOTEIO, N_("Remote I/O error"))
 5158  #endif
 5159  #ifdef ENOMEDIUM
 5160 -_S(ERR_MAP(ENOMEDIUM), N_("No medium found"))
 5161 +_S(ENOMEDIUM, N_("No medium found"))
 5162  #endif
 5163  #ifdef EMEDIUMTYPE
 5164 -_S(ERR_MAP(EMEDIUMTYPE), N_("Wrong medium type"))
 5165 +_S(EMEDIUMTYPE, N_("Wrong medium type"))
 5166  #endif
 5167  #ifdef ENOKEY
 5168 -_S(ERR_MAP(ENOKEY), N_("Required key not available"))
 5169 +_S(ENOKEY, N_("Required key not available"))
 5170  #endif
 5171  #ifdef EKEYEXPIRED
 5172 -_S(ERR_MAP(EKEYEXPIRED), N_("Key has expired"))
 5173 +_S(EKEYEXPIRED, N_("Key has expired"))
 5174  #endif
 5175  #ifdef EKEYREVOKED
 5176 -_S(ERR_MAP(EKEYREVOKED), N_("Key has been revoked"))
 5177 +_S(EKEYREVOKED, N_("Key has been revoked"))
 5178  #endif
 5179  #ifdef EKEYREJECTED
 5180 -_S(ERR_MAP(EKEYREJECTED), N_("Key was rejected by service"))
 5181 +_S(EKEYREJECTED, N_("Key was rejected by service"))
 5182  #endif
 5183  #ifdef ERFKILL
 5184 -_S(ERR_MAP(ERFKILL), N_("Operation not possible due to RF-kill"))
 5185 +_S(ERFKILL, N_("Operation not possible due to RF-kill"))
 5186  #endif
 5187  #ifdef EHWPOISON
 5188 -_S(ERR_MAP(EHWPOISON), N_("Memory page has hardware error"))
 5189 +_S(EHWPOISON, N_("Memory page has hardware error"))
 5190  #endif
 5191  #ifdef EBADRPC
 5192 -_S(ERR_MAP(EBADRPC), N_("RPC struct is bad"))
 5193 +_S(EBADRPC, N_("RPC struct is bad"))
 5194  #endif
 5195  #ifdef EFTYPE
 5196  /*
 5197 @@ -693,40 +690,40 @@ TRANS operation, or a data file had the wrong format.
 5198  TRANS
 5199  TRANS On some systems @code{chmod} returns this error if you try to set the
 5200  TRANS sticky bit on a non-directory file; @pxref{Setting Permissions}. */
 5201 -_S(ERR_MAP(EFTYPE), N_("Inappropriate file type or format"))
 5202 +_S(EFTYPE, N_("Inappropriate file type or format"))
 5203  #endif
 5204  #ifdef EPROCUNAVAIL
 5205 -_S(ERR_MAP(EPROCUNAVAIL), N_("RPC bad procedure for program"))
 5206 +_S(EPROCUNAVAIL, N_("RPC bad procedure for program"))
 5207  #endif
 5208  #ifdef EAUTH
 5209 -_S(ERR_MAP(EAUTH), N_("Authentication error"))
 5210 +_S(EAUTH, N_("Authentication error"))
 5211  #endif
 5212  #ifdef EDIED
 5213  /*
 5214  TRANS On @gnuhurdsystems{}, opening a file returns this error when the file is
 5215  TRANS translated by a program and the translator program dies while starting
 5216  TRANS up, before it has connected to the file. */
 5217 -_S(ERR_MAP(EDIED), N_("Translator died"))
 5218 +_S(EDIED, N_("Translator died"))
 5219  #endif
 5220  #ifdef ERPCMISMATCH
 5221 -_S(ERR_MAP(ERPCMISMATCH), N_("RPC version wrong"))
 5222 +_S(ERPCMISMATCH, N_("RPC version wrong"))
 5223  #endif
 5224  #ifdef EGREGIOUS
 5225  /*
 5226  TRANS You did @strong{what}? */
 5227 -_S(ERR_MAP(EGREGIOUS), N_("You really blew it this time"))
 5228 +_S(EGREGIOUS, N_("You really blew it this time"))
 5229  #endif
 5230  #ifdef EPROCLIM
 5231  /*
 5232  TRANS This means that the per-user limit on new process would be exceeded by
 5233  TRANS an attempted @code{fork}.  @xref{Limits on Resources}, for details on
 5234  TRANS the @code{RLIMIT_NPROC} limit. */
 5235 -_S(ERR_MAP(EPROCLIM), N_("Too many processes"))
 5236 +_S(EPROCLIM, N_("Too many processes"))
 5237  #endif
 5238  #ifdef EGRATUITOUS
 5239  /*
 5240  TRANS This error code has no purpose. */
 5241 -_S(ERR_MAP(EGRATUITOUS), N_("Gratuitous error"))
 5242 +_S(EGRATUITOUS, N_("Gratuitous error"))
 5243  #endif
 5244  #if defined (ENOTSUP) && ENOTSUP != EOPNOTSUPP
 5245  /*
 5246 @@ -742,10 +739,10 @@ TRANS values.
 5247  TRANS
 5248  TRANS If the entire function is not available at all in the implementation,
 5249  TRANS it returns @code{ENOSYS} instead. */
 5250 -_S(ERR_MAP(ENOTSUP), N_("Not supported"))
 5251 +_S(ENOTSUP, N_("Not supported"))
 5252  #endif
 5253  #ifdef EPROGMISMATCH
 5254 -_S(ERR_MAP(EPROGMISMATCH), N_("RPC program version wrong"))
 5255 +_S(EPROGMISMATCH, N_("RPC program version wrong"))
 5256  #endif
 5257  #ifdef EBACKGROUND
 5258  /*
 5259 @@ -755,7 +752,7 @@ TRANS foreground process group of the terminal.  Users do not usually see this
 5260  TRANS error because functions such as @code{read} and @code{write} translate
 5261  TRANS it into a @code{SIGTTIN} or @code{SIGTTOU} signal.  @xref{Job Control},
 5262  TRANS for information on process groups and these signals. */
 5263 -_S(ERR_MAP(EBACKGROUND), N_("Inappropriate operation for background process"))
 5264 +_S(EBACKGROUND, N_("Inappropriate operation for background process"))
 5265  #endif
 5266  #ifdef EIEIO
 5267  /*
 5268 @@ -773,7 +770,7 @@ TRANS @c "bought the farm" means "died".  -jtobey
 5269  TRANS @c
 5270  TRANS @c Translators, please do not translate this litteraly, translate it into
 5271  TRANS @c an idiomatic funny way of saying that the computer died. */
 5272 -_S(ERR_MAP(EIEIO), N_("Computer bought the farm"))
 5273 +_S(EIEIO, N_("Computer bought the farm"))
 5274  #endif
 5275  #if defined (EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
 5276  /*
 5277 @@ -782,18 +779,18 @@ TRANS The values are always the same, on every operating system.
 5278  TRANS
 5279  TRANS C libraries in many older Unix systems have @code{EWOULDBLOCK} as a
 5280  TRANS separate error code. */
 5281 -_S(ERR_MAP(EWOULDBLOCK), N_("Operation would block"))
 5282 +_S(EWOULDBLOCK, N_("Operation would block"))
 5283  #endif
 5284  #ifdef ENEEDAUTH
 5285 -_S(ERR_MAP(ENEEDAUTH), N_("Need authenticator"))
 5286 +_S(ENEEDAUTH, N_("Need authenticator"))
 5287  #endif
 5288  #ifdef ED
 5289  /*
 5290  TRANS The experienced user will know what is wrong.
 5291  TRANS @c This error code is a joke.  Its perror text is part of the joke.
 5292  TRANS @c Don't change it. */
 5293 -_S(ERR_MAP(ED), N_("?"))
 5294 +_S(ED, N_("?"))
 5295  #endif
 5296  #ifdef EPROGUNAVAIL
 5297 -_S(ERR_MAP(EPROGUNAVAIL), N_("RPC program not available"))
 5298 +_S(EPROGUNAVAIL, N_("RPC program not available"))
 5299  #endif
 5300 diff --git a/sysdeps/i386/dl-machine.h b/sysdeps/i386/dl-machine.h
 5301 index 0f08079e48..672d8f27ce 100644
 5302 --- a/sysdeps/i386/dl-machine.h
 5303 +++ b/sysdeps/i386/dl-machine.h
 5304 @@ -338,16 +338,22 @@ elf_machine_rel (struct link_map *map, const Elf32_Rel *reloc,
 5305  	{
 5306  # ifndef RTLD_BOOTSTRAP
 5307  	  if (sym_map != map
 5308 -	      && sym_map->l_type != lt_executable
 5309  	      && !sym_map->l_relocated)
 5310  	    {
 5311  	      const char *strtab
 5312  		= (const char *) D_PTR (map, l_info[DT_STRTAB]);
 5313 -	      _dl_error_printf ("\
 5314 +	      if (sym_map->l_type == lt_executable)
 5315 +		_dl_fatal_printf ("\
 5316 +%s: IFUNC symbol '%s' referenced in '%s' is defined in the executable \
 5317 +and creates an unsatisfiable circular dependency.\n",
 5318 +				  RTLD_PROGNAME, strtab + refsym->st_name,
 5319 +				  map->l_name);
 5320 +	      else
 5321 +		_dl_error_printf ("\
 5322  %s: Relink `%s' with `%s' for IFUNC symbol `%s'\n",
 5323 -				RTLD_PROGNAME, map->l_name,
 5324 -				sym_map->l_name,
 5325 -				strtab + refsym->st_name);
 5326 +				  RTLD_PROGNAME, map->l_name,
 5327 +				  sym_map->l_name,
 5328 +				  strtab + refsym->st_name);
 5329  	    }
 5330  # endif
 5331  	  value = ((Elf32_Addr (*) (void)) value) ();
 5332 diff --git a/sysdeps/powerpc/powerpc64/backtrace.c b/sysdeps/powerpc/powerpc64/backtrace.c
 5333 index 8a53a1088f..362a2b713c 100644
 5334 --- a/sysdeps/powerpc/powerpc64/backtrace.c
 5335 +++ b/sysdeps/powerpc/powerpc64/backtrace.c
 5336 @@ -54,11 +54,22 @@ struct signal_frame_64 {
 5337    /* We don't care about the rest, since the IP value is at 'uc' field.  */
 5338  };
 5339  
 5340 +/* Test if the address match to the inside the trampoline code.
 5341 +   Up to and including kernel 5.8, returning from an interrupt or syscall to a
 5342 +   signal handler starts execution directly at the handler's entry point, with
 5343 +   LR set to address of the sigreturn trampoline (the vDSO symbol).
 5344 +   Newer kernels will branch to signal handler from the trampoline instead, so
 5345 +   checking the stacktrace against the vDSO entrypoint does not work in such
 5346 +   case.
 5347 +   The vDSO branches with a 'bctrl' instruction, so checking either the
 5348 +   vDSO address itself and the next instruction should cover all kernel
 5349 +   versions.  */
 5350  static inline bool
 5351  is_sigtramp_address (void *nip)
 5352  {
 5353  #ifdef HAVE_SIGTRAMP_RT64
 5354 -  if (nip == GLRO (dl_vdso_sigtramp_rt64))
 5355 +  if (nip == GLRO (dl_vdso_sigtramp_rt64) ||
 5356 +      nip == GLRO (dl_vdso_sigtramp_rt64) + 4)
 5357      return true;
 5358  #endif
 5359    return false;
 5360 diff --git a/sysdeps/pthread/Makefile b/sysdeps/pthread/Makefile
 5361 index 920d875420..bf9b7f7223 100644
 5362 --- a/sysdeps/pthread/Makefile
 5363 +++ b/sysdeps/pthread/Makefile
 5364 @@ -107,6 +107,7 @@ tests += tst-cnd-basic tst-mtx-trylock tst-cnd-broadcast \
 5365  	 tst-unload \
 5366  	 tst-unwind-thread \
 5367  	 tst-pt-vfork1 tst-pt-vfork2 tst-vfork1x tst-vfork2x \
 5368 +	 tst-pthread-exit-signal \
 5369  
 5370  
 5371  # Files which must not be linked with libpthread.
 5372 diff --git a/sysdeps/pthread/tst-pthread-exit-signal.c b/sysdeps/pthread/tst-pthread-exit-signal.c
 5373 new file mode 100644
 5374 index 0000000000..b4526fe663
 5375 --- /dev/null
 5376 +++ b/sysdeps/pthread/tst-pthread-exit-signal.c
 5377 @@ -0,0 +1,45 @@
 5378 +/* Test that pending signals are not delivered on thread exit (bug 28607).
 5379 +   Copyright (C) 2021 Free Software Foundation, Inc.
 5380 +   This file is part of the GNU C Library.
 5381 +
 5382 +   The GNU C Library is free software; you can redistribute it and/or
 5383 +   modify it under the terms of the GNU Lesser General Public
 5384 +   License as published by the Free Software Foundation; either
 5385 +   version 2.1 of the License, or (at your option) any later version.
 5386 +
 5387 +   The GNU C Library is distributed in the hope that it will be useful,
 5388 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
 5389 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 5390 +   Lesser General Public License for more details.
 5391 +
 5392 +   You should have received a copy of the GNU Lesser General Public
 5393 +   License along with the GNU C Library; if not, see
 5394 +   <https://www.gnu.org/licenses/>.  */
 5395 +
 5396 +/* Due to bug 28607, pthread_kill (or pthread_cancel) restored the
 5397 +   signal mask during during thread exit, triggering the delivery of a
 5398 +   blocked pending signal (SIGUSR1 in this test).  */
 5399 +
 5400 +#include <support/xthread.h>
 5401 +#include <support/xsignal.h>
 5402 +
 5403 +static void *
 5404 +threadfunc (void *closure)
 5405 +{
 5406 +  sigset_t sigmask;
 5407 +  sigfillset (&sigmask);
 5408 +  xpthread_sigmask (SIG_SETMASK, &sigmask, NULL);
 5409 +  xpthread_kill (pthread_self (), SIGUSR1);
 5410 +  pthread_exit (NULL);
 5411 +  return NULL;
 5412 +}
 5413 +
 5414 +static int
 5415 +do_test (void)
 5416 +{
 5417 +  pthread_t thr = xpthread_create (NULL, threadfunc, NULL);
 5418 +  xpthread_join (thr);
 5419 +  return 0;
 5420 +}
 5421 +
 5422 +#include <support/test-driver.c>
 5423 diff --git a/sysdeps/s390/configure b/sysdeps/s390/configure
 5424 index fa46e9e351..e7f576338d 100644
 5425 --- a/sysdeps/s390/configure
 5426 +++ b/sysdeps/s390/configure
 5427 @@ -123,7 +123,9 @@ void testinsn (char *buf)
 5428      __asm__ (".machine \"arch13\" \n\t"
 5429  	     ".machinemode \"zarch_nohighgprs\" \n\t"
 5430  	     "lghi %%r0,16 \n\t"
 5431 -	     "mvcrl 0(%0),32(%0)" : : "a" (buf) : "memory", "r0");
 5432 +	     "mvcrl 0(%0),32(%0) \n\t"
 5433 +	     "vstrs %%v20,%%v20,%%v20,%%v20,0,2"
 5434 +	     : : "a" (buf) : "memory", "r0");
 5435  }
 5436  EOF
 5437  if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS --shared conftest.c
 5438 @@ -271,7 +273,9 @@ else
 5439  void testinsn (char *buf)
 5440  {
 5441      __asm__ ("lghi %%r0,16 \n\t"
 5442 -	     "mvcrl 0(%0),32(%0)" : : "a" (buf) : "memory", "r0");
 5443 +	     "mvcrl 0(%0),32(%0) \n\t"
 5444 +	     "vstrs %%v20,%%v20,%%v20,%%v20,0,2"
 5445 +	     : : "a" (buf) : "memory", "r0");
 5446  }
 5447  EOF
 5448  if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS --shared conftest.c
 5449 diff --git a/sysdeps/s390/configure.ac b/sysdeps/s390/configure.ac
 5450 index 3ed5a8ef87..5c3479e8cf 100644
 5451 --- a/sysdeps/s390/configure.ac
 5452 +++ b/sysdeps/s390/configure.ac
 5453 @@ -88,7 +88,9 @@ void testinsn (char *buf)
 5454      __asm__ (".machine \"arch13\" \n\t"
 5455  	     ".machinemode \"zarch_nohighgprs\" \n\t"
 5456  	     "lghi %%r0,16 \n\t"
 5457 -	     "mvcrl 0(%0),32(%0)" : : "a" (buf) : "memory", "r0");
 5458 +	     "mvcrl 0(%0),32(%0) \n\t"
 5459 +	     "vstrs %%v20,%%v20,%%v20,%%v20,0,2"
 5460 +	     : : "a" (buf) : "memory", "r0");
 5461  }
 5462  EOF
 5463  dnl test, if assembler supports S390 arch13 instructions
 5464 @@ -195,7 +197,9 @@ cat > conftest.c <<\EOF
 5465  void testinsn (char *buf)
 5466  {
 5467      __asm__ ("lghi %%r0,16 \n\t"
 5468 -	     "mvcrl 0(%0),32(%0)" : : "a" (buf) : "memory", "r0");
 5469 +	     "mvcrl 0(%0),32(%0) \n\t"
 5470 +	     "vstrs %%v20,%%v20,%%v20,%%v20,0,2"
 5471 +	     : : "a" (buf) : "memory", "r0");
 5472  }
 5473  EOF
 5474  dnl test, if assembler supports S390 arch13 zarch instructions as default
 5475 diff --git a/sysdeps/s390/memmove.c b/sysdeps/s390/memmove.c
 5476 index 5fc85e129f..ee59b5de14 100644
 5477 --- a/sysdeps/s390/memmove.c
 5478 +++ b/sysdeps/s390/memmove.c
 5479 @@ -43,7 +43,7 @@ extern __typeof (__redirect_memmove) MEMMOVE_ARCH13 attribute_hidden;
 5480  s390_libc_ifunc_expr (__redirect_memmove, memmove,
 5481  		      ({
 5482  			s390_libc_ifunc_expr_stfle_init ();
 5483 -			(HAVE_MEMMOVE_ARCH13
 5484 +			(HAVE_MEMMOVE_ARCH13 && (hwcap & HWCAP_S390_VXRS_EXT2)
 5485  			 && S390_IS_ARCH13_MIE3 (stfle_bits))
 5486  			  ? MEMMOVE_ARCH13
 5487  			  : (HAVE_MEMMOVE_Z13 && (hwcap & HWCAP_S390_VX))
 5488 diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
 5489 index e6195c6e26..17c0cc3952 100644
 5490 --- a/sysdeps/s390/multiarch/ifunc-impl-list.c
 5491 +++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
 5492 @@ -171,7 +171,8 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
 5493      IFUNC_IMPL (i, name, memmove,
 5494  # if HAVE_MEMMOVE_ARCH13
 5495  		IFUNC_IMPL_ADD (array, i, memmove,
 5496 -				S390_IS_ARCH13_MIE3 (stfle_bits),
 5497 +				((dl_hwcap & HWCAP_S390_VXRS_EXT2)
 5498 +				 && S390_IS_ARCH13_MIE3 (stfle_bits)),
 5499  				MEMMOVE_ARCH13)
 5500  # endif
 5501  # if HAVE_MEMMOVE_Z13
 5502 diff --git a/sysdeps/sh/be/sh4/fpu/Implies b/sysdeps/sh/be/sh4/fpu/Implies
 5503 new file mode 100644
 5504 index 0000000000..71b28ee1a4
 5505 --- /dev/null
 5506 +++ b/sysdeps/sh/be/sh4/fpu/Implies
 5507 @@ -0,0 +1 @@
 5508 +sh/sh4/fpu
 5509 diff --git a/sysdeps/sh/le/sh4/fpu/Implies b/sysdeps/sh/le/sh4/fpu/Implies
 5510 new file mode 100644
 5511 index 0000000000..71b28ee1a4
 5512 --- /dev/null
 5513 +++ b/sysdeps/sh/le/sh4/fpu/Implies
 5514 @@ -0,0 +1 @@
 5515 +sh/sh4/fpu
 5516 diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
 5517 index 9b2a253032..34748ffcd1 100644
 5518 --- a/sysdeps/unix/sysv/linux/Makefile
 5519 +++ b/sysdeps/unix/sysv/linux/Makefile
 5520 @@ -100,7 +100,7 @@ tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \
 5521  	 tst-quota tst-sync_file_range tst-sysconf-iov_max tst-ttyname \
 5522  	 test-errno-linux tst-memfd_create tst-mlock2 tst-pkey \
 5523  	 tst-rlimit-infinity tst-ofdlocks tst-gettid tst-gettid-kill \
 5524 -	 tst-tgkill
 5525 +	 tst-tgkill tst-sysvsem-linux tst-sysvmsg-linux tst-sysvshm-linux
 5526  tests-internal += tst-ofdlocks-compat tst-sigcontext-get_pc
 5527  
 5528  CFLAGS-tst-sigcontext-get_pc.c = -fasynchronous-unwind-tables
 5529 diff --git a/sysdeps/unix/sysv/linux/aarch64/cpu-features.h b/sysdeps/unix/sysv/linux/aarch64/cpu-features.h
 5530 index fc688450ee..00a4d0c8e7 100644
 5531 --- a/sysdeps/unix/sysv/linux/aarch64/cpu-features.h
 5532 +++ b/sysdeps/unix/sysv/linux/aarch64/cpu-features.h
 5533 @@ -54,6 +54,10 @@
 5534                          && MIDR_PARTNUM(midr) == 0x000)
 5535  #define IS_NEOVERSE_N1(midr) (MIDR_IMPLEMENTOR(midr) == 'A'		      \
 5536  			      && MIDR_PARTNUM(midr) == 0xd0c)
 5537 +#define IS_NEOVERSE_N2(midr) (MIDR_IMPLEMENTOR(midr) == 'A'		      \
 5538 +			      && MIDR_PARTNUM(midr) == 0xd49)
 5539 +#define IS_NEOVERSE_V1(midr) (MIDR_IMPLEMENTOR(midr) == 'A'		      \
 5540 +			      && MIDR_PARTNUM(midr) == 0xd40)
 5541  
 5542  #define IS_EMAG(midr) (MIDR_IMPLEMENTOR(midr) == 'P'			      \
 5543                         && MIDR_PARTNUM(midr) == 0x000)
 5544 diff --git a/sysdeps/unix/sysv/linux/mq_notify.c b/sysdeps/unix/sysv/linux/mq_notify.c
 5545 index 61bbb03b64..2bb98172c8 100644
 5546 --- a/sysdeps/unix/sysv/linux/mq_notify.c
 5547 +++ b/sysdeps/unix/sysv/linux/mq_notify.c
 5548 @@ -132,9 +132,12 @@ helper_thread (void *arg)
 5549  	       to wait until it is done with it.  */
 5550  	    (void) __pthread_barrier_wait (&notify_barrier);
 5551  	}
 5552 -      else if (data.raw[NOTIFY_COOKIE_LEN - 1] == NOTIFY_REMOVED)
 5553 -	/* The only state we keep is the copy of the thread attributes.  */
 5554 -	free (data.attr);
 5555 +      else if (data.raw[NOTIFY_COOKIE_LEN - 1] == NOTIFY_REMOVED && data.attr != NULL)
 5556 +	{
 5557 +	  /* The only state we keep is the copy of the thread attributes.  */
 5558 +	  pthread_attr_destroy (data.attr);
 5559 +	  free (data.attr);
 5560 +	}
 5561      }
 5562    return NULL;
 5563  }
 5564 @@ -255,8 +258,14 @@ mq_notify (mqd_t mqdes, const struct sigevent *notification)
 5565        if (data.attr == NULL)
 5566  	return -1;
 5567  
 5568 -      memcpy (data.attr, notification->sigev_notify_attributes,
 5569 -	      sizeof (pthread_attr_t));
 5570 +      int ret = __pthread_attr_copy (data.attr,
 5571 +				     notification->sigev_notify_attributes);
 5572 +      if (ret != 0)
 5573 +	{
 5574 +	  free (data.attr);
 5575 +	  __set_errno (ret);
 5576 +	  return -1;
 5577 +	}
 5578      }
 5579  
 5580    /* Construct the new request.  */
 5581 @@ -269,8 +278,11 @@ mq_notify (mqd_t mqdes, const struct sigevent *notification)
 5582    int retval = INLINE_SYSCALL (mq_notify, 2, mqdes, &se);
 5583  
 5584    /* If it failed, free the allocated memory.  */
 5585 -  if (__glibc_unlikely (retval != 0))
 5586 -    free (data.attr);
 5587 +  if (retval != 0 && data.attr != NULL)
 5588 +    {
 5589 +      pthread_attr_destroy (data.attr);
 5590 +      free (data.attr);
 5591 +    }
 5592  
 5593    return retval;
 5594  }
 5595 diff --git a/sysdeps/unix/sysv/linux/msgctl.c b/sysdeps/unix/sysv/linux/msgctl.c
 5596 index 0776472d5e..a1f24ab242 100644
 5597 --- a/sysdeps/unix/sysv/linux/msgctl.c
 5598 +++ b/sysdeps/unix/sysv/linux/msgctl.c
 5599 @@ -90,8 +90,15 @@ __msgctl64 (int msqid, int cmd, struct __msqid64_ds *buf)
 5600    struct kernel_msqid64_ds ksemid, *arg = NULL;
 5601    if (buf != NULL)
 5602      {
 5603 -      msqid64_to_kmsqid64 (buf, &ksemid);
 5604 -      arg = &ksemid;
 5605 +      /* This is a Linux extension where kernel returns a 'struct msginfo'
 5606 +	 instead.  */
 5607 +      if (cmd == IPC_INFO || cmd == MSG_INFO)
 5608 +	arg = (struct kernel_msqid64_ds *) buf;
 5609 +      else
 5610 +	{
 5611 +	  msqid64_to_kmsqid64 (buf, &ksemid);
 5612 +	  arg = &ksemid;
 5613 +	}
 5614      }
 5615  # ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T
 5616    if (cmd == IPC_SET)
 5617 @@ -169,8 +176,15 @@ __msgctl (int msqid, int cmd, struct msqid_ds *buf)
 5618    struct __msqid64_ds msqid64, *buf64 = NULL;
 5619    if (buf != NULL)
 5620      {
 5621 -      msqid_to_msqid64 (&msqid64, buf);
 5622 -      buf64 = &msqid64;
 5623 +      /* This is a Linux extension where kernel returns a 'struct msginfo'
 5624 +	 instead.  */
 5625 +      if (cmd == IPC_INFO || cmd == MSG_INFO)
 5626 +	buf64 = (struct __msqid64_ds *) buf;
 5627 +      else
 5628 +	{
 5629 +	  msqid_to_msqid64 (&msqid64, buf);
 5630 +	  buf64 = &msqid64;
 5631 +	}
 5632      }
 5633  
 5634    int ret = __msgctl64 (msqid, cmd, buf64);
 5635 diff --git a/sysdeps/unix/sysv/linux/semctl.c b/sysdeps/unix/sysv/linux/semctl.c
 5636 index f131a26fc7..1cdabde8f2 100644
 5637 --- a/sysdeps/unix/sysv/linux/semctl.c
 5638 +++ b/sysdeps/unix/sysv/linux/semctl.c
 5639 @@ -102,6 +102,7 @@ semun64_to_ksemun64 (int cmd, union semun64 semun64,
 5640        r.array = semun64.array;
 5641        break;
 5642      case SEM_STAT:
 5643 +    case SEM_STAT_ANY:
 5644      case IPC_STAT:
 5645      case IPC_SET:
 5646        r.buf = buf;
 5647 @@ -150,6 +151,7 @@ __semctl64 (int semid, int semnum, int cmd, ...)
 5648      case IPC_STAT:      /* arg.buf */
 5649      case IPC_SET:
 5650      case SEM_STAT:
 5651 +    case SEM_STAT_ANY:
 5652      case IPC_INFO:      /* arg.__buf */
 5653      case SEM_INFO:
 5654        va_start (ap, cmd);
 5655 @@ -238,6 +240,7 @@ semun_to_semun64 (int cmd, union semun semun, struct __semid64_ds *semid64)
 5656        r.array = semun.array;
 5657        break;
 5658      case SEM_STAT:
 5659 +    case SEM_STAT_ANY:
 5660      case IPC_STAT:
 5661      case IPC_SET:
 5662        r.buf = semid64;
 5663 @@ -267,6 +270,7 @@ __semctl (int semid, int semnum, int cmd, ...)
 5664      case IPC_STAT:      /* arg.buf */
 5665      case IPC_SET:
 5666      case SEM_STAT:
 5667 +    case SEM_STAT_ANY:
 5668      case IPC_INFO:      /* arg.__buf */
 5669      case SEM_INFO:
 5670        va_start (ap, cmd);
 5671 @@ -321,6 +325,7 @@ __semctl_mode16 (int semid, int semnum, int cmd, ...)
 5672      case IPC_STAT:      /* arg.buf */
 5673      case IPC_SET:
 5674      case SEM_STAT:
 5675 +    case SEM_STAT_ANY:
 5676      case IPC_INFO:      /* arg.__buf */
 5677      case SEM_INFO:
 5678        va_start (ap, cmd);
 5679 @@ -354,6 +359,7 @@ __old_semctl (int semid, int semnum, int cmd, ...)
 5680      case IPC_STAT:      /* arg.buf */
 5681      case IPC_SET:
 5682      case SEM_STAT:
 5683 +    case SEM_STAT_ANY:
 5684      case IPC_INFO:      /* arg.__buf */
 5685      case SEM_INFO:
 5686        va_start (ap, cmd);
 5687 diff --git a/sysdeps/unix/sysv/linux/sh/be/sh4/fpu/Implies b/sysdeps/unix/sysv/linux/sh/be/sh4/fpu/Implies
 5688 new file mode 100644
 5689 index 0000000000..7eeaf15a5a
 5690 --- /dev/null
 5691 +++ b/sysdeps/unix/sysv/linux/sh/be/sh4/fpu/Implies
 5692 @@ -0,0 +1 @@
 5693 +unix/sysv/linux/sh/sh4/fpu
 5694 diff --git a/sysdeps/unix/sysv/linux/sh/le/sh4/fpu/Implies b/sysdeps/unix/sysv/linux/sh/le/sh4/fpu/Implies
 5695 new file mode 100644
 5696 index 0000000000..7eeaf15a5a
 5697 --- /dev/null
 5698 +++ b/sysdeps/unix/sysv/linux/sh/le/sh4/fpu/Implies
 5699 @@ -0,0 +1 @@
 5700 +unix/sysv/linux/sh/sh4/fpu
 5701 diff --git a/sysdeps/unix/sysv/linux/shmctl.c b/sysdeps/unix/sysv/linux/shmctl.c
 5702 index 76d88441f1..1d19a798b1 100644
 5703 --- a/sysdeps/unix/sysv/linux/shmctl.c
 5704 +++ b/sysdeps/unix/sysv/linux/shmctl.c
 5705 @@ -90,8 +90,15 @@ __shmctl64 (int shmid, int cmd, struct __shmid64_ds *buf)
 5706    struct kernel_shmid64_ds kshmid, *arg = NULL;
 5707    if (buf != NULL)
 5708      {
 5709 -      shmid64_to_kshmid64 (buf, &kshmid);
 5710 -      arg = &kshmid;
 5711 +      /* This is a Linux extension where kernel expects either a
 5712 +	 'struct shminfo' (IPC_INFO) or 'struct shm_info' (SHM_INFO).  */
 5713 +      if (cmd == IPC_INFO || cmd == SHM_INFO)
 5714 +	arg = (struct kernel_shmid64_ds *) buf;
 5715 +      else
 5716 +	{
 5717 +	  shmid64_to_kshmid64 (buf, &kshmid);
 5718 +	  arg = &kshmid;
 5719 +	}
 5720      }
 5721  # ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T
 5722    if (cmd == IPC_SET)
 5723 @@ -107,7 +114,6 @@ __shmctl64 (int shmid, int cmd, struct __shmid64_ds *buf)
 5724  
 5725    switch (cmd)
 5726      {
 5727 -      case IPC_INFO:
 5728        case IPC_STAT:
 5729        case SHM_STAT:
 5730        case SHM_STAT_ANY:
 5731 @@ -168,8 +174,15 @@ __shmctl (int shmid, int cmd, struct shmid_ds *buf)
 5732    struct __shmid64_ds shmid64, *buf64 = NULL;
 5733    if (buf != NULL)
 5734      {
 5735 -      shmid_to_shmid64 (&shmid64, buf);
 5736 -      buf64 = &shmid64;
 5737 +      /* This is a Linux extension where kernel expects either a
 5738 +	 'struct shminfo' (IPC_INFO) or 'struct shm_info' (SHM_INFO).  */
 5739 +      if (cmd == IPC_INFO || cmd == SHM_INFO)
 5740 +	buf64 = (struct __shmid64_ds *) buf;
 5741 +      else
 5742 +	{
 5743 +	  shmid_to_shmid64 (&shmid64, buf);
 5744 +	  buf64 = &shmid64;
 5745 +	}
 5746      }
 5747  
 5748    int ret = __shmctl64 (shmid, cmd, buf64);
 5749 @@ -178,7 +191,6 @@ __shmctl (int shmid, int cmd, struct shmid_ds *buf)
 5750  
 5751    switch (cmd)
 5752      {
 5753 -      case IPC_INFO:
 5754        case IPC_STAT:
 5755        case SHM_STAT:
 5756        case SHM_STAT_ANY:
 5757 diff --git a/sysdeps/unix/sysv/linux/tst-sysvmsg-linux.c b/sysdeps/unix/sysv/linux/tst-sysvmsg-linux.c
 5758 new file mode 100644
 5759 index 0000000000..630f4f792c
 5760 --- /dev/null
 5761 +++ b/sysdeps/unix/sysv/linux/tst-sysvmsg-linux.c
 5762 @@ -0,0 +1,177 @@
 5763 +/* Basic tests for Linux SYSV message queue extensions.
 5764 +   Copyright (C) 2020 Free Software Foundation, Inc.
 5765 +   This file is part of the GNU C Library.
 5766 +
 5767 +   The GNU C Library is free software; you can redistribute it and/or
 5768 +   modify it under the terms of the GNU Lesser General Public
 5769 +   License as published by the Free Software Foundation; either
 5770 +   version 2.1 of the License, or (at your option) any later version.
 5771 +
 5772 +   The GNU C Library is distributed in the hope that it will be useful,
 5773 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
 5774 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 5775 +   Lesser General Public License for more details.
 5776 +
 5777 +   You should have received a copy of the GNU Lesser General Public
 5778 +   License along with the GNU C Library; if not, see
 5779 +   <https://www.gnu.org/licenses/>.  */
 5780 +
 5781 +#include <sys/ipc.h>
 5782 +#include <sys/msg.h>
 5783 +#include <errno.h>
 5784 +#include <stdlib.h>
 5785 +#include <stdbool.h>
 5786 +#include <stdio.h>
 5787 +
 5788 +#include <support/check.h>
 5789 +#include <support/temp_file.h>
 5790 +
 5791 +#define MSGQ_MODE 0644
 5792 +
 5793 +/* These are for the temporary file we generate.  */
 5794 +static char *name;
 5795 +static int msqid;
 5796 +
 5797 +static void
 5798 +remove_msq (void)
 5799 +{
 5800 +  /* Enforce message queue removal in case of early test failure.
 5801 +     Ignore error since the msg may already have being removed.  */
 5802 +  msgctl (msqid, IPC_RMID, NULL);
 5803 +}
 5804 +
 5805 +static void
 5806 +do_prepare (int argc, char *argv[])
 5807 +{
 5808 +  TEST_VERIFY_EXIT (create_temp_file ("tst-sysvmsg.", &name) != -1);
 5809 +}
 5810 +
 5811 +#define PREPARE do_prepare
 5812 +
 5813 +struct test_msginfo
 5814 +{
 5815 +  int msgmax;
 5816 +  int msgmnb;
 5817 +  int msgmni;
 5818 +};
 5819 +
 5820 +/* It tries to obtain some system-wide SysV messsage queue information from
 5821 +   /proc to check against IPC_INFO/MSG_INFO.  The /proc only returns the
 5822 +   tunables value of MSGMAX, MSGMNB, and MSGMNI.
 5823 +
 5824 +   The kernel also returns constant value for MSGSSZ, MSGSEG and also MSGMAP,
 5825 +   MSGPOOL, and MSGTQL (for IPC_INFO).  The issue to check them is they might
 5826 +   change over kernel releases.  */
 5827 +
 5828 +static int
 5829 +read_proc_file (const char *file)
 5830 +{
 5831 +  FILE *f = fopen (file, "r");
 5832 +  if (f == NULL)
 5833 +    FAIL_UNSUPPORTED ("/proc is not mounted or %s is not available", file);
 5834 +
 5835 +  int v;
 5836 +  int r = fscanf (f, "%d", & v);
 5837 +  TEST_VERIFY_EXIT (r == 1);
 5838 +
 5839 +  fclose (f);
 5840 +  return v;
 5841 +}
 5842 +
 5843 +
 5844 +/* Check if the message queue with IDX (index into the kernel's internal
 5845 +   array) matches the one with KEY.  The CMD is either MSG_STAT or
 5846 +   MSG_STAT_ANY.  */
 5847 +
 5848 +static bool
 5849 +check_msginfo (int idx, key_t key, int cmd)
 5850 +{
 5851 +  struct msqid_ds msginfo;
 5852 +  int mid = msgctl (idx, cmd, &msginfo);
 5853 +  /* Ignore unused array slot returned by the kernel or information from
 5854 +     unknown message queue.  */
 5855 +  if ((mid == -1 && errno == EINVAL) || mid != msqid)
 5856 +    return false;
 5857 +
 5858 +  if (mid == -1)
 5859 +    FAIL_EXIT1 ("msgctl with %s failed: %m",
 5860 +		cmd == MSG_STAT ? "MSG_STAT" : "MSG_STAT_ANY");
 5861 +
 5862 +  TEST_COMPARE (msginfo.msg_perm.__key, key);
 5863 +  TEST_COMPARE (msginfo.msg_perm.mode, MSGQ_MODE);
 5864 +  TEST_COMPARE (msginfo.msg_qnum, 0);
 5865 +
 5866 +  return true;
 5867 +}
 5868 +
 5869 +static int
 5870 +do_test (void)
 5871 +{
 5872 +  atexit (remove_msq);
 5873 +
 5874 +  key_t key = ftok (name, 'G');
 5875 +  if (key == -1)
 5876 +    FAIL_EXIT1 ("ftok failed: %m");
 5877 +
 5878 +  msqid = msgget (key, MSGQ_MODE | IPC_CREAT);
 5879 +  if (msqid == -1)
 5880 +    FAIL_EXIT1 ("msgget failed: %m");
 5881 +
 5882 +  struct test_msginfo tipcinfo;
 5883 +  tipcinfo.msgmax = read_proc_file ("/proc/sys/kernel/msgmax");
 5884 +  tipcinfo.msgmnb = read_proc_file ("/proc/sys/kernel/msgmnb");
 5885 +  tipcinfo.msgmni = read_proc_file ("/proc/sys/kernel/msgmni");
 5886 +
 5887 +  int msqidx;
 5888 +
 5889 +  {
 5890 +    struct msginfo ipcinfo;
 5891 +    msqidx = msgctl (msqid, IPC_INFO, (struct msqid_ds *) &ipcinfo);
 5892 +    if (msqidx == -1)
 5893 +      FAIL_EXIT1 ("msgctl with IPC_INFO failed: %m");
 5894 +
 5895 +    TEST_COMPARE (ipcinfo.msgmax, tipcinfo.msgmax);
 5896 +    TEST_COMPARE (ipcinfo.msgmnb, tipcinfo.msgmnb);
 5897 +    TEST_COMPARE (ipcinfo.msgmni, tipcinfo.msgmni);
 5898 +  }
 5899 +
 5900 +  /* Same as before but with MSG_INFO.  */
 5901 +  {
 5902 +    struct msginfo ipcinfo;
 5903 +    msqidx = msgctl (msqid, MSG_INFO, (struct msqid_ds *) &ipcinfo);
 5904 +    if (msqidx == -1)
 5905 +      FAIL_EXIT1 ("msgctl with IPC_INFO failed: %m");
 5906 +
 5907 +    TEST_COMPARE (ipcinfo.msgmax, tipcinfo.msgmax);
 5908 +    TEST_COMPARE (ipcinfo.msgmnb, tipcinfo.msgmnb);
 5909 +    TEST_COMPARE (ipcinfo.msgmni, tipcinfo.msgmni);
 5910 +  }
 5911 +
 5912 +  /* We check if the created message queue shows in global list.  */
 5913 +  bool found = false;
 5914 +  for (int i = 0; i <= msqidx; i++)
 5915 +    {
 5916 +      /* We can't tell apart if MSG_STAT_ANY is not supported (kernel older
 5917 +	 than 4.17) or if the index used is invalid.  So it just check if the
 5918 +	 value returned from a valid call matches the created message
 5919 +	 queue.  */
 5920 +      check_msginfo (i, key, MSG_STAT_ANY);
 5921 +
 5922 +      if (check_msginfo (i, key, MSG_STAT))
 5923 +	{
 5924 +	  found = true;
 5925 +	  break;
 5926 +	}
 5927 +    }
 5928 +
 5929 +  if (!found)
 5930 +    FAIL_EXIT1 ("msgctl with MSG_STAT/MSG_STAT_ANY could not find the "
 5931 +		"created message queue");
 5932 +
 5933 +  if (msgctl (msqid, IPC_RMID, NULL) == -1)
 5934 +    FAIL_EXIT1 ("msgctl failed");
 5935 +
 5936 +  return 0;
 5937 +}
 5938 +
 5939 +#include <support/test-driver.c>
 5940 diff --git a/sysdeps/unix/sysv/linux/tst-sysvsem-linux.c b/sysdeps/unix/sysv/linux/tst-sysvsem-linux.c
 5941 new file mode 100644
 5942 index 0000000000..45f19e2d37
 5943 --- /dev/null
 5944 +++ b/sysdeps/unix/sysv/linux/tst-sysvsem-linux.c
 5945 @@ -0,0 +1,184 @@
 5946 +/* Basic tests for Linux SYSV semaphore extensions.
 5947 +   Copyright (C) 2020 Free Software Foundation, Inc.
 5948 +   This file is part of the GNU C Library.
 5949 +
 5950 +   The GNU C Library is free software; you can redistribute it and/or
 5951 +   modify it under the terms of the GNU Lesser General Public
 5952 +   License as published by the Free Software Foundation; either
 5953 +   version 2.1 of the License, or (at your option) any later version.
 5954 +
 5955 +   The GNU C Library is distributed in the hope that it will be useful,
 5956 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
 5957 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 5958 +   Lesser General Public License for more details.
 5959 +
 5960 +   You should have received a copy of the GNU Lesser General Public
 5961 +   License along with the GNU C Library; if not, see
 5962 +   <https://www.gnu.org/licenses/>.  */
 5963 +
 5964 +#include <sys/ipc.h>
 5965 +#include <sys/sem.h>
 5966 +#include <errno.h>
 5967 +#include <stdlib.h>
 5968 +#include <stdbool.h>
 5969 +#include <stdio.h>
 5970 +
 5971 +#include <support/check.h>
 5972 +#include <support/temp_file.h>
 5973 +
 5974 +/* These are for the temporary file we generate.  */
 5975 +static char *name;
 5976 +static int semid;
 5977 +
 5978 +static void
 5979 +remove_sem (void)
 5980 +{
 5981 +  /* Enforce message queue removal in case of early test failure.
 5982 +     Ignore error since the sem may already have being removed.  */
 5983 +  semctl (semid, 0, IPC_RMID, 0);
 5984 +}
 5985 +
 5986 +static void
 5987 +do_prepare (int argc, char *argv[])
 5988 +{
 5989 +  TEST_VERIFY_EXIT (create_temp_file ("tst-sysvsem.", &name) != -1);
 5990 +}
 5991 +
 5992 +#define PREPARE do_prepare
 5993 +
 5994 +#define SEM_MODE 0644
 5995 +
 5996 +union semun
 5997 +{
 5998 +  int val;
 5999 +  struct semid_ds *buf;
 6000 +  unsigned short  *array;
 6001 +  struct seminfo *__buf;
 6002 +};
 6003 +
 6004 +struct test_seminfo
 6005 +{
 6006 +  int semmsl;
 6007 +  int semmns;
 6008 +  int semopm;
 6009 +  int semmni;
 6010 +};
 6011 +
 6012 +/* It tries to obtain some system-wide SysV semaphore information from /proc
 6013 +   to check against IPC_INFO/SEM_INFO.  The /proc only returns the tunables
 6014 +   value of SEMMSL, SEMMNS, SEMOPM, and SEMMNI.
 6015 +
 6016 +   The kernel also returns constant value for SEMVMX, SEMMNU, SEMMAP, SEMUME,
 6017 +   and also SEMUSZ and SEMAEM (for IPC_INFO).  The issue to check them is they
 6018 +   might change over kernel releases.  */
 6019 +
 6020 +static void
 6021 +read_sem_stat (struct test_seminfo *tseminfo)
 6022 +{
 6023 +  FILE *f = fopen ("/proc/sys/kernel/sem", "r");
 6024 +  if (f == NULL)
 6025 +    FAIL_UNSUPPORTED ("/proc is not mounted or /proc/sys/kernel/sem is not "
 6026 +		      "available");
 6027 +
 6028 +  int r = fscanf (f, "%d %d %d %d",
 6029 +		  &tseminfo->semmsl, &tseminfo->semmns, &tseminfo->semopm,
 6030 +		  &tseminfo->semmni);
 6031 +  TEST_VERIFY_EXIT (r == 4);
 6032 +
 6033 +  fclose (f);
 6034 +}
 6035 +
 6036 +
 6037 +/* Check if the semaphore with IDX (index into the kernel's internal array)
 6038 +   matches the one with KEY.  The CMD is either SEM_STAT or SEM_STAT_ANY.  */
 6039 +
 6040 +static bool
 6041 +check_seminfo (int idx, key_t key, int cmd)
 6042 +{
 6043 +  struct semid_ds seminfo;
 6044 +  int sid = semctl (idx, 0, cmd, (union semun) { .buf = &seminfo });
 6045 +  /* Ignore unused array slot returned by the kernel or information from
 6046 +     unknown semaphores.  */
 6047 +  if ((sid == -1 && errno == EINVAL) || sid != semid)
 6048 +    return false;
 6049 +
 6050 +  if (sid == -1)
 6051 +    FAIL_EXIT1 ("semctl with SEM_STAT failed (errno=%d)", errno);
 6052 +
 6053 +  TEST_COMPARE (seminfo.sem_perm.__key, key);
 6054 +  TEST_COMPARE (seminfo.sem_perm.mode, SEM_MODE);
 6055 +  TEST_COMPARE (seminfo.sem_nsems, 1);
 6056 +
 6057 +  return true;
 6058 +}
 6059 +
 6060 +static int
 6061 +do_test (void)
 6062 +{
 6063 +  atexit (remove_sem);
 6064 +
 6065 +  key_t key = ftok (name, 'G');
 6066 +  if (key == -1)
 6067 +    FAIL_EXIT1 ("ftok failed: %m");
 6068 +
 6069 +  semid = semget (key, 1, IPC_CREAT | IPC_EXCL | SEM_MODE);
 6070 +  if (semid == -1)
 6071 +    FAIL_EXIT1 ("semget failed: %m");
 6072 +
 6073 +  struct test_seminfo tipcinfo;
 6074 +  read_sem_stat (&tipcinfo);
 6075 +
 6076 +  int semidx;
 6077 +
 6078 +  {
 6079 +    struct seminfo ipcinfo;
 6080 +    semidx = semctl (semid, 0, IPC_INFO, (union semun) { .__buf = &ipcinfo });
 6081 +    if (semidx == -1)
 6082 +      FAIL_EXIT1 ("semctl with IPC_INFO failed: %m");
 6083 +
 6084 +    TEST_COMPARE (ipcinfo.semmsl, tipcinfo.semmsl);
 6085 +    TEST_COMPARE (ipcinfo.semmns, tipcinfo.semmns);
 6086 +    TEST_COMPARE (ipcinfo.semopm, tipcinfo.semopm);
 6087 +    TEST_COMPARE (ipcinfo.semmni, tipcinfo.semmni);
 6088 +  }
 6089 +
 6090 +  /* Same as before but with SEM_INFO.  */
 6091 +  {
 6092 +    struct seminfo ipcinfo;
 6093 +    semidx = semctl (semid, 0, SEM_INFO, (union semun) { .__buf = &ipcinfo });
 6094 +    if (semidx == -1)
 6095 +      FAIL_EXIT1 ("semctl with IPC_INFO failed: %m");
 6096 +
 6097 +    TEST_COMPARE (ipcinfo.semmsl, tipcinfo.semmsl);
 6098 +    TEST_COMPARE (ipcinfo.semmns, tipcinfo.semmns);
 6099 +    TEST_COMPARE (ipcinfo.semopm, tipcinfo.semopm);
 6100 +    TEST_COMPARE (ipcinfo.semmni, tipcinfo.semmni);
 6101 +  }
 6102 +
 6103 +  /* We check if the created semaphore shows in the system-wide status.  */
 6104 +  bool found = false;
 6105 +  for (int i = 0; i <= semidx; i++)
 6106 +    {
 6107 +      /* We can't tell apart if SEM_STAT_ANY is not supported (kernel older
 6108 +	 than 4.17) or if the index used is invalid.  So it just check if
 6109 +	 value returned from a valid call matches the created semaphore.  */
 6110 +      check_seminfo (i, key, SEM_STAT_ANY);
 6111 +
 6112 +      if (check_seminfo (i, key, SEM_STAT))
 6113 +	{
 6114 +	  found = true;
 6115 +	  break;
 6116 +	}
 6117 +    }
 6118 +
 6119 +  if (!found)
 6120 +    FAIL_EXIT1 ("semctl with SEM_STAT/SEM_STAT_ANY could not find the "
 6121 +		"created  semaphore");
 6122 +
 6123 +  if (semctl (semid, 0, IPC_RMID, 0) == -1)
 6124 +    FAIL_EXIT1 ("semctl failed: %m");
 6125 +
 6126 +  return 0;
 6127 +}
 6128 +
 6129 +#include <support/test-driver.c>
 6130 diff --git a/sysdeps/unix/sysv/linux/tst-sysvshm-linux.c b/sysdeps/unix/sysv/linux/tst-sysvshm-linux.c
 6131 new file mode 100644
 6132 index 0000000000..bb154592a6
 6133 --- /dev/null
 6134 +++ b/sysdeps/unix/sysv/linux/tst-sysvshm-linux.c
 6135 @@ -0,0 +1,188 @@
 6136 +/* Basic tests for Linux SYSV shared memory extensions.
 6137 +   Copyright (C) 2020 Free Software Foundation, Inc.
 6138 +   This file is part of the GNU C Library.
 6139 +
 6140 +   The GNU C Library is free software; you can redistribute it and/or
 6141 +   modify it under the terms of the GNU Lesser General Public
 6142 +   License as published by the Free Software Foundation; either
 6143 +   version 2.1 of the License, or (at your option) any later version.
 6144 +
 6145 +   The GNU C Library is distributed in the hope that it will be useful,
 6146 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
 6147 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 6148 +   Lesser General Public License for more details.
 6149 +
 6150 +   You should have received a copy of the GNU Lesser General Public
 6151 +   License along with the GNU C Library; if not, see
 6152 +   <https://www.gnu.org/licenses/>.  */
 6153 +
 6154 +#include <sys/ipc.h>
 6155 +#include <sys/shm.h>
 6156 +#include <errno.h>
 6157 +#include <stdlib.h>
 6158 +#include <stdbool.h>
 6159 +#include <stdio.h>
 6160 +#include <unistd.h>
 6161 +#include <inttypes.h>
 6162 +#include <limits.h>
 6163 +
 6164 +#include <support/check.h>
 6165 +#include <support/temp_file.h>
 6166 +
 6167 +#define SHM_MODE 0644
 6168 +
 6169 +/* These are for the temporary file we generate.  */
 6170 +static char *name;
 6171 +static int shmid;
 6172 +static long int pgsz;
 6173 +
 6174 +static void
 6175 +remove_shm (void)
 6176 +{
 6177 +  /* Enforce message queue removal in case of early test failure.
 6178 +     Ignore error since the shm may already have being removed.  */
 6179 +  shmctl (shmid, IPC_RMID, NULL);
 6180 +}
 6181 +
 6182 +static void
 6183 +do_prepare (int argc, char *argv[])
 6184 +{
 6185 +  TEST_VERIFY_EXIT (create_temp_file ("tst-sysvshm.", &name) != -1);
 6186 +}
 6187 +
 6188 +#define PREPARE do_prepare
 6189 +
 6190 +struct test_shminfo
 6191 +{
 6192 +  __syscall_ulong_t shmall;
 6193 +  __syscall_ulong_t shmmax;
 6194 +  __syscall_ulong_t shmmni;
 6195 +};
 6196 +
 6197 +/* It tries to obtain some system-wide SysV shared memory information from
 6198 +   /proc to check against IPC_INFO/SHM_INFO.  The /proc only returns the
 6199 +   tunables value of SHMALL, SHMMAX, and SHMMNI.  */
 6200 +
 6201 +static uint64_t
 6202 +read_proc_file (const char *file)
 6203 +{
 6204 +  FILE *f = fopen (file, "r");
 6205 +  if (f == NULL)
 6206 +    FAIL_UNSUPPORTED ("/proc is not mounted or %s is not available", file);
 6207 +
 6208 +  /* Handle 32-bit binaries running on 64-bit kernels.  */
 6209 +  uint64_t v;
 6210 +  int r = fscanf (f, "%" SCNu64, &v);
 6211 +  TEST_VERIFY_EXIT (r == 1);
 6212 +
 6213 +  fclose (f);
 6214 +  return v;
 6215 +}
 6216 +
 6217 +
 6218 +/* Check if the message queue with IDX (index into the kernel's internal
 6219 +   array) matches the one with KEY.  The CMD is either SHM_STAT or
 6220 +   SHM_STAT_ANY.  */
 6221 +
 6222 +static bool
 6223 +check_shminfo (int idx, key_t key, int cmd)
 6224 +{
 6225 +  struct shmid_ds shminfo;
 6226 +  int sid = shmctl (idx, cmd, &shminfo);
 6227 +  /* Ignore unused array slot returned by the kernel or information from
 6228 +     unknown message queue.  */
 6229 +  if ((sid == -1 && errno == EINVAL) || sid != shmid)
 6230 +    return false;
 6231 +
 6232 +  if (sid == -1)
 6233 +    FAIL_EXIT1 ("shmctl with %s failed: %m",
 6234 +		cmd == SHM_STAT ? "SHM_STAT" : "SHM_STAT_ANY");
 6235 +
 6236 +  TEST_COMPARE (shminfo.shm_perm.__key, key);
 6237 +  TEST_COMPARE (shminfo.shm_perm.mode, SHM_MODE);
 6238 +  TEST_COMPARE (shminfo.shm_segsz, pgsz);
 6239 +
 6240 +  return true;
 6241 +}
 6242 +
 6243 +static int
 6244 +do_test (void)
 6245 +{
 6246 +  atexit (remove_shm);
 6247 +
 6248 +  pgsz = sysconf (_SC_PAGESIZE);
 6249 +  if (pgsz == -1)
 6250 +    FAIL_EXIT1 ("sysconf (_SC_PAGESIZE) failed: %m");
 6251 +
 6252 +  key_t key = ftok (name, 'G');
 6253 +  if (key == -1)
 6254 +    FAIL_EXIT1 ("ftok failed: %m");
 6255 +
 6256 +  shmid = shmget (key, pgsz, IPC_CREAT | IPC_EXCL | SHM_MODE);
 6257 +  if (shmid == -1)
 6258 +    FAIL_EXIT1 ("shmget failed: %m");
 6259 +
 6260 +  /* It does not check shmmax because kernel clamp its value to INT_MAX for:
 6261 +
 6262 +     1. Compat symbols with IPC_64, i.e, 32-bit binaries running on 64-bit
 6263 +        kernels.
 6264 +
 6265 +     2. Default symbol without IPC_64 (defined as IPC_OLD within Linux) and
 6266 +        glibc always use IPC_64 for 32-bit ABIs (to support 64-bit time_t).
 6267 +        It means that 32-bit binaries running on 32-bit kernels will not see
 6268 +        shmmax being clamped.
 6269 +
 6270 +     And finding out whether the compat symbol is used would require checking
 6271 +     the underlying kernel against the current ABI.  The shmall and shmmni
 6272 +     already provided enough coverage.  */
 6273 +
 6274 +  struct test_shminfo tipcinfo;
 6275 +  tipcinfo.shmall = read_proc_file ("/proc/sys/kernel/shmall");
 6276 +  tipcinfo.shmmni = read_proc_file ("/proc/sys/kernel/shmmni");
 6277 +
 6278 +  int shmidx;
 6279 +
 6280 +  /* Note: SHM_INFO does not return a shminfo, but rather a 'struct shm_info'.
 6281 +     It is tricky to verify its values since the syscall returns system wide
 6282 +     resources consumed by shared memory.  The shmctl implementation handles
 6283 +     SHM_INFO as IPC_INFO, so the IPC_INFO test should validate SHM_INFO as
 6284 +     well.  */
 6285 +
 6286 +  {
 6287 +    struct shminfo ipcinfo;
 6288 +    shmidx = shmctl (shmid, IPC_INFO, (struct shmid_ds *) &ipcinfo);
 6289 +    if (shmidx == -1)
 6290 +      FAIL_EXIT1 ("shmctl with IPC_INFO failed: %m");
 6291 +
 6292 +    TEST_COMPARE (ipcinfo.shmall, tipcinfo.shmall);
 6293 +    TEST_COMPARE (ipcinfo.shmmni, tipcinfo.shmmni);
 6294 +  }
 6295 +
 6296 +  /* We check if the created shared memory shows in the global list.  */
 6297 +  bool found = false;
 6298 +  for (int i = 0; i <= shmidx; i++)
 6299 +    {
 6300 +      /* We can't tell apart if SHM_STAT_ANY is not supported (kernel older
 6301 +	 than 4.17) or if the index used is invalid.  So it just check if
 6302 +	 value returned from a valid call matches the created message
 6303 +	 queue.  */
 6304 +      check_shminfo (i, key, SHM_STAT_ANY);
 6305 +
 6306 +      if (check_shminfo (i, key, SHM_STAT))
 6307 +	{
 6308 +	  found = true;
 6309 +	  break;
 6310 +	}
 6311 +    }
 6312 +
 6313 +  if (!found)
 6314 +    FAIL_EXIT1 ("shmctl with SHM_STAT/SHM_STAT_ANY could not find the "
 6315 +		"created shared memory");
 6316 +
 6317 +  if (shmctl (shmid, IPC_RMID, NULL) == -1)
 6318 +    FAIL_EXIT1 ("shmctl failed");
 6319 +
 6320 +  return 0;
 6321 +}
 6322 +
 6323 +#include <support/test-driver.c>
 6324 diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
 6325 index a6736aef25..9736a13e7b 100644
 6326 --- a/sysdeps/x86/Makefile
 6327 +++ b/sysdeps/x86/Makefile
 6328 @@ -12,6 +12,12 @@ endif
 6329  ifeq ($(subdir),setjmp)
 6330  gen-as-const-headers += jmp_buf-ssp.sym
 6331  sysdep_routines += __longjmp_cancel
 6332 +ifneq ($(enable-cet),no)
 6333 +ifneq ($(have-tunables),no)
 6334 +tests += tst-setjmp-cet
 6335 +tst-setjmp-cet-ENV = GLIBC_TUNABLES=glibc.cpu.x86_ibt=on:glibc.cpu.x86_shstk=on
 6336 +endif
 6337 +endif
 6338  endif
 6339  
 6340  ifeq ($(subdir),string)
 6341 diff --git a/sysdeps/x86/cacheinfo.c b/sysdeps/x86/cacheinfo.c
 6342 index 217c21c34f..3fb4a028d8 100644
 6343 --- a/sysdeps/x86/cacheinfo.c
 6344 +++ b/sysdeps/x86/cacheinfo.c
 6345 @@ -808,7 +808,7 @@ init_cacheinfo (void)
 6346  	      threads = 1 << ((ecx >> 12) & 0x0f);
 6347  	    }
 6348  
 6349 -	  if (threads == 0)
 6350 +	  if (threads == 0 || cpu_features->basic.family >= 0x17)
 6351  	    {
 6352  	      /* If APIC ID width is not available, use logical
 6353  		 processor count.  */
 6354 @@ -823,8 +823,22 @@ init_cacheinfo (void)
 6355  	  if (threads > 0)
 6356  	    shared /= threads;
 6357  
 6358 -	  /* Account for exclusive L2 and L3 caches.  */
 6359 -	  shared += core;
 6360 +	  /* Get shared cache per ccx for Zen architectures.  */
 6361 +	  if (cpu_features->basic.family >= 0x17)
 6362 +	    {
 6363 +	      unsigned int eax;
 6364 +
 6365 +	      /* Get number of threads share the L3 cache in CCX.  */
 6366 +	      __cpuid_count (0x8000001D, 0x3, eax, ebx, ecx, edx);
 6367 +
 6368 +	      unsigned int threads_per_ccx = ((eax >> 14) & 0xfff) + 1;
 6369 +	      shared *= threads_per_ccx;
 6370 +	    }
 6371 +	  else
 6372 +	    {
 6373 +	      /* Account for exclusive L2 and L3 caches.  */
 6374 +	      shared += core;
 6375 +            }
 6376  	}
 6377      }
 6378  
 6379 @@ -854,14 +868,20 @@ init_cacheinfo (void)
 6380        __x86_shared_cache_size = shared;
 6381      }
 6382  
 6383 -  /* The large memcpy micro benchmark in glibc shows that 6 times of
 6384 -     shared cache size is the approximate value above which non-temporal
 6385 -     store becomes faster on a 8-core processor.  This is the 3/4 of the
 6386 -     total shared cache size.  */
 6387 +  /* The default setting for the non_temporal threshold is 3/4 of one
 6388 +     thread's share of the chip's cache. For most Intel and AMD processors
 6389 +     with an initial release date between 2017 and 2020, a thread's typical
 6390 +     share of the cache is from 500 KBytes to 2 MBytes. Using the 3/4
 6391 +     threshold leaves 125 KBytes to 500 KBytes of the thread's data
 6392 +     in cache after a maximum temporal copy, which will maintain
 6393 +     in cache a reasonable portion of the thread's stack and other
 6394 +     active data. If the threshold is set higher than one thread's
 6395 +     share of the cache, it has a substantial risk of negatively
 6396 +     impacting the performance of other threads running on the chip. */
 6397    __x86_shared_non_temporal_threshold
 6398      = (cpu_features->non_temporal_threshold != 0
 6399         ? cpu_features->non_temporal_threshold
 6400 -       : __x86_shared_cache_size * threads * 3 / 4);
 6401 +       : __x86_shared_cache_size * 3 / 4);
 6402  
 6403    /* NB: The REP MOVSB threshold must be greater than VEC_SIZE * 8.  */
 6404    unsigned int minimum_rep_movsb_threshold;
 6405 diff --git a/sysdeps/x86/dl-cet.c b/sysdeps/x86/dl-cet.c
 6406 index 03572f7af6..3cc54a8d53 100644
 6407 --- a/sysdeps/x86/dl-cet.c
 6408 +++ b/sysdeps/x86/dl-cet.c
 6409 @@ -47,7 +47,10 @@ dl_cet_check (struct link_map *m, const char *program)
 6410    /* No legacy object check if both IBT and SHSTK are always on.  */
 6411    if (enable_ibt_type == cet_always_on
 6412        && enable_shstk_type == cet_always_on)
 6413 -    return;
 6414 +    {
 6415 +      THREAD_SETMEM (THREAD_SELF, header.feature_1, GL(dl_x86_feature_1));
 6416 +      return;
 6417 +    }
 6418  
 6419    /* Check if IBT is enabled by kernel.  */
 6420    bool ibt_enabled
 6421 diff --git a/sysdeps/x86/dl-prop.h b/sysdeps/x86/dl-prop.h
 6422 index 89911e19e2..4eb3b85a7b 100644
 6423 --- a/sysdeps/x86/dl-prop.h
 6424 +++ b/sysdeps/x86/dl-prop.h
 6425 @@ -145,15 +145,15 @@ _dl_process_cet_property_note (struct link_map *l,
 6426  }
 6427  
 6428  static inline void __attribute__ ((unused))
 6429 -_dl_process_pt_note (struct link_map *l, const ElfW(Phdr) *ph)
 6430 +_dl_process_pt_note (struct link_map *l, int fd, const ElfW(Phdr) *ph)
 6431  {
 6432    const ElfW(Nhdr) *note = (const void *) (ph->p_vaddr + l->l_addr);
 6433    _dl_process_cet_property_note (l, note, ph->p_memsz, ph->p_align);
 6434  }
 6435  
 6436  static inline int __attribute__ ((always_inline))
 6437 -_dl_process_gnu_property (struct link_map *l, uint32_t type, uint32_t datasz,
 6438 -			  void *data)
 6439 +_dl_process_gnu_property (struct link_map *l, int fd, uint32_t type,
 6440 +			  uint32_t datasz, void *data)
 6441  {
 6442    return 0;
 6443  }
 6444 diff --git a/sysdeps/x86/tst-setjmp-cet.c b/sysdeps/x86/tst-setjmp-cet.c
 6445 new file mode 100644
 6446 index 0000000000..42c795d2a8
 6447 --- /dev/null
 6448 +++ b/sysdeps/x86/tst-setjmp-cet.c
 6449 @@ -0,0 +1 @@
 6450 +#include <setjmp/tst-setjmp.c>
 6451 diff --git a/sysdeps/x86_64/configure b/sysdeps/x86_64/configure
 6452 old mode 100644
 6453 new mode 100755
 6454 index 84f82c2406..fc1840e23f
 6455 --- a/sysdeps/x86_64/configure
 6456 +++ b/sysdeps/x86_64/configure
 6457 @@ -107,39 +107,6 @@ if test x"$build_mathvec" = xnotset; then
 6458    build_mathvec=yes
 6459  fi
 6460  
 6461 -if test "$static_pie" = yes; then
 6462 -  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for linker static PIE support" >&5
 6463 -$as_echo_n "checking for linker static PIE support... " >&6; }
 6464 -if ${libc_cv_ld_static_pie+:} false; then :
 6465 -  $as_echo_n "(cached) " >&6
 6466 -else
 6467 -  cat > conftest.s <<\EOF
 6468 -	.text
 6469 -	.global _start
 6470 -	.weak foo
 6471 -_start:
 6472 -	leaq	foo(%rip), %rax
 6473 -EOF
 6474 -  libc_cv_pie_option="-Wl,-pie"
 6475 -  if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -nostartfiles -nostdlib $no_ssp $libc_cv_pie_option -o conftest conftest.s 1>&5'
 6476 -  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
 6477 -  (eval $ac_try) 2>&5
 6478 -  ac_status=$?
 6479 -  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
 6480 -  test $ac_status = 0; }; }; then
 6481 -    libc_cv_ld_static_pie=yes
 6482 -  else
 6483 -    libc_cv_ld_static_pie=no
 6484 -  fi
 6485 -rm -f conftest*
 6486 -fi
 6487 -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_ld_static_pie" >&5
 6488 -$as_echo "$libc_cv_ld_static_pie" >&6; }
 6489 -  if test "$libc_cv_ld_static_pie" != yes; then
 6490 -    as_fn_error $? "linker support for static PIE needed" "$LINENO" 5
 6491 -  fi
 6492 -fi
 6493 -
 6494  $as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
 6495  
 6496  
 6497 diff --git a/sysdeps/x86_64/configure.ac b/sysdeps/x86_64/configure.ac
 6498 index cdaba0c075..611a7d9ba3 100644
 6499 --- a/sysdeps/x86_64/configure.ac
 6500 +++ b/sysdeps/x86_64/configure.ac
 6501 @@ -53,31 +53,6 @@ if test x"$build_mathvec" = xnotset; then
 6502    build_mathvec=yes
 6503  fi
 6504  
 6505 -dnl Check if linker supports static PIE with the fix for
 6506 -dnl
 6507 -dnl https://sourceware.org/bugzilla/show_bug.cgi?id=21782
 6508 -dnl
 6509 -if test "$static_pie" = yes; then
 6510 -  AC_CACHE_CHECK(for linker static PIE support, libc_cv_ld_static_pie, [dnl
 6511 -cat > conftest.s <<\EOF
 6512 -	.text
 6513 -	.global _start
 6514 -	.weak foo
 6515 -_start:
 6516 -	leaq	foo(%rip), %rax
 6517 -EOF
 6518 -  libc_cv_pie_option="-Wl,-pie"
 6519 -  if AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -nostartfiles -nostdlib $no_ssp $libc_cv_pie_option -o conftest conftest.s 1>&AS_MESSAGE_LOG_FD); then
 6520 -    libc_cv_ld_static_pie=yes
 6521 -  else
 6522 -    libc_cv_ld_static_pie=no
 6523 -  fi
 6524 -rm -f conftest*])
 6525 -  if test "$libc_cv_ld_static_pie" != yes; then
 6526 -    AC_MSG_ERROR([linker support for static PIE needed])
 6527 -  fi
 6528 -fi
 6529 -
 6530  dnl It is always possible to access static and hidden symbols in an
 6531  dnl position independent way.
 6532  AC_DEFINE(PI_STATIC_AND_HIDDEN)
 6533 diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h
 6534 index ca73d8fef9..363a749cb2 100644
 6535 --- a/sysdeps/x86_64/dl-machine.h
 6536 +++ b/sysdeps/x86_64/dl-machine.h
 6537 @@ -315,16 +315,22 @@ elf_machine_rela (struct link_map *map, const ElfW(Rela) *reloc,
 6538  	{
 6539  # ifndef RTLD_BOOTSTRAP
 6540  	  if (sym_map != map
 6541 -	      && sym_map->l_type != lt_executable
 6542  	      && !sym_map->l_relocated)
 6543  	    {
 6544  	      const char *strtab
 6545  		= (const char *) D_PTR (map, l_info[DT_STRTAB]);
 6546 -	      _dl_error_printf ("\
 6547 +	      if (sym_map->l_type == lt_executable)
 6548 +		_dl_fatal_printf ("\
 6549 +%s: IFUNC symbol '%s' referenced in '%s' is defined in the executable \
 6550 +and creates an unsatisfiable circular dependency.\n",
 6551 +				  RTLD_PROGNAME, strtab + refsym->st_name,
 6552 +				  map->l_name);
 6553 +	      else
 6554 +		_dl_error_printf ("\
 6555  %s: Relink `%s' with `%s' for IFUNC symbol `%s'\n",
 6556 -				RTLD_PROGNAME, map->l_name,
 6557 -				sym_map->l_name,
 6558 -				strtab + refsym->st_name);
 6559 +				  RTLD_PROGNAME, map->l_name,
 6560 +				  sym_map->l_name,
 6561 +				  strtab + refsym->st_name);
 6562  	    }
 6563  # endif
 6564  	  value = ((ElfW(Addr) (*) (void)) value) ();
 6565 diff --git a/sysdeps/x86_64/fpu/multiarch/ifunc-fma4.h b/sysdeps/x86_64/fpu/multiarch/ifunc-fma4.h
 6566 index 7659758972..e5fd5ac9cb 100644
 6567 --- a/sysdeps/x86_64/fpu/multiarch/ifunc-fma4.h
 6568 +++ b/sysdeps/x86_64/fpu/multiarch/ifunc-fma4.h
 6569 @@ -32,7 +32,7 @@ IFUNC_SELECTOR (void)
 6570        && CPU_FEATURE_USABLE_P (cpu_features, AVX2))
 6571      return OPTIMIZE (fma);
 6572  
 6573 -  if (CPU_FEATURE_USABLE_P (cpu_features, FMA))
 6574 +  if (CPU_FEATURE_USABLE_P (cpu_features, FMA4))
 6575      return OPTIMIZE (fma4);
 6576  
 6577    return OPTIMIZE (sse2);
 6578 diff --git a/sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S b/sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S
 6579 index bd5dc1a3f3..092f364bb6 100644
 6580 --- a/sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S
 6581 +++ b/sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S
 6582 @@ -56,6 +56,13 @@
 6583  # endif
 6584  #endif
 6585  
 6586 +/* Avoid short distance rep movsb only with non-SSE vector.  */
 6587 +#ifndef AVOID_SHORT_DISTANCE_REP_MOVSB
 6588 +# define AVOID_SHORT_DISTANCE_REP_MOVSB (VEC_SIZE > 16)
 6589 +#else
 6590 +# define AVOID_SHORT_DISTANCE_REP_MOVSB 0
 6591 +#endif
 6592 +
 6593  #ifndef PREFETCH
 6594  # define PREFETCH(addr) prefetcht0 addr
 6595  #endif
 6596 @@ -243,7 +250,21 @@ L(movsb):
 6597  	cmpq	%r9, %rdi
 6598  	/* Avoid slow backward REP MOVSB.  */
 6599  	jb	L(more_8x_vec_backward)
 6600 +# if AVOID_SHORT_DISTANCE_REP_MOVSB
 6601 +	movq	%rdi, %rcx
 6602 +	subq	%rsi, %rcx
 6603 +	jmp	2f
 6604 +# endif
 6605  1:
 6606 +# if AVOID_SHORT_DISTANCE_REP_MOVSB
 6607 +	movq	%rsi, %rcx
 6608 +	subq	%rdi, %rcx
 6609 +2:
 6610 +/* Avoid "rep movsb" if RCX, the distance between source and destination,
 6611 +   is N*4GB + [1..63] with N >= 0.  */
 6612 +	cmpl	$63, %ecx
 6613 +	jbe	L(more_2x_vec)	/* Avoid "rep movsb" if ECX <= 63.  */
 6614 +# endif
 6615  	mov	%RDX_LP, %RCX_LP
 6616  	rep movsb
 6617  L(nop):
 6618 diff --git a/sysvipc/test-sysvsem.c b/sysvipc/test-sysvsem.c
 6619 index 01dbff343a..b7284e0b48 100644
 6620 --- a/sysvipc/test-sysvsem.c
 6621 +++ b/sysvipc/test-sysvsem.c
 6622 @@ -20,6 +20,7 @@
 6623  #include <stdlib.h>
 6624  #include <errno.h>
 6625  #include <string.h>
 6626 +#include <stdbool.h>
 6627  #include <sys/types.h>
 6628  #include <sys/ipc.h>
 6629  #include <sys/sem.h>
 6630 diff --git a/version.h b/version.h
 6631 index 83cd196798..e6ca7a8857 100644
 6632 --- a/version.h
 6633 +++ b/version.h
 6634 @@ -1,4 +1,4 @@
 6635  /* This file just defines the current version number of libc.  */
 6636  
 6637 -#define RELEASE "release"
 6638 +#define RELEASE "stable"
 6639  #define VERSION "2.32"
 6640 diff -pruN glibc-2.32.orig/sysdeps/unix/sysv/linux/x86_64/64/configure glibc-2.32/sysdeps/unix/sysv/linux/x86_64/64/configure
 6641 --- glibc-2.32.orig/sysdeps/unix/sysv/linux/x86_64/64/configure	2021-09-18 21:02:32.741186019 +1000
 6642 +++ glibc-2.32/sysdeps/unix/sysv/linux/x86_64/64/configure	2021-09-18 21:03:05.314302356 +1000
 6643 @@ -4,10 +4,10 @@
 6644  test -n "$libc_cv_slibdir" ||
 6645  case "$prefix" in
 6646  /usr | /usr/)
 6647 -  libc_cv_slibdir='/lib64'
 6648 -  libc_cv_rtlddir='/lib64'
 6649 +  libc_cv_slibdir='/lib'
 6650 +  libc_cv_rtlddir='/lib'
 6651    if test "$libdir" = '${exec_prefix}/lib'; then
 6652 -    libdir='${exec_prefix}/lib64';
 6653 +    libdir='${exec_prefix}/lib';
 6654      # Locale data can be shared between 32-bit and 64-bit libraries.
 6655      libc_cv_complocaledir='${exec_prefix}/lib/locale'
 6656    fi
 6657 diff -pruN glibc-2.32.orig/sysdeps/unix/sysv/linux/x86_64/ldconfig.h glibc-2.32/sysdeps/unix/sysv/linux/x86_64/ldconfig.h
 6658 --- glibc-2.32.orig/sysdeps/unix/sysv/linux/x86_64/ldconfig.h	2021-09-18 21:02:32.742186053 +1000
 6659 +++ glibc-2.32/sysdeps/unix/sysv/linux/x86_64/ldconfig.h	2021-09-18 21:03:05.314302356 +1000
 6660 @@ -18,9 +18,9 @@
 6661  #include <sysdeps/generic/ldconfig.h>
 6662  
 6663  #define SYSDEP_KNOWN_INTERPRETER_NAMES \
 6664 -  { "/lib/ld-linux.so.2", FLAG_ELF_LIBC6 }, \
 6665 +  { "/lib32/ld-linux.so.2", FLAG_ELF_LIBC6 }, \
 6666    { "/libx32/ld-linux-x32.so.2", FLAG_ELF_LIBC6 }, \
 6667 -  { "/lib64/ld-linux-x86-64.so.2", FLAG_ELF_LIBC6 },
 6668 +  { "/lib/ld-linux-x86-64.so.2", FLAG_ELF_LIBC6 },
 6669  #define SYSDEP_KNOWN_LIBRARY_NAMES \
 6670    { "libc.so.6", FLAG_ELF_LIBC6 },	\
 6671    { "libm.so.6", FLAG_ELF_LIBC6 },

Generated by cgit