Internal change

PiperOrigin-RevId: 450838629
Change-Id: Ia23a963da2f4b5721fa54fc166b1e3527b576324
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/Makeconfig b/google3/third_party/grte/v5_src/glibc-2.27/Makeconfig
index c1a395a..fea770f 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/Makeconfig
+++ b/google3/third_party/grte/v5_src/glibc-2.27/Makeconfig
@@ -662,11 +662,10 @@
 +preinit = $(addprefix $(csu-objpfx),crti.o)
 +postinit = $(addprefix $(csu-objpfx),crtn.o)
 ifeq ($(with-clang),yes)
-# With clang, use the crt*.o files from llvm's compiler-rt package.
-# The files normally have an architecture name appended, in case of
-# variants (32/64, le/be etc) installed in the same directory.
-+prector = `$(CC) $(sysdep-LDFLAGS) --print-file-name=clang_rt.crtbegin-$(config-machine).o`
-+postctor = `$(CC) $(sysdep-LDFLAGS) --print-file-name=clang_rt.crtend-$(config-machine).o`
+# With clang, use the clang_rt.crt*.o files from the compiler-rt package
+# in a LLVM_ENABLE_RUNTIMES build.
++prector = `$(CC) $(sysdep-LDFLAGS) --print-file-name=clang_rt.crtbegin.o`
++postctor = `$(CC) $(sysdep-LDFLAGS) --print-file-name=clang_rt.crtend.o`
 else
 +prector = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbegin.o`
 +postctor = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtend.o`
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/Makerules b/google3/third_party/grte/v5_src/glibc-2.27/Makerules
index 1bffdcc..98611ca 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/Makerules
+++ b/google3/third_party/grte/v5_src/glibc-2.27/Makerules
@@ -1133,20 +1133,13 @@
 # for the configuration we are building.  We put this statement into
 # the linker scripts we install for -lc et al so that they will not be
 # used by a link for a different format on a multi-architecture system.
-$(common-objpfx)format.lds: $(..)scripts/output-format.sed \
-			    $(common-objpfx)config.make \
+$(common-objpfx)format.lds: $(common-objpfx)config.make \
 			    $(common-objpfx)config.h $(..)Makerules
-ifneq (unknown,$(output-format))
-	echo > $@.new 'OUTPUT_FORMAT($(output-format))'
-else
 	$(LINK.o) -shared $(sysdep-LDFLAGS) $(rtld-LDFLAGS) \
 		  $(LDFLAGS.so) $(LDFLAGS-lib.so) \
-		  -x c /dev/null -o $@.so -Wl,--verbose -v 2>&1 \
-	| sed -n -f $< > $@.new
-	test -s $@.new
+		  -x c /dev/null -o $@.so 2>/dev/null
+	$(OBJDUMP) -f $@.so | sed -n 's/.*file format \(.*\)/OUTPUT_FORMAT(\1)/;T;p' > $@
 	rm -f $@.so
-endif
-	mv -f $@.new $@
 common-generated += format.lds
 
 ifndef subdir
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/aclocal.m4 b/google3/third_party/grte/v5_src/glibc-2.27/aclocal.m4
index 08fa1ac..fb3eaad 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/aclocal.m4
+++ b/google3/third_party/grte/v5_src/glibc-2.27/aclocal.m4
@@ -223,20 +223,17 @@
 [AC_MSG_CHECKING([for linker that supports $1])
 libc_linker_feature=no
 if test x"$gnu_ld" = x"yes"; then
-  libc_linker_check=`$LD -v --help 2>/dev/null | grep "\$1"`
-  if test -n "$libc_linker_check"; then
-    cat > conftest.c <<EOF
+  cat > conftest.c <<EOF
 int _start (void) { return 42; }
 EOF
-    if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS $no_ssp
-				$2 -nostdlib -nostartfiles
-				-fPIC -shared -o conftest.so conftest.c
-				1>&AS_MESSAGE_LOG_FD])
-    then
-      libc_linker_feature=yes
-    fi
-    rm -f conftest*
+  if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS $no_ssp
+		    $2 -nostdlib -nostartfiles
+		    -fPIC -shared -o conftest.so conftest.c
+		    1>&AS_MESSAGE_LOG_FD])
+  then
+    libc_linker_feature=yes
   fi
+  rm -f conftest*
 fi
 if test $libc_linker_feature = yes; then
   $3
diff --git "a/google3/third_party/grte/v5_src/glibc-2.27/benchtests/strcoll-inputs/filelist\043en_US.UTF-8" "b/google3/third_party/grte/v5_src/glibc-2.27/benchtests/strcoll-inputs/filelist\043en_US.UTF-8"
index aa44107..cb981de 100644
--- "a/google3/third_party/grte/v5_src/glibc-2.27/benchtests/strcoll-inputs/filelist\043en_US.UTF-8"
+++ "b/google3/third_party/grte/v5_src/glibc-2.27/benchtests/strcoll-inputs/filelist\043en_US.UTF-8"
@@ -9450,7 +9450,6 @@
 check-execstack.awk
 pylint
 pylintrc
-output-format.sed
 merge-test-results.sh
 update-copyrights
 config-uname.sh
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/config.h.in b/google3/third_party/grte/v5_src/glibc-2.27/config.h.in
index 9d0f535..7385ddd 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/config.h.in
+++ b/google3/third_party/grte/v5_src/glibc-2.27/config.h.in
@@ -171,8 +171,8 @@
 /* Define if gcc supports attribute ifunc.  */
 #undef HAVE_GCC_IFUNC
 
-/* Define if the linker defines __ehdr_start.  */
-#undef HAVE_EHDR_START
+/* Define if CC supports attribute retain.  */
+#undef HAVE_GNU_RETAIN
 
 #define WANT_FLOAT128 0
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/config.make.in b/google3/third_party/grte/v5_src/glibc-2.27/config.make.in
index 58f56c3..d967eaa 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/config.make.in
+++ b/google3/third_party/grte/v5_src/glibc-2.27/config.make.in
@@ -72,7 +72,6 @@
 bind-now = @bindnow@
 have-hash-style = @libc_cv_hashstyle@
 use-default-link = @use_default_link@
-output-format = @libc_cv_output_format@
 have-cxx-thread_local = @libc_cv_cxx_thread_local@
 have-loop-to-function = @libc_cv_cc_loop_to_function@
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/configure b/google3/third_party/grte/v5_src/glibc-2.27/configure
index ccb8c29..447318e 100755
--- a/google3/third_party/grte/v5_src/glibc-2.27/configure
+++ b/google3/third_party/grte/v5_src/glibc-2.27/configure
@@ -623,7 +623,6 @@
 libc_cv_cc_nofma
 libc_cv_mtls_dialect_gnu2
 fno_unit_at_a_time
-libc_cv_output_format
 libc_cv_has_glob_dat
 libc_cv_hashstyle
 libc_cv_fpie
@@ -731,7 +730,6 @@
 docdir
 oldincludedir
 includedir
-runstatedir
 localstatedir
 sharedstatedir
 sysconfdir
@@ -845,7 +843,6 @@
 sysconfdir='${prefix}/etc'
 sharedstatedir='${prefix}/com'
 localstatedir='${prefix}/var'
-runstatedir='${localstatedir}/run'
 includedir='${prefix}/include'
 oldincludedir='/usr/include'
 docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
@@ -1098,15 +1095,6 @@
   | -silent | --silent | --silen | --sile | --sil)
     silent=yes ;;
 
-  -runstatedir | --runstatedir | --runstatedi | --runstated \
-  | --runstate | --runstat | --runsta | --runst | --runs \
-  | --run | --ru | --r)
-    ac_prev=runstatedir ;;
-  -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
-  | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
-  | --run=* | --ru=* | --r=*)
-    runstatedir=$ac_optarg ;;
-
   -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
     ac_prev=sbindir ;;
   -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
@@ -1244,7 +1232,7 @@
 for ac_var in	exec_prefix prefix bindir sbindir libexecdir datarootdir \
 		datadir sysconfdir sharedstatedir localstatedir includedir \
 		oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
-		libdir localedir mandir runstatedir
+		libdir localedir mandir
 do
   eval ac_val=\$$ac_var
   # Remove trailing slashes.
@@ -1397,7 +1385,6 @@
   --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
   --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
   --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
-  --runstatedir=DIR       modifiable per-process data [LOCALSTATEDIR/run]
   --libdir=DIR            object code libraries [EPREFIX/lib]
   --includedir=DIR        C header files [PREFIX/include]
   --oldincludedir=DIR     C header files for non-gcc [/usr/include]
@@ -4061,6 +4048,31 @@
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_gcc_indirect_function" >&5
 $as_echo "$libc_cv_gcc_indirect_function" >&6; }
 
+# Check if CC supports attribute retain as it is used in attribute_used_retain macro.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU attribute retain support" >&5
+$as_echo_n "checking for GNU attribute retain support... " >&6; }
+if ${libc_cv_gnu_retain+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat > conftest.c <<EOF
+static int var  __attribute__ ((used, retain, section ("__libc_atexit")));
+EOF
+libc_cv_gnu_retain=no
+if ${CC-cc} -Werror -c conftest.c -o /dev/null 1>&5 \
+   2>&5 ; then
+  libc_cv_gnu_retain=yes
+fi
+rm -f conftest*
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_gnu_retain" >&5
+$as_echo "$libc_cv_gnu_retain" >&6; }
+if test $libc_cv_gnu_retain = yes; then
+  $as_echo "#define HAVE_GNU_RETAIN 1" >>confdefs.h
+
+fi
+config_vars="$config_vars
+have-gnu-retain = $libc_cv_gnu_retain"
+
 # Check if gcc warns about alias for function with incompatible types.
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking if compiler warns about alias for function with incompatible types" >&5
 $as_echo_n "checking if compiler warns about alias for function with incompatible types... " >&6; }
@@ -5884,18 +5896,17 @@
 $as_echo "$libc_linker_feature" >&6; }
 
 
-if test "$with_lld" = no; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for linker that supports --no-dynamic-linker" >&5
-$as_echo_n "checking for linker that supports --no-dynamic-linker... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for linker that supports -z start-stop-gc" >&5
+$as_echo_n "checking for linker that supports -z start-stop-gc... " >&6; }
 libc_linker_feature=no
 if test x"$gnu_ld" = x"yes"; then
-  libc_linker_check=`$LD -v --help 2>/dev/null | grep "\--no-dynamic-linker"`
+  libc_linker_check=`$LD -v --help 2>/dev/null | grep "\-z start-stop-gc"`
   if test -n "$libc_linker_check"; then
     cat > conftest.c <<EOF
 int _start (void) { return 42; }
 EOF
     if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS $no_ssp
-				-Wl,--no-dynamic-linker -nostdlib -nostartfiles
+				-Wl,-z,start-stop-gc -nostdlib -nostartfiles
 				-fPIC -shared -o conftest.so conftest.c
 				1>&5'
   { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
@@ -5910,15 +5921,74 @@
   fi
 fi
 if test $libc_linker_feature = yes; then
+  libc_cv_z_start_stop_gc=yes
+else
+  libc_cv_z_start_stop_gc=no
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_linker_feature" >&5
+$as_echo "$libc_linker_feature" >&6; }
+config_vars="$config_vars
+have-z-start-stop-gc = $libc_cv_z_start_stop_gc"
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for linker that supports -z pack-relative-relocs" >&5
+$as_echo_n "checking for linker that supports -z pack-relative-relocs... " >&6; }
+libc_linker_feature=no
+if test x"$gnu_ld" = x"yes"; then
+  cat > conftest.c <<EOF
+int _start (void) { return 42; }
+EOF
+  if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS $no_ssp
+		    -Wl,-z,pack-relative-relocs -nostdlib -nostartfiles
+		    -fPIC -shared -o conftest.so conftest.c
+		    1>&5'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }
+  then
+    libc_linker_feature=yes
+  fi
+  rm -f conftest*
+fi
+if test $libc_linker_feature = yes; then
+  libc_cv_dt_relr=yes
+else
+  libc_cv_dt_relr=no
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_linker_feature" >&5
+$as_echo "$libc_linker_feature" >&6; }
+config_vars="$config_vars
+have-dt-relr = $libc_cv_dt_relr"
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for linker that supports --no-dynamic-linker" >&5
+$as_echo_n "checking for linker that supports --no-dynamic-linker... " >&6; }
+libc_linker_feature=no
+if test x"$gnu_ld" = x"yes"; then
+  cat > conftest.c <<EOF
+int _start (void) { return 42; }
+EOF
+  if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS $no_ssp
+		    -Wl,--no-dynamic-linker -nostdlib -nostartfiles
+		    -fPIC -shared -o conftest.so conftest.c
+		    1>&5'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }
+  then
+    libc_linker_feature=yes
+  fi
+  rm -f conftest*
+fi
+if test $libc_linker_feature = yes; then
   libc_cv_no_dynamic_linker=yes
 else
   libc_cv_no_dynamic_linker=no
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_linker_feature" >&5
 $as_echo "$libc_linker_feature" >&6; }
-else
-  libc_cv_no_dynamic_linker=yes
-fi
 config_vars="$config_vars
 have-no-dynamic-linker = $libc_cv_no_dynamic_linker"
 
@@ -6089,24 +6159,6 @@
 $as_echo "$libc_cv_has_glob_dat" >&6; }
 
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking linker output format" >&5
-$as_echo_n "checking linker output format... " >&6; }
-if ${libc_cv_output_format+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  if libc_cv_output_format=`
-${CC-cc} -nostartfiles -nostdlib $no_ssp -Wl,--print-output-format 2>&5`
-then
-  :
-else
-  libc_cv_output_format=
-fi
-test -n "$libc_cv_output_format" || libc_cv_output_format=unknown
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_output_format" >&5
-$as_echo "$libc_cv_output_format" >&6; }
-
-
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -fno-toplevel-reorder -fno-section-anchors" >&5
 $as_echo_n "checking for -fno-toplevel-reorder -fno-section-anchors... " >&6; }
 if ${libc_cv_fno_toplevel_reorder+:} false; then :
@@ -6573,58 +6625,6 @@
 fi
 
 
-# Some linkers on some architectures support __ehdr_start but with
-# bugs.  Make sure usage of it does not create relocations in the
-# output (as the linker should resolve them all for us).
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the linker provides working __ehdr_start" >&5
-$as_echo_n "checking whether the linker provides working __ehdr_start... " >&6; }
-if ${libc_cv_ehdr_start+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-
-old_CFLAGS="$CFLAGS"
-old_LDFLAGS="$LDFLAGS"
-old_LIBS="$LIBS"
-CFLAGS="$CFLAGS -fPIC"
-LDFLAGS="$LDFLAGS -nostdlib -nostartfiles -shared $no_ssp"
-LIBS=
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-typedef struct {
-  char foo;
-  long val;
-} Ehdr;
-extern const Ehdr __ehdr_start __attribute__ ((visibility ("hidden")));
-long ehdr (void) { return __ehdr_start.val; }
-
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  if $READELF -r conftest | grep -F __ehdr_start >/dev/null; then
-		  libc_cv_ehdr_start=broken
-		else
-		  libc_cv_ehdr_start=yes
-		fi
-else
-  libc_cv_ehdr_start=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-CFLAGS="$old_CFLAGS"
-LDFLAGS="$old_LDFLAGS"
-LIBS="$old_LIBS"
-
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_ehdr_start" >&5
-$as_echo "$libc_cv_ehdr_start" >&6; }
-if test "$libc_cv_ehdr_start" = yes; then
-  $as_echo "#define HAVE_EHDR_START 1" >>confdefs.h
-
-elif test "$libc_cv_ehdr_start" = broken; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: linker is broken -- you should upgrade" >&5
-$as_echo "$as_me: WARNING: linker is broken -- you should upgrade" >&2;}
-fi
-
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for __builtin_trap with no external dependencies" >&5
 $as_echo_n "checking for __builtin_trap with no external dependencies... " >&6; }
 if ${libc_cv_builtin_trap+:} false; then :
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/configure.ac b/google3/third_party/grte/v5_src/glibc-2.27/configure.ac
index f9f5003..b1a1530 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/configure.ac
+++ b/google3/third_party/grte/v5_src/glibc-2.27/configure.ac
@@ -670,6 +670,23 @@
 fi
 rm -f conftest*])
 
+# Check if CC supports attribute retain as it is used in attribute_used_retain macro.
+AC_CACHE_CHECK([for GNU attribute retain support],
+	       libc_cv_gnu_retain, [dnl
+cat > conftest.c <<EOF
+static int var  __attribute__ ((used, retain, section ("__libc_atexit")));
+EOF
+libc_cv_gnu_retain=no
+if ${CC-cc} -Werror -c conftest.c -o /dev/null 1>&AS_MESSAGE_LOG_FD \
+   2>&AS_MESSAGE_LOG_FD ; then
+  libc_cv_gnu_retain=yes
+fi
+rm -f conftest*])
+if test $libc_cv_gnu_retain = yes; then
+  AC_DEFINE(HAVE_GNU_RETAIN)
+fi
+LIBC_CONFIG_VAR([have-gnu-retain], [$libc_cv_gnu_retain])
+
 # Check if gcc warns about alias for function with incompatible types.
 AC_CACHE_CHECK([if compiler warns about alias for function with incompatible types],
 	       libc_cv_gcc_incompatible_alias, [dnl
@@ -1333,14 +1350,19 @@
 		    [libc_cv_z_execstack=yes], [libc_cv_z_execstack=no])
 AC_SUBST(libc_cv_z_execstack)
 
-if test "$with_lld" = no; then
-  LIBC_LINKER_FEATURE([--no-dynamic-linker],
-		      [-Wl,--no-dynamic-linker],
-		      [libc_cv_no_dynamic_linker=yes],
-		      [libc_cv_no_dynamic_linker=no])
-else
-  libc_cv_no_dynamic_linker=yes
-fi
+LIBC_LINKER_FEATURE([-z start-stop-gc], [-Wl,-z,start-stop-gc],
+		    [libc_cv_z_start_stop_gc=yes], [libc_cv_z_start_stop_gc=no])
+LIBC_CONFIG_VAR([have-z-start-stop-gc], [$libc_cv_z_start_stop_gc])
+
+LIBC_LINKER_FEATURE([-z pack-relative-relocs],
+		    [-Wl,-z,pack-relative-relocs],
+		    [libc_cv_dt_relr=yes], [libc_cv_dt_relr=no])
+LIBC_CONFIG_VAR([have-dt-relr], [$libc_cv_dt_relr])
+
+LIBC_LINKER_FEATURE([--no-dynamic-linker],
+		    [-Wl,--no-dynamic-linker],
+		    [libc_cv_no_dynamic_linker=yes],
+		    [libc_cv_no_dynamic_linker=no])
 LIBC_CONFIG_VAR([have-no-dynamic-linker], [$libc_cv_no_dynamic_linker])
 
 AC_CACHE_CHECK(for -static-pie, libc_cv_static_pie, [dnl
@@ -1448,17 +1470,6 @@
 rm -f conftest*])
 AC_SUBST(libc_cv_has_glob_dat)
 
-AC_CACHE_CHECK(linker output format, libc_cv_output_format, [dnl
-if libc_cv_output_format=`
-${CC-cc} -nostartfiles -nostdlib $no_ssp -Wl,--print-output-format 2>&AS_MESSAGE_LOG_FD`
-then
-  :
-else
-  libc_cv_output_format=
-fi
-test -n "$libc_cv_output_format" || libc_cv_output_format=unknown])
-AC_SUBST(libc_cv_output_format)
-
 AC_CACHE_CHECK(for -fno-toplevel-reorder -fno-section-anchors, libc_cv_fno_toplevel_reorder, [dnl
 cat > conftest.c <<EOF
 int foo;
@@ -1669,40 +1680,6 @@
 fi
 AC_SUBST(CPPUNDEFS)
 
-# Some linkers on some architectures support __ehdr_start but with
-# bugs.  Make sure usage of it does not create relocations in the
-# output (as the linker should resolve them all for us).
-AC_CACHE_CHECK([whether the linker provides working __ehdr_start],
-	       libc_cv_ehdr_start, [
-old_CFLAGS="$CFLAGS"
-old_LDFLAGS="$LDFLAGS"
-old_LIBS="$LIBS"
-CFLAGS="$CFLAGS -fPIC"
-LDFLAGS="$LDFLAGS -nostdlib -nostartfiles -shared $no_ssp"
-LIBS=
-AC_LINK_IFELSE([AC_LANG_SOURCE([
-typedef struct {
-  char foo;
-  long val;
-} Ehdr;
-extern const Ehdr __ehdr_start __attribute__ ((visibility ("hidden")));
-long ehdr (void) { return __ehdr_start.val; }
-])],
-	       [if $READELF -r conftest | grep -F __ehdr_start >/dev/null; then
-		  libc_cv_ehdr_start=broken
-		else
-		  libc_cv_ehdr_start=yes
-		fi], [libc_cv_ehdr_start=no])
-CFLAGS="$old_CFLAGS"
-LDFLAGS="$old_LDFLAGS"
-LIBS="$old_LIBS"
-])
-if test "$libc_cv_ehdr_start" = yes; then
-  AC_DEFINE([HAVE_EHDR_START])
-elif test "$libc_cv_ehdr_start" = broken; then
-  AC_MSG_WARN([linker is broken -- you should upgrade])
-fi
-
 AC_CACHE_CHECK(for __builtin_trap with no external dependencies,
 	       libc_cv_builtin_trap, [dnl
 libc_cv_builtin_trap=no
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/csu/check_fds.c b/google3/third_party/grte/v5_src/glibc-2.27/csu/check_fds.c
index abcdfc0..2b181d4 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/csu/check_fds.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/csu/check_fds.c
@@ -50,12 +50,12 @@
       if ((mode & O_ACCMODE) == O_WRONLY)
 	{
 	  name = _PATH_DEV "full";
-	  dev = makedev (DEV_FULL_MAJOR, DEV_FULL_MINOR);
+	  dev = __gnu_dev_makedev (DEV_FULL_MAJOR, DEV_FULL_MINOR);
 	}
       else
 	{
 	  name = _PATH_DEVNULL;
-	  dev = makedev (DEV_NULL_MAJOR, DEV_NULL_MINOR);
+	  dev = __gnu_dev_makedev (DEV_NULL_MAJOR, DEV_NULL_MINOR);
 	}
 
       /* Something is wrong with this descriptor, it's probably not
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/csu/libc-start.c b/google3/third_party/grte/v5_src/glibc-2.27/csu/libc-start.c
index 2dee3f2..605222f 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/csu/libc-start.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/csu/libc-start.c
@@ -141,7 +141,7 @@
   __libc_multiple_libcs = &_dl_starting_up && !_dl_starting_up;
 
 #ifndef SHARED
-  int irel_applied = _dl_relocate_static_pie ();
+  _dl_relocate_static_pie ();
 
   char **ev = &argv[argc + 1];
 
@@ -191,8 +191,7 @@
   ARCH_INIT_CPU_FEATURES ();
 
   /* Perform IREL{,A} relocations.  */
-  if (!irel_applied)
-    ARCH_SETUP_IREL ();
+  ARCH_SETUP_IREL ();
 
   /* The stack guard goes into the TCB, so initialize it early.  */
   __libc_setup_tls ();
@@ -200,8 +199,7 @@
   /* In some architectures, IREL{,A} relocations happen after TLS setup in
      order to let IFUNC resolvers benefit from TCB information, e.g. powerpc's
      hwcap and platform fields available in the TCB.  */
-  if (!irel_applied)
-    ARCH_APPLY_IREL ();
+  ARCH_APPLY_IREL ();
 
   /* Set up the stack checker's canary.  */
   uintptr_t stack_chk_guard = _dl_setup_stack_chk_guard (_dl_random);
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/csu/static-reloc.c b/google3/third_party/grte/v5_src/glibc-2.27/csu/static-reloc.c
index 05ecc37..70729fb 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/csu/static-reloc.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/csu/static-reloc.c
@@ -19,9 +19,8 @@
 #if ENABLE_STATIC_PIE
 #include <ldsodefs.h>
 
-int
+void
 _dl_relocate_static_pie (void)
 {
-  return 0;
 }
 #endif
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/ctype/ctype.c b/google3/third_party/grte/v5_src/glibc-2.27/ctype/ctype.c
index e86c5b0..6cb8000 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/ctype/ctype.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/ctype/ctype.c
@@ -45,9 +45,11 @@
 {
   return c >= -128 && c < 256 ? __ctype_tolower[c] : c;
 }
+libc_hidden_def (tolower)
 
 int
 toupper (int c)
 {
   return c >= -128 && c < 256 ? __ctype_toupper[c] : c;
 }
+libc_hidden_def (toupper)
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/elf/Makefile b/google3/third_party/grte/v5_src/glibc-2.27/elf/Makefile
index 6b2a347..7b44740 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/elf/Makefile
+++ b/google3/third_party/grte/v5_src/glibc-2.27/elf/Makefile
@@ -65,9 +65,6 @@
 # Hack around a clang alias+optimization problem.
 CFLAGS-rtld.c += -O0
 
-# elf_get_dynamic_info reads _dl_debug_mask before relocations are applied. Work around with R_X86_64_REX_GOTPCRELX.
-CFLAGS-dl-reloc-static-pie.c += -Wa,-mrelax-relocations=yes
-
 CFLAGS-dl-runtime.c += -fexceptions -fasynchronous-unwind-tables
 CFLAGS-dl-lookup.c += -fexceptions -fasynchronous-unwind-tables
 CFLAGS-dl-iterate-phdr.c += $(uses-callbacks)
@@ -155,7 +152,7 @@
 	       tst-dl-iter-static \
 	       tst-tlsalign-static tst-tlsalign-extern-static \
 	       tst-linkall-static tst-env-setuid tst-env-setuid-tunables
-tests-static-internal := tst-tls1-static tst-tls2-static \
+tests-static-internal := tst-tls1-static \
 	       tst-ptrguard1-static tst-stackguard1-static \
 	       tst-tls1-static-non-pie tst-libc_dlvsym-static
 
@@ -165,7 +162,7 @@
 tests := tst-tls9 tst-leaks1 \
 	tst-array1 tst-array2 tst-array3 tst-array4 tst-array5 \
 	tst-auxv
-tests-internal := tst-tls1 tst-tls2 $(tests-static-internal)
+tests-internal := tst-tls1 $(tests-static-internal)
 tests-static := $(tests-static-normal) $(tests-static-internal)
 
 ifeq (yes,$(build-shared))
@@ -212,6 +209,44 @@
 endif
 endif
 endif
+ifeq ($(have-dt-relr),yes)
+tests += \
+  tst-relr \
+  tst-relr2 \
+  tst-relr3 \
+  tst-relr4 \
+# tests
+modules-names-dt-relr = \
+  tst-relr-mod2 \
+  tst-relr-mod3a \
+  tst-relr-mod3b \
+  tst-relr-mod4a \
+  tst-relr-mod4b \
+# modules-names-dt-relr
+modules-names += $(modules-names-dt-relr)
+# These shared libraries have special build rules.
+modules-names-nobuild += $(modules-names-dt-relr)
+ifeq ($(have-fpie),yes)
+tests += \
+  tst-relr-pie \
+# tests
+tests-pie += \
+  tst-relr-pie \
+# tests-pie
+tests-special += \
+  $(objpfx)check-tst-relr-pie.out \
+# tests-special
+endif
+CFLAGS-tst-relr-pie.c += $(pie-ccflag)
+LDFLAGS-tst-relr += -Wl,-z,pack-relative-relocs
+LDFLAGS-tst-relr-pie += -Wl,-z,pack-relative-relocs
+LDFLAGS-tst-relr2 += -Wl,--allow-shlib-undefined
+CFLAGS-tst-relr-mod2.c += $(no-stack-protector)
+CFLAGS-tst-relr-mod3a.c += $(no-stack-protector)
+CFLAGS-tst-relr-mod3b.c += $(no-stack-protector)
+CFLAGS-tst-relr-mod4a.c += $(no-stack-protector)
+CFLAGS-tst-relr-mod4b.c += $(no-stack-protector)
+endif
 ifeq ($(run-built-tests),yes)
 tests-special += $(objpfx)tst-leaks1-mem.out \
 		 $(objpfx)tst-leaks1-static-mem.out $(objpfx)noload-mem.out \
@@ -655,7 +690,7 @@
 $(objpfx)unload6mod3.so: $(libdl)
 $(objpfx)unload7mod1.so: $(libdl)
 $(objpfx)unload7mod2.so: $(objpfx)unload7mod1.so
-$(objpfx)unload8mod1.so: $(objpfx)unload8mod2.so
+$(objpfx)unload8mod1.so: $(objpfx)unload8mod2.so $(libdl)
 $(objpfx)unload8mod2.so: $(objpfx)unload8mod3.so
 $(objpfx)unload8mod3.so: $(libdl)
 $(objpfx)tst-initordera2.so: $(objpfx)tst-initordera1.so
@@ -1485,3 +1520,56 @@
 	dd if=$(objpfx)tst-dlopen-offset-mod3.so of=$(objpfx)tst-dlopen-offset-comb.so bs=1024 seek=192
 
 $(objpfx)tst-big-note: $(objpfx)tst-big-note-lib.so
+
+$(objpfx)check-tst-relr-pie.out: $(objpfx)tst-relr-pie
+	LC_ALL=C $(OBJDUMP) -p $< \
+		| sed -ne '/required from libc.so/,$$ p' \
+		| grep GLIBC_ABI_DT_RELR > $@; \
+	$(evaluate-test)
+
+# The test checks if a DT_RELR shared library without DT_NEEDED works as
+# intended, so it uses an explicit link rule.
+$(objpfx)tst-relr2: $(objpfx)tst-relr-mod2.so
+$(objpfx)tst-relr-mod2.so: $(objpfx)tst-relr-mod2.os
+	$(LINK.o) -nostdlib -nostartfiles -Wl,-z,pack-relative-relocs \
+	$(LDFLAGS-soname-fname) \
+	-shared -o $@.new $(filter-out $(map-file),$^)
+	$(call after-link,$@.new)
+	mv -f $@.new $@
+
+# The test checks if a DT_RELR shared library without DT_VERNEED works as
+# intended, so it uses an explicit link rule.
+$(objpfx)tst-relr3: $(objpfx)tst-relr-mod3a.so
+$(objpfx)tst-relr-mod3b.so: $(objpfx)tst-relr-mod3b.os
+	$(LINK.o) -nostdlib -nostartfiles -Wl,-z,pack-relative-relocs \
+	$(LDFLAGS-soname-fname) \
+	-shared -o $@.new $(filter-out $(map-file),$^)
+	$(call after-link,$@.new)
+	mv -f $@.new $@
+
+$(objpfx)tst-relr-mod3a.so: $(objpfx)tst-relr-mod3a.os \
+  $(objpfx)tst-relr-mod3b.so
+	$(LINK.o) -nostdlib -nostartfiles -Wl,-z,pack-relative-relocs \
+	$(LDFLAGS-soname-fname) \
+	-shared -o $@.new $(filter-out $(map-file),$^)
+	$(call after-link,$@.new)
+	mv -f $@.new $@
+
+# The test checks if a DT_RELR shared library without libc.so on DT_NEEDED
+# works as intended, so it uses an explicit link rule.
+$(objpfx)tst-relr4: $(objpfx)tst-relr-mod4a.so
+$(objpfx)tst-relr-mod4b.so: $(objpfx)tst-relr-mod4b.os
+	$(LINK.o) -nostdlib -nostartfiles -Wl,-z,pack-relative-relocs \
+	$(LDFLAGS-soname-fname) \
+	-Wl,--version-script=tst-relr-mod4b.map \
+	-shared -o $@.new $(filter-out $(map-file),$^)
+	$(call after-link,$@.new)
+	mv -f $@.new $@
+
+$(objpfx)tst-relr-mod4a.so: $(objpfx)tst-relr-mod4a.os \
+  $(objpfx)tst-relr-mod4b.so
+	$(LINK.o) -nostdlib -nostartfiles -Wl,-z,pack-relative-relocs \
+	$(LDFLAGS-soname-fname) \
+	-shared -o $@.new $(filter-out $(map-file),$^)
+	$(call after-link,$@.new)
+	mv -f $@.new $@
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/elf/Versions b/google3/third_party/grte/v5_src/glibc-2.27/elf/Versions
index 05eba2a..7fa8f67 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/elf/Versions
+++ b/google3/third_party/grte/v5_src/glibc-2.27/elf/Versions
@@ -20,6 +20,11 @@
     __register_frame_info_table_bases; _Unwind_Find_FDE;
   }
 %endif
+  GLIBC_ABI_DT_RELR {
+    # This symbol is used only for empty version map and will be removed
+    # by scripts/versions.awk.
+    __placeholder_only_for_empty_version_map;
+  }
   GLIBC_PRIVATE {
     # functions used in other libraries
     _dl_addr;
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/elf/dl-load.c b/google3/third_party/grte/v5_src/glibc-2.27/elf/dl-load.c
index 1ae72aa..957f1b9 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/elf/dl-load.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/elf/dl-load.c
@@ -877,6 +877,7 @@
   *p = n;
 }
 
+/* 'name' must be the exact pointer originally passed to lib_hash_addname(). */
 static void
 lib_hash_delname (const char *name, struct link_map *lib)
 {
@@ -885,8 +886,7 @@
   while (*p)
     {
       struct lib_hash_namenode *n = *p;
-      if (n->hash == hash && n->lib == lib &&
-          (n->name == name || !strcmp (n->name, name))) {
+      if (n->hash == hash && n->lib == lib && n->name == name) {
         *p = n->next;
         free (n);
         return;
@@ -1018,16 +1018,7 @@
          Just bump its reference count and return it.  */
       __close (fd);
 
-      /* If the name is not in the list of names for this object add
-         it.  */
       free (realname);
-      if (offset == 0)
-        {
-          /* If offset!=0, foo.so/@0x<offset> should be the *only*
-             name for this object. b/20141439.  */
-          add_name_to_object (l, name);
-          lib_hash_addname (name, l);
-        }
 
       return l;
     }
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/elf/dl-reloc-static-pie.c b/google3/third_party/grte/v5_src/glibc-2.27/elf/dl-reloc-static-pie.c
index 1f6c824..42d1529 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/elf/dl-reloc-static-pie.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/elf/dl-reloc-static-pie.c
@@ -19,7 +19,6 @@
 #if ENABLE_STATIC_PIE
 #include <unistd.h>
 #include <ldsodefs.h>
-#include "dynamic-link.h"
 
 #ifndef NESTING
 # define STATIC_PIE_BOOTSTRAP
@@ -30,7 +29,7 @@
 
 /* Relocate static executable with PIE.  */
 
-int
+void
 _dl_relocate_static_pie (void)
 {
   struct link_map *main_map = _dl_get_dl_main_map ();
@@ -61,7 +60,5 @@
 #endif
                         );
   main_map->l_relocated = 1;
-
-  return 1;
 }
 #endif
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/elf/dynamic-link.h b/google3/third_party/grte/v5_src/glibc-2.27/elf/dynamic-link.h
index f576d78..e9d7fac 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/elf/dynamic-link.h
+++ b/google3/third_party/grte/v5_src/glibc-2.27/elf/dynamic-link.h
@@ -128,7 +128,9 @@
 	     __typeof (((ElfW(Dyn) *) 0)->d_un.d_val) nrelative; int lazy; }  \
       ranges[2] = { { 0, 0, 0, 0 }, { 0, 0, 0, 0 } };			      \
 									      \
-    if ((map)->l_info[DT_##RELOC])					      \
+    /* With DT_RELR, DT_RELA/DT_REL can have zero value.  */		      \
+    if ((map)->l_info[DT_##RELOC] != NULL				      \
+	&& (map)->l_info[DT_##RELOC]->d_un.d_ptr != 0)			      \
       {									      \
 	ranges[0].start = D_PTR ((map), l_info[DT_##RELOC]);		      \
 	ranges[0].size = (map)->l_info[DT_##RELOC##SZ]->d_un.d_val;	      \
@@ -142,6 +144,8 @@
 	ElfW(Addr) start = D_PTR ((map), l_info[DT_JMPREL]);		      \
 	ElfW(Addr) size = (map)->l_info[DT_PLTRELSZ]->d_un.d_val;	      \
 									      \
+	if (ranges[0].start == 0)					      \
+	  ranges[0].start = start;					      \
 	if (ranges[0].start + ranges[0].size == (start + size))		      \
 	  ranges[0].size -= size;					      \
 	if (ELF_DURING_STARTUP						      \
@@ -253,12 +257,48 @@
 #  define ELF_DYNAMIC_DO_RELA(map, lazy, skip_ifunc, boot_map) /* Nothing to do.  */
 # endif
 
+/* Google-local: b/208156916.  To not bump DT_NUM, use DT_VERSYM+1 for DT_RELR
+   and DT_VERSYM+2 for DT_RELRSZ.  */
+# define ELF_DYNAMIC_DO_RELR(map)					      \
+  do {									      \
+    ElfW(Addr) l_addr = (map)->l_addr, *where = 0;			      \
+    const ElfW(Relr) *r, *end;						      \
+    if (!(map)->l_info[VERSYMIDX (DT_VERSYM + 1)])			      \
+      break;								      \
+    r = (const ElfW(Relr) *)D_PTR((map), l_info[VERSYMIDX (DT_VERSYM + 1)]);  \
+    end = (const ElfW(Relr) *)((const char *)r +			      \
+                               (map)->l_info[VERSYMIDX (DT_VERSYM + 2)]->d_un.d_val); \
+    for (; r < end; r++)						      \
+      {									      \
+	ElfW(Relr) entry = *r;						      \
+	if ((entry & 1) == 0)						      \
+	  {								      \
+	    where = (ElfW(Addr) *)(l_addr + entry);			      \
+	    *where++ += l_addr;						      \
+	  }								      \
+	else 								      \
+	  {								      \
+	    for (long i = 0; (entry >>= 1) != 0; i++)			      \
+	      if ((entry & 1) != 0)					      \
+		where[i] += l_addr;					      \
+	    where += CHAR_BIT * sizeof(ElfW(Relr)) - 1;			      \
+	  }								      \
+      }									      \
+  } while (0);
+
 /* This can't just be an inline function because GCC is too dumb
    to inline functions containing inlines themselves.  */
+# ifdef RTLD_BOOTSTRAP
+#  define DO_RTLD_BOOTSTRAP 1
+# else
+#  define DO_RTLD_BOOTSTRAP 0
+# endif
 # define ELF_DYNAMIC_RELOCATE(map, lazy, consider_profile, skip_ifunc, boot_map) \
   do {									      \
     int edr_lazy = elf_machine_runtime_setup ((map), (lazy),		      \
 					      (consider_profile));	      \
+    if (((map) != &GL(dl_rtld_map) || DO_RTLD_BOOTSTRAP))		      \
+      ELF_DYNAMIC_DO_RELR (map);					      \
     ELF_DYNAMIC_DO_REL ((map), edr_lazy, skip_ifunc, boot_map);			\
     ELF_DYNAMIC_DO_RELA ((map), edr_lazy, skip_ifunc, boot_map);			\
   } while (0)
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/elf/elf.h b/google3/third_party/grte/v5_src/glibc-2.27/elf/elf.h
index 954f326..35ff17c 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/elf/elf.h
+++ b/google3/third_party/grte/v5_src/glibc-2.27/elf/elf.h
@@ -444,8 +444,9 @@
 #define SHT_FINI_ARRAY	  15		/* Array of destructors */
 #define SHT_PREINIT_ARRAY 16		/* Array of pre-constructors */
 #define SHT_GROUP	  17		/* Section group */
-#define SHT_SYMTAB_SHNDX  18		/* Extended section indeces */
-#define	SHT_NUM		  19		/* Number of defined types.  */
+#define SHT_SYMTAB_SHNDX  18		/* Extended section indices */
+#define SHT_RELR	  19            /* RELR relative relocations */
+#define	SHT_NUM		  20		/* Number of defined types.  */
 #define SHT_LOOS	  0x60000000	/* Start OS-specific.  */
 #define SHT_GNU_ATTRIBUTES 0x6ffffff5	/* Object attributes.  */
 #define SHT_GNU_HASH	  0x6ffffff6	/* GNU-style hash table.  */
@@ -663,6 +664,11 @@
   Elf64_Sxword	r_addend;		/* Addend */
 } Elf64_Rela;
 
+/* RELR relocation table entry */
+
+typedef Elf32_Word	Elf32_Relr;
+typedef Elf64_Xword	Elf64_Relr;
+
 /* How to extract and insert information held in the r_info field.  */
 
 #define ELF32_R_SYM(val)		((val) >> 8)
@@ -861,6 +867,11 @@
 #define DT_ENCODING	32		/* Start of encoded range */
 #define DT_PREINIT_ARRAY 32		/* Array with addresses of preinit fct*/
 #define DT_PREINIT_ARRAYSZ 33		/* size in bytes of DT_PREINIT_ARRAY */
+#define DT_SYMTAB_SHNDX	34		/* Address of SYMTAB_SHNDX section */
+#define DT_RELRSZ	35		/* Total size of RELR relative relocations */
+#define DT_RELR		36		/* Address of RELR relative relocations */
+#define DT_RELRENT	37		/* Size of one RELR relative relocaction */
+/* Google-local: b/208156916.  Don't bump DT_NUM.  */
 #define	DT_NUM		34		/* Number used */
 #define DT_LOOS		0x6000000d	/* Start of OS-specific */
 #define DT_HIOS		0x6ffff000	/* End of OS-specific */
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/elf/get-dynamic-info.h b/google3/third_party/grte/v5_src/glibc-2.27/elf/get-dynamic-info.h
index f9c5b84..02ba549 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/elf/get-dynamic-info.h
+++ b/google3/third_party/grte/v5_src/glibc-2.27/elf/get-dynamic-info.h
@@ -49,7 +49,12 @@
 
   while (dyn->d_tag != DT_NULL)
     {
-      if ((d_tag_utype) dyn->d_tag < DT_NUM)
+      /* Google-local: b/208156916.  See ELF_DYNAMIC_DO_RELR.  */
+      if (dyn->d_tag == DT_RELR)
+	info[VERSYMIDX (DT_VERSYM + 1)] = dyn;
+      else if (dyn->d_tag == DT_RELRSZ)
+	info[VERSYMIDX (DT_VERSYM + 2)] = dyn;
+      else if ((d_tag_utype) dyn->d_tag < DT_NUM)
 	info[dyn->d_tag] = dyn;
       else if (dyn->d_tag >= DT_LOPROC &&
 	       dyn->d_tag < DT_LOPROC + DT_THISPROCNUM)
@@ -104,16 +109,27 @@
       ADJUST_DYN_INFO (DT_PLTGOT);
       ADJUST_DYN_INFO (DT_STRTAB);
       ADJUST_DYN_INFO (DT_SYMTAB);
+      ADJUST_DYN_INFO (VERSYMIDX (DT_VERSYM + 1)); /* DT_RELR */
+      ADJUST_DYN_INFO (DT_JMPREL);
+      ADJUST_DYN_INFO (VERSYMIDX (DT_VERSYM));
+      ADJUST_DYN_INFO (DT_ADDRTAGIDX (DT_GNU_HASH) + DT_NUM + DT_THISPROCNUM
+		       + DT_VERSIONTAGNUM + DT_EXTRANUM + DT_VALNUM);
+# undef ADJUST_DYN_INFO
+
+      /* DT_RELA/DT_REL are mandatory.  But they may have zero value if
+	 there is DT_RELR.  Don't relocate them if they are zero.  */
+# define ADJUST_DYN_INFO(tag) \
+      do								      \
+	if (info[tag] != NULL && info[tag]->d_un.d_ptr != 0)		      \
+         info[tag]->d_un.d_ptr += l_addr;				      \
+      while (0)
+
 # if ! ELF_MACHINE_NO_RELA
       ADJUST_DYN_INFO (DT_RELA);
 # endif
 # if ! ELF_MACHINE_NO_REL
       ADJUST_DYN_INFO (DT_REL);
 # endif
-      ADJUST_DYN_INFO (DT_JMPREL);
-      ADJUST_DYN_INFO (VERSYMIDX (DT_VERSYM));
-      ADJUST_DYN_INFO (DT_ADDRTAGIDX (DT_GNU_HASH) + DT_NUM + DT_THISPROCNUM
-		       + DT_VERSIONTAGNUM + DT_EXTRANUM + DT_VALNUM);
 # undef ADJUST_DYN_INFO
       assert (cnt <= DL_RO_DYN_TEMP_CNT);
     }
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/elf/rtld.c b/google3/third_party/grte/v5_src/glibc-2.27/elf/rtld.c
index 9d951f2..3b60b49 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/elf/rtld.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/elf/rtld.c
@@ -519,16 +519,6 @@
 
   /* Read our own dynamic section and fill in the info array.  */
   bootstrap_map.l_ld = (void *) bootstrap_map.l_addr + elf_machine_dynamic ();
-  /* As a workaround for lld placing _GLOBAL_OFFSET_TABLE at an
-     unexpected location, detect when the bootstrap map base and
-     dynamic section have the same address, and patch the base value
-     back to something plausible.  This is probably x86_64-specific,
-     and should go away once lld does the right thing.  */
-#ifdef HAVE_EHDR_START
-  extern const ElfW(Ehdr) __ehdr_start __attribute__ ((visibility ("hidden")));
-  if (bootstrap_map.l_ld == ((void *) bootstrap_map.l_addr))
-    bootstrap_map.l_addr -= (((char *) bootstrap_map.l_addr) - ((char *) &__ehdr_start));
-#endif
   elf_get_dynamic_info (&bootstrap_map, NULL);
 
 #if NO_TLS_OFFSET != 0
@@ -1395,21 +1385,16 @@
   if (GLRO(dl_use_load_bias) == (ElfW(Addr)) -2)
     GLRO(dl_use_load_bias) = main_map->l_addr == 0 ? -1 : 0;
 
-  /* Set up the program header information for the dynamic linker
-     itself.  It is needed in the dl_iterate_phdr callbacks.  */
-  const ElfW(Ehdr) *rtld_ehdr;
-
   /* Starting from binutils-2.23, the linker will define the magic symbol
      __ehdr_start to point to our own ELF header if it is visible in a
      segment that also includes the phdrs.  If that's not available, we use
      the old method that assumes the beginning of the file is part of the
      lowest-addressed PT_LOAD segment.  */
-#ifdef HAVE_EHDR_START
   extern const ElfW(Ehdr) __ehdr_start __attribute__ ((visibility ("hidden")));
-  rtld_ehdr = &__ehdr_start;
-#else
-  rtld_ehdr = (void *) GL(dl_rtld_map).l_map_start;
-#endif
+
+  /* Set up the program header information for the dynamic linker
+     itself.  It is needed in the dl_iterate_phdr callbacks.  */
+  const ElfW(Ehdr) *rtld_ehdr = &__ehdr_start;
   assert (rtld_ehdr->e_ehsize == sizeof *rtld_ehdr);
   assert (rtld_ehdr->e_phentsize == sizeof (ElfW(Phdr)));
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/elf/tls-macros.h b/google3/third_party/grte/v5_src/glibc-2.27/elf/tls-macros.h
deleted file mode 100644
index 772862d..0000000
--- a/google3/third_party/grte/v5_src/glibc-2.27/elf/tls-macros.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/* Macros to support TLS testing in times of missing compiler support.  */
-
-#define COMMON_INT_DEF(x) \
-  __thread int x;
-/* XXX Until we get compiler support we don't need declarations.  */
-#define COMMON_INT_DECL(x)
-
-/* XXX This definition will probably be machine specific, too.  */
-#define VAR_INT_DEF(x) \
-  asm (".section .tdata\n\t"						      \
-       ".globl " #x "\n"						      \
-       ".balign 4\n"							      \
-       #x ":\t.long 0\n\t"						      \
-       ".size " #x ",4\n\t"						      \
-       ".previous")
-/* XXX Until we get compiler support we don't need declarations.  */
-#define VAR_INT_DECL(x)
-
-#include_next <tls-macros.h>
-
-  /* XXX Each architecture must have its own asm for now.  */
-#if !defined TLS_LE || !defined TLS_IE \
-      || !defined TLS_LD || !defined TLS_GD
-# error "No support for this architecture so far."
-#endif
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr-mod2.c b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr-mod2.c
new file mode 100644
index 0000000..dc0a633
--- /dev/null
+++ b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr-mod2.c
@@ -0,0 +1,46 @@
+/* Test for DT_RELR in a shared library without DT_NEEDED.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <array_length.h>
+
+static int o, x;
+
+#define ELEMS O O O O O O O O X X X X X X X O O X O O X X X E X E E O X O E
+#define E 0,
+
+#define O &o,
+#define X &x,
+void *arr[] = { ELEMS };
+#undef O
+#undef X
+
+#define O 1,
+#define X 2,
+static char val[] = { ELEMS };
+
+int
+foo (void)
+{
+  int err = 0;
+  for (int i = 0; i < array_length (arr); i++)
+    if (!((arr[i] == 0 && val[i] == 0)
+	  || (arr[i] == &o && val[i] == 1)
+	  || (arr[i] == &x && val[i] == 2)))
+      err++;
+  return err;
+}
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr-mod3a.c b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr-mod3a.c
new file mode 100644
index 0000000..d1621c9
--- /dev/null
+++ b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr-mod3a.c
@@ -0,0 +1,49 @@
+/* Test for DT_RELR in a shared library without DT_VERNEED.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <array_length.h>
+
+static int o, x;
+
+#define ELEMS O O O O O O O O X X X X X X X O O X O O X X X E X E E O X O E
+#define E 0,
+
+#define O &o,
+#define X &x,
+void *arr[] = { ELEMS };
+#undef O
+#undef X
+
+#define O 1,
+#define X 2,
+static char val[] = { ELEMS };
+
+extern void bar (void);
+
+int
+foo (void)
+{
+  int err = 0;
+  for (int i = 0; i < array_length (arr); i++)
+    if (!((arr[i] == 0 && val[i] == 0)
+	  || (arr[i] == &o && val[i] == 1)
+	  || (arr[i] == &x && val[i] == 2)))
+      err++;
+  bar ();
+  return err;
+}
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/libc-lowlevellock.S b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr-mod3b.c
similarity index 78%
rename from google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/libc-lowlevellock.S
rename to google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr-mod3b.c
index a1ddaaf..544cb4b 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/libc-lowlevellock.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr-mod3b.c
@@ -1,6 +1,6 @@
-/* Copyright (C) 2002-2018 Free Software Foundation, Inc.
+/* Test for DT_RELR in a shared library without DT_VERNEED.
+   Copyright (C) 2022 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -14,6 +14,9 @@
 
    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
+   <https://www.gnu.org/licenses/>.  */
 
-#include "lowlevellock.S"
+void
+bar (void)
+{
+}
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/libc-lowlevellock.S b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr-mod4a.c
similarity index 77%
copy from google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/libc-lowlevellock.S
copy to google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr-mod4a.c
index a1ddaaf..e1bfebd 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/libc-lowlevellock.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr-mod4a.c
@@ -1,6 +1,6 @@
-/* Copyright (C) 2002-2018 Free Software Foundation, Inc.
+/* Test for DT_RELR in a shared library without libc.so on DT_NEEDED.
+   Copyright (C) 2022 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -14,6 +14,6 @@
 
    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
+   <https://www.gnu.org/licenses/>.  */
 
-#include "lowlevellock.S"
+#include "tst-relr-mod3a.c"
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/libc-lowlevellock.S b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr-mod4b.c
similarity index 77%
copy from google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/libc-lowlevellock.S
copy to google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr-mod4b.c
index a1ddaaf..617dff7 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/libc-lowlevellock.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr-mod4b.c
@@ -1,6 +1,6 @@
-/* Copyright (C) 2002-2018 Free Software Foundation, Inc.
+/* Test for DT_RELR in a shared library without libc.so on DT_NEEDED.
+   Copyright (C) 2022 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -14,6 +14,6 @@
 
    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
+   <https://www.gnu.org/licenses/>.  */
 
-#include "lowlevellock.S"
+#include "tst-relr-mod3b.c"
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr-mod4b.map b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr-mod4b.map
new file mode 100644
index 0000000..7f02247
--- /dev/null
+++ b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr-mod4b.map
@@ -0,0 +1,3 @@
+DT_RELR {
+  global: bar;
+};
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr-pie.c b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr-pie.c
new file mode 100644
index 0000000..7df0cdb
--- /dev/null
+++ b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr-pie.c
@@ -0,0 +1 @@
+#include "tst-relr.c"
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr.c b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr.c
new file mode 100644
index 0000000..c634ce0
--- /dev/null
+++ b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr.c
@@ -0,0 +1,65 @@
+/* Basic tests for DT_RELR.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <link.h>
+#include <stdbool.h>
+#include <array_length.h>
+#include <support/check.h>
+
+static int o, x;
+
+#define ELEMS O O O O O O O O X X X X X X X O O X O O X X X E X E E O X O E
+#define E 0,
+
+#define O &o,
+#define X &x,
+void *arr[] = { ELEMS };
+#undef O
+#undef X
+
+#define O 1,
+#define X 2,
+static char val[] = { ELEMS };
+
+static int
+do_test (void)
+{
+  ElfW(Dyn) *d = _DYNAMIC;
+  if (d)
+    {
+      bool has_relr = false;
+      for (; d->d_tag != DT_NULL; d++)
+	if (d->d_tag == DT_RELR)
+	  has_relr = true;
+
+#if defined __PIE__ || defined __pie__ || defined PIE || defined pie
+      TEST_VERIFY (has_relr);
+#else
+      TEST_VERIFY (!has_relr);
+#endif
+    }
+
+  for (int i = 0; i < array_length (arr); i++)
+    TEST_VERIFY ((arr[i] == 0 && val[i] == 0)
+		 || (arr[i] == &o && val[i] == 1)
+		 || (arr[i] == &x && val[i] == 2));
+
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/libc-lowlevellock.S b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr2.c
similarity index 72%
copy from google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/libc-lowlevellock.S
copy to google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr2.c
index a1ddaaf..10d77f1 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/libc-lowlevellock.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr2.c
@@ -1,6 +1,6 @@
-/* Copyright (C) 2002-2018 Free Software Foundation, Inc.
+/* Test for DT_RELR in a shared library without DT_NEEDED.
+   Copyright (C) 2022 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -14,6 +14,14 @@
 
    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
+   <https://www.gnu.org/licenses/>.  */
 
-#include "lowlevellock.S"
+extern int foo (void);
+
+static int
+do_test (void)
+{
+  return foo ();
+}
+
+#include <support/test-driver.c>
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/libc-lowlevellock.S b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr3.c
similarity index 71%
copy from google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/libc-lowlevellock.S
copy to google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr3.c
index a1ddaaf..69106cf 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/libc-lowlevellock.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr3.c
@@ -1,6 +1,6 @@
-/* Copyright (C) 2002-2018 Free Software Foundation, Inc.
+/* Test for DT_RELR in a shared library without libc.so on DT_NEEDED.
+   Copyright (C) 2022 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -14,6 +14,14 @@
 
    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
+   <https://www.gnu.org/licenses/>.  */
 
-#include "lowlevellock.S"
+extern int foo (void);
+
+static int
+do_test (void)
+{
+  return foo ();
+}
+
+#include <support/test-driver.c>
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr4.c b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr4.c
new file mode 100644
index 0000000..19a7501
--- /dev/null
+++ b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-relr4.c
@@ -0,0 +1 @@
+#include "tst-relr3.c"
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tls1.c b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tls1.c
index 4bb5cc5..b341221 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tls1.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tls1.c
@@ -1,13 +1,14 @@
 /* glibc test for TLS in ld.so.  */
 #include <stdio.h>
 
-#include "tls-macros.h"
 
-
-/* Two common 'int' variables in TLS.  */
-COMMON_INT_DEF(foo);
-COMMON_INT_DEF(bar);
-
+__thread int foo, bar __attribute__ ((tls_model("local-exec")));
+extern __thread int foo_gd asm ("foo") __attribute__ ((tls_model("global-dynamic")));
+extern __thread int foo_ld asm ("foo") __attribute__ ((tls_model("local-dynamic")));
+extern __thread int foo_ie asm ("foo") __attribute__ ((tls_model("initial-exec")));
+extern __thread int bar_gd asm ("bar") __attribute__ ((tls_model("global-dynamic")));
+extern __thread int bar_ld asm ("bar") __attribute__ ((tls_model("local-dynamic")));
+extern __thread int bar_ie asm ("bar") __attribute__ ((tls_model("initial-exec")));
 
 static int
 do_test (void)
@@ -18,66 +19,47 @@
 
   /* Set the variable using the local exec model.  */
   puts ("set bar to 1 (LE)");
-  ap = TLS_LE (bar);
-  *ap = 1;
+  bar = 1;
 
 
   /* Get variables using initial exec model.  */
   fputs ("get sum of foo and bar (IE)", stdout);
-  ap = TLS_IE (foo);
-  bp = TLS_IE (bar);
+  ap = &foo_ie;
+  bp = &bar_ie;
   printf (" = %d\n", *ap + *bp);
   result |= *ap + *bp != 1;
-  if (*ap != 0)
+  if (*ap != 0 || *bp != 1)
     {
-      printf ("foo = %d\n", *ap);
-      result = 1;
-    }
-  if (*bp != 1)
-    {
-      printf ("bar = %d\n", *bp);
+      printf ("foo = %d\nbar = %d\n", *ap, *bp);
       result = 1;
     }
 
-  /* clang integrated assembler does not handle the tlsgd reloc needed by TLS_LD
-     and TLS_GD macros, so just skip this part of the test.  */
-#if !defined(__clang__) || !defined(__aarch64__)
-  /* Get variables using local dynamic model.  */
-  fputs ("get sum of foo and bar (LD)", stdout);
-  ap = TLS_LD (foo);
-  bp = TLS_LD (bar);
-  printf (" = %d\n", *ap + *bp);
-  result |= *ap + *bp != 1;
-  if (*ap != 0)
-    {
-      printf ("foo = %d\n", *ap);
-      result = 1;
-    }
-  if (*bp != 1)
-    {
-      printf ("bar = %d\n", *bp);
-      result = 1;
-    }
-#endif
 
-#if !defined(__clang__) || !defined(__aarch64__)
-  /* Get variables using generic dynamic model.  */
-  fputs ("get sum of foo and bar (GD)", stdout);
-  ap = TLS_GD (foo);
-  bp = TLS_GD (bar);
+  /* Get variables using local dynamic model or TLSDESC.  */
+  fputs ("get sum of foo and bar (LD or TLSDESC)", stdout);
+  ap = &foo_ld;
+  bp = &bar_ld;
   printf (" = %d\n", *ap + *bp);
   result |= *ap + *bp != 1;
-  if (*ap != 0)
+  if (*ap != 0 || *bp != 1)
     {
-      printf ("foo = %d\n", *ap);
+      printf ("foo = %d\nbar = %d\n", *ap, *bp);
       result = 1;
     }
-  if (*bp != 1)
+
+
+  /* Get variables using general dynamic model or TLSDESC.  */
+  fputs ("get sum of foo and bar (GD or TLSDESC)", stdout);
+  ap = &foo_gd;
+  bp = &bar_gd;
+  printf (" = %d\n", *ap + *bp);
+  result |= *ap + *bp != 1;
+  if (*ap != 0 || *bp != 1)
     {
-      printf ("bar = %d\n", *bp);
+      printf ("foo = %d\nbar = %d\n", *ap, *bp);
       result = 1;
     }
-#endif
+
 
   return result;
 }
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tls2.c b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tls2.c
deleted file mode 100644
index b16abad..0000000
--- a/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tls2.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/* glibc test for TLS in ld.so.  */
-#include <stdio.h>
-
-#include "tls-macros.h"
-
-
-/* Two 'int' variables in TLS.  */
-VAR_INT_DEF(foo);
-VAR_INT_DEF(bar);
-
-
-static int
-do_test (void)
-{
-  int result = 0;
-  int *ap, *bp;
-
-
-  /* Set the variable using the local exec model.  */
-  puts ("set bar to 1 (LE)");
-  ap = TLS_LE (bar);
-  *ap = 1;
-
-
-  /* Get variables using initial exec model.  */
-  fputs ("get sum of foo and bar (IE)", stdout);
-  ap = TLS_IE (foo);
-  bp = TLS_IE (bar);
-  printf (" = %d\n", *ap + *bp);
-  result |= *ap + *bp != 1;
-  if (*ap != 0)
-    {
-      printf ("foo = %d\n", *ap);
-      result = 1;
-    }
-  if (*bp != 1)
-    {
-      printf ("bar = %d\n", *bp);
-      result = 1;
-    }
-
-#if !defined(__clang__) || !defined(__aarch64__)
-  /* Get variables using local dynamic model.  */
-  fputs ("get sum of foo and bar (LD)", stdout);
-  ap = TLS_LD (foo);
-  bp = TLS_LD (bar);
-  printf (" = %d\n", *ap + *bp);
-  result |= *ap + *bp != 1;
-  if (*ap != 0)
-    {
-      printf ("foo = %d\n", *ap);
-      result = 1;
-    }
-  if (*bp != 1)
-    {
-      printf ("bar = %d\n", *bp);
-      result = 1;
-    }
-#endif
-
-#if !defined(__clang__) || !defined(__aarch64__)
-  /* Get variables using generic dynamic model.  */
-  fputs ("get sum of foo and bar (GD)", stdout);
-  ap = TLS_GD (foo);
-  bp = TLS_GD (bar);
-  printf (" = %d\n", *ap + *bp);
-  result |= *ap + *bp != 1;
-  if (*ap != 0)
-    {
-      printf ("foo = %d\n", *ap);
-      result = 1;
-    }
-  if (*bp != 1)
-    {
-      printf ("bar = %d\n", *bp);
-      result = 1;
-    }
-#endif
-
-  return result;
-}
-
-
-#include <support/test-driver.c>
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tls3.c b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tls3.c
index 58d7f2a..222b179 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tls3.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tls3.c
@@ -1,13 +1,12 @@
 /* glibc test for TLS in ld.so.  */
 #include <stdio.h>
 
-#include "tls-macros.h"
 
-
-/* One define int variable, two externs.  */
-COMMON_INT_DECL(foo);
-VAR_INT_DECL(bar);
-VAR_INT_DEF(baz);
+__thread int foo, bar __attribute__ ((tls_model("initial-exec")));
+__thread int baz __attribute__ ((tls_model("local-exec")));
+extern __thread int foo_gd __attribute__ ((alias("foo"), tls_model("global-dynamic")));
+extern __thread int bar_gd __attribute__ ((alias("bar"), tls_model("global-dynamic")));
+extern __thread int baz_ld __attribute__ ((alias("baz"), tls_model("local-dynamic")));
 
 
 extern int in_dso (void);
@@ -22,23 +21,20 @@
 
   /* Set the variable using the local exec model.  */
   puts ("set baz to 3 (LE)");
-  ap = TLS_LE (baz);
-  *ap = 3;
+  baz = 3;
 
 
   /* Get variables using initial exec model.  */
   puts ("set variables foo and bar (IE)");
-  ap = TLS_IE (foo);
-  *ap = 1;
-  bp = TLS_IE (bar);
-  *bp = 2;
+  foo = 1;
+  bar = 2;
 
-#if !defined(__clang__) || !defined(__aarch64__)
+
   /* Get variables using local dynamic model.  */
   fputs ("get sum of foo, bar (GD) and baz (LD)", stdout);
-  ap = TLS_GD (foo);
-  bp = TLS_GD (bar);
-  cp = TLS_LD (baz);
+  ap = &foo_gd;
+  bp = &bar_gd;
+  cp = &baz_ld;
   printf (" = %d\n", *ap + *bp + *cp);
   result |= *ap + *bp + *cp != 6;
   if (*ap != 1)
@@ -56,7 +52,7 @@
       printf ("baz = %d\n", *cp);
       result = 1;
     }
-#endif
+
 
   result |= in_dso ();
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tlsmod1.c b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tlsmod1.c
index 5e73e2b..a448c4d 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tlsmod1.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tlsmod1.c
@@ -1,12 +1,12 @@
 #include <stdio.h>
 
-#include "tls-macros.h"
 
+__thread int foo, bar __attribute__ ((tls_model("global-dynamic")));
+extern __thread int baz __attribute__ ((tls_model("global-dynamic")));
+extern __thread int foo_ie asm ("foo") __attribute__ ((tls_model("initial-exec")));
+extern __thread int bar_ie asm ("bar") __attribute__ ((tls_model("initial-exec")));
+extern __thread int baz_ie asm ("baz") __attribute__ ((tls_model("initial-exec")));
 
-/* One define int variable, two externs.  */
-COMMON_INT_DEF(foo);
-VAR_INT_DEF(bar);
-VAR_INT_DECL(baz);
 
 extern int in_dso (void);
 
@@ -19,8 +19,8 @@
   /* Get variables using initial exec model.  */
   fputs ("get sum of foo and bar (IE)", stdout);
   asm ("" ::: "memory");
-  ap = TLS_IE (foo);
-  bp = TLS_IE (bar);
+  ap = &foo_ie;
+  bp = &bar_ie;
   printf (" = %d\n", *ap + *bp);
   result |= *ap + *bp != 3;
   if (*ap != 1)
@@ -34,12 +34,12 @@
       result = 1;
     }
 
-#if !defined(__clang__) || !defined(__aarch64__)
-  /* Get variables using generic dynamic model.  */
-  fputs ("get sum of foo and bar and baz (GD)", stdout);
-  ap = TLS_GD (foo);
-  bp = TLS_GD (bar);
-  cp = TLS_GD (baz);
+
+  /* Get variables using generic dynamic model or TLSDESC.  */
+  fputs ("get sum of foo and bar and baz (GD or TLSDESC)", stdout);
+  ap = &foo;
+  bp = &bar;
+  cp = &baz;
   printf (" = %d\n", *ap + *bp + *cp);
   result |= *ap + *bp + *cp != 6;
   if (*ap != 1)
@@ -57,7 +57,6 @@
       printf ("baz = %d\n", *cp);
       result = 1;
     }
-#endif
 
   return result;
 }
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tlsmod2.c b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tlsmod2.c
index bad37af..3223fe4 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tlsmod2.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tlsmod2.c
@@ -1,9 +1,7 @@
 #include <stdio.h>
 
-#include "tls-macros.h"
 
-
-COMMON_INT_DEF(foo);
+__thread int foo;
 
 
 int
@@ -15,8 +13,7 @@
   puts ("foo");			/* Make sure PLT is used before macros.  */
   asm ("" ::: "memory");
 
-#if !defined(__clang__) || !defined(__aarch64__)
-  foop = TLS_GD (foo);
+  foop = &foo;
 
   if (caller_foop != NULL && foop != caller_foop)
     {
@@ -30,7 +27,6 @@
     }
 
   *foop = 16;
-#endif
 
   return result;
 }
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tlsmod3.c b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tlsmod3.c
index 80621ee..d6e7498 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tlsmod3.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tlsmod3.c
@@ -1,10 +1,10 @@
 #include <stdio.h>
 
-#include "tls-macros.h"
 
 extern int in_dso (int n, int *caller_foop);
 
-COMMON_INT_DEF(comm_n);
+extern __thread int foo;
+__thread int comm_n;
 
 
 
@@ -20,9 +20,8 @@
   puts ("foo");			/* Make sure PLT is used before macros.  */
   asm ("" ::: "memory");
 
-#if !defined(__clang__) || !defined(__aarch64__)
-  foop = TLS_GD (foo);
-  np = TLS_GD (comm_n);
+  foop = &foo;
+  np = &comm_n;
 
   if (n != *np)
     {
@@ -33,7 +32,6 @@
   result |= in_dso (*foop = 42 + n++, foop);
 
   *foop = 16;
-#endif
 
   return result;
 }
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tlsmod4.c b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tlsmod4.c
index 303ab78..f38919a 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tlsmod4.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tlsmod4.c
@@ -1,9 +1,7 @@
 #include <stdio.h>
 
-#include "tls-macros.h"
 
-
-COMMON_INT_DEF(baz);
+__thread int baz;
 
 
 int
@@ -15,8 +13,7 @@
   puts ("foo");			/* Make sure PLT is used before macros.  */
   asm ("" ::: "memory");
 
-#if !defined(__clang__) || !defined(__aarch64__)
-  bazp = TLS_GD (baz);
+  bazp = &baz;
 
   if (caller_bazp != NULL && bazp != caller_bazp)
     {
@@ -30,7 +27,6 @@
     }
 
   *bazp = 16;
-#endif
 
   return result;
 }
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tlsmod5.c b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tlsmod5.c
index a97c7e5..3f39c5b 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tlsmod5.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tlsmod5.c
@@ -1,3 +1 @@
-#include "tls-macros.h"
-
-COMMON_INT_DEF(foo);
+__thread int foo;
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tlsmod6.c b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tlsmod6.c
index e968596..7b3571f 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tlsmod6.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/elf/tst-tlsmod6.c
@@ -1,3 +1 @@
-#include "tls-macros.h"
-
-COMMON_INT_DEF(bar);
+__thread int bar;
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/elf/unload8.c b/google3/third_party/grte/v5_src/glibc-2.27/elf/unload8.c
index f984a38..363af13 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/elf/unload8.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/elf/unload8.c
@@ -27,7 +27,48 @@
     }
 
   mod1 ();
+
+  // Additional test to detect when the fastload hash table has bad pointers to
+  // names of unloaded libraries hanging around in it.
+
+  int (*mod1b) (void) = dlsym (h, "mod1b");
+  if (mod1b == NULL)
+    {
+      puts ("dlsym failed");
+      return 1;
+    }
+
+  mod1b ();
+
   dlclose (h);
 
+  void *h2x = dlopen ("$ORIGIN/unload8mod2.so", RTLD_LAZY);
+  if (h2x == NULL)
+    {
+      puts ("dlopen unload8mod2.so failed");
+      return 1;
+    }
+
+
+  void *h2xx = dlopen ("$ORIGIN/unload8mod1x.so", RTLD_LAZY);
+  if (h2xx == NULL)
+    {
+      puts ("dlopen unload8mod1x.so failed");
+      return 1;
+    }
+
+  dlclose (h);
+  dlclose (h2x);
+  dlclose (h2xx);
+
+  void *h3xx = dlopen ("$ORIGIN/unload8mod3.so", RTLD_LAZY);
+  if (h3xx == NULL)
+    {
+      puts ("dlopen unload8mod3.so failed");
+      return 1;
+    }
+
+  dlclose (h3xx);
+
   return 0;
 }
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/elf/unload8mod1.c b/google3/third_party/grte/v5_src/glibc-2.27/elf/unload8mod1.c
index fe7e81c..8df93a0 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/elf/unload8mod1.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/elf/unload8mod1.c
@@ -1,3 +1,5 @@
+#include <dlfcn.h>
+
 extern void mod2 (void);
 
 void
@@ -5,3 +7,15 @@
 {
   mod2 ();
 }
+
+int
+mod1b (void)
+{
+  void *h = dlopen ("$ORIGIN/unload8mod3.so", RTLD_LAZY);
+  if (h == NULL)
+    {
+      puts ("dlopen unload8mod3.so failed");
+      return 1;
+    }
+  return 0;
+}
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/iconv/Makefile b/google3/third_party/grte/v5_src/glibc-2.27/iconv/Makefile
index d71319b..c8b9836 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/iconv/Makefile
+++ b/google3/third_party/grte/v5_src/glibc-2.27/iconv/Makefile
@@ -26,7 +26,7 @@
 routines	= iconv_open iconv iconv_close \
 		  gconv_open gconv gconv_close gconv_db gconv_conf \
 		  gconv_builtin gconv_simple gconv_trans gconv_cache
-routines	+= gconv_dl
+routines	+= gconv_dl gconv_charset
 
 vpath %.c ../locale/programs ../intl
 
@@ -43,7 +43,8 @@
 CFLAGS-linereader.c += -DNO_TRANSLITERATION
 CFLAGS-simple-hash.c += -I../locale
 
-tests	= tst-iconv1 tst-iconv2 tst-iconv3 tst-iconv4 tst-iconv5 tst-iconv6
+tests	= tst-iconv1 tst-iconv2 tst-iconv3 tst-iconv4 tst-iconv5 tst-iconv6 \
+	  tst-iconv8 # tst-iconv-opt needs work to add back
 
 others		= iconv_prog iconvconfig
 install-others-programs	= $(inst_bindir)/iconv
@@ -60,6 +61,7 @@
 
 ifeq ($(run-built-tests),yes)
 xtests-special += $(objpfx)test-iconvconfig.out
+tests-special += $(objpfx)tst-iconv_prog.out
 endif
 
 # Make a copy of the file because gconv module names are constructed
@@ -78,6 +80,13 @@
 
 include ../Rules
 
+ifeq ($(run-built-tests),yes)
+LOCALES := en_US.UTF-8
+include ../gen-locales.mk
+
+$(objpfx)tst-iconv-opt.out: $(gen-locales)
+endif
+
 $(inst_bindir)/iconv: $(objpfx)iconv_prog $(+force)
 	$(do-install-program)
 
@@ -92,3 +101,8 @@
 	 cmp $$tmp $(inst_gconvdir)/gconv-modules.cache; \
 	 rm -f $$tmp) > $@; \
 	$(evaluate-test)
+
+$(objpfx)tst-iconv_prog.out: tst-iconv_prog.sh $(objpfx)iconv_prog
+	$(BASH) $< $(common-objdir) '$(test-wrapper-env)' \
+		 '$(run-program-env)' > $@; \
+	$(evaluate-test)
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/iconv/Versions b/google3/third_party/grte/v5_src/glibc-2.27/iconv/Versions
index 60ab10a..d51af52 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/iconv/Versions
+++ b/google3/third_party/grte/v5_src/glibc-2.27/iconv/Versions
@@ -7,6 +7,9 @@
     # functions shared with iconv program
     __gconv_get_alias_db; __gconv_get_cache; __gconv_get_modules_db;
 
+    # functions used elsewhere in glibc
+    __gconv_open; __gconv_create_spec; __gconv_destroy_spec;
+
     # function used by the gconv modules
     __gconv_transliterate;
   }
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/iconv/gconv_charset.c b/google3/third_party/grte/v5_src/glibc-2.27/iconv/gconv_charset.c
new file mode 100644
index 0000000..4ba0aa9
--- /dev/null
+++ b/google3/third_party/grte/v5_src/glibc-2.27/iconv/gconv_charset.c
@@ -0,0 +1,228 @@
+/* Charset name normalization.
+   Copyright (C) 2020 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+
+#include <stdlib.h>
+#include <ctype.h>
+#include <locale.h>
+#include <stdbool.h>
+#include <string.h>
+#include <sys/stat.h>
+#include "gconv_int.h"
+#include "gconv_charset.h"
+
+
+/* This function returns a pointer to the last suffix in a conversion code
+   string.  Valid suffixes matched by this function are of the form: '/' or ','
+   followed by arbitrary text that doesn't contain '/' or ','.  It does not
+   edit the string in any way.  The caller is expected to parse the suffix and
+   remove it (by e.g. truncating the string) before the next call.  */
+static char *
+find_suffix (char *s)
+{
+  /* The conversion code is in the form of a triplet, separated by '/' chars.
+     The third component of the triplet contains suffixes. If we don't have two
+     slashes, we don't have a suffix.  */
+
+  int slash_count = 0;
+  char *suffix_term = NULL;
+
+  for (int i = 0; s[i] != '\0'; i++)
+    switch (s[i])
+      {
+        case '/':
+          slash_count++;
+          /* Fallthrough */
+        case ',':
+          suffix_term = &s[i];
+      }
+
+  if (slash_count >= 2)
+    return suffix_term;
+
+  return NULL;
+}
+
+
+struct gconv_parsed_code
+{
+  char *code;
+  bool translit;
+  bool ignore;
+};
+
+
+/* This function parses an iconv_open encoding PC.CODE, strips any suffixes
+   (such as TRANSLIT or IGNORE) from it and sets corresponding flags in it.  */
+static void
+gconv_parse_code (struct gconv_parsed_code *pc)
+{
+  pc->translit = false;
+  pc->ignore = false;
+
+  while (1)
+    {
+      /* First drop any trailing whitespaces and separators.  */
+      size_t len = strlen (pc->code);
+      while ((len > 0)
+             && (isspace (pc->code[len - 1])
+                 || pc->code[len - 1] == ','
+                 || pc->code[len - 1] == '/'))
+        len--;
+
+      pc->code[len] = '\0';
+
+      if (len == 0)
+        return;
+
+      char * suffix = find_suffix (pc->code);
+      if (suffix == NULL)
+        {
+          /* At this point, we have processed and removed all suffixes from the
+             code and what remains of the code is suffix free.  */
+          return;
+        }
+      else
+        {
+          /* A suffix is processed from the end of the code array going
+             backwards, one suffix at a time.  The suffix is an index into the
+             code character array and points to: one past the end of the code
+             and any unprocessed suffixes, and to the beginning of the suffix
+             currently being processed during this iteration.  We must process
+             this suffix and then drop it from the code by terminating the
+             preceding text with NULL.
+
+             We want to allow and recognize suffixes such as:
+
+             "/TRANSLIT"         i.e. single suffix
+             "//TRANSLIT"        i.e. single suffix and multiple separators
+             "//TRANSLIT/IGNORE" i.e. suffixes separated by "/"
+             "/TRANSLIT//IGNORE" i.e. suffixes separated by "//"
+             "//IGNORE,TRANSLIT" i.e. suffixes separated by ","
+             "//IGNORE,"         i.e. trailing ","
+             "//TRANSLIT/"       i.e. trailing "/"
+             "//TRANSLIT//"      i.e. trailing "//"
+             "/"                 i.e. empty suffix.
+
+             Unknown suffixes are silently discarded and ignored.  */
+
+          if ((__strcasecmp_l (suffix,
+                               GCONV_TRIPLE_SEPARATOR
+                               GCONV_TRANSLIT_SUFFIX,
+                               _nl_C_locobj_ptr) == 0)
+              || (__strcasecmp_l (suffix,
+                                  GCONV_SUFFIX_SEPARATOR
+                                  GCONV_TRANSLIT_SUFFIX,
+                                  _nl_C_locobj_ptr) == 0))
+            pc->translit = true;
+
+          if ((__strcasecmp_l (suffix,
+                               GCONV_TRIPLE_SEPARATOR
+                               GCONV_IGNORE_ERRORS_SUFFIX,
+                               _nl_C_locobj_ptr) == 0)
+              || (__strcasecmp_l (suffix,
+                                  GCONV_SUFFIX_SEPARATOR
+                                  GCONV_IGNORE_ERRORS_SUFFIX,
+                                  _nl_C_locobj_ptr) == 0))
+            pc->ignore = true;
+
+          /* We just processed this suffix.  We can now drop it from the
+             code string by truncating it at the suffix's position.  */
+          suffix[0] = '\0';
+        }
+    }
+}
+
+
+/* This function accepts the charset names of the source and destination of the
+   conversion and populates *conv_spec with an equivalent conversion
+   specification that may later be used by __gconv_open.  The charset names
+   might contain options in the form of suffixes that alter the conversion,
+   e.g. "ISO-10646/UTF-8/TRANSLIT".  It processes the charset names, ignoring
+   and truncating any suffix options in fromcode, and processing and truncating
+   any suffix options in tocode.  Supported suffix options ("TRANSLIT" or
+   "IGNORE") when found in tocode lead to the corresponding flag in *conv_spec
+   to be set to true.  Unrecognized suffix options are silently discarded.  If
+   the function succeeds, it returns conv_spec back to the caller.  It returns
+   NULL upon failure.  conv_spec must be allocated and freed by the caller.  */
+struct gconv_spec *
+__gconv_create_spec (struct gconv_spec *conv_spec, const char *fromcode,
+                   const char *tocode)
+{
+  struct gconv_parsed_code pfc, ptc;
+  struct gconv_spec *ret = NULL;
+
+  pfc.code = __strdup (fromcode);
+  ptc.code = __strdup (tocode);
+
+  if ((pfc.code == NULL)
+      || (ptc.code == NULL))
+    goto out;
+
+  gconv_parse_code (&pfc);
+  gconv_parse_code (&ptc);
+
+  /* We ignore suffixes in the fromcode because that is how the current
+     implementation has always handled them.  Only suffixes in the tocode are
+     processed and handled.  The reality is that invalid input in the input
+     character set should only be ignored if the fromcode specifies IGNORE.
+     The current implementation ignores invalid intput in the input character
+     set if the tocode contains IGNORE.  We preserve this behavior for
+     backwards compatibility.  In the future we may split the handling of
+     IGNORE to allow a finer grained specification of ignorning invalid input
+     and/or ignoring invalid output.  */
+  conv_spec->translit = ptc.translit;
+  conv_spec->ignore = ptc.ignore;
+
+  /* 3 extra bytes because 1 extra for '\0', and 2 extra so strip might
+     be able to add one or two trailing '/' characters if necessary.  */
+  conv_spec->fromcode = malloc (strlen (fromcode) + 3);
+  if (conv_spec->fromcode == NULL)
+    goto out;
+
+  conv_spec->tocode = malloc (strlen (tocode) + 3);
+  if (conv_spec->tocode == NULL)
+    {
+      free (conv_spec->fromcode);
+      conv_spec->fromcode = NULL;
+      goto out;
+    }
+
+  /* Strip unrecognized characters and ensure that the code has two '/'
+     characters as per conversion code triplet specification.  */
+  strip (conv_spec->fromcode, pfc.code);
+  strip (conv_spec->tocode, ptc.code);
+  ret = conv_spec;
+
+out:
+  free (pfc.code);
+  free (ptc.code);
+
+  return ret;
+}
+libc_hidden_def (__gconv_create_spec)
+
+
+void
+__gconv_destroy_spec (struct gconv_spec *conv_spec)
+{
+  free (conv_spec->fromcode);
+  free (conv_spec->tocode);
+  return;
+}
+libc_hidden_def (__gconv_destroy_spec)
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/iconv/gconv_charset.h b/google3/third_party/grte/v5_src/glibc-2.27/iconv/gconv_charset.h
index 123e2a6..4b98073 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/iconv/gconv_charset.h
+++ b/google3/third_party/grte/v5_src/glibc-2.27/iconv/gconv_charset.h
@@ -19,9 +19,41 @@
 
 #include <ctype.h>
 #include <locale.h>
+#include <stdbool.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+#include "gconv_int.h"
 
 
-static void
+/* An iconv encoding is in the form of a triplet, with parts separated by
+   a '/' character.  The first part is the standard name, the second part is
+   the character set, and the third part is the error handler.  If the first
+   part is sufficient to identify both the standard and the character set
+   then the second part can be empty e.g. UTF-8//.  If the first part is not
+   sufficient to identify both the standard and the character set then the
+   second part is required e.g. ISO-10646/UTF8/.  If neither the first or
+   second parts are provided e.g. //, then the current locale is used.
+   The actual values used in the first and second parts are not entirely
+   relevant to the implementation.  The values themselves are used in a hash
+   table to lookup modules and so the naming convention of the first two parts
+   is somewhat arbitrary and only helps locate the entries in the cache.
+   The third part is the error handler and is comprised of a ',' or '/'
+   separated list of suffixes.  Currently, we support "TRANSLIT" for
+   transliteration and "IGNORE" for ignoring conversion errors due to
+   unrecognized input characters.  */
+#define GCONV_TRIPLE_SEPARATOR "/"
+#define GCONV_SUFFIX_SEPARATOR ","
+#define GCONV_TRANSLIT_SUFFIX "TRANSLIT"
+#define GCONV_IGNORE_ERRORS_SUFFIX "IGNORE"
+
+
+/* This function copies in-order, characters from the source 's' that are
+   either alpha-numeric or one in one of these: "_-.,:/" - into the destination
+   'wp' while dropping all other characters.  In the process, it converts all
+   alphabetical characters to upper case.  It then appends up to two '/'
+   characters so that the total number of '/'es in the destination is 2.  */
+static inline void __attribute__ ((unused, always_inline))
 strip (char *wp, const char *s)
 {
   int slash_count = 0;
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/iconv/gconv_int.h b/google3/third_party/grte/v5_src/glibc-2.27/iconv/gconv_int.h
index 3742557..8067a34 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/iconv/gconv_int.h
+++ b/google3/third_party/grte/v5_src/glibc-2.27/iconv/gconv_int.h
@@ -92,6 +92,15 @@
 };
 
 
+/* The specification of the conversion that needs to be performed.  */
+struct gconv_spec
+{
+  char *fromcode;
+  char *tocode;
+  bool translit;
+  bool ignore;
+};
+
 /* Flags for `gconv_open'.  */
 enum
 {
@@ -154,10 +163,33 @@
   })
 
 
-/* Return in *HANDLE decriptor for transformation from FROMSET to TOSET.  */
-extern int __gconv_open (const char *toset, const char *fromset,
-			 __gconv_t *handle, int flags)
-     attribute_hidden;
+/* Return in *HANDLE, a decriptor for the transformation.  The function expects
+   the specification of the transformation in the structure pointed to by
+   CONV_SPEC.  It only reads *CONV_SPEC and does not take ownership of it.  */
+extern int __gconv_open (struct gconv_spec *conv_spec,
+                         __gconv_t *handle, int flags);
+libc_hidden_proto (__gconv_open)
+
+/* This function accepts the charset names of the source and destination of the
+   conversion and populates *conv_spec with an equivalent conversion
+   specification that may later be used by __gconv_open.  The charset names
+   might contain options in the form of suffixes that alter the conversion,
+   e.g. "ISO-10646/UTF-8/TRANSLIT".  It processes the charset names, ignoring
+   and truncating any suffix options in fromcode, and processing and truncating
+   any suffix options in tocode.  Supported suffix options ("TRANSLIT" or
+   "IGNORE") when found in tocode lead to the corresponding flag in *conv_spec
+   to be set to true.  Unrecognized suffix options are silently discarded.  If
+   the function succeeds, it returns conv_spec back to the caller.  It returns
+   NULL upon failure.  */
+extern struct gconv_spec *
+__gconv_create_spec (struct gconv_spec *conv_spec, const char *fromcode,
+                     const char *tocode);
+libc_hidden_proto (__gconv_create_spec)
+
+/* This function frees all heap memory allocated by __gconv_create_spec.  */
+extern void
+__gconv_destroy_spec (struct gconv_spec *conv_spec);
+libc_hidden_proto (__gconv_destroy_spec)
 
 /* Free resources associated with transformation descriptor CD.  */
 extern int __gconv_close (__gconv_t cd)
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/iconv/gconv_open.c b/google3/third_party/grte/v5_src/glibc-2.27/iconv/gconv_open.c
index f739561..002faa1 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/iconv/gconv_open.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/iconv/gconv_open.c
@@ -27,7 +27,7 @@
 
 
 int
-__gconv_open (const char *toset, const char *fromset, __gconv_t *handle,
+__gconv_open (struct gconv_spec *conv_spec, __gconv_t *handle,
 	      int flags)
 {
   struct __gconv_step *steps;
@@ -36,77 +36,38 @@
   size_t cnt = 0;
   int res;
   int conv_flags = 0;
-  const char *errhand;
-  const char *ignore;
   bool translit = false;
+  char *tocode, *fromcode;
 
   /* Find out whether any error handling method is specified.  */
-  errhand = strchr (toset, '/');
-  if (errhand != NULL)
-    errhand = strchr (errhand + 1, '/');
-  if (__glibc_likely (errhand != NULL))
-    {
-      if (*++errhand == '\0')
-	errhand = NULL;
-      else
-	{
-	  /* Make copy without the error handling description.  */
-	  char *newtoset = (char *) alloca (errhand - toset + 1);
-	  char *tok;
-	  char *ptr = NULL /* Work around a bogus warning */;
+  translit = conv_spec->translit;
 
-	  newtoset[errhand - toset] = '\0';
-	  toset = memcpy (newtoset, toset, errhand - toset);
+  if (conv_spec->ignore)
+    conv_flags |= __GCONV_IGNORE_ERRORS;
 
-	  /* Find the appropriate transliteration handlers.  */
-	  tok = strdupa (errhand);
-
-	  tok = __strtok_r (tok, ",", &ptr);
-	  while (tok != NULL)
-	    {
-	      if (__strcasecmp_l (tok, "TRANSLIT", _nl_C_locobj_ptr) == 0)
-		translit = true;
-	      else if (__strcasecmp_l (tok, "IGNORE", _nl_C_locobj_ptr) == 0)
-		/* Set the flag to ignore all errors.  */
-		conv_flags |= __GCONV_IGNORE_ERRORS;
-
-	      tok = __strtok_r (NULL, ",", &ptr);
-	    }
-	}
-    }
-
-  /* For the source character set we ignore the error handler specification.
-     XXX Is this really always the best?  */
-  ignore = strchr (fromset, '/');
-  if (ignore != NULL && (ignore = strchr (ignore + 1, '/')) != NULL
-      && *++ignore != '\0')
-    {
-      char *newfromset = (char *) alloca (ignore - fromset + 1);
-
-      newfromset[ignore - fromset] = '\0';
-      fromset = memcpy (newfromset, fromset, ignore - fromset);
-    }
+  tocode = conv_spec->tocode;
+  fromcode = conv_spec->fromcode;
 
   /* If the string is empty define this to mean the charset of the
      currently selected locale.  */
-  if (strcmp (toset, "//") == 0)
+  if (strcmp (tocode, "//") == 0)
     {
       const char *codeset = _NL_CURRENT (LC_CTYPE, CODESET);
       size_t len = strlen (codeset);
       char *dest;
-      toset = dest = (char *) alloca (len + 3);
+      tocode = dest = (char *) alloca (len + 3);
       memcpy (__mempcpy (dest, codeset, len), "//", 3);
     }
-  if (strcmp (fromset, "//") == 0)
+  if (strcmp (fromcode, "//") == 0)
     {
       const char *codeset = _NL_CURRENT (LC_CTYPE, CODESET);
       size_t len = strlen (codeset);
       char *dest;
-      fromset = dest = (char *) alloca (len + 3);
+      fromcode = dest = (char *) alloca (len + 3);
       memcpy (__mempcpy (dest, codeset, len), "//", 3);
     }
 
-  res = __gconv_find_transform (toset, fromset, &steps, &nsteps, flags);
+  res = __gconv_find_transform (tocode, fromcode, &steps, &nsteps, flags);
   if (res == __GCONV_OK)
     {
       /* Allocate room for handle.  */
@@ -205,3 +166,4 @@
   *handle = result;
   return res;
 }
+libc_hidden_def (__gconv_open)
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/iconv/gconv_simple.c b/google3/third_party/grte/v5_src/glibc-2.27/iconv/gconv_simple.c
index 506c92c..8c84a43 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/iconv/gconv_simple.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/iconv/gconv_simple.c
@@ -237,11 +237,9 @@
   int flags = step_data->__flags;
   const unsigned char *inptr = *inptrp;
   unsigned char *outptr = *outptrp;
-  size_t n_convert = MIN (inend - inptr, outend - outptr) / 4;
   int result;
-  size_t cnt;
 
-  for (cnt = 0; cnt < n_convert; ++cnt, inptr += 4)
+  for (; inptr + 4 <= inend && outptr + 4 <= outend; inptr += 4)
     {
       uint32_t inval;
 
@@ -304,11 +302,9 @@
   int flags = step_data->__flags;
   const unsigned char *inptr = *inptrp;
   unsigned char *outptr = *outptrp;
-  size_t n_convert = MIN (inend - inptr, outend - outptr) / 4;
   int result;
-  size_t cnt;
 
-  for (cnt = 0; cnt < n_convert; ++cnt, inptr += 4)
+  for (; inptr + 4 <= inend && outptr + 4 <= outend; inptr += 4)
     {
       if (__glibc_unlikely (inptr[0] > 0x80))
 	{
@@ -607,11 +603,9 @@
   int flags = step_data->__flags;
   const unsigned char *inptr = *inptrp;
   unsigned char *outptr = *outptrp;
-  size_t n_convert = MIN (inend - inptr, outend - outptr) / 4;
   int result;
-  size_t cnt;
 
-  for (cnt = 0; cnt < n_convert; ++cnt, inptr += 4)
+  for (; inptr + 4 <= inend && outptr + 4 <= outend; inptr += 4)
     {
       uint32_t inval;
 
@@ -677,11 +671,9 @@
   int flags = step_data->__flags;
   const unsigned char *inptr = *inptrp;
   unsigned char *outptr = *outptrp;
-  size_t n_convert = MIN (inend - inptr, outend - outptr) / 4;
   int result;
-  size_t cnt;
 
-  for (cnt = 0; cnt < n_convert; ++cnt, inptr += 4)
+  for (; inptr + 4 <= inend && outptr + 4 <= outend; inptr += 4)
     {
       if (__glibc_unlikely (inptr[3] > 0x80))
 	{
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/iconv/iconv_open.c b/google3/third_party/grte/v5_src/glibc-2.27/iconv/iconv_open.c
index 9f5c32c..46da33b 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/iconv/iconv_open.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/iconv/iconv_open.c
@@ -31,49 +31,15 @@
 iconv_t
 iconv_open (const char *tocode, const char *fromcode)
 {
-  /* Normalize the name.  We remove all characters beside alpha-numeric,
-     '_', '-', '/', '.', and ':'.  */
-  size_t tocode_len = strlen (tocode) + 3;
-  char *tocode_conv;
-  bool tocode_usealloca = __libc_use_alloca (tocode_len);
-  if (tocode_usealloca)
-    tocode_conv = (char *) alloca (tocode_len);
-  else
-    {
-      tocode_conv = (char *) malloc (tocode_len);
-      if (tocode_conv == NULL)
-	return (iconv_t) -1;
-    }
-  strip (tocode_conv, tocode);
-  tocode = (tocode_conv[2] == '\0' && tocode[0] != '\0'
-	    ? upstr (tocode_conv, tocode) : tocode_conv);
-
-  size_t fromcode_len = strlen (fromcode) + 3;
-  char *fromcode_conv;
-  bool fromcode_usealloca = __libc_use_alloca (fromcode_len);
-  if (fromcode_usealloca)
-    fromcode_conv = (char *) alloca (fromcode_len);
-  else
-    {
-      fromcode_conv = (char *) malloc (fromcode_len);
-      if (fromcode_conv == NULL)
-	{
-	  if (! tocode_usealloca)
-	    free (tocode_conv);
-	  return (iconv_t) -1;
-	}
-    }
-  strip (fromcode_conv, fromcode);
-  fromcode = (fromcode_conv[2] == '\0' && fromcode[0] != '\0'
-	      ? upstr (fromcode_conv, fromcode) : fromcode_conv);
-
   __gconv_t cd;
-  int res = __gconv_open (tocode, fromcode, &cd, 0);
+  struct gconv_spec conv_spec;
 
-  if (! fromcode_usealloca)
-    free (fromcode_conv);
-  if (! tocode_usealloca)
-    free (tocode_conv);
+  if (__gconv_create_spec (&conv_spec, fromcode, tocode) == NULL)
+    return (iconv_t) -1;
+
+  int res = __gconv_open (&conv_spec, &cd, 0);
+
+  __gconv_destroy_spec (&conv_spec);
 
   if (__builtin_expect (res, __GCONV_OK) != __GCONV_OK)
     {
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/iconv/iconv_prog.c b/google3/third_party/grte/v5_src/glibc-2.27/iconv/iconv_prog.c
index 52e9d3f..e26e9d0 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/iconv/iconv_prog.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/iconv/iconv_prog.c
@@ -39,6 +39,7 @@
 #include <gconv_int.h>
 #include "iconv_prog.h"
 #include "iconvconfig.h"
+#include "gconv_charset.h"
 
 /* Get libc version number.  */
 #include "../version.h"
@@ -118,8 +119,7 @@
 {
   int status = EXIT_SUCCESS;
   int remaining;
-  iconv_t cd;
-  const char *orig_to_code;
+  __gconv_t cd;
   struct charmap_t *from_charmap = NULL;
   struct charmap_t *to_charmap = NULL;
 
@@ -139,39 +139,6 @@
       exit (EXIT_SUCCESS);
     }
 
-  /* If we have to ignore errors make sure we use the appropriate name for
-     the to-character-set.  */
-  orig_to_code = to_code;
-  if (omit_invalid)
-    {
-      const char *errhand = strchrnul (to_code, '/');
-      int nslash = 2;
-      char *newp;
-      char *cp;
-
-      if (*errhand == '/')
-	{
-	  --nslash;
-	  errhand = strchrnul (errhand + 1, '/');
-
-	  if (*errhand == '/')
-	    {
-	      --nslash;
-	      errhand = strchr (errhand, '\0');
-	    }
-	}
-
-      newp = (char *) alloca (errhand - to_code + nslash + 7 + 1);
-      cp = mempcpy (newp, to_code, errhand - to_code);
-      while (nslash-- > 0)
-	*cp++ = '/';
-      if (cp[-1] != '/')
-	*cp++ = ',';
-      memcpy (cp, "IGNORE", sizeof ("IGNORE"));
-
-      to_code = newp;
-    }
-
   /* POSIX 1003.2b introduces a silly thing: the arguments to -t anf -f
      can be file names of charmaps.  In this case iconv will have to read
      those charmaps and use them to do the conversion.  But there are
@@ -184,10 +151,10 @@
        file.  */
     from_charmap = charmap_read (from_code, /*0, 1*/1, 0, 0, 0);
 
-  if (strchr (orig_to_code, '/') != NULL)
+  if (strchr (to_code, '/') != NULL)
     /* The to-name might be a charmap file name.  Try reading the
        file.  */
-    to_charmap = charmap_read (orig_to_code, /*0, 1,*/1, 0, 0, 0);
+    to_charmap = charmap_read (to_code, /*0, 1,*/1, 0, 0, 0);
 
 
   /* At this point we have to handle two cases.  The first one is
@@ -201,9 +168,25 @@
 				 argc, remaining, argv, output_file);
   else
     {
+      struct gconv_spec conv_spec;
+      int res;
+
+      if (__gconv_create_spec (&conv_spec, from_code, to_code) == NULL)
+        {
+          error (EXIT_FAILURE, errno,
+                 _("failed to start conversion processing"));
+          exit (1);
+        }
+
+      if (omit_invalid)
+        conv_spec.ignore = true;
+
       /* Let's see whether we have these coded character sets.  */
-      cd = iconv_open (to_code, from_code);
-      if (cd == (iconv_t) -1)
+      res = __gconv_open (&conv_spec, &cd, 0);
+
+      __gconv_destroy_spec (&conv_spec);
+
+      if (res != __GCONV_OK)
 	{
 	  if (errno == EINVAL)
 	    {
@@ -221,7 +204,7 @@
 	      const char *from_pretty =
 		(from_code[0] ? from_code : nl_langinfo (CODESET));
 	      const char *to_pretty =
-		(orig_to_code[0] ? orig_to_code : nl_langinfo (CODESET));
+		(to_code[0] ? to_code : nl_langinfo (CODESET));
 
 	      if (from_wrong)
 		{
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/iconv/tst-iconv-opt.c b/google3/third_party/grte/v5_src/glibc-2.27/iconv/tst-iconv-opt.c
new file mode 100644
index 0000000..669d812
--- /dev/null
+++ b/google3/third_party/grte/v5_src/glibc-2.27/iconv/tst-iconv-opt.c
@@ -0,0 +1,347 @@
+/* Test iconv's TRANSLIT and IGNORE option handling
+
+   Copyright (C) 2020 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+
+#include <iconv.h>
+#include <locale.h>
+#include <errno.h>
+#include <string.h>
+#include <support/support.h>
+#include <support/check.h>
+
+
+/* Run one iconv test.  Arguments:
+   to: destination character set and options
+   from: source character set
+   input: input string to be converted
+   exp_in: expected number of bytes consumed
+   exp_ret: expected return value (error or number of irreversible conversions)
+   exp_out: expected output string
+   exp_err: expected value of `errno' after iconv returns.  */
+static void
+test_iconv (const char *to, const char *from, char *input, size_t exp_in,
+            size_t exp_ret, const char *exp_out, int exp_err)
+{
+  iconv_t cd;
+  char outbuf[500];
+  size_t inlen, outlen;
+  char *inptr, *outptr;
+  size_t n;
+
+  cd = iconv_open (to, from);
+  TEST_VERIFY (cd != (iconv_t) -1);
+
+  inlen = strlen (input);
+  outlen = sizeof (outbuf);
+  inptr = input;
+  outptr = outbuf;
+
+  errno = 0;
+  n = iconv (cd, &inptr, &inlen, &outptr, &outlen);
+
+  TEST_COMPARE (n, exp_ret);
+  TEST_VERIFY (inptr == input + exp_in);
+  TEST_COMPARE (errno, exp_err);
+  TEST_COMPARE_BLOB (outbuf, outptr - outbuf, exp_out, strlen (exp_out));
+  TEST_VERIFY (iconv_close (cd) == 0);
+}
+
+
+/* We test option parsing by converting UTF-8 inputs to ASCII under various
+   option combinations. The UTF-8 inputs fall into three categories:
+   - ASCII-only,
+   - non-ASCII,
+   - non-ASCII with invalid UTF-8 characters.  */
+
+/* 1.  */
+char ascii[] = "Just some ASCII text";
+
+/* 2. Valid UTF-8 input and some corresponding expected outputs with various
+   options.  The two non-ASCII characters below are accented alphabets:
+   an `a' then an `o'.  */
+char utf8[] = "UTF-8 text with \u00E1 couple \u00F3f non-ASCII characters";
+char u2a[] = "UTF-8 text with ";
+char u2a_translit[] = "UTF-8 text with a couple of non-ASCII characters";
+char u2a_ignore[] = "UTF-8 text with  couple f non-ASCII characters";
+
+/* 3. Invalid UTF-8 input and some corresponding expected outputs.  \xff is
+   invalid UTF-8. It's followed by some valid but non-ASCII UTF-8.  */
+char iutf8[] = "Invalid UTF-8 \xff\u27E6text\u27E7";
+char iu2a[] = "Invalid UTF-8 ";
+char iu2a_ignore[] = "Invalid UTF-8 text";
+char iu2a_both[] = "Invalid UTF-8 [|text|]";
+
+/* 4. Another invalid UTF-8 input and corresponding expected outputs. This time
+   the valid non-ASCII UTF-8 characters appear before the invalid \xff.  */
+char jutf8[] = "Invalid \u27E6UTF-8\u27E7 \xfftext";
+char ju2a[] = "Invalid ";
+char ju2a_translit[] = "Invalid [|UTF-8|] ";
+char ju2a_ignore[] = "Invalid UTF-8 text";
+char ju2a_both[] = "Invalid [|UTF-8|] text";
+
+/* We also test option handling for character set names that have the form
+   "A/B".  In this test, we test conversions "ISO-10646/UTF-8", and either
+   ISO-8859-1 or ASCII.  */
+
+/* 5. Accented 'A' and 'a' characters in ISO-8859-1 and UTF-8, and an
+   equivalent ASCII transliteration.  */
+char iso8859_1_a[] = {0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, /* Accented A's.  */
+                      0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, /* Accented a's.  */
+                      0x00};
+char utf8_a[] = "\u00C0\u00C1\u00C2\u00C3\u00C4\u00C5"
+                "\u00E0\u00E1\u00E2\u00E3\u00E4\u00E5";
+char ascii_a[] = "AAAAAAaaaaaa";
+
+/* 6. An invalid ASCII string where [0] is invalid and [1] is '~'.  */
+char iascii [] = {0x80, '~', '\0'};
+char empty[] = "";
+char ia2u_ignore[] = "~";
+
+static int
+do_test (void)
+{
+  xsetlocale (LC_ALL, "en_US.UTF-8");
+
+
+  /* 0. iconv_open should gracefully fail for invalid character sets.  */
+
+  TEST_VERIFY (iconv_open ("INVALID", "UTF-8") == (iconv_t) -1);
+  TEST_VERIFY (iconv_open ("UTF-8", "INVALID") == (iconv_t) -1);
+  TEST_VERIFY (iconv_open ("INVALID", "INVALID") == (iconv_t) -1);
+
+
+  /* 1. ASCII-only UTF-8 input should convert to ASCII with no changes:  */
+
+  test_iconv ("ASCII", "UTF-8", ascii, strlen (ascii), 0, ascii, 0);
+  test_iconv ("ASCII//", "UTF-8", ascii, strlen (ascii), 0, ascii, 0);
+  test_iconv ("ASCII//TRANSLIT", "UTF-8", ascii, strlen (ascii), 0, ascii, 0);
+  test_iconv ("ASCII//TRANSLIT//", "UTF-8", ascii, strlen (ascii), 0, ascii,
+              0);
+  test_iconv ("ASCII//IGNORE", "UTF-8", ascii, strlen (ascii), 0, ascii, 0);
+  test_iconv ("ASCII//IGNORE//", "UTF-8", ascii, strlen (ascii), 0, ascii, 0);
+
+
+  /* 2. Valid UTF-8 input with non-ASCII characters:  */
+
+  /* EILSEQ when converted to ASCII.  */
+  test_iconv ("ASCII", "UTF-8", utf8, strlen (u2a), (size_t) -1, u2a, EILSEQ);
+
+  /* Converted without error with TRANSLIT enabled.  */
+  test_iconv ("ASCII//TRANSLIT", "UTF-8", utf8, strlen (utf8), 2, u2a_translit,
+              0);
+
+  /* EILSEQ with IGNORE enabled.  Non-ASCII chars dropped from output.  */
+  test_iconv ("ASCII//IGNORE", "UTF-8", utf8, strlen (utf8), (size_t) -1,
+              u2a_ignore, EILSEQ);
+
+  /* With TRANSLIT and IGNORE enabled, transliterated without error.  We test
+     four combinations.  */
+
+  test_iconv ("ASCII//TRANSLIT,IGNORE", "UTF-8", utf8, strlen (utf8), 2,
+              u2a_translit, 0);
+  test_iconv ("ASCII//TRANSLIT//IGNORE", "UTF-8", utf8, strlen (utf8), 2,
+              u2a_translit, 0);
+  test_iconv ("ASCII//IGNORE,TRANSLIT", "UTF-8", utf8, strlen (utf8), 2,
+              u2a_translit, 0);
+  /* Due to bug 19519, iconv was ignoring TRANSLIT for the following input.  */
+  test_iconv ("ASCII//IGNORE//TRANSLIT", "UTF-8", utf8, strlen (utf8), 2,
+              u2a_translit, 0);
+
+  /* Misspellings of TRANSLIT and IGNORE are ignored, but conversion still
+     works while respecting any other correctly spelled options.  */
+
+  test_iconv ("ASCII//T", "UTF-8", utf8, strlen (u2a), (size_t) -1, u2a,
+              EILSEQ);
+  test_iconv ("ASCII//TRANSLITERATE", "UTF-8", utf8, strlen (u2a), (size_t) -1,
+              u2a, EILSEQ);
+  test_iconv ("ASCII//I", "UTF-8", utf8, strlen (u2a), (size_t) -1, u2a,
+              EILSEQ);
+  test_iconv ("ASCII//IGNORED", "UTF-8", utf8, strlen (u2a), (size_t) -1, u2a,
+              EILSEQ);
+  test_iconv ("ASCII//TRANSLITERATE//IGNORED", "UTF-8", utf8, strlen (u2a),
+              (size_t) -1, u2a, EILSEQ);
+  test_iconv ("ASCII//IGNORED,TRANSLITERATE", "UTF-8", utf8, strlen (u2a),
+              (size_t) -1, u2a, EILSEQ);
+  test_iconv ("ASCII//T//I", "UTF-8", utf8, strlen (u2a), (size_t) -1, u2a,
+              EILSEQ);
+
+  test_iconv ("ASCII//TRANSLIT//I", "UTF-8", utf8, strlen (utf8), 2,
+              u2a_translit, 0);
+  /* Due to bug 19519, iconv was ignoring TRANSLIT for the following input.  */
+  test_iconv ("ASCII//I//TRANSLIT", "UTF-8", utf8, strlen (utf8), 2,
+              u2a_translit, 0);
+  test_iconv ("ASCII//IGNORED,TRANSLIT", "UTF-8", utf8, strlen (utf8), 2,
+              u2a_translit, 0);
+  test_iconv ("ASCII//TRANSLIT,IGNORED", "UTF-8", utf8, strlen (utf8), 2,
+              u2a_translit, 0);
+
+  test_iconv ("ASCII//IGNORE,T", "UTF-8", utf8, strlen (utf8), (size_t) -1,
+              u2a_ignore, EILSEQ);
+  test_iconv ("ASCII//T,IGNORE", "UTF-8", utf8, strlen (utf8), (size_t) -1,
+              u2a_ignore, EILSEQ);
+  /* Due to bug 19519, iconv was ignoring IGNORE for the following input.  */
+  test_iconv ("ASCII//TRANSLITERATE//IGNORE", "UTF-8", utf8, strlen (utf8),
+              (size_t) -1, u2a_ignore, EILSEQ);
+  test_iconv ("ASCII//IGNORE//TRANSLITERATE", "UTF-8", utf8, strlen (utf8),
+              (size_t) -1, u2a_ignore, EILSEQ);
+
+
+  /* 3. Invalid UTF-8 followed by some valid non-ASCII UTF-8 characters:  */
+
+  /* EILSEQ; output is truncated at the first invalid UTF-8 character.  */
+  test_iconv ("ASCII", "UTF-8", iutf8, strlen (iu2a), (size_t) -1, iu2a,
+              EILSEQ);
+
+  /* With TRANSLIT enabled: EILSEQ; output still truncated at the first invalid
+     UTF-8 character.  */
+  test_iconv ("ASCII//TRANSLIT", "UTF-8", iutf8, strlen (iu2a), (size_t) -1,
+              iu2a, EILSEQ);
+
+  /* With IGNORE enabled: EILSEQ; output omits invalid UTF-8 characters and
+     valid UTF-8 non-ASCII characters.  */
+  test_iconv ("ASCII//IGNORE", "UTF-8", iutf8, strlen (iutf8), (size_t) -1,
+              iu2a_ignore, EILSEQ);
+
+  /* With TRANSLIT and IGNORE enabled, output omits only invalid UTF-8
+     characters and transliterates valid non-ASCII UTF-8 characters.  We test
+     four combinations.  */
+
+  test_iconv ("ASCII//TRANSLIT,IGNORE", "UTF-8", iutf8, strlen (iutf8), 2,
+              iu2a_both, 0);
+  /* Due to bug 19519, iconv was ignoring IGNORE for the following input.  */
+  test_iconv ("ASCII//TRANSLIT//IGNORE", "UTF-8", iutf8, strlen (iutf8), 2,
+              iu2a_both, 0);
+  test_iconv ("ASCII//IGNORE,TRANSLIT", "UTF-8", iutf8, strlen (iutf8), 2,
+              iu2a_both, 0);
+  /* Due to bug 19519, iconv was ignoring TRANSLIT for the following input.  */
+  test_iconv ("ASCII//IGNORE//TRANSLIT", "UTF-8", iutf8, strlen (iutf8), 2,
+              iu2a_both, 0);
+
+
+  /* 4. Invalid UTF-8 with valid non-ASCII UTF-8 chars appearing first:  */
+
+  /* EILSEQ; output is truncated at the first non-ASCII character.  */
+  test_iconv ("ASCII", "UTF-8", jutf8, strlen (ju2a), (size_t) -1, ju2a,
+              EILSEQ);
+
+  /* With TRANSLIT enabled: EILSEQ; output now truncated at the first invalid
+     UTF-8 character.  */
+  test_iconv ("ASCII//TRANSLIT", "UTF-8", jutf8, strlen (jutf8) - 5,
+              (size_t) -1, ju2a_translit, EILSEQ);
+  test_iconv ("ASCII//translit", "UTF-8", jutf8, strlen (jutf8) - 5,
+              (size_t) -1, ju2a_translit, EILSEQ);
+
+  /* With IGNORE enabled: EILSEQ; output omits invalid UTF-8 characters and
+     valid UTF-8 non-ASCII characters.  */
+  test_iconv ("ASCII//IGNORE", "UTF-8", jutf8, strlen (jutf8), (size_t) -1,
+              ju2a_ignore, EILSEQ);
+  test_iconv ("ASCII//ignore", "UTF-8", jutf8, strlen (jutf8), (size_t) -1,
+              ju2a_ignore, EILSEQ);
+
+  /* With TRANSLIT and IGNORE enabled, output omits only invalid UTF-8
+     characters and transliterates valid non-ASCII UTF-8 characters.  We test
+     several combinations.  */
+
+  test_iconv ("ASCII//TRANSLIT,IGNORE", "UTF-8", jutf8, strlen (jutf8), 2,
+              ju2a_both, 0);
+  /* Due to bug 19519, iconv was ignoring IGNORE for the following input.  */
+  test_iconv ("ASCII//TRANSLIT//IGNORE", "UTF-8", jutf8, strlen (jutf8), 2,
+              ju2a_both, 0);
+  test_iconv ("ASCII//IGNORE,TRANSLIT", "UTF-8", jutf8, strlen (jutf8), 2,
+              ju2a_both, 0);
+  /* Due to bug 19519, iconv was ignoring TRANSLIT for the following input.  */
+  test_iconv ("ASCII//IGNORE//TRANSLIT", "UTF-8", jutf8, strlen (jutf8), 2,
+              ju2a_both, 0);
+  test_iconv ("ASCII//translit,ignore", "UTF-8", jutf8, strlen (jutf8), 2,
+              ju2a_both, 0);
+  /* Trailing whitespace and separators should be ignored.  */
+  test_iconv ("ASCII//IGNORE,TRANSLIT ", "UTF-8", jutf8, strlen (jutf8), 2,
+              ju2a_both, 0);
+  test_iconv ("ASCII//IGNORE,TRANSLIT/", "UTF-8", jutf8, strlen (jutf8), 2,
+              ju2a_both, 0);
+  test_iconv ("ASCII//IGNORE,TRANSLIT//", "UTF-8", jutf8, strlen (jutf8), 2,
+              ju2a_both, 0);
+  test_iconv ("ASCII//IGNORE,TRANSLIT,", "UTF-8", jutf8, strlen (jutf8), 2,
+              ju2a_both, 0);
+  test_iconv ("ASCII//IGNORE,TRANSLIT,,", "UTF-8", jutf8, strlen (jutf8), 2,
+              ju2a_both, 0);
+  test_iconv ("ASCII//IGNORE,TRANSLIT /,", "UTF-8", jutf8, strlen (jutf8), 2,
+              ju2a_both, 0);
+
+  /* TRANSLIT or IGNORE suffixes in fromcode should be ignored.  */
+  test_iconv ("ASCII", "UTF-8//TRANSLIT", jutf8, strlen (ju2a), (size_t) -1,
+              ju2a, EILSEQ);
+  test_iconv ("ASCII", "UTF-8//IGNORE", jutf8, strlen (ju2a), (size_t) -1,
+              ju2a, EILSEQ);
+  test_iconv ("ASCII", "UTF-8//TRANSLIT,IGNORE", jutf8, strlen (ju2a),
+              (size_t) -1, ju2a, EILSEQ);
+
+
+  /* 5. Charset names of the form "A/B/":  */
+
+  /* ISO-8859-1 is converted to UTF-8 without needing transliteration.  */
+  test_iconv ("ISO-10646/UTF-8", "ISO-8859-1", iso8859_1_a,
+              strlen (iso8859_1_a), 0, utf8_a, 0);
+  test_iconv ("ISO-10646/UTF-8/", "ISO-8859-1", iso8859_1_a,
+              strlen (iso8859_1_a), 0, utf8_a, 0);
+  test_iconv ("ISO-10646/UTF-8/IGNORE", "ISO-8859-1", iso8859_1_a,
+              strlen (iso8859_1_a), 0, utf8_a, 0);
+  test_iconv ("ISO-10646/UTF-8//IGNORE", "ISO-8859-1", iso8859_1_a,
+              strlen (iso8859_1_a), 0, utf8_a, 0);
+  test_iconv ("ISO-10646/UTF-8/TRANSLIT", "ISO-8859-1", iso8859_1_a,
+              strlen (iso8859_1_a), 0, utf8_a, 0);
+  test_iconv ("ISO-10646/UTF-8//TRANSLIT", "ISO-8859-1", iso8859_1_a,
+              strlen (iso8859_1_a), 0, utf8_a, 0);
+  test_iconv ("ISO-10646/UTF-8//TRANSLIT/IGNORE", "ISO-8859-1", iso8859_1_a,
+              strlen (iso8859_1_a), 0, utf8_a, 0);
+  test_iconv ("ISO-10646/UTF-8//TRANSLIT//IGNORE", "ISO-8859-1", iso8859_1_a,
+              strlen (iso8859_1_a), 0, utf8_a, 0);
+  test_iconv ("ISO-10646/UTF-8/TRANSLIT,IGNORE", "ISO-8859-1", iso8859_1_a,
+              strlen (iso8859_1_a), 0, utf8_a, 0);
+
+  /* UTF-8 with accented A's is converted to ASCII with transliteration.  */
+  test_iconv ("ASCII", "ISO-10646/UTF-8", utf8_a,
+              0, (size_t) -1, empty, EILSEQ);
+  test_iconv ("ASCII//IGNORE", "ISO-10646/UTF-8", utf8_a,
+              strlen (utf8_a), (size_t) -1, empty, EILSEQ);
+  test_iconv ("ASCII//TRANSLIT", "ISO-10646/UTF-8", utf8_a,
+              strlen (utf8_a), 12, ascii_a, 0);
+
+  /* Invalid ASCII is converted to UTF-8 only with IGNORE.  */
+  test_iconv ("ISO-10646/UTF-8", "ASCII", iascii, strlen (empty), (size_t) -1,
+              empty, EILSEQ);
+  test_iconv ("ISO-10646/UTF-8/TRANSLIT", "ASCII", iascii, strlen (empty),
+              (size_t) -1, empty, EILSEQ);
+  test_iconv ("ISO-10646/UTF-8/IGNORE", "ASCII", iascii, strlen (iascii),
+              (size_t) -1, ia2u_ignore, EILSEQ);
+  test_iconv ("ISO-10646/UTF-8/TRANSLIT,IGNORE", "ASCII", iascii,
+              strlen (iascii), (size_t) -1, ia2u_ignore, EILSEQ);
+  /* Due to bug 19519, iconv was ignoring IGNORE for the following three
+     inputs: */
+  test_iconv ("ISO-10646/UTF-8/TRANSLIT/IGNORE", "ASCII", iascii,
+              strlen (iascii), (size_t) -1, ia2u_ignore, EILSEQ);
+  test_iconv ("ISO-10646/UTF-8//TRANSLIT,IGNORE", "ASCII", iascii,
+              strlen (iascii), (size_t) -1, ia2u_ignore, EILSEQ);
+  test_iconv ("ISO-10646/UTF-8//TRANSLIT//IGNORE", "ASCII", iascii,
+              strlen (iascii), (size_t) -1, ia2u_ignore, EILSEQ);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/iconv/tst-iconv8.c b/google3/third_party/grte/v5_src/glibc-2.27/iconv/tst-iconv8.c
new file mode 100644
index 0000000..0b92b19
--- /dev/null
+++ b/google3/third_party/grte/v5_src/glibc-2.27/iconv/tst-iconv8.c
@@ -0,0 +1,50 @@
+/* Test iconv behavior on UCS4 conversions with //IGNORE.
+   Copyright (C) 2020 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Derived from BZ #26923 */
+#include <errno.h>
+#include <iconv.h>
+#include <stdio.h>
+#include <support/check.h>
+
+static int
+do_test (void)
+{
+  iconv_t cd = iconv_open ("UTF-8//IGNORE", "ISO-10646/UCS4/");
+  TEST_VERIFY_EXIT (cd != (iconv_t) -1);
+
+  /*
+   * Convert sequence beginning with an irreversible character into buffer that
+   * is too small.
+   */
+  char input[12] = "\xe1\x80\xa1" "AAAAAAAAA";
+  char *inptr = input;
+  size_t insize = sizeof (input);
+  char output[6];
+  char *outptr = output;
+  size_t outsize = sizeof (output);
+
+  TEST_VERIFY (iconv (cd, &inptr, &insize, &outptr, &outsize) == -1);
+  TEST_VERIFY (errno == E2BIG);
+
+  TEST_VERIFY_EXIT (iconv_close (cd) != -1);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/iconv/tst-iconv_prog.sh b/google3/third_party/grte/v5_src/glibc-2.27/iconv/tst-iconv_prog.sh
new file mode 100644
index 0000000..8298136
--- /dev/null
+++ b/google3/third_party/grte/v5_src/glibc-2.27/iconv/tst-iconv_prog.sh
@@ -0,0 +1,280 @@
+#!/bin/bash
+# Test for some known iconv(1) hangs from bug 19519, and miscellaneous
+# iconv(1) program error conditions.
+# Copyright (C) 2020 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+
+# The GNU C Library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+
+# The GNU C Library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public
+# License along with the GNU C Library; if not, see
+# <https://www.gnu.org/licenses/>.
+
+codir=$1
+test_wrapper_env="$2"
+run_program_env="$3"
+
+# We have to have some directories in the library path.
+LIBPATH=$codir:$codir/iconvdata
+
+# How the start the iconv(1) program.  $from is not defined/expanded yet.
+ICONV='
+$codir/elf/ld.so --library-path $LIBPATH --inhibit-rpath ${from}.so
+$codir/iconv/iconv_prog
+'
+ICONV="$test_wrapper_env $run_program_env $ICONV"
+
+# List of known hangs;
+# Gathered by running an exhaustive 2 byte input search against glibc-2.28
+hangarray=(
+"\x00\x23;-c;ANSI_X3.110;UTF-8//TRANSLIT//IGNORE"
+"\x00\xa1;-c;ARMSCII-8;UTF-8//TRANSLIT//IGNORE"
+"\x00\xa1;-c;ASMO_449;UTF-8//TRANSLIT//IGNORE"
+"\x00\x81;-c;BIG5;UTF-8//TRANSLIT//IGNORE"
+"\x00\xff;-c;BIG5HKSCS;UTF-8//TRANSLIT//IGNORE"
+"\x00\xff;-c;BRF;UTF-8//TRANSLIT//IGNORE"
+"\x00\xff;-c;BS_4730;UTF-8//TRANSLIT//IGNORE"
+"\x00\x81;-c;CP1250;UTF-8//TRANSLIT//IGNORE"
+"\x00\x98;-c;CP1251;UTF-8//TRANSLIT//IGNORE"
+"\x00\x81;-c;CP1252;UTF-8//TRANSLIT//IGNORE"
+"\x00\x81;-c;CP1253;UTF-8//TRANSLIT//IGNORE"
+"\x00\x81;-c;CP1254;UTF-8//TRANSLIT//IGNORE"
+"\x00\x81;-c;CP1255;UTF-8//TRANSLIT//IGNORE"
+"\x00\x81;-c;CP1257;UTF-8//TRANSLIT//IGNORE"
+"\x00\x81;-c;CP1258;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;CP932;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;CSA_Z243.4-1985-1;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;CSA_Z243.4-1985-2;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;DEC-MCS;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;DIN_66003;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;DS_2089;UTF-8//TRANSLIT//IGNORE"
+"\x00\x41;-c;EBCDIC-AT-DE;UTF-8//TRANSLIT//IGNORE"
+"\x00\x41;-c;EBCDIC-AT-DE-A;UTF-8//TRANSLIT//IGNORE"
+"\x00\x41;-c;EBCDIC-CA-FR;UTF-8//TRANSLIT//IGNORE"
+"\x00\x41;-c;EBCDIC-DK-NO;UTF-8//TRANSLIT//IGNORE"
+"\x00\x41;-c;EBCDIC-DK-NO-A;UTF-8//TRANSLIT//IGNORE"
+"\x00\x41;-c;EBCDIC-ES;UTF-8//TRANSLIT//IGNORE"
+"\x00\x41;-c;EBCDIC-ES-A;UTF-8//TRANSLIT//IGNORE"
+"\x00\x41;-c;EBCDIC-ES-S;UTF-8//TRANSLIT//IGNORE"
+"\x00\x41;-c;EBCDIC-FI-SE;UTF-8//TRANSLIT//IGNORE"
+"\x00\x41;-c;EBCDIC-FI-SE-A;UTF-8//TRANSLIT//IGNORE"
+"\x00\x41;-c;EBCDIC-FR;UTF-8//TRANSLIT//IGNORE"
+"\x00\x41;-c;EBCDIC-IS-FRISS;UTF-8//TRANSLIT//IGNORE"
+"\x00\x41;-c;EBCDIC-IT;UTF-8//TRANSLIT//IGNORE"
+"\x00\x41;-c;EBCDIC-PT;UTF-8//TRANSLIT//IGNORE"
+"\x00\x41;-c;EBCDIC-UK;UTF-8//TRANSLIT//IGNORE"
+"\x00\x41;-c;EBCDIC-US;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;ES;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;ES2;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;EUC-CN;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;EUC-JISX0213;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;EUC-JP;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;EUC-JP-MS;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;EUC-KR;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;EUC-TW;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;GB18030;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;GB_1988-80;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;GBK;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;GOST_19768-74;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;GREEK7;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;GREEK7-OLD;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;GREEK-CCITT;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;HP-GREEK8;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;HP-ROMAN8;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;HP-ROMAN9;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;HP-THAI8;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;HP-TURKISH8;UTF-8//TRANSLIT//IGNORE"
+"\x00\x41;-c;IBM038;UTF-8//TRANSLIT//IGNORE"
+"\x00\x80;-c;IBM1004;UTF-8//TRANSLIT//IGNORE"
+"\x00\xff;-c;IBM1008;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;IBM1046;UTF-8//TRANSLIT//IGNORE"
+"\x00\x51;-c;IBM1132;UTF-8//TRANSLIT//IGNORE"
+"\x00\xa0;-c;IBM1133;UTF-8//TRANSLIT//IGNORE"
+"\x00\xce;-c;IBM1137;UTF-8//TRANSLIT//IGNORE"
+"\x00\x80;-c;IBM1161;UTF-8//TRANSLIT//IGNORE"
+"\x00\xdb;-c;IBM1162;UTF-8//TRANSLIT//IGNORE"
+"\x00\x70;-c;IBM12712;UTF-8//TRANSLIT//IGNORE"
+# These are known hangs that are yet to be fixed:
+# "\x00\x0f;-c;IBM1364;UTF-8"
+# "\x00\x0f;-c;IBM1371;UTF-8"
+# "\x00\x0f;-c;IBM1388;UTF-8"
+# "\x00\x0f;-c;IBM1390;UTF-8"
+# "\x00\x0f;-c;IBM1399;UTF-8"
+"\x00\x53;-c;IBM16804;UTF-8//TRANSLIT//IGNORE"
+"\x00\x41;-c;IBM274;UTF-8//TRANSLIT//IGNORE"
+"\x00\x41;-c;IBM275;UTF-8//TRANSLIT//IGNORE"
+"\x00\x41;-c;IBM281;UTF-8//TRANSLIT//IGNORE"
+"\x00\x57;-c;IBM290;UTF-8//TRANSLIT//IGNORE"
+"\x00\x45;-c;IBM420;UTF-8//TRANSLIT//IGNORE"
+"\x00\x68;-c;IBM423;UTF-8//TRANSLIT//IGNORE"
+"\x00\x70;-c;IBM424;UTF-8//TRANSLIT//IGNORE"
+"\x00\x53;-c;IBM4517;UTF-8//TRANSLIT//IGNORE"
+"\x00\x53;-c;IBM4899;UTF-8//TRANSLIT//IGNORE"
+"\x00\xa5;-c;IBM4909;UTF-8//TRANSLIT//IGNORE"
+"\x00\xdc;-c;IBM4971;UTF-8//TRANSLIT//IGNORE"
+"\x00\x41;-c;IBM803;UTF-8//TRANSLIT//IGNORE"
+"\x00\x91;-c;IBM851;UTF-8//TRANSLIT//IGNORE"
+"\x00\x9b;-c;IBM856;UTF-8//TRANSLIT//IGNORE"
+"\x00\xd5;-c;IBM857;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;IBM864;UTF-8//TRANSLIT//IGNORE"
+"\x00\x94;-c;IBM868;UTF-8//TRANSLIT//IGNORE"
+"\x00\x94;-c;IBM869;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;IBM874;UTF-8//TRANSLIT//IGNORE"
+"\x00\x6a;-c;IBM875;UTF-8//TRANSLIT//IGNORE"
+"\x00\x41;-c;IBM880;UTF-8//TRANSLIT//IGNORE"
+"\x00\x80;-c;IBM891;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;IBM903;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;IBM904;UTF-8//TRANSLIT//IGNORE"
+"\x00\x41;-c;IBM905;UTF-8//TRANSLIT//IGNORE"
+"\x00\x80;-c;IBM9066;UTF-8//TRANSLIT//IGNORE"
+"\x00\x48;-c;IBM918;UTF-8//TRANSLIT//IGNORE"
+"\x00\x57;-c;IBM930;UTF-8//TRANSLIT//IGNORE"
+"\x00\x80;-c;IBM932;UTF-8//TRANSLIT//IGNORE"
+"\x00\x41;-c;IBM933;UTF-8//TRANSLIT//IGNORE"
+"\x00\x41;-c;IBM935;UTF-8//TRANSLIT//IGNORE"
+"\x00\x41;-c;IBM937;UTF-8//TRANSLIT//IGNORE"
+"\x00\x41;-c;IBM939;UTF-8//TRANSLIT//IGNORE"
+"\x00\x80;-c;IBM943;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;INIS;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;INIS-8;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;INIS-CYRILLIC;UTF-8//TRANSLIT//IGNORE"
+"\x00\xec;-c;ISIRI-3342;UTF-8//TRANSLIT//IGNORE"
+"\x00\xec;-c;ISO_10367-BOX;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;ISO-2022-CN;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;ISO-2022-CN-EXT;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;ISO-2022-JP;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;ISO-2022-JP-2;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;ISO-2022-JP-3;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;ISO-2022-KR;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;ISO_2033;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;ISO_5427;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;ISO_5427-EXT;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;ISO_5428;UTF-8//TRANSLIT//IGNORE"
+"\x00\xa4;-c;ISO_6937;UTF-8//TRANSLIT//IGNORE"
+"\x00\xa0;-c;ISO_6937-2;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;ISO-8859-11;UTF-8//TRANSLIT//IGNORE"
+"\x00\xa5;-c;ISO-8859-3;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;ISO-8859-6;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;ISO-8859-7;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;ISO-8859-8;UTF-8//TRANSLIT//IGNORE"
+"\x00\x80;-c;ISO-IR-197;UTF-8//TRANSLIT//IGNORE"
+"\x00\x80;-c;ISO-IR-209;UTF-8//TRANSLIT//IGNORE"
+"\x00\x80;-c;IT;UTF-8//TRANSLIT//IGNORE"
+"\x00\x80;-c;JIS_C6220-1969-RO;UTF-8//TRANSLIT//IGNORE"
+"\x00\x80;-c;JIS_C6229-1984-B;UTF-8//TRANSLIT//IGNORE"
+"\x00\x80;-c;JOHAB;UTF-8//TRANSLIT//IGNORE"
+"\x00\x80;-c;JUS_I.B1.002;UTF-8//TRANSLIT//IGNORE"
+"\x00\x80;-c;KOI-8;UTF-8//TRANSLIT//IGNORE"
+"\x00\x88;-c;KOI8-T;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;KSC5636;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;LATIN-GREEK;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;LATIN-GREEK-1;UTF-8//TRANSLIT//IGNORE"
+"\x00\xf6;-c;MAC-IS;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;MSZ_7795.3;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;NATS-DANO;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;NATS-SEFI;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;NC_NC00-10;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;NF_Z_62-010;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;NF_Z_62-010_1973;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;NS_4551-1;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;NS_4551-2;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;PT;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;PT2;UTF-8//TRANSLIT//IGNORE"
+"\x00\x98;-c;RK1048;UTF-8//TRANSLIT//IGNORE"
+"\x00\x98;-c;SEN_850200_B;UTF-8//TRANSLIT//IGNORE"
+"\x00\x98;-c;SEN_850200_C;UTF-8//TRANSLIT//IGNORE"
+"\x00\x80;-c;Shift_JISX0213;UTF-8//TRANSLIT//IGNORE"
+"\x00\x80;-c;SJIS;UTF-8//TRANSLIT//IGNORE"
+"\x00\x23;-c;T.61-8BIT;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;TIS-620;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;TSCII;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;UHC;UTF-8//TRANSLIT//IGNORE"
+"\x00\xd8;-c;UNICODE;UTF-8//TRANSLIT//IGNORE"
+"\x00\xdc;-c;UTF-16;UTF-8//TRANSLIT//IGNORE"
+"\xdc\x00;-c;UTF-16BE;UTF-8//TRANSLIT//IGNORE"
+"\x00\xdc;-c;UTF-16LE;UTF-8//TRANSLIT//IGNORE"
+"\xff\xff;-c;UTF-7;UTF-8//TRANSLIT//IGNORE"
+"\x00\x81;-c;WIN-SAMI-2;UTF-8//TRANSLIT//IGNORE"
+)
+
+# List of option combinations that *should* lead to an error
+errorarray=(
+# Converting from/to invalid character sets should cause error
+"\x00\x00;;INVALID;INVALID"
+"\x00\x00;;INVALID;UTF-8"
+"\x00\x00;;UTF-8;INVALID"
+)
+
+# Requires $twobyte input, $c flag, $from, and $to to be set; sets $ret
+execute_test ()
+{
+  eval PROG=\"$ICONV\"
+  echo -en "$twobyte" \
+    | timeout -k 4 3 $PROG $c -f $from -t "$to" &>/dev/null
+  ret=$?
+}
+
+check_hangtest_result ()
+{
+  if [ "$ret" -eq "124" ] || [ "$ret" -eq "137" ]; then # timeout/hang
+    result="HANG"
+  else
+    if [ "$ret" -eq "139" ]; then # segfault
+      result="SEGFAULT"
+    else
+      if [ "$ret" -gt "127" ]; then # unexpected error
+        result="UNEXPECTED"
+      else
+        result="OK"
+      fi
+    fi
+  fi
+
+  echo -n "$result: from: \"$from\", to: \"$to\","
+  echo    " input \"$twobyte\", flags \"$c\""
+
+  if [ "$result" != "OK" ]; then
+    exit 1
+  fi
+}
+
+for hangcommand in "${hangarray[@]}"; do
+  twobyte="$(echo "$hangcommand" | cut -d";" -f 1)"
+  c="$(echo "$hangcommand" | cut -d";" -f 2)"
+  from="$(echo "$hangcommand" | cut -d";" -f 3)"
+  to="$(echo "$hangcommand" | cut -d";" -f 4)"
+  execute_test
+  check_hangtest_result
+done
+
+check_errtest_result ()
+{
+  if [ "$ret" -eq "1" ]; then # we errored out as expected
+    result="PASS"
+  else
+    result="FAIL"
+  fi
+  echo -n "$result: from: \"$from\", to: \"$to\","
+  echo    " input \"$twobyte\", flags \"$c\", return code $ret"
+
+  if [ "$result" != "PASS" ]; then
+    exit 1
+  fi
+}
+
+for errorcommand in "${errorarray[@]}"; do
+  twobyte="$(echo "$errorcommand" | cut -d";" -f 1)"
+  c="$(echo "$errorcommand" | cut -d";" -f 2)"
+  from="$(echo "$errorcommand" | cut -d";" -f 3)"
+  to="$(echo "$errorcommand" | cut -d";" -f 4)"
+  execute_test
+  check_errtest_result
+done
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/iconvdata/Makefile b/google3/third_party/grte/v5_src/glibc-2.27/iconvdata/Makefile
index 06e161d..7951f56 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/iconvdata/Makefile
+++ b/google3/third_party/grte/v5_src/glibc-2.27/iconvdata/Makefile
@@ -73,7 +73,8 @@
 ifeq (yes,$(build-shared))
 tests = bug-iconv1 bug-iconv2 tst-loading tst-e2big tst-iconv4 bug-iconv4 \
 	tst-iconv6 bug-iconv5 bug-iconv6 tst-iconv7 bug-iconv8 bug-iconv9 \
-	bug-iconv10 bug-iconv11 bug-iconv12
+	bug-iconv10 bug-iconv11 bug-iconv12 \
+	bug-iconv13 bug-iconv14
 ifeq ($(have-thread-library),yes)
 tests += bug-iconv3
 endif
@@ -316,6 +317,8 @@
 			  $(addprefix $(objpfx),$(modules.so))
 $(objpfx)bug-iconv12.out: $(objpfx)gconv-modules \
 			  $(addprefix $(objpfx),$(modules.so))
+$(objpfx)bug-iconv14.out: $(objpfx)gconv-modules \
+			  $(addprefix $(objpfx),$(modules.so))
 
 $(objpfx)iconv-test.out: run-iconv-test.sh $(objpfx)gconv-modules \
 			 $(addprefix $(objpfx),$(modules.so)) \
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/iconvdata/bug-iconv13.c b/google3/third_party/grte/v5_src/glibc-2.27/iconvdata/bug-iconv13.c
new file mode 100644
index 0000000..87aaff3
--- /dev/null
+++ b/google3/third_party/grte/v5_src/glibc-2.27/iconvdata/bug-iconv13.c
@@ -0,0 +1,53 @@
+/* bug 24973: Test EUC-KR module
+   Copyright (C) 2020 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <iconv.h>
+#include <stdio.h>
+#include <support/check.h>
+
+static int
+do_test (void)
+{
+  iconv_t cd = iconv_open ("UTF-8//IGNORE", "EUC-KR");
+  TEST_VERIFY_EXIT (cd != (iconv_t) -1);
+
+  /* 0xfe (->0x7e : row 94) and 0xc9 (->0x49 : row 41) are user-defined
+     areas, which are not allowed and should be skipped over due to
+     //IGNORE.  The trailing 0xfe also is an incomplete sequence, which
+     should be checked first.  */
+  char input[4] = { '\xc9', '\xa1', '\0', '\xfe' };
+  char *inptr = input;
+  size_t insize = sizeof (input);
+  char output[4];
+  char *outptr = output;
+  size_t outsize = sizeof (output);
+
+  /* This used to crash due to buffer overrun.  */
+  TEST_VERIFY (iconv (cd, &inptr, &insize, &outptr, &outsize) == (size_t) -1);
+  TEST_VERIFY (errno == EINVAL);
+  /* The conversion should produce one character, the converted null
+     character.  */
+  TEST_VERIFY (sizeof (output) - outsize == 1);
+
+  TEST_VERIFY_EXIT (iconv_close (cd) != -1);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/iconvdata/bug-iconv14.c b/google3/third_party/grte/v5_src/glibc-2.27/iconvdata/bug-iconv14.c
new file mode 100644
index 0000000..902f140
--- /dev/null
+++ b/google3/third_party/grte/v5_src/glibc-2.27/iconvdata/bug-iconv14.c
@@ -0,0 +1,127 @@
+/* Assertion in ISO-2022-JP-3 due to two-character sequence (bug 27256).
+   Copyright (C) 2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <iconv.h>
+#include <string.h>
+#include <errno.h>
+#include <support/check.h>
+
+/* Use an escape sequence to return to the initial state.  */
+static void
+with_escape_sequence (void)
+{
+  iconv_t c = iconv_open ("UTF-8", "ISO-2022-JP-3");
+  TEST_VERIFY_EXIT (c != (iconv_t) -1);
+
+  char in[] = "\e$(O+D\e(B";
+  char *inbuf = in;
+  size_t inleft = strlen (in);
+  char out[3];                  /* Space for one output character.  */
+  char *outbuf;
+  size_t outleft;
+
+  outbuf = out;
+  outleft = sizeof (out);
+  TEST_COMPARE (iconv (c, &inbuf, &inleft, &outbuf, &outleft), (size_t) -1);
+  TEST_COMPARE (errno, E2BIG);
+  TEST_COMPARE (inleft, 3);
+  TEST_COMPARE (inbuf - in, strlen (in) - 3);
+  TEST_COMPARE (outleft, sizeof (out) - 2);
+  TEST_COMPARE (outbuf - out, 2);
+  TEST_COMPARE (out[0] & 0xff, 0xc3);
+  TEST_COMPARE (out[1] & 0xff, 0xa6);
+
+  /* Return to the initial shift state, producing the pending
+     character.  */
+  outbuf = out;
+  outleft = sizeof (out);
+  TEST_COMPARE (iconv (c, &inbuf, &inleft, &outbuf, &outleft), 0);
+  TEST_COMPARE (inleft, 0);
+  TEST_COMPARE (inbuf - in, strlen (in));
+  TEST_COMPARE (outleft, sizeof (out) - 2);
+  TEST_COMPARE (outbuf - out, 2);
+  TEST_COMPARE (out[0] & 0xff, 0xcc);
+  TEST_COMPARE (out[1] & 0xff, 0x80);
+
+  /* Nothing should be flushed the second time.  */
+  outbuf = out;
+  outleft = sizeof (out);
+  TEST_COMPARE (iconv (c, NULL, 0, &outbuf, &outleft), 0);
+  TEST_COMPARE (outleft, sizeof (out));
+  TEST_COMPARE (outbuf - out, 0);
+  TEST_COMPARE (out[0] & 0xff, 0xcc);
+  TEST_COMPARE (out[1] & 0xff, 0x80);
+
+  TEST_COMPARE (iconv_close (c), 0);
+}
+
+/* Use an explicit flush to return to the initial state.  */
+static void
+with_flush (void)
+{
+  iconv_t c = iconv_open ("UTF-8", "ISO-2022-JP-3");
+  TEST_VERIFY_EXIT (c != (iconv_t) -1);
+
+  char in[] = "\e$(O+D";
+  char *inbuf = in;
+  size_t inleft = strlen (in);
+  char out[3];                  /* Space for one output character.  */
+  char *outbuf;
+  size_t outleft;
+
+  outbuf = out;
+  outleft = sizeof (out);
+  TEST_COMPARE (iconv (c, &inbuf, &inleft, &outbuf, &outleft), (size_t) -1);
+  TEST_COMPARE (errno, E2BIG);
+  TEST_COMPARE (inleft, 0);
+  TEST_COMPARE (inbuf - in, strlen (in));
+  TEST_COMPARE (outleft, sizeof (out) - 2);
+  TEST_COMPARE (outbuf - out, 2);
+  TEST_COMPARE (out[0] & 0xff, 0xc3);
+  TEST_COMPARE (out[1] & 0xff, 0xa6);
+
+  /* Flush the pending character.  */
+  outbuf = out;
+  outleft = sizeof (out);
+  TEST_COMPARE (iconv (c, NULL, 0, &outbuf, &outleft), 0);
+  TEST_COMPARE (outleft, sizeof (out) - 2);
+  TEST_COMPARE (outbuf - out, 2);
+  TEST_COMPARE (out[0] & 0xff, 0xcc);
+  TEST_COMPARE (out[1] & 0xff, 0x80);
+
+  /* Nothing should be flushed the second time.  */
+  outbuf = out;
+  outleft = sizeof (out);
+  TEST_COMPARE (iconv (c, NULL, 0, &outbuf, &outleft), 0);
+  TEST_COMPARE (outleft, sizeof (out));
+  TEST_COMPARE (outbuf - out, 0);
+  TEST_COMPARE (out[0] & 0xff, 0xcc);
+  TEST_COMPARE (out[1] & 0xff, 0x80);
+
+  TEST_COMPARE (iconv_close (c), 0);
+}
+
+static int
+do_test (void)
+{
+  with_escape_sequence ();
+  with_flush ();
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/iconvdata/euc-kr.c b/google3/third_party/grte/v5_src/glibc-2.27/iconvdata/euc-kr.c
index 73e0281..dc7eaa6 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/iconvdata/euc-kr.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/iconvdata/euc-kr.c
@@ -80,11 +80,7 @@
 									      \
     if (ch <= 0x9f)							      \
       ++inptr;								      \
-    /* 0xfe(->0x7e : row 94) and 0xc9(->0x59 : row 41) are		      \
-       user-defined areas.  */						      \
-    else if (__builtin_expect (ch == 0xa0, 0)				      \
-	     || __builtin_expect (ch > 0xfe, 0)				      \
-	     || __builtin_expect (ch == 0xc9, 0))			      \
+    else if (__glibc_unlikely (ch == 0xa0))				      \
       {									      \
 	/* This is illegal.  */						      \
 	STANDARD_FROM_LOOP_ERR_HANDLER (1);				      \
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/iconvdata/ibm1364.c b/google3/third_party/grte/v5_src/glibc-2.27/iconvdata/ibm1364.c
index b833273..27900c4 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/iconvdata/ibm1364.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/iconvdata/ibm1364.c
@@ -157,24 +157,14 @@
 									      \
     if (__builtin_expect (ch, 0) == SO)					      \
       {									      \
-	/* Shift OUT, change to DBCS converter.  */			      \
-	if (curcs == db)						      \
-	  {								      \
-	    result = __GCONV_ILLEGAL_INPUT;				      \
-	    break;							      \
-	  }								      \
+	/* Shift OUT, change to DBCS converter (redundant escape okay).  */   \
 	curcs = db;							      \
 	++inptr;							      \
 	continue;							      \
       }									      \
     if (__builtin_expect (ch, 0) == SI)					      \
       {									      \
-	/* Shift IN, change to SBCS converter.  */			      \
-	if (curcs == sb)						      \
-	  {								      \
-	    result = __GCONV_ILLEGAL_INPUT;				      \
-	    break;							      \
-	  }								      \
+	/* Shift IN, change to SBCS converter (redundant escape okay).  */    \
 	curcs = sb;							      \
 	++inptr;							      \
 	continue;							      \
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/iconvdata/iso-2022-jp-3.c b/google3/third_party/grte/v5_src/glibc-2.27/iconvdata/iso-2022-jp-3.c
index de25958..047fab8 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/iconvdata/iso-2022-jp-3.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/iconvdata/iso-2022-jp-3.c
@@ -67,23 +67,34 @@
   CURRENT_SEL_MASK = 7 << 3
 };
 
-/* During UCS-4 to ISO-2022-JP-3 conversion, the COUNT element of the state
-   also contains the last two bytes to be output, shifted by 6 bits, and a
-   one-bit indicator whether they must be preceded by the shift sequence,
-   in bit 22.  */
+/* During UCS-4 to ISO-2022-JP-3 conversion, the COUNT element of the
+   state also contains the last two bytes to be output, shifted by 6
+   bits, and a one-bit indicator whether they must be preceded by the
+   shift sequence, in bit 22.  During ISO-2022-JP-3 to UCS-4
+   conversion, COUNT may also contain a non-zero pending wide
+   character, shifted by six bits.  This happens for certain inputs in
+   JISX0213_1_2004_set and JISX0213_2_set if the second wide character
+   in a combining sequence cannot be written because the buffer is
+   full.  */
 
 /* Since this is a stateful encoding we have to provide code which resets
    the output state to the initial state.  This has to be done during the
    flushing.  */
 #define EMIT_SHIFT_TO_INIT \
-  if ((data->__statep->__count & ~7) != ASCII_set)			      \
+  if (data->__statep->__count != ASCII_set)			      \
     {									      \
       if (FROM_DIRECTION)						      \
 	{								      \
-	  /* It's easy, we don't have to emit anything, we just reset the     \
-	     state for the input.  */					      \
-	  data->__statep->__count &= 7;					      \
-	  data->__statep->__count |= ASCII_set;				      \
+	  if (__glibc_likely (outbuf + 4 <= outend))			      \
+	    {								      \
+	      /* Write out the last character.  */			      \
+	      *((uint32_t *) outbuf) = data->__statep->__count >> 6;	      \
+	      outbuf += sizeof (uint32_t);				      \
+	      data->__statep->__count = ASCII_set;			\
+	    }								      \
+	  else								      \
+	    /* We don't have enough room in the output buffer.  */	      \
+	    status = __GCONV_FULL_OUTPUT;				      \
 	}								      \
       else								      \
 	{								      \
@@ -151,7 +162,21 @@
 #define LOOPFCT			FROM_LOOP
 #define BODY \
   {									      \
-    uint32_t ch = *inptr;						      \
+    uint32_t ch;							      \
+									      \
+    /* Output any pending character.  */				      \
+    ch = set >> 6;							      \
+    if (__glibc_unlikely (ch != 0))					      \
+      {									      \
+	put32 (outptr, ch);						      \
+	outptr += 4;							      \
+	/* Remove the pending character, but preserve state bits.  */	      \
+	set &= (1 << 6) - 1;						      \
+	continue;							      \
+      }									      \
+									      \
+    /* Otherwise read the next input byte.  */				      \
+    ch = *inptr;							      \
 									      \
     /* Recognize escape sequences.  */					      \
     if (__glibc_unlikely (ch == ESC))					      \
@@ -297,21 +322,25 @@
 	    uint32_t u1 = __jisx0213_to_ucs_combining[ch - 1][0];	      \
 	    uint32_t u2 = __jisx0213_to_ucs_combining[ch - 1][1];	      \
 									      \
+	    inptr += 2;							      \
+									      \
+	    put32 (outptr, u1);						      \
+	    outptr += 4;						      \
+									      \
 	    /* See whether we have room for two characters.  */		      \
-	    if (outptr + 8 <= outend)					      \
+	    if (outptr + 4 <= outend)					      \
 	      {								      \
-		inptr += 2;						      \
-		put32 (outptr, u1);					      \
-		outptr += 4;						      \
 		put32 (outptr, u2);					      \
 		outptr += 4;						      \
 		continue;						      \
 	      }								      \
-	    else							      \
-	      {								      \
-		result = __GCONV_FULL_OUTPUT;				      \
-		break;							      \
-	      }								      \
+									      \
+	    /* Otherwise store only the first character now, and	      \
+	       put the second one into the queue.  */			      \
+	    set |= u2 << 6;						      \
+	    /* Tell the caller why we terminate the loop.  */		      \
+	    result = __GCONV_FULL_OUTPUT;				      \
+	    break;							      \
 	  }								      \
 									      \
 	inptr += 2;							      \
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/iconvdata/ksc5601.h b/google3/third_party/grte/v5_src/glibc-2.27/iconvdata/ksc5601.h
index 5588d3a..fa2d306 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/iconvdata/ksc5601.h
+++ b/google3/third_party/grte/v5_src/glibc-2.27/iconvdata/ksc5601.h
@@ -50,15 +50,15 @@
   unsigned char ch2;
   int idx;
 
+  if (avail < 2)
+    return 0;
+
   /* row 94(0x7e) and row 41(0x49) are user-defined area in KS C 5601 */
 
   if (ch < offset || (ch - offset) <= 0x20 || (ch - offset) >= 0x7e
       || (ch - offset) == 0x49)
     return __UNKNOWN_10646_CHAR;
 
-  if (avail < 2)
-    return 0;
-
   ch2 = (*s)[1];
   if (ch2 < offset || (ch2 - offset) <= 0x20 || (ch2 - offset) >= 0x7f)
     return __UNKNOWN_10646_CHAR;
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/include/argz.h b/google3/third_party/grte/v5_src/glibc-2.27/include/argz.h
index 770f02e..e081b2a 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/include/argz.h
+++ b/google3/third_party/grte/v5_src/glibc-2.27/include/argz.h
@@ -39,6 +39,8 @@
 libc_hidden_proto (argz_delete)
 libc_hidden_proto (__argz_count)
 libc_hidden_proto (__argz_stringify)
+libc_hidden_proto (argz_next)
+libc_hidden_proto (__argz_next)
 
 # endif /* !_ISOMAC */
 #endif
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/include/ctype.h b/google3/third_party/grte/v5_src/glibc-2.27/include/ctype.h
index ac6db79..493a6f8 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/include/ctype.h
+++ b/google3/third_party/grte/v5_src/glibc-2.27/include/ctype.h
@@ -11,6 +11,9 @@
    So defeat macro expansion with parens for this declaration.  */
 extern int (__isctype) (int __c, int __mask);
 
+libc_hidden_proto (tolower)
+libc_hidden_proto (toupper)
+
 # if IS_IN (libc)
 
 /* These accessors are used by the optimized macros to find the
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/include/libc-symbols.h b/google3/third_party/grte/v5_src/glibc-2.27/include/libc-symbols.h
index c40f5fb..1e00fcb 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/include/libc-symbols.h
+++ b/google3/third_party/grte/v5_src/glibc-2.27/include/libc-symbols.h
@@ -286,6 +286,12 @@
 
 */
 
+#ifdef HAVE_GNU_RETAIN
+# define attribute_used_retain __attribute__ ((__used__, __retain__))
+#else
+# define attribute_used_retain __attribute__ ((__used__))
+#endif
+
 /* Symbol set support macros.  */
 
 /* Make SYMBOL, which is in the text segment, an element of SET.  */
@@ -301,12 +307,12 @@
 /* When building a shared library, make the set section writable,
    because it will need to be relocated at run time anyway.  */
 # define _elf_set_element(set, symbol) \
-  static const void *__elf_set_##set##_element_##symbol##__ \
-    __attribute__ ((used, section (#set))) = &(symbol)
+    static const void *__elf_set_##set##_element_##symbol##__ \
+      attribute_used_retain __attribute__ ((section (#set))) = &(symbol)
 #else
 # define _elf_set_element(set, symbol) \
-  static const void *const __elf_set_##set##_element_##symbol##__ \
-    __attribute__ ((used, section (#set))) = &(symbol)
+    static const void *const __elf_set_##set##_element_##symbol##__ \
+      attribute_used_retain __attribute__ ((section (#set))) = &(symbol)
 #endif
 
 /* Define SET as a symbol set.  This may be required (it is in a.out) to
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/include/stdio.h b/google3/third_party/grte/v5_src/glibc-2.27/include/stdio.h
index f1e987a..6759ed3 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/include/stdio.h
+++ b/google3/third_party/grte/v5_src/glibc-2.27/include/stdio.h
@@ -135,6 +135,10 @@
 #   define fclose(fp) _IO_new_fclose (fp)
 extern int _IO_fputs (const char*, _IO_FILE*);
 libc_hidden_proto (_IO_fputs)
+/* The compiler may optimize calls to fprintf into calls to fputs.
+   Use libc_hidden_proto to ensure that those calls, not redirected by
+   the fputs macro, also do not go through the PLT.  */
+libc_hidden_proto (fputs)
 #   define fputs(str, fp) _IO_fputs (str, fp)
 extern int _IO_new_fsetpos (_IO_FILE *, const _IO_fpos_t *);
 #   define fsetpos(fp, posp) _IO_new_fsetpos (fp, posp)
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/include/stdlib.h b/google3/third_party/grte/v5_src/glibc-2.27/include/stdlib.h
index 5974fb3..114e12d 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/include/stdlib.h
+++ b/google3/third_party/grte/v5_src/glibc-2.27/include/stdlib.h
@@ -210,6 +210,8 @@
 libc_hidden_proto (strtoul)
 libc_hidden_proto (strtoull)
 
+libc_hidden_proto (atoi)
+
 extern float __strtof_nan (const char *, char **, char);
 extern double __strtod_nan (const char *, char **, char);
 extern long double __strtold_nan (const char *, char **, char);
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/include/sys/socket.h b/google3/third_party/grte/v5_src/glibc-2.27/include/sys/socket.h
index baec6e6..26db0e0 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/include/sys/socket.h
+++ b/google3/third_party/grte/v5_src/glibc-2.27/include/sys/socket.h
@@ -154,5 +154,7 @@
 # define SA_LEN(_x)      __libc_sa_len((_x)->sa_family)
 #endif
 
+libc_hidden_proto (__cmsg_nxthdr)
+
 #endif
 #endif
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/include/sys/sysmacros.h b/google3/third_party/grte/v5_src/glibc-2.27/include/sys/sysmacros.h
index 87813c5..3c2b9c2 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/include/sys/sysmacros.h
+++ b/google3/third_party/grte/v5_src/glibc-2.27/include/sys/sysmacros.h
@@ -1 +1,52 @@
+/* Definitions of macros to access 'dev_t' values.  Internal header.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _ISOMAC
+# define __SYSMACROS_NEED_IMPLEMENTATION
+#endif
+
 #include <misc/sys/sysmacros.h>
+
+#if !defined _SYS_SYSMACROS_H_WRAPPER && !defined _ISOMAC
+# define _SYS_SYSMACROS_H_WRAPPER 1
+
+libc_hidden_proto (gnu_dev_major)
+libc_hidden_proto (gnu_dev_minor)
+libc_hidden_proto (gnu_dev_makedev)
+
+# undef __SYSMACROS_DECL_TEMPL
+# define __SYSMACROS_DECL_TEMPL(rtype, name, proto)	\
+  extern rtype __gnu_dev_##name proto			\
+  __THROW __attribute_const__ attribute_hidden;
+
+# undef __SYSMACROS_IMPL_TEMPL
+# define __SYSMACROS_IMPL_TEMPL(rtype, name, proto)		\
+  __extension__ __extern_inline __attribute_const__ rtype	\
+  __NTH (__gnu_dev_##name proto)
+
+__SYSMACROS_DECLARE_MAJOR (__SYSMACROS_DECL_TEMPL)
+__SYSMACROS_DECLARE_MINOR (__SYSMACROS_DECL_TEMPL)
+__SYSMACROS_DECLARE_MAKEDEV (__SYSMACROS_DECL_TEMPL)
+
+# ifdef __USE_EXTERN_INLINES
+__SYSMACROS_DEFINE_MAJOR (__SYSMACROS_IMPL_TEMPL)
+__SYSMACROS_DEFINE_MINOR (__SYSMACROS_IMPL_TEMPL)
+__SYSMACROS_DEFINE_MAKEDEV (__SYSMACROS_IMPL_TEMPL)
+# endif
+
+#endif
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/intl/dcigettext.c b/google3/third_party/grte/v5_src/glibc-2.27/intl/dcigettext.c
index 2a50369..b65d244 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/intl/dcigettext.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/intl/dcigettext.c
@@ -1120,11 +1120,19 @@
 		      outcharset = encoding;
 
 # ifdef _LIBC
+
+		      struct gconv_spec conv_spec;
+
+                      __gconv_create_spec (&conv_spec, charset, outcharset);
+
 		      /* We always want to use transliteration.  */
-		      outcharset = norm_add_slashes (outcharset, "TRANSLIT");
-		      charset = norm_add_slashes (charset, "");
-		      int r = __gconv_open (outcharset, charset, &convd->conv,
-					    GCONV_AVOID_NOCONV);
+                      conv_spec.translit = true;
+
+		      int r = __gconv_open (&conv_spec, &convd->conv,
+		                            GCONV_AVOID_NOCONV);
+
+                      __gconv_destroy_spec (&conv_spec);
+
 		      if (__builtin_expect (r != __GCONV_OK, 0))
 			{
 			  /* If the output encoding is the same there is
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/intl/tst-codeset.c b/google3/third_party/grte/v5_src/glibc-2.27/intl/tst-codeset.c
index e71382a..6a640bc 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/intl/tst-codeset.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/intl/tst-codeset.c
@@ -22,39 +22,35 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <support/check.h>
 
 static int
 do_test (void)
 {
-  char *s;
-  int result = 0;
-
   unsetenv ("LANGUAGE");
   unsetenv ("OUTPUT_CHARSET");
   setlocale (LC_ALL, "de_DE.ISO-8859-1");
   textdomain ("codeset");
   bindtextdomain ("codeset", OBJPFX "domaindir");
 
+#if 0 /* needs updated test framework */
   /* Here we expect output in ISO-8859-1.  */
-  s = gettext ("cheese");
-  if (strcmp (s, "K\344se"))
-    {
-      printf ("call 1 returned: %s\n", s);
-      result = 1;
-    }
-
-  bind_textdomain_codeset ("codeset", "UTF-8");
+  TEST_COMPARE_STRING (gettext ("cheese"), "K\344se");
 
   /* Here we expect output in UTF-8.  */
-  s = gettext ("cheese");
-  if (strcmp (s, "K\303\244se"))
-    {
-      printf ("call 2 returned: %s\n", s);
-      result = 1;
-    }
+  bind_textdomain_codeset ("codeset", "UTF-8");
+  TEST_COMPARE_STRING (gettext ("cheese"), "K\303\244se");
 
-  return result;
+  /* `a with umlaut' is transliterated to `ae'.  */
+  bind_textdomain_codeset ("codeset", "ASCII//TRANSLIT");
+  TEST_COMPARE_STRING (gettext ("cheese"), "Kaese");
+
+  /* Transliteration also works by default even if not set.  */
+  bind_textdomain_codeset ("codeset", "ASCII");
+  TEST_COMPARE_STRING (gettext ("cheese"), "Kaese");
+#endif
+
+  return 0;
 }
 
-#define TEST_FUNCTION do_test ()
-#include "../test-skeleton.c"
+#include <support/test-driver.c>
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/io/tst-copy_file_range.c b/google3/third_party/grte/v5_src/glibc-2.27/io/tst-copy_file_range.c
index 3d531a1..3876332 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/io/tst-copy_file_range.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/io/tst-copy_file_range.c
@@ -759,8 +759,7 @@
           }
 
         struct stat64 cstat;
-        xstat (path, &cstat);
-        if (cstat.st_dev == instat.st_dev)
+        if (stat (path, &cstat) != 0 || cstat.st_dev == instat.st_dev)
           {
             free (to_free);
             continue;
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/libio/Makefile b/google3/third_party/grte/v5_src/glibc-2.27/libio/Makefile
index 918a86b..bc4cd34 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/libio/Makefile
+++ b/google3/third_party/grte/v5_src/glibc-2.27/libio/Makefile
@@ -177,6 +177,26 @@
 # library is enabled since they depend on tst-fopenloc.out.
 tests-special += $(objpfx)tst-fopenloc-cmp.out $(objpfx)tst-fopenloc-mem.out
 endif
+
+tests += tst-cleanup-default tst-cleanup-default-static
+tests-static += tst-cleanup-default-static
+tests-special += $(objpfx)tst-cleanup-default-cmp.out $(objpfx)tst-cleanup-default-static-cmp.out
+LDFLAGS-tst-cleanup-default = -Wl,--gc-sections
+LDFLAGS-tst-cleanup-default-static = -Wl,--gc-sections
+
+ifeq ($(have-gnu-retain)$(have-z-start-stop-gc),yesyes)
+tests += tst-cleanup-start-stop-gc tst-cleanup-start-stop-gc-static \
+		tst-cleanup-nostart-stop-gc tst-cleanup-nostart-stop-gc-static
+tests-static += tst-cleanup-start-stop-gc-static tst-cleanup-nostart-stop-gc-static
+tests-special += $(objpfx)tst-cleanup-start-stop-gc-cmp.out \
+		$(objpfx)tst-cleanup-start-stop-gc-static-cmp.out \
+		$(objpfx)tst-cleanup-nostart-stop-gc-cmp.out \
+		$(objpfx)tst-cleanup-nostart-stop-gc-static-cmp.out
+LDFLAGS-tst-cleanup-start-stop-gc := -Wl,--gc-sections,-z,start-stop-gc
+LDFLAGS-tst-cleanup-start-stop-gc-static := -Wl,--gc-sections,-z,start-stop-gc
+LDFLAGS-tst-cleanup-nostart-stop-gc := -Wl,--gc-sections,-z,nostart-stop-gc
+LDFLAGS-tst-cleanup-nostart-stop-gc-static := -Wl,--gc-sections,-z,nostart-stop-gc
+endif
 endif
 
 include ../Rules
@@ -205,6 +225,14 @@
 $(objpfx)tst_wprintf2.out: $(gen-locales)
 endif
 
+define gen-tst-cleanup
+$(objpfx)tst-cleanup-$1-cmp.out: tst-cleanup.exp $(objpfx)tst-cleanup-$1.out
+	cmp $$^ > $$@; $$(evaluate-test)
+endef
+
+$(foreach t,default default-static start-stop-gc start-stop-gc-static nostart-stop-gc nostart-stop-gc-static, \
+  $(eval $(call gen-tst-cleanup,$(t))))
+
 $(objpfx)test-freopen.out: test-freopen.sh $(objpfx)test-freopen
 	$(SHELL) $< $(common-objpfx) '$(test-program-prefix)'	\
 	$(common-objpfx)libio/ > $@; \
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/libio/iofputs.c b/google3/third_party/grte/v5_src/glibc-2.27/libio/iofputs.c
index b4fbeb5..176e9ed 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/libio/iofputs.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/libio/iofputs.c
@@ -43,6 +43,7 @@
 libc_hidden_def (_IO_fputs)
 
 weak_alias (_IO_fputs, fputs)
+libc_hidden_weak (fputs)
 
 # ifndef _IO_MTSAFE_IO
 strong_alias (_IO_fputs, __fputs_unlocked)
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/libio/tst-cleanup-default-static.c b/google3/third_party/grte/v5_src/glibc-2.27/libio/tst-cleanup-default-static.c
new file mode 100644
index 0000000..c39956e
--- /dev/null
+++ b/google3/third_party/grte/v5_src/glibc-2.27/libio/tst-cleanup-default-static.c
@@ -0,0 +1 @@
+#include "tst-cleanup.c"
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/libio/tst-cleanup-default.c b/google3/third_party/grte/v5_src/glibc-2.27/libio/tst-cleanup-default.c
new file mode 100644
index 0000000..c39956e
--- /dev/null
+++ b/google3/third_party/grte/v5_src/glibc-2.27/libio/tst-cleanup-default.c
@@ -0,0 +1 @@
+#include "tst-cleanup.c"
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/libio/tst-cleanup-nostart-stop-gc-static.c b/google3/third_party/grte/v5_src/glibc-2.27/libio/tst-cleanup-nostart-stop-gc-static.c
new file mode 100644
index 0000000..c39956e
--- /dev/null
+++ b/google3/third_party/grte/v5_src/glibc-2.27/libio/tst-cleanup-nostart-stop-gc-static.c
@@ -0,0 +1 @@
+#include "tst-cleanup.c"
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/libio/tst-cleanup-nostart-stop-gc.c b/google3/third_party/grte/v5_src/glibc-2.27/libio/tst-cleanup-nostart-stop-gc.c
new file mode 100644
index 0000000..c39956e
--- /dev/null
+++ b/google3/third_party/grte/v5_src/glibc-2.27/libio/tst-cleanup-nostart-stop-gc.c
@@ -0,0 +1 @@
+#include "tst-cleanup.c"
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/libio/tst-cleanup-start-stop-gc-static.c b/google3/third_party/grte/v5_src/glibc-2.27/libio/tst-cleanup-start-stop-gc-static.c
new file mode 100644
index 0000000..c39956e
--- /dev/null
+++ b/google3/third_party/grte/v5_src/glibc-2.27/libio/tst-cleanup-start-stop-gc-static.c
@@ -0,0 +1 @@
+#include "tst-cleanup.c"
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/libio/tst-cleanup-start-stop-gc.c b/google3/third_party/grte/v5_src/glibc-2.27/libio/tst-cleanup-start-stop-gc.c
new file mode 100644
index 0000000..c39956e
--- /dev/null
+++ b/google3/third_party/grte/v5_src/glibc-2.27/libio/tst-cleanup-start-stop-gc.c
@@ -0,0 +1 @@
+#include "tst-cleanup.c"
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S b/google3/third_party/grte/v5_src/glibc-2.27/libio/tst-cleanup.c
similarity index 66%
copy from google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S
copy to google3/third_party/grte/v5_src/glibc-2.27/libio/tst-cleanup.c
index ed7af0d..837feac 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/libio/tst-cleanup.c
@@ -1,6 +1,5 @@
-/* Copyright (C) 2009-2018 Free Software Foundation, Inc.
+/* Copyright (C) 2021 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2009.
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -14,8 +13,22 @@
 
    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
+   <https://www.gnu.org/licenses/>.  */
 
-#define __pthread_enable_asynccancel __libc_enable_asynccancel
-#define __pthread_disable_asynccancel __libc_disable_asynccancel
-#include "cancellation.S"
+/* Test that stdout is flushed after atexit callbacks were run, even if the
+ * executable is linked with --gc-sections.  */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+void
+hook (void)
+{
+  puts ("hello");
+}
+
+int
+main (void)
+{
+  atexit (hook);
+}
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/libio/tst-cleanup.exp b/google3/third_party/grte/v5_src/glibc-2.27/libio/tst-cleanup.exp
new file mode 100644
index 0000000..ce01362
--- /dev/null
+++ b/google3/third_party/grte/v5_src/glibc-2.27/libio/tst-cleanup.exp
@@ -0,0 +1 @@
+hello
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/locale/C-ctype.c b/google3/third_party/grte/v5_src/glibc-2.27/locale/C-ctype.c
index 9397a1e..6a7b257 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/locale/C-ctype.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/locale/C-ctype.c
@@ -18,6 +18,7 @@
 
 #include "localeinfo.h"
 #include <endian.h>
+#include <stdalign.h>
 #include <stdint.h>
 
 #include "C-translit.h"
@@ -30,7 +31,7 @@
    In the `_nl_C_LC_CTYPE_class' array the value for EOF (== -1)
    is set to always return 0 and the conversion arrays return EOF.  */
 
-const char _nl_C_LC_CTYPE_class[768] attribute_hidden =
+alignas (uint16_t) const char _nl_C_LC_CTYPE_class[768] attribute_hidden =
   /* 0x80 */ "\000\000" "\000\000" "\000\000" "\000\000" "\000\000" "\000\000"
   /* 0x86 */ "\000\000" "\000\000" "\000\000" "\000\000" "\000\000" "\000\000"
   /* 0x8c */ "\000\000" "\000\000" "\000\000" "\000\000" "\000\000" "\000\000"
@@ -96,7 +97,7 @@
   /* 0xf4 */ "\000\000" "\000\000" "\000\000" "\000\000" "\000\000" "\000\000"
   /* 0xfa */ "\000\000" "\000\000" "\000\000" "\000\000" "\000\000" "\000\000"
 ;
-const char _nl_C_LC_CTYPE_class32[1024] attribute_hidden =
+alignas (uint32_t) const char _nl_C_LC_CTYPE_class32[1024] attribute_hidden =
   /* 0x00 */ "\000\000\002\000" "\000\000\002\000" "\000\000\002\000"
   /* 0x03 */ "\000\000\002\000" "\000\000\002\000" "\000\000\002\000"
   /* 0x06 */ "\000\000\002\000" "\000\000\002\000" "\000\000\002\000"
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/misc/makedev.c b/google3/third_party/grte/v5_src/glibc-2.27/misc/makedev.c
index 5da14ce..bc5bfc5 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/misc/makedev.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/misc/makedev.c
@@ -23,8 +23,14 @@
 #include <sys/sysmacros.h>
 
 #define OUT_OF_LINE_IMPL_TEMPL(rtype, name, proto) \
-  rtype gnu_dev_##name proto
+  rtype __gnu_dev_##name proto
 
 __SYSMACROS_DEFINE_MAJOR(OUT_OF_LINE_IMPL_TEMPL)
+weak_alias (__gnu_dev_major, gnu_dev_major)
+libc_hidden_weak (gnu_dev_major)
 __SYSMACROS_DEFINE_MINOR(OUT_OF_LINE_IMPL_TEMPL)
+weak_alias (__gnu_dev_minor, gnu_dev_minor)
+libc_hidden_weak (gnu_dev_minor)
 __SYSMACROS_DEFINE_MAKEDEV(OUT_OF_LINE_IMPL_TEMPL)
+weak_alias (__gnu_dev_makedev, gnu_dev_makedev)
+libc_hidden_weak (gnu_dev_makedev)
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/posix/Makefile b/google3/third_party/grte/v5_src/glibc-2.27/posix/Makefile
index 95dc80d..088c0d9 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/posix/Makefile
+++ b/google3/third_party/grte/v5_src/glibc-2.27/posix/Makefile
@@ -95,7 +95,8 @@
 		   tst-posix_spawn-fd tst-posix_spawn-setsid \
 		   tst-posix_fadvise tst-posix_fadvise64 \
 		   tst-sysconf-empty-chroot tst-glob_symlinks tst-fexecve \
-		   tst-glob-tilde
+		   tst-glob-tilde bug-regex37 \
+		   bug-regex38
 tests-internal	:= bug-regex5 bug-regex20 bug-regex33 \
 		   tst-rfc3484 tst-rfc3484-2 tst-rfc3484-3 \
 		   tst-glob_lstat_compat
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/posix/PCRE.tests b/google3/third_party/grte/v5_src/glibc-2.27/posix/PCRE.tests
index 0fb9cad..da63b86 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/posix/PCRE.tests
+++ b/google3/third_party/grte/v5_src/glibc-2.27/posix/PCRE.tests
@@ -1774,19 +1774,6 @@
  0: abcabc
  1: abc
 
-/(a)|\1/
-    a
- 0: a
- 1: a
-    *** Failers
- 0: a
- 1: a
-    ab
- 0: a
- 1: a
-    x
-No match
-
 /abc/i
     ABC
  0: ABC
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/posix/bug-regex28.c b/google3/third_party/grte/v5_src/glibc-2.27/posix/bug-regex28.c
index 5353edf..ba263b2 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/posix/bug-regex28.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/posix/bug-regex28.c
@@ -21,18 +21,22 @@
 #include <stdio.h>
 #include <string.h>
 
+#include <support/test-driver.h>
+#include <support/check.h>
+
 struct tests
 {
   const char *regex;
   const char *string;
   reg_syntax_t syntax;
   int retval;
-} tests[] = {
+};
+static const struct tests tests[] = {
 #define EGREP RE_SYNTAX_EGREP
 #define EGREP_NL (RE_SYNTAX_EGREP | RE_DOT_NEWLINE) & ~RE_HAT_LISTS_NOT_NEWLINE
-  { "a.b", "a\nb", EGREP, -1 },
+  { "a.b", "a\nb", EGREP, 0 },
   { "a.b", "a\nb", EGREP_NL, 0 },
-  { "a[^x]b", "a\nb", EGREP, -1 },
+  { "a[^x]b", "a\nb", EGREP, 0 },
   { "a[^x]b", "a\nb", EGREP_NL, 0 },
   /* While \S and \W are internally handled as [^[:space:]] and [^[:alnum:]_],
      RE_HAT_LISTS_NOT_NEWLINE did not make any difference, so ensure
@@ -42,33 +46,33 @@
   { "a\\Wb", "a\nb", EGREP, 0 },
   { "a\\Wb", "a\nb", EGREP_NL, 0 }
 };
+static const size_t tests_size = sizeof (tests) / sizeof (tests[0]);
 
-int
-main (void)
+static int
+do_test (void)
 {
   struct re_pattern_buffer r;
-  size_t i;
-  int ret = 0;
 
-  for (i = 0; i < sizeof (tests) / sizeof (tests[i]); ++i)
+  for (size_t i = 0; i < tests_size; i++)
     {
       re_set_syntax (tests[i].syntax);
       memset (&r, 0, sizeof (r));
-      if (re_compile_pattern (tests[i].regex, strlen (tests[i].regex), &r))
-	{
-	  printf ("re_compile_pattern %zd failed\n", i);
-	  ret = 1;
-	  continue;
-	}
+      const char *re = re_compile_pattern (tests[i].regex,
+					   strlen (tests[i].regex), &r);
+      TEST_VERIFY (re == NULL);
+      if (re != NULL)
+        continue;
+
       size_t len = strlen (tests[i].string);
       int rv = re_search (&r, tests[i].string, len, 0, len, NULL);
-      if (rv != tests[i].retval)
-	{
-	  printf ("re_search %zd unexpected value %d != %d\n",
-		  i, rv, tests[i].retval);
-	  ret = 1;
-	}
+      TEST_VERIFY (rv == tests[i].retval);
+      if (test_verbose > 0)
+        printf ("info: i=%zu rv=%d expected=%d\n", i, rv, tests[i].retval);
+
       regfree (&r);
     }
-  return ret;
+
+  return 0;
 }
+
+#include <support/test-driver.c>
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S b/google3/third_party/grte/v5_src/glibc-2.27/posix/bug-regex37.c
similarity index 66%
rename from google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S
rename to google3/third_party/grte/v5_src/glibc-2.27/posix/bug-regex37.c
index ed7af0d..87a0916 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/posix/bug-regex37.c
@@ -1,6 +1,6 @@
-/* Copyright (C) 2009-2018 Free Software Foundation, Inc.
+/* Test regcomp return for invalid expression (BZ #21163).
+   Copyright (C) 2018 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2009.
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -16,6 +16,17 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define __pthread_enable_asynccancel __libc_enable_asynccancel
-#define __pthread_disable_asynccancel __libc_disable_asynccancel
-#include "cancellation.S"
+#include <regex.h>
+
+#include <support/check.h>
+
+static int
+do_test (void)
+{
+  char const pattern[] = "()*)|\\1)*";
+  regex_t r;
+  TEST_VERIFY_EXIT (regcomp (&r, pattern, REG_EXTENDED) == REG_ESUBREG);
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S b/google3/third_party/grte/v5_src/glibc-2.27/posix/bug-regex38.c
similarity index 65%
copy from google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S
copy to google3/third_party/grte/v5_src/glibc-2.27/posix/bug-regex38.c
index ed7af0d..cb0eb7d 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/posix/bug-regex38.c
@@ -1,6 +1,6 @@
-/* Copyright (C) 2009-2018 Free Software Foundation, Inc.
+/* Diagnose invalid back-reference in the ERE '()|\1' (BZ #18986).
+   Copyright (C) 2018 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2009.
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -16,6 +16,17 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define __pthread_enable_asynccancel __libc_enable_asynccancel
-#define __pthread_disable_asynccancel __libc_disable_asynccancel
-#include "cancellation.S"
+#include <regex.h>
+
+#include <support/check.h>
+
+static int
+do_test (void)
+{
+  char const pattern[] = "0|()0|\\1|0";
+  regex_t r;
+  TEST_VERIFY_EXIT (regcomp (&r, pattern, REG_EXTENDED) == REG_ESUBREG);
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/posix/glob.c b/google3/third_party/grte/v5_src/glibc-2.27/posix/glob.c
index 8444b2f..1b389d2 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/posix/glob.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/posix/glob.c
@@ -827,31 +827,32 @@
 	      {
 		size_t home_len = strlen (p->pw_dir);
 		size_t rest_len = end_name == NULL ? 0 : strlen (end_name);
-		char *d;
+		char *d, *newp;
+		bool use_alloca = glob_use_alloca (alloca_used,
+						   home_len + rest_len + 1);
 
-		if (__glibc_unlikely (malloc_dirname))
-		  free (dirname);
-		malloc_dirname = 0;
-
-		if (glob_use_alloca (alloca_used, home_len + rest_len + 1))
-		  dirname = alloca_account (home_len + rest_len + 1,
-					    alloca_used);
+		if (use_alloca)
+		  newp = alloca_account (home_len + rest_len + 1, alloca_used);
 		else
 		  {
-		    dirname = malloc (home_len + rest_len + 1);
-		    if (dirname == NULL)
+		    newp = malloc (home_len + rest_len + 1);
+		    if (newp == NULL)
 		      {
 			scratch_buffer_free (&pwtmpbuf);
 			retval = GLOB_NOSPACE;
 			goto out;
 		      }
-		    malloc_dirname = 1;
 		  }
-		d = mempcpy (dirname, p->pw_dir, home_len);
+		d = mempcpy (newp, p->pw_dir, home_len);
 		if (end_name != NULL)
 		  d = mempcpy (d, end_name, rest_len);
 		*d = '\0';
 
+		if (__glibc_unlikely (malloc_dirname))
+		  free (dirname);
+		dirname = newp;
+		malloc_dirname = !use_alloca;
+
 		dirlen = home_len + rest_len;
 		dirname_modified = 1;
 	      }
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/posix/regcomp.c b/google3/third_party/grte/v5_src/glibc-2.27/posix/regcomp.c
index 327846f..4963462 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/posix/regcomp.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/posix/regcomp.c
@@ -15,9 +15,7 @@
 
    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <stdint.h>
+   <https://www.gnu.org/licenses/>.  */
 
 #ifdef _LIBC
 # include <locale/weight.h>
@@ -51,14 +49,14 @@
 static reg_errcode_t calc_first (void *extra, bin_tree_t *node);
 static reg_errcode_t calc_next (void *extra, bin_tree_t *node);
 static reg_errcode_t link_nfa_nodes (void *extra, bin_tree_t *node);
-static int duplicate_node (re_dfa_t *dfa, int org_idx, unsigned int constraint);
-static int search_duplicated_node (const re_dfa_t *dfa, int org_node,
+static Idx duplicate_node (re_dfa_t *dfa, Idx org_idx, unsigned int constraint);
+static Idx search_duplicated_node (const re_dfa_t *dfa, Idx org_node,
 				   unsigned int constraint);
 static reg_errcode_t calc_eclosure (re_dfa_t *dfa);
 static reg_errcode_t calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa,
-					 int node, int root);
+					 Idx node, bool root);
 static reg_errcode_t calc_inveclosure (re_dfa_t *dfa);
-static int fetch_number (re_string_t *input, re_token_t *token,
+static Idx fetch_number (re_string_t *input, re_token_t *token,
 			 reg_syntax_t syntax);
 static int peek_token (re_token_t *token, re_string_t *input,
 			reg_syntax_t syntax);
@@ -66,16 +64,16 @@
 			  reg_syntax_t syntax, reg_errcode_t *err);
 static bin_tree_t *parse_reg_exp (re_string_t *regexp, regex_t *preg,
 				  re_token_t *token, reg_syntax_t syntax,
-				  int nest, reg_errcode_t *err);
+				  Idx nest, reg_errcode_t *err);
 static bin_tree_t *parse_branch (re_string_t *regexp, regex_t *preg,
 				 re_token_t *token, reg_syntax_t syntax,
-				 int nest, reg_errcode_t *err);
+				 Idx nest, reg_errcode_t *err);
 static bin_tree_t *parse_expression (re_string_t *regexp, regex_t *preg,
 				     re_token_t *token, reg_syntax_t syntax,
-				     int nest, reg_errcode_t *err);
+				     Idx nest, reg_errcode_t *err);
 static bin_tree_t *parse_sub_exp (re_string_t *regexp, regex_t *preg,
 				  re_token_t *token, reg_syntax_t syntax,
-				  int nest, reg_errcode_t *err);
+				  Idx nest, reg_errcode_t *err);
 static bin_tree_t *parse_dup_op (bin_tree_t *dup_elem, re_string_t *regexp,
 				 re_dfa_t *dfa, re_token_t *token,
 				 reg_syntax_t syntax, reg_errcode_t *err);
@@ -87,34 +85,34 @@
 					    re_token_t *token, int token_len,
 					    re_dfa_t *dfa,
 					    reg_syntax_t syntax,
-					    int accept_hyphen);
+					    bool accept_hyphen);
 static reg_errcode_t parse_bracket_symbol (bracket_elem_t *elem,
 					  re_string_t *regexp,
 					  re_token_t *token);
 #ifdef RE_ENABLE_I18N
 static reg_errcode_t build_equiv_class (bitset_t sbcset,
 					re_charset_t *mbcset,
-					int *equiv_class_alloc,
+					Idx *equiv_class_alloc,
 					const unsigned char *name);
 static reg_errcode_t build_charclass (RE_TRANSLATE_TYPE trans,
 				      bitset_t sbcset,
 				      re_charset_t *mbcset,
-				      int *char_class_alloc,
-				      const unsigned char *class_name,
+				      Idx *char_class_alloc,
+				      const char *class_name,
 				      reg_syntax_t syntax);
 #else  /* not RE_ENABLE_I18N */
 static reg_errcode_t build_equiv_class (bitset_t sbcset,
 					const unsigned char *name);
 static reg_errcode_t build_charclass (RE_TRANSLATE_TYPE trans,
 				      bitset_t sbcset,
-				      const unsigned char *class_name,
+				      const char *class_name,
 				      reg_syntax_t syntax);
 #endif /* not RE_ENABLE_I18N */
 static bin_tree_t *build_charclass_op (re_dfa_t *dfa,
 				       RE_TRANSLATE_TYPE trans,
-				       const unsigned char *class_name,
-				       const unsigned char *extra,
-				       int non_match, reg_errcode_t *err);
+				       const char *class_name,
+				       const char *extra,
+				       bool non_match, reg_errcode_t *err);
 static bin_tree_t *create_tree (re_dfa_t *dfa,
 				bin_tree_t *left, bin_tree_t *right,
 				re_token_type_t type);
@@ -131,7 +129,7 @@
    POSIX doesn't require that we do anything for REG_NOERROR,
    but why not be nice?  */
 
-const char __re_error_msgid[] attribute_hidden =
+static const char __re_error_msgid[] =
   {
 #define REG_NOERROR_IDX	0
     gettext_noop ("Success")	/* REG_NOERROR */
@@ -155,9 +153,9 @@
     gettext_noop ("Invalid back reference") /* REG_ESUBREG */
     "\0"
 #define REG_EBRACK_IDX	(REG_ESUBREG_IDX + sizeof "Invalid back reference")
-    gettext_noop ("Unmatched [ or [^")	/* REG_EBRACK */
+    gettext_noop ("Unmatched [, [^, [:, [., or [=")	/* REG_EBRACK */
     "\0"
-#define REG_EPAREN_IDX	(REG_EBRACK_IDX + sizeof "Unmatched [ or [^")
+#define REG_EPAREN_IDX	(REG_EBRACK_IDX + sizeof "Unmatched [, [^, [:, [., or [=")
     gettext_noop ("Unmatched ( or \\(") /* REG_EPAREN */
     "\0"
 #define REG_EBRACE_IDX	(REG_EPAREN_IDX + sizeof "Unmatched ( or \\(")
@@ -185,7 +183,7 @@
     gettext_noop ("Unmatched ) or \\)") /* REG_ERPAREN */
   };
 
-const size_t __re_error_msgid_idx[] attribute_hidden =
+static const size_t __re_error_msgid_idx[] =
   {
     REG_NOERROR_IDX,
     REG_NOMATCH_IDX,
@@ -269,7 +267,7 @@
 int
 re_compile_fastmap (struct re_pattern_buffer *bufp)
 {
-  re_dfa_t *dfa = (re_dfa_t *) bufp->buffer;
+  re_dfa_t *dfa = bufp->buffer;
   char *fastmap = bufp->fastmap;
 
   memset (fastmap, '\0', sizeof (char) * SBC_MAX);
@@ -303,12 +301,12 @@
 re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
 			 char *fastmap)
 {
-  re_dfa_t *dfa = (re_dfa_t *) bufp->buffer;
-  int node_cnt;
-  int icase = (dfa->mb_cur_max == 1 && (bufp->syntax & RE_ICASE));
+  re_dfa_t *dfa = bufp->buffer;
+  Idx node_cnt;
+  bool icase = (dfa->mb_cur_max == 1 && (bufp->syntax & RE_ICASE));
   for (node_cnt = 0; node_cnt < init_state->nodes.nelem; ++node_cnt)
     {
-      int node = init_state->nodes.elems[node_cnt];
+      Idx node = init_state->nodes.elems[node_cnt];
       re_token_type_t type = dfa->nodes[node].type;
 
       if (type == CHARACTER)
@@ -317,7 +315,8 @@
 #ifdef RE_ENABLE_I18N
 	  if ((bufp->syntax & RE_ICASE) && dfa->mb_cur_max > 1)
 	    {
-	      unsigned char *buf = alloca (dfa->mb_cur_max), *p;
+	      unsigned char buf[MB_LEN_MAX];
+	      unsigned char *p;
 	      wchar_t wc;
 	      mbstate_t state;
 
@@ -332,7 +331,7 @@
 			     &state) == p - buf
 		  && (__wcrtomb ((char *) buf, __towlower (wc), &state)
 		      != (size_t) -1))
-		re_set_fastmap (fastmap, 0, buf[0]);
+		re_set_fastmap (fastmap, false, buf[0]);
 	    }
 #endif
 	}
@@ -352,7 +351,7 @@
       else if (type == COMPLEX_BRACKET)
 	{
 	  re_charset_t *cset = dfa->nodes[node].opr.mbcset;
-	  int i;
+	  Idx i;
 
 # ifdef _LIBC
 	  /* See if we have to try all bytes which start multiple collation
@@ -465,7 +464,7 @@
    the return codes and their meanings.)  */
 
 int
-regcomp (regex_t *__restrict preg, const char *__restrict pattern, int cflags)
+regcomp (regex_t *_Restrict_ preg, const char *_Restrict_ pattern, int cflags)
 {
   reg_errcode_t ret;
   reg_syntax_t syntax = ((cflags & REG_EXTENDED) ? RE_SYNTAX_POSIX_EXTENDED
@@ -525,7 +524,7 @@
    from either regcomp or regexec.   We don't use PREG here.  */
 
 size_t
-regerror (int errcode, const regex_t *__restrict preg, char *__restrict errbuf,
+regerror (int errcode, const regex_t *_Restrict_ preg, char *_Restrict_ errbuf,
 	  size_t errbuf_size)
 {
   const char *msg;
@@ -546,17 +545,13 @@
 
   if (BE (errbuf_size != 0, 1))
     {
+      size_t cpy_size = msg_size;
       if (BE (msg_size > errbuf_size, 0))
 	{
-#if defined HAVE_MEMPCPY || defined _LIBC
-	  *((char *) __mempcpy (errbuf, msg, errbuf_size - 1)) = '\0';
-#else
-	  memcpy (errbuf, msg, errbuf_size - 1);
-	  errbuf[errbuf_size - 1] = 0;
-#endif
+	  cpy_size = errbuf_size - 1;
+	  errbuf[cpy_size] = '\0';
 	}
-      else
-	memcpy (errbuf, msg, msg_size);
+      memcpy (errbuf, msg, cpy_size);
     }
 
   return msg_size;
@@ -574,7 +569,23 @@
 static const bitset_t utf8_sb_map =
 {
   /* Set the first 128 bits.  */
+# if defined __GNUC__ && !defined __STRICT_ANSI__
   [0 ... 0x80 / BITSET_WORD_BITS - 1] = BITSET_WORD_MAX
+# else
+#  if 4 * BITSET_WORD_BITS < ASCII_CHARS
+#   error "bitset_word_t is narrower than 32 bits"
+#  elif 3 * BITSET_WORD_BITS < ASCII_CHARS
+  BITSET_WORD_MAX, BITSET_WORD_MAX, BITSET_WORD_MAX,
+#  elif 2 * BITSET_WORD_BITS < ASCII_CHARS
+  BITSET_WORD_MAX, BITSET_WORD_MAX,
+#  elif 1 * BITSET_WORD_BITS < ASCII_CHARS
+  BITSET_WORD_MAX,
+#  endif
+  (BITSET_WORD_MAX
+   >> (SBC_MAX % BITSET_WORD_BITS == 0
+       ? 0
+       : BITSET_WORD_BITS - SBC_MAX % BITSET_WORD_BITS))
+# endif
 };
 #endif
 
@@ -582,7 +593,7 @@
 static void
 free_dfa_content (re_dfa_t *dfa)
 {
-  int i, j;
+  Idx i, j;
 
   if (dfa->nodes)
     for (i = 0; i < dfa->nodes_len; ++i)
@@ -632,9 +643,12 @@
 void
 regfree (regex_t *preg)
 {
-  re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+  re_dfa_t *dfa = preg->buffer;
   if (BE (dfa != NULL, 1))
-    free_dfa_content (dfa);
+    {
+      lock_fini (dfa->lock);
+      free_dfa_content (dfa);
+    }
   preg->buffer = NULL;
   preg->allocated = 0;
 
@@ -687,7 +701,7 @@
 
   if (re_comp_buf.fastmap == NULL)
     {
-      re_comp_buf.fastmap = (char *) malloc (SBC_MAX);
+      re_comp_buf.fastmap = re_malloc (char, SBC_MAX);
       if (re_comp_buf.fastmap == NULL)
 	return (char *) gettext (__re_error_msgid
 				 + __re_error_msgid_idx[(int) REG_ESPACE]);
@@ -704,7 +718,7 @@
   if (!ret)
     return NULL;
 
-  /* Yes, we're discarding `const' here if !HAVE_LIBINTL.  */
+  /* Yes, we're discarding 'const' here if !HAVE_LIBINTL.  */
   return (char *) gettext (__re_error_msgid + __re_error_msgid_idx[(int) ret]);
 }
 
@@ -739,7 +753,7 @@
   preg->regs_allocated = REGS_UNALLOCATED;
 
   /* Initialize the dfa.  */
-  dfa = (re_dfa_t *) preg->buffer;
+  dfa = preg->buffer;
   if (BE (preg->allocated < sizeof (re_dfa_t), 0))
     {
       /* If zero allocated, but buffer is non-null, try to realloc
@@ -750,11 +764,13 @@
       if (dfa == NULL)
 	return REG_ESPACE;
       preg->allocated = sizeof (re_dfa_t);
-      preg->buffer = (unsigned char *) dfa;
+      preg->buffer = dfa;
     }
   preg->used = sizeof (re_dfa_t);
 
   err = init_dfa (dfa, length);
+  if (BE (err == REG_NOERROR && lock_init (dfa->lock) != 0, 0))
+    err = REG_ESPACE;
   if (BE (err != REG_NOERROR, 0))
     {
       free_dfa_content (dfa);
@@ -768,15 +784,14 @@
   strncpy (dfa->re_str, pattern, length + 1);
 #endif
 
-  __libc_lock_init (dfa->lock);
-
   err = re_string_construct (&regexp, pattern, length, preg->translate,
-			     syntax & RE_ICASE, dfa);
+			     (syntax & RE_ICASE) != 0, dfa);
   if (BE (err != REG_NOERROR, 0))
     {
     re_compile_internal_free_return:
       free_workarea_compile (preg);
       re_string_destruct (&regexp);
+      lock_fini (dfa->lock);
       free_dfa_content (dfa);
       preg->buffer = NULL;
       preg->allocated = 0;
@@ -809,6 +824,7 @@
 
   if (BE (err != REG_NOERROR, 0))
     {
+      lock_fini (dfa->lock);
       free_dfa_content (dfa);
       preg->buffer = NULL;
       preg->allocated = 0;
@@ -823,18 +839,32 @@
 static reg_errcode_t
 init_dfa (re_dfa_t *dfa, size_t pat_len)
 {
-  unsigned int table_size;
+  __re_size_t table_size;
 #ifndef _LIBC
-  char *codeset_name;
+  const char *codeset_name;
 #endif
+#ifdef RE_ENABLE_I18N
+  size_t max_i18n_object_size = MAX (sizeof (wchar_t), sizeof (wctype_t));
+#else
+  size_t max_i18n_object_size = 0;
+#endif
+  size_t max_object_size =
+    MAX (sizeof (struct re_state_table_entry),
+	 MAX (sizeof (re_token_t),
+	      MAX (sizeof (re_node_set),
+		   MAX (sizeof (regmatch_t),
+			max_i18n_object_size))));
 
   memset (dfa, '\0', sizeof (re_dfa_t));
 
   /* Force allocation of str_tree_storage the first time.  */
   dfa->str_tree_storage_idx = BIN_TREE_STORAGE_SIZE;
 
-  /* Avoid overflows.  */
-  if (pat_len == SIZE_MAX)
+  /* Avoid overflows.  The extra "/ 2" is for the table_size doubling
+     calculation below, and for similar doubling calculations
+     elsewhere.  And it's <= rather than <, because some of the
+     doubling calculations add 1 afterwards.  */
+  if (BE (MIN (IDX_MAX, SIZE_MAX / max_object_size) / 2 <= pat_len, 0))
     return REG_ESPACE;
 
   dfa->nodes_alloc = pat_len + 1;
@@ -856,22 +886,11 @@
   dfa->map_notascii = (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_MAP_TO_NONASCII)
 		       != 0);
 #else
-# ifdef HAVE_LANGINFO_CODESET
   codeset_name = nl_langinfo (CODESET);
-# else
-  codeset_name = getenv ("LC_ALL");
-  if (codeset_name == NULL || codeset_name[0] == '\0')
-    codeset_name = getenv ("LC_CTYPE");
-  if (codeset_name == NULL || codeset_name[0] == '\0')
-    codeset_name = getenv ("LANG");
-  if (codeset_name == NULL)
-    codeset_name = "";
-  else if (strchr (codeset_name, '.') !=  NULL)
-    codeset_name = strchr (codeset_name, '.') + 1;
-# endif
-
-  if (strcasecmp (codeset_name, "UTF-8") == 0
-      || strcasecmp (codeset_name, "UTF8") == 0)
+  if ((codeset_name[0] == 'U' || codeset_name[0] == 'u')
+      && (codeset_name[1] == 'T' || codeset_name[1] == 't')
+      && (codeset_name[2] == 'F' || codeset_name[2] == 'f')
+      && strcmp (codeset_name + 3 + (codeset_name[3] == '-'), "8") == 0)
     dfa->is_utf8 = 1;
 
   /* We check exhaustively in the loop below if this charset is a
@@ -920,9 +939,10 @@
 static void
 init_word_char (re_dfa_t *dfa)
 {
-  dfa->word_ops_used = 1;
   int i = 0;
+  int j;
   int ch = 0;
+  dfa->word_ops_used = 1;
   if (BE (dfa->map_notascii == 0, 1))
     {
       /* Avoid uint32_t and uint64_t as some non-GCC platforms lack
@@ -959,7 +979,7 @@
 
  general_case:
   for (; i < BITSET_WORDS; ++i)
-    for (int j = 0; j < BITSET_WORD_BITS; ++j, ++ch)
+    for (j = 0; j < BITSET_WORD_BITS; ++j, ++ch)
       if (isalnum (ch) || ch == '_')
 	dfa->word_char[i] |= (bitset_word_t) 1 << j;
 }
@@ -969,7 +989,7 @@
 static void
 free_workarea_compile (regex_t *preg)
 {
-  re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+  re_dfa_t *dfa = preg->buffer;
   bin_tree_storage_t *storage, *next;
   for (storage = dfa->str_tree_storage; storage; storage = next)
     {
@@ -988,7 +1008,7 @@
 static reg_errcode_t
 create_initial_state (re_dfa_t *dfa)
 {
-  int first, i;
+  Idx first, i;
   reg_errcode_t err;
   re_node_set init_nodes;
 
@@ -1007,10 +1027,10 @@
   if (dfa->nbackref > 0)
     for (i = 0; i < init_nodes.nelem; ++i)
       {
-	int node_idx = init_nodes.elems[i];
+	Idx node_idx = init_nodes.elems[i];
 	re_token_type_t type = dfa->nodes[node_idx].type;
 
-	int clexp_idx;
+	Idx clexp_idx;
 	if (type != OP_BACK_REF)
 	  continue;
 	for (clexp_idx = 0; clexp_idx < init_nodes.nelem; ++clexp_idx)
@@ -1026,14 +1046,13 @@
 
 	if (type == OP_BACK_REF)
 	  {
-	    int dest_idx = dfa->edests[node_idx].elems[0];
+	    Idx dest_idx = dfa->edests[node_idx].elems[0];
 	    if (!re_node_set_contains (&init_nodes, dest_idx))
 	      {
-		reg_errcode_t err = re_node_set_merge (&init_nodes,
-						       dfa->eclosures
-						       + dest_idx);
-		if (err != REG_NOERROR)
-		  return err;
+		reg_errcode_t merge_err
+                  = re_node_set_merge (&init_nodes, dfa->eclosures + dest_idx);
+		if (merge_err != REG_NOERROR)
+		  return merge_err;
 		i = 0;
 	      }
 	  }
@@ -1074,14 +1093,17 @@
 static void
 optimize_utf8 (re_dfa_t *dfa)
 {
-  int node, i, mb_chars = 0, has_period = 0;
+  Idx node;
+  int i;
+  bool mb_chars = false;
+  bool has_period = false;
 
   for (node = 0; node < dfa->nodes_len; ++node)
     switch (dfa->nodes[node].type)
       {
       case CHARACTER:
-	if (dfa->nodes[node].opr.c >= 0x80)
-	  mb_chars = 1;
+	if (dfa->nodes[node].opr.c >= ASCII_CHARS)
+	  mb_chars = true;
 	break;
       case ANCHOR:
 	switch (dfa->nodes[node].opr.ctx_type)
@@ -1099,7 +1121,7 @@
 	  }
 	break;
       case OP_PERIOD:
-	has_period = 1;
+	has_period = true;
 	break;
       case OP_BACK_REF:
       case OP_ALT:
@@ -1111,11 +1133,18 @@
       case COMPLEX_BRACKET:
 	return;
       case SIMPLE_BRACKET:
-	/* Just double check.  The non-ASCII range starts at 0x80.  */
-	assert (0x80 % BITSET_WORD_BITS == 0);
-	for (i = 0x80 / BITSET_WORD_BITS; i < BITSET_WORDS; ++i)
-	  if (dfa->nodes[node].opr.sbcset[i])
-	    return;
+	/* Just double check.  */
+	{
+	  int rshift = (ASCII_CHARS % BITSET_WORD_BITS == 0
+			? 0
+			: BITSET_WORD_BITS - ASCII_CHARS % BITSET_WORD_BITS);
+	  for (i = ASCII_CHARS / BITSET_WORD_BITS; i < BITSET_WORDS; ++i)
+	    {
+	      if (dfa->nodes[node].opr.sbcset[i] >> rshift != 0)
+		return;
+	      rshift = 0;
+	    }
+	}
 	break;
       default:
 	abort ();
@@ -1125,7 +1154,7 @@
     for (node = 0; node < dfa->nodes_len; ++node)
       {
 	if (dfa->nodes[node].type == CHARACTER
-	    && dfa->nodes[node].opr.c >= 0x80)
+	    && dfa->nodes[node].opr.c >= ASCII_CHARS)
 	  dfa->nodes[node].mb_partial = 0;
 	else if (dfa->nodes[node].type == OP_PERIOD)
 	  dfa->nodes[node].type = OP_UTF8_PERIOD;
@@ -1144,22 +1173,22 @@
 static reg_errcode_t
 analyze (regex_t *preg)
 {
-  re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+  re_dfa_t *dfa = preg->buffer;
   reg_errcode_t ret;
 
   /* Allocate arrays.  */
-  dfa->nexts = re_malloc (int, dfa->nodes_alloc);
-  dfa->org_indices = re_malloc (int, dfa->nodes_alloc);
+  dfa->nexts = re_malloc (Idx, dfa->nodes_alloc);
+  dfa->org_indices = re_malloc (Idx, dfa->nodes_alloc);
   dfa->edests = re_malloc (re_node_set, dfa->nodes_alloc);
   dfa->eclosures = re_malloc (re_node_set, dfa->nodes_alloc);
   if (BE (dfa->nexts == NULL || dfa->org_indices == NULL || dfa->edests == NULL
 	  || dfa->eclosures == NULL, 0))
     return REG_ESPACE;
 
-  dfa->subexp_map = re_malloc (int, preg->re_nsub);
+  dfa->subexp_map = re_malloc (Idx, preg->re_nsub);
   if (dfa->subexp_map != NULL)
     {
-      int i;
+      Idx i;
       for (i = 0; i < preg->re_nsub; i++)
 	dfa->subexp_map[i] = i;
       preorder (dfa->str_tree, optimize_subexps, dfa);
@@ -1168,7 +1197,7 @@
 	  break;
       if (i == preg->re_nsub)
 	{
-	  free (dfa->subexp_map);
+	  re_free (dfa->subexp_map);
 	  dfa->subexp_map = NULL;
 	}
     }
@@ -1284,7 +1313,7 @@
   else if (node->token.type == SUBEXP
 	   && node->left && node->left->token.type == SUBEXP)
     {
-      int other_idx = node->left->token.opr.idx;
+      Idx other_idx = node->left->token.opr.idx;
 
       node->left = node->left->left;
       if (node->left)
@@ -1292,7 +1321,7 @@
 
       dfa->subexp_map[other_idx] = dfa->subexp_map[node->token.opr.idx];
       if (other_idx < BITSET_WORD_BITS)
-	  dfa->used_bkref_map &= ~((bitset_word_t) 1 << other_idx);
+	dfa->used_bkref_map &= ~((bitset_word_t) 1 << other_idx);
     }
 
   return REG_NOERROR;
@@ -1325,7 +1354,7 @@
 static bin_tree_t *
 lower_subexp (reg_errcode_t *err, regex_t *preg, bin_tree_t *node)
 {
-  re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+  re_dfa_t *dfa = preg->buffer;
   bin_tree_t *body = node->left;
   bin_tree_t *op, *cls, *tree1, *tree;
 
@@ -1408,7 +1437,7 @@
 link_nfa_nodes (void *extra, bin_tree_t *node)
 {
   re_dfa_t *dfa = (re_dfa_t *) extra;
-  int idx = node->node_idx;
+  Idx idx = node->node_idx;
   reg_errcode_t err = REG_NOERROR;
 
   switch (node->token.type)
@@ -1423,7 +1452,7 @@
     case OP_DUP_ASTERISK:
     case OP_ALT:
       {
-	int left, right;
+	Idx left, right;
 	dfa->has_plural_match = 1;
 	if (node->left != NULL)
 	  left = node->left->first->node_idx;
@@ -1465,14 +1494,15 @@
    to their own constraint.  */
 
 static reg_errcode_t
-duplicate_node_closure (re_dfa_t *dfa, int top_org_node, int top_clone_node,
-			int root_node, unsigned int init_constraint)
+duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, Idx top_clone_node,
+			Idx root_node, unsigned int init_constraint)
 {
-  int org_node, clone_node, ret;
+  Idx org_node, clone_node;
+  bool ok;
   unsigned int constraint = init_constraint;
   for (org_node = top_org_node, clone_node = top_clone_node;;)
     {
-      int org_dest, clone_dest;
+      Idx org_dest, clone_dest;
       if (dfa->nodes[org_node].type == OP_BACK_REF)
 	{
 	  /* If the back reference epsilon-transit, its destination must
@@ -1485,8 +1515,8 @@
 	  if (BE (clone_dest == -1, 0))
 	    return REG_ESPACE;
 	  dfa->nexts[clone_node] = dfa->nexts[org_node];
-	  ret = re_node_set_insert (dfa->edests + clone_node, clone_dest);
-	  if (BE (ret < 0, 0))
+	  ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
+	  if (BE (! ok, 0))
 	    return REG_ESPACE;
 	}
       else if (dfa->edests[org_node].nelem == 0)
@@ -1504,12 +1534,12 @@
 	  org_dest = dfa->edests[org_node].elems[0];
 	  re_node_set_empty (dfa->edests + clone_node);
 	  /* If the node is root_node itself, it means the epsilon closure
-	     has a loop.   Then tie it to the destination of the root_node.  */
+	     has a loop.  Then tie it to the destination of the root_node.  */
 	  if (org_node == root_node && clone_node != org_node)
 	    {
-	      ret = re_node_set_insert (dfa->edests + clone_node, org_dest);
-	      if (BE (ret < 0, 0))
-		return REG_ESPACE;
+	      ok = re_node_set_insert (dfa->edests + clone_node, org_dest);
+	      if (BE (! ok, 0))
+	        return REG_ESPACE;
 	      break;
 	    }
 	  /* In case the node has another constraint, append it.  */
@@ -1517,8 +1547,8 @@
 	  clone_dest = duplicate_node (dfa, org_dest, constraint);
 	  if (BE (clone_dest == -1, 0))
 	    return REG_ESPACE;
-	  ret = re_node_set_insert (dfa->edests + clone_node, clone_dest);
-	  if (BE (ret < 0, 0))
+	  ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
+	  if (BE (! ok, 0))
 	    return REG_ESPACE;
 	}
       else /* dfa->edests[org_node].nelem == 2 */
@@ -1536,8 +1566,8 @@
 	      clone_dest = duplicate_node (dfa, org_dest, constraint);
 	      if (BE (clone_dest == -1, 0))
 		return REG_ESPACE;
-	      ret = re_node_set_insert (dfa->edests + clone_node, clone_dest);
-	      if (BE (ret < 0, 0))
+	      ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
+	      if (BE (! ok, 0))
 		return REG_ESPACE;
 	      err = duplicate_node_closure (dfa, org_dest, clone_dest,
 					    root_node, constraint);
@@ -1548,8 +1578,8 @@
 	    {
 	      /* There is a duplicated node which satisfies the constraint,
 		 use it to avoid infinite loop.  */
-	      ret = re_node_set_insert (dfa->edests + clone_node, clone_dest);
-	      if (BE (ret < 0, 0))
+	      ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
+	      if (BE (! ok, 0))
 		return REG_ESPACE;
 	    }
 
@@ -1557,8 +1587,8 @@
 	  clone_dest = duplicate_node (dfa, org_dest, constraint);
 	  if (BE (clone_dest == -1, 0))
 	    return REG_ESPACE;
-	  ret = re_node_set_insert (dfa->edests + clone_node, clone_dest);
-	  if (BE (ret < 0, 0))
+	  ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
+	  if (BE (! ok, 0))
 	    return REG_ESPACE;
 	}
       org_node = org_dest;
@@ -1570,11 +1600,11 @@
 /* Search for a node which is duplicated from the node ORG_NODE, and
    satisfies the constraint CONSTRAINT.  */
 
-static int
-search_duplicated_node (const re_dfa_t *dfa, int org_node,
+static Idx
+search_duplicated_node (const re_dfa_t *dfa, Idx org_node,
 			unsigned int constraint)
 {
-  int idx;
+  Idx idx;
   for (idx = dfa->nodes_len - 1; dfa->nodes[idx].duplicated && idx > 0; --idx)
     {
       if (org_node == dfa->org_indices[idx]
@@ -1588,10 +1618,10 @@
    Return the index of the new node, or -1 if insufficient storage is
    available.  */
 
-static int
-duplicate_node (re_dfa_t *dfa, int org_idx, unsigned int constraint)
+static Idx
+duplicate_node (re_dfa_t *dfa, Idx org_idx, unsigned int constraint)
 {
-  int dup_idx = re_dfa_add_node (dfa, dfa->nodes[org_idx]);
+  Idx dup_idx = re_dfa_add_node (dfa, dfa->nodes[org_idx]);
   if (BE (dup_idx != -1, 1))
     {
       dfa->nodes[dup_idx].constraint = constraint;
@@ -1607,17 +1637,18 @@
 static reg_errcode_t
 calc_inveclosure (re_dfa_t *dfa)
 {
-  int src, idx, ret;
+  Idx src, idx;
+  bool ok;
   for (idx = 0; idx < dfa->nodes_len; ++idx)
     re_node_set_init_empty (dfa->inveclosures + idx);
 
   for (src = 0; src < dfa->nodes_len; ++src)
     {
-      int *elems = dfa->eclosures[src].elems;
+      Idx *elems = dfa->eclosures[src].elems;
       for (idx = 0; idx < dfa->eclosures[src].nelem; ++idx)
 	{
-	  ret = re_node_set_insert_last (dfa->inveclosures + elems[idx], src);
-	  if (BE (ret == -1, 0))
+	  ok = re_node_set_insert_last (dfa->inveclosures + elems[idx], src);
+	  if (BE (! ok, 0))
 	    return REG_ESPACE;
 	}
     }
@@ -1630,11 +1661,12 @@
 static reg_errcode_t
 calc_eclosure (re_dfa_t *dfa)
 {
-  int node_idx, incomplete;
+  Idx node_idx;
+  bool incomplete;
 #ifdef DEBUG
   assert (dfa->nodes_len > 0);
 #endif
-  incomplete = 0;
+  incomplete = false;
   /* For each nodes, calculate epsilon closure.  */
   for (node_idx = 0; ; ++node_idx)
     {
@@ -1644,7 +1676,7 @@
 	{
 	  if (!incomplete)
 	    break;
-	  incomplete = 0;
+	  incomplete = false;
 	  node_idx = 0;
 	}
 
@@ -1656,13 +1688,13 @@
       if (dfa->eclosures[node_idx].nelem != 0)
 	continue;
       /* Calculate epsilon closure of 'node_idx'.  */
-      err = calc_eclosure_iter (&eclosure_elem, dfa, node_idx, 1);
+      err = calc_eclosure_iter (&eclosure_elem, dfa, node_idx, true);
       if (BE (err != REG_NOERROR, 0))
 	return err;
 
       if (dfa->eclosures[node_idx].nelem == 0)
 	{
-	  incomplete = 1;
+	  incomplete = true;
 	  re_node_set_free (&eclosure_elem);
 	}
     }
@@ -1672,13 +1704,13 @@
 /* Calculate epsilon closure of NODE.  */
 
 static reg_errcode_t
-calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, int node, int root)
+calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root)
 {
   reg_errcode_t err;
-  int i;
+  Idx i;
   re_node_set eclosure;
-  int ret;
-  int incomplete = 0;
+  bool ok;
+  bool incomplete = false;
   err = re_node_set_alloc (&eclosure, dfa->edests[node].nelem + 1);
   if (BE (err != REG_NOERROR, 0))
     return err;
@@ -1704,19 +1736,19 @@
     for (i = 0; i < dfa->edests[node].nelem; ++i)
       {
 	re_node_set eclosure_elem;
-	int edest = dfa->edests[node].elems[i];
-	/* If calculating the epsilon closure of `edest' is in progress,
+	Idx edest = dfa->edests[node].elems[i];
+	/* If calculating the epsilon closure of 'edest' is in progress,
 	   return intermediate result.  */
 	if (dfa->eclosures[edest].nelem == -1)
 	  {
-	    incomplete = 1;
+	    incomplete = true;
 	    continue;
 	  }
-	/* If we haven't calculated the epsilon closure of `edest' yet,
+	/* If we haven't calculated the epsilon closure of 'edest' yet,
 	   calculate now. Otherwise use calculated epsilon closure.  */
 	if (dfa->eclosures[edest].nelem == 0)
 	  {
-	    err = calc_eclosure_iter (&eclosure_elem, dfa, edest, 0);
+	    err = calc_eclosure_iter (&eclosure_elem, dfa, edest, false);
 	    if (BE (err != REG_NOERROR, 0))
 	      return err;
 	  }
@@ -1730,14 +1762,14 @@
 	   the epsilon closure of this node is also incomplete.  */
 	if (dfa->eclosures[edest].nelem == 0)
 	  {
-	    incomplete = 1;
+	    incomplete = true;
 	    re_node_set_free (&eclosure_elem);
 	  }
       }
 
   /* An epsilon closure includes itself.  */
-  ret = re_node_set_insert (&eclosure, node);
-  if (BE (ret < 0, 0))
+  ok = re_node_set_insert (&eclosure, node);
+  if (BE (! ok, 0))
     return REG_ESPACE;
   if (incomplete && !root)
     dfa->eclosures[node].nelem = 0;
@@ -2046,16 +2078,18 @@
 	case '.':
 	  token->type = OP_OPEN_COLL_ELEM;
 	  break;
+
 	case '=':
 	  token->type = OP_OPEN_EQUIV_CLASS;
 	  break;
+
 	case ':':
 	  if (syntax & RE_CHAR_CLASSES)
 	    {
 	      token->type = OP_OPEN_CHAR_CLASS;
 	      break;
 	    }
-	  /* else fall through.  */
+	  FALLTHROUGH;
 	default:
 	  token->type = CHARACTER;
 	  token->opr.c = c;
@@ -2099,7 +2133,7 @@
 parse (re_string_t *regexp, regex_t *preg, reg_syntax_t syntax,
        reg_errcode_t *err)
 {
-  re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+  re_dfa_t *dfa = preg->buffer;
   bin_tree_t *tree, *eor, *root;
   re_token_t current_token;
   dfa->syntax = syntax;
@@ -2131,10 +2165,11 @@
 
 static bin_tree_t *
 parse_reg_exp (re_string_t *regexp, regex_t *preg, re_token_t *token,
-	       reg_syntax_t syntax, int nest, reg_errcode_t *err)
+	       reg_syntax_t syntax, Idx nest, reg_errcode_t *err)
 {
-  re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+  re_dfa_t *dfa = preg->buffer;
   bin_tree_t *tree, *branch = NULL;
+  bitset_word_t initial_bkref_map = dfa->completed_bkref_map;
   tree = parse_branch (regexp, preg, token, syntax, nest, err);
   if (BE (*err != REG_NOERROR && tree == NULL, 0))
     return NULL;
@@ -2145,6 +2180,8 @@
       if (token->type != OP_ALT && token->type != END_OF_RE
 	  && (nest == 0 || token->type != OP_CLOSE_SUBEXP))
 	{
+	  bitset_word_t accumulated_bkref_map = dfa->completed_bkref_map;
+	  dfa->completed_bkref_map = initial_bkref_map;
 	  branch = parse_branch (regexp, preg, token, syntax, nest, err);
 	  if (BE (*err != REG_NOERROR && branch == NULL, 0))
 	    {
@@ -2152,6 +2189,7 @@
 		postorder (tree, free_tree, NULL);
 	      return NULL;
 	    }
+	  dfa->completed_bkref_map |= accumulated_bkref_map;
 	}
       else
 	branch = NULL;
@@ -2176,10 +2214,10 @@
 
 static bin_tree_t *
 parse_branch (re_string_t *regexp, regex_t *preg, re_token_t *token,
-	      reg_syntax_t syntax, int nest, reg_errcode_t *err)
+	      reg_syntax_t syntax, Idx nest, reg_errcode_t *err)
 {
-  bin_tree_t *tree, *exp;
-  re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+  bin_tree_t *tree, *expr;
+  re_dfa_t *dfa = preg->buffer;
   tree = parse_expression (regexp, preg, token, syntax, nest, err);
   if (BE (*err != REG_NOERROR && tree == NULL, 0))
     return NULL;
@@ -2187,19 +2225,19 @@
   while (token->type != OP_ALT && token->type != END_OF_RE
 	 && (nest == 0 || token->type != OP_CLOSE_SUBEXP))
     {
-      exp = parse_expression (regexp, preg, token, syntax, nest, err);
-      if (BE (*err != REG_NOERROR && exp == NULL, 0))
+      expr = parse_expression (regexp, preg, token, syntax, nest, err);
+      if (BE (*err != REG_NOERROR && expr == NULL, 0))
 	{
 	  if (tree != NULL)
 	    postorder (tree, free_tree, NULL);
 	  return NULL;
 	}
-      if (tree != NULL && exp != NULL)
+      if (tree != NULL && expr != NULL)
 	{
-	  bin_tree_t *newtree = create_tree (dfa, tree, exp, CONCAT);
+	  bin_tree_t *newtree = create_tree (dfa, tree, expr, CONCAT);
 	  if (newtree == NULL)
 	    {
-	      postorder (exp, free_tree, NULL);
+	      postorder (expr, free_tree, NULL);
 	      postorder (tree, free_tree, NULL);
 	      *err = REG_ESPACE;
 	      return NULL;
@@ -2207,8 +2245,8 @@
 	  tree = newtree;
 	}
       else if (tree == NULL)
-	tree = exp;
-      /* Otherwise exp == NULL, we don't need to create new tree.  */
+	tree = expr;
+      /* Otherwise expr == NULL, we don't need to create new tree.  */
     }
   return tree;
 }
@@ -2221,9 +2259,9 @@
 
 static bin_tree_t *
 parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
-		  reg_syntax_t syntax, int nest, reg_errcode_t *err)
+		  reg_syntax_t syntax, Idx nest, reg_errcode_t *err)
 {
-  re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+  re_dfa_t *dfa = preg->buffer;
   bin_tree_t *tree;
   switch (token->type)
     {
@@ -2253,16 +2291,19 @@
 	}
 #endif
       break;
+
     case OP_OPEN_SUBEXP:
       tree = parse_sub_exp (regexp, preg, token, syntax, nest + 1, err);
       if (BE (*err != REG_NOERROR && tree == NULL, 0))
 	return NULL;
       break;
+
     case OP_OPEN_BRACKET:
       tree = parse_bracket_exp (regexp, dfa, token, syntax, err);
       if (BE (*err != REG_NOERROR && tree == NULL, 0))
 	return NULL;
       break;
+
     case OP_BACK_REF:
       if (!BE (dfa->completed_bkref_map & (1 << token->opr.idx), 1))
 	{
@@ -2279,13 +2320,14 @@
       ++dfa->nbackref;
       dfa->has_mb_node = 1;
       break;
+
     case OP_OPEN_DUP_NUM:
       if (syntax & RE_CONTEXT_INVALID_DUP)
 	{
 	  *err = REG_BADRPT;
 	  return NULL;
 	}
-      /* FALLTHROUGH */
+      FALLTHROUGH;
     case OP_DUP_ASTERISK:
     case OP_DUP_PLUS:
     case OP_DUP_QUESTION:
@@ -2299,7 +2341,7 @@
 	  fetch_token (token, regexp, syntax);
 	  return parse_expression (regexp, preg, token, syntax, nest, err);
 	}
-      /* else fall through  */
+      FALLTHROUGH;
     case OP_CLOSE_SUBEXP:
       if ((token->type == OP_CLOSE_SUBEXP) &&
 	  !(syntax & RE_UNMATCHED_RIGHT_PAREN_ORD))
@@ -2307,7 +2349,7 @@
 	  *err = REG_ERPAREN;
 	  return NULL;
 	}
-      /* else fall through  */
+      FALLTHROUGH;
     case OP_CLOSE_DUP_NUM:
       /* We treat it as a normal character.  */
 
@@ -2322,6 +2364,7 @@
 	  return NULL;
 	}
       break;
+
     case ANCHOR:
       if ((token->opr.ctx_type
 	   & (WORD_DELIM | NOT_WORD_DELIM | WORD_FIRST | WORD_LAST))
@@ -2366,6 +2409,7 @@
 	     it must not be "<ANCHOR(^)><REPEAT(*)>".  */
       fetch_token (token, regexp, syntax);
       return tree;
+
     case OP_PERIOD:
       tree = create_token_tree (dfa, NULL, NULL, token);
       if (BE (tree == NULL, 0))
@@ -2376,30 +2420,35 @@
       if (dfa->mb_cur_max > 1)
 	dfa->has_mb_node = 1;
       break;
+
     case OP_WORD:
     case OP_NOTWORD:
       tree = build_charclass_op (dfa, regexp->trans,
-				 (const unsigned char *) "alnum",
-				 (const unsigned char *) "_",
+				 "alnum",
+				 "_",
 				 token->type == OP_NOTWORD, err);
       if (BE (*err != REG_NOERROR && tree == NULL, 0))
 	return NULL;
       break;
+
     case OP_SPACE:
     case OP_NOTSPACE:
       tree = build_charclass_op (dfa, regexp->trans,
-				 (const unsigned char *) "space",
-				 (const unsigned char *) "",
+				 "space",
+				 "",
 				 token->type == OP_NOTSPACE, err);
       if (BE (*err != REG_NOERROR && tree == NULL, 0))
 	return NULL;
       break;
+
     case OP_ALT:
     case END_OF_RE:
       return NULL;
+
     case BACK_SLASH:
       *err = REG_EESCAPE;
       return NULL;
+
     default:
       /* Must not happen?  */
 #ifdef DEBUG
@@ -2412,7 +2461,8 @@
   while (token->type == OP_DUP_ASTERISK || token->type == OP_DUP_PLUS
 	 || token->type == OP_DUP_QUESTION || token->type == OP_OPEN_DUP_NUM)
     {
-      bin_tree_t *dup_tree = parse_dup_op (tree, regexp, dfa, token, syntax, err);
+      bin_tree_t *dup_tree = parse_dup_op (tree, regexp, dfa, token,
+					   syntax, err);
       if (BE (*err != REG_NOERROR && dup_tree == NULL, 0))
 	{
 	  if (tree != NULL)
@@ -2444,9 +2494,9 @@
 
 static bin_tree_t *
 parse_sub_exp (re_string_t *regexp, regex_t *preg, re_token_t *token,
-	       reg_syntax_t syntax, int nest, reg_errcode_t *err)
+	       reg_syntax_t syntax, Idx nest, reg_errcode_t *err)
 {
-  re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+  re_dfa_t *dfa = preg->buffer;
   bin_tree_t *tree;
   size_t cur_nsub;
   cur_nsub = preg->re_nsub++;
@@ -2489,7 +2539,7 @@
 	      re_token_t *token, reg_syntax_t syntax, reg_errcode_t *err)
 {
   bin_tree_t *tree = NULL, *old_tree = NULL;
-  int i, start, end, start_idx = re_string_cur_idx (regexp);
+  Idx i, start, end, start_idx = re_string_cur_idx (regexp);
   re_token_t start_token = *token;
 
   if (token->type == OP_OPEN_DUP_NUM)
@@ -2535,12 +2585,19 @@
 	  return elem;
 	}
 
-      if (BE ((end != -1 && start > end) || token->type != OP_CLOSE_DUP_NUM, 0))
+      if (BE ((end != -1 && start > end)
+	      || token->type != OP_CLOSE_DUP_NUM, 0))
 	{
 	  /* First number greater than second.  */
 	  *err = REG_BADBR;
 	  return NULL;
 	}
+
+      if (BE (RE_DUP_MAX < (end == -1 ? start : end), 0))
+	{
+	  *err = REG_ESIZE;
+	  return NULL;
+	}
     }
   else
     {
@@ -2583,26 +2640,31 @@
     old_tree = NULL;
 
   if (elem->token.type == SUBEXP)
-    postorder (elem, mark_opt_subexp, (void *) (long) elem->token.opr.idx);
+    {
+      uintptr_t subidx = elem->token.opr.idx;
+      postorder (elem, mark_opt_subexp, (void *) subidx);
+    }
 
-  tree = create_tree (dfa, elem, NULL, (end == -1 ? OP_DUP_ASTERISK : OP_ALT));
+  tree = create_tree (dfa, elem, NULL,
+		      (end == -1 ? OP_DUP_ASTERISK : OP_ALT));
   if (BE (tree == NULL, 0))
     goto parse_dup_op_espace;
 
   /* This loop is actually executed only when end != -1,
      to rewrite <re>{0,n} as (<re>(<re>...<re>?)?)?...  We have
      already created the start+1-th copy.  */
-  for (i = start + 2; i <= end; ++i)
-    {
-      elem = duplicate_tree (elem, dfa);
-      tree = create_tree (dfa, tree, elem, CONCAT);
-      if (BE (elem == NULL || tree == NULL, 0))
-	goto parse_dup_op_espace;
+  if (TYPE_SIGNED (Idx) || end != -1)
+    for (i = start + 2; i <= end; ++i)
+      {
+	elem = duplicate_tree (elem, dfa);
+	tree = create_tree (dfa, tree, elem, CONCAT);
+	if (BE (elem == NULL || tree == NULL, 0))
+	  goto parse_dup_op_espace;
 
-      tree = create_tree (dfa, tree, NULL, OP_ALT);
-      if (BE (tree == NULL, 0))
-	goto parse_dup_op_espace;
-    }
+	tree = create_tree (dfa, tree, NULL, OP_ALT);
+	if (BE (tree == NULL, 0))
+	  goto parse_dup_op_espace;
+      }
 
   if (old_tree)
     tree = create_tree (dfa, old_tree, tree, CONCAT);
@@ -2619,6 +2681,19 @@
 #define BRACKET_NAME_BUF_SIZE 32
 
 #ifndef _LIBC
+
+# ifdef RE_ENABLE_I18N
+/* Convert the byte B to the corresponding wide character.  In a
+   unibyte locale, treat B as itself if it is an encoding error.
+   In a multibyte locale, return WEOF if B is an encoding error.  */
+static wint_t
+parse_byte (unsigned char b, re_charset_t *mbcset)
+{
+  wint_t wc = __btowc (b);
+  return wc == WEOF && !mbcset ? b : wc;
+}
+#endif
+
   /* Local function for parse_bracket_exp only used in case of NOT _LIBC.
      Build the range expression which starts from START_ELEM, and ends
      at END_ELEM.  The result are written to MBCSET and SBCSET.
@@ -2628,11 +2703,17 @@
 
 static reg_errcode_t
 # ifdef RE_ENABLE_I18N
-build_range_exp (bitset_t sbcset, re_charset_t *mbcset, int *range_alloc,
-		 bracket_elem_t *start_elem, bracket_elem_t *end_elem)
+build_range_exp (const reg_syntax_t syntax,
+                 bitset_t sbcset,
+                 re_charset_t *mbcset,
+                 Idx *range_alloc,
+                 const bracket_elem_t *start_elem,
+                 const bracket_elem_t *end_elem)
 # else /* not RE_ENABLE_I18N */
-build_range_exp (bitset_t sbcset, bracket_elem_t *start_elem,
-		 bracket_elem_t *end_elem)
+build_range_exp (const reg_syntax_t syntax,
+                 bitset_t sbcset,
+                 const bracket_elem_t *start_elem,
+                 const bracket_elem_t *end_elem)
 # endif /* not RE_ENABLE_I18N */
 {
   unsigned int start_ch, end_ch;
@@ -2655,7 +2736,6 @@
     wchar_t wc;
     wint_t start_wc;
     wint_t end_wc;
-    wchar_t cmp_buf[6] = {L'\0', L'\0', L'\0', L'\0', L'\0', L'\0'};
 
     start_ch = ((start_elem->type == SB_CHAR) ? start_elem->opr.ch
 		: ((start_elem->type == COLL_SYM) ? start_elem->opr.name[0]
@@ -2664,14 +2744,12 @@
 	      : ((end_elem->type == COLL_SYM) ? end_elem->opr.name[0]
 		 : 0));
     start_wc = ((start_elem->type == SB_CHAR || start_elem->type == COLL_SYM)
-		? __btowc (start_ch) : start_elem->opr.wch);
+		? parse_byte (start_ch, mbcset) : start_elem->opr.wch);
     end_wc = ((end_elem->type == SB_CHAR || end_elem->type == COLL_SYM)
-	      ? __btowc (end_ch) : end_elem->opr.wch);
+	      ? parse_byte (end_ch, mbcset) : end_elem->opr.wch);
     if (start_wc == WEOF || end_wc == WEOF)
       return REG_ECOLLATE;
-    cmp_buf[0] = start_wc;
-    cmp_buf[4] = end_wc;
-    if (__wcscoll (cmp_buf, cmp_buf + 4) > 0)
+    else if (BE ((syntax & RE_NO_EMPTY_RANGES) && start_wc > end_wc, 0))
       return REG_ERANGE;
 
     /* Got valid collation sequence values, add them as a new entry.
@@ -2686,7 +2764,7 @@
 	  {
 	    /* There is not enough space, need realloc.  */
 	    wchar_t *new_array_start, *new_array_end;
-	    int new_nranges;
+	    Idx new_nranges;
 
 	    /* +1 in case of mbcset->nranges is 0.  */
 	    new_nranges = 2 * mbcset->nranges + 1;
@@ -2698,7 +2776,11 @@
 					new_nranges);
 
 	    if (BE (new_array_start == NULL || new_array_end == NULL, 0))
-	      return REG_ESPACE;
+	      {
+		re_free (new_array_start);
+		re_free (new_array_end);
+		return REG_ESPACE;
+	      }
 
 	    mbcset->range_starts = new_array_start;
 	    mbcset->range_ends = new_array_end;
@@ -2712,9 +2794,7 @@
     /* Build the table for single byte characters.  */
     for (wc = 0; wc < SBC_MAX; ++wc)
       {
-	cmp_buf[2] = wc;
-	if (__wcscoll (cmp_buf, cmp_buf + 2) <= 0
-	    && __wcscoll (cmp_buf + 2, cmp_buf + 4) <= 0)
+	if (start_wc <= wc && wc <= end_wc)
 	  bitset_set (sbcset, wc);
       }
   }
@@ -2749,7 +2829,7 @@
 static reg_errcode_t
 # ifdef RE_ENABLE_I18N
 build_collating_symbol (bitset_t sbcset, re_charset_t *mbcset,
-			int *coll_sym_alloc, const unsigned char *name)
+			Idx *coll_sym_alloc, const unsigned char *name)
 # else /* not RE_ENABLE_I18N */
 build_collating_symbol (bitset_t sbcset, const unsigned char *name)
 # endif /* not RE_ENABLE_I18N */
@@ -3153,6 +3233,7 @@
 	      0))
 	return REG_ERANGE;
 
+      /* FIXME: Implement rational ranges here, too.  */
       start_collseq = lookup_collation_sequence_value (start_elem);
       end_collseq = lookup_collation_sequence_value (end_elem);
       /* Check start/end collation sequence values.  */
@@ -3173,7 +3254,7 @@
 	      /* There is not enough space, need realloc.  */
 	      uint32_t *new_array_start;
 	      uint32_t *new_array_end;
-	      int new_nranges;
+	      Idx new_nranges;
 
 	      /* +1 in case of mbcset->nranges is 0.  */
 	      new_nranges = 2 * mbcset->nranges + 1;
@@ -3220,7 +3301,7 @@
   auto inline reg_errcode_t
   __attribute__ ((always_inline))
   build_collating_symbol (bitset_t sbcset, re_charset_t *mbcset,
-			  int *coll_sym_alloc, const unsigned char *name)
+			  Idx *coll_sym_alloc, const unsigned char *name)
     {
       int32_t elem, idx;
       size_t name_len = strlen ((const char *) name);
@@ -3250,7 +3331,7 @@
 	    {
 	      /* Not enough, realloc it.  */
 	      /* +1 in case of mbcset->ncoll_syms is 0.  */
-	      int new_coll_sym_alloc = 2 * mbcset->ncoll_syms + 1;
+	      Idx new_coll_sym_alloc = 2 * mbcset->ncoll_syms + 1;
 	      /* Use realloc since mbcset->coll_syms is NULL
 		 if *alloc == 0.  */
 	      int32_t *new_coll_syms = re_realloc (mbcset->coll_syms, int32_t,
@@ -3281,13 +3362,13 @@
   re_bitset_ptr_t sbcset;
 #ifdef RE_ENABLE_I18N
   re_charset_t *mbcset;
-  int coll_sym_alloc = 0, range_alloc = 0, mbchar_alloc = 0;
-  int equiv_class_alloc = 0, char_class_alloc = 0;
+  Idx coll_sym_alloc = 0, range_alloc = 0, mbchar_alloc = 0;
+  Idx equiv_class_alloc = 0, char_class_alloc = 0;
 #endif /* not RE_ENABLE_I18N */
-  int non_match = 0;
+  bool non_match = false;
   bin_tree_t *work_tree;
   int token_len;
-  int first_round = 1;
+  bool first_round = true;
 #ifdef _LIBC
   collseqmb = (const unsigned char *)
     _NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQMB);
@@ -3334,7 +3415,7 @@
 #ifdef RE_ENABLE_I18N
       mbcset->non_match = 1;
 #endif /* not RE_ENABLE_I18N */
-      non_match = 1;
+      non_match = true;
       if (syntax & RE_HAT_LISTS_NOT_NEWLINE)
 	bitset_set (sbcset, '\n');
       re_string_skip_bytes (regexp, token_len); /* Skip a token.  */
@@ -3356,7 +3437,8 @@
       unsigned char start_name_buf[BRACKET_NAME_BUF_SIZE];
       unsigned char end_name_buf[BRACKET_NAME_BUF_SIZE];
       reg_errcode_t ret;
-      int token_len2 = 0, is_range_exp = 0;
+      int token_len2 = 0;
+      bool is_range_exp = false;
       re_token_t token2;
 
       start_elem.opr.name = start_name_buf;
@@ -3368,7 +3450,7 @@
 	  *err = ret;
 	  goto parse_bracket_exp_free_return;
 	}
-      first_round = 0;
+      first_round = false;
 
       /* Get information about the next token.  We need it in any case.  */
       token_len = peek_token_bracket (token, regexp, syntax);
@@ -3397,16 +3479,16 @@
 		  token->type = CHARACTER;
 		}
 	      else
-		is_range_exp = 1;
+		is_range_exp = true;
 	    }
 	}
 
-      if (is_range_exp == 1)
+      if (is_range_exp == true)
 	{
 	  end_elem.opr.name = end_name_buf;
 	  end_elem.type = COLL_SYM;
 	  ret = parse_bracket_element (&end_elem, regexp, &token2, token_len2,
-				       dfa, syntax, 1);
+				       dfa, syntax, true);
 	  if (BE (ret != REG_NOERROR, 0))
 	    {
 	      *err = ret;
@@ -3427,11 +3509,11 @@
 # endif /* NESTING */
 #else
 # ifdef RE_ENABLE_I18N
-	  *err = build_range_exp (sbcset,
+	  *err = build_range_exp (syntax, sbcset,
 				  dfa->mb_cur_max > 1 ? mbcset : NULL,
 				  &range_alloc, &start_elem, &end_elem);
 # else
-	  *err = build_range_exp (sbcset, &start_elem, &end_elem);
+	  *err = build_range_exp (syntax, sbcset, &start_elem, &end_elem);
 # endif
 #endif /* RE_ENABLE_I18N */
 	  if (BE (*err != REG_NOERROR, 0))
@@ -3490,7 +3572,8 @@
 #ifdef RE_ENABLE_I18N
 				      mbcset, &char_class_alloc,
 #endif /* RE_ENABLE_I18N */
-				      start_elem.opr.name, syntax);
+				      (const char *) start_elem.opr.name,
+				      syntax);
 	      if (BE (*err != REG_NOERROR, 0))
 	       goto parse_bracket_exp_free_return;
 	      break;
@@ -3587,7 +3670,7 @@
 static reg_errcode_t
 parse_bracket_element (bracket_elem_t *elem, re_string_t *regexp,
 		       re_token_t *token, int token_len, re_dfa_t *dfa,
-		       reg_syntax_t syntax, int accept_hyphen)
+		       reg_syntax_t syntax, bool accept_hyphen)
 {
 #ifdef RE_ENABLE_I18N
   int cur_char_size;
@@ -3674,7 +3757,7 @@
 static reg_errcode_t
 #ifdef RE_ENABLE_I18N
 build_equiv_class (bitset_t sbcset, re_charset_t *mbcset,
-		   int *equiv_class_alloc, const unsigned char *name)
+		   Idx *equiv_class_alloc, const unsigned char *name)
 #else /* not RE_ENABLE_I18N */
 build_equiv_class (bitset_t sbcset, const unsigned char *name)
 #endif /* not RE_ENABLE_I18N */
@@ -3736,7 +3819,7 @@
 	{
 	  /* Not enough, realloc it.  */
 	  /* +1 in case of mbcset->nequiv_classes is 0.  */
-	  int new_equiv_class_alloc = 2 * mbcset->nequiv_classes + 1;
+	  Idx new_equiv_class_alloc = 2 * mbcset->nequiv_classes + 1;
 	  /* Use realloc since the array is NULL if *alloc == 0.  */
 	  int32_t *new_equiv_classes = re_realloc (mbcset->equiv_classes,
 						   int32_t,
@@ -3767,15 +3850,15 @@
 static reg_errcode_t
 #ifdef RE_ENABLE_I18N
 build_charclass (RE_TRANSLATE_TYPE trans, bitset_t sbcset,
-		 re_charset_t *mbcset, int *char_class_alloc,
-		 const unsigned char *class_name, reg_syntax_t syntax)
+		 re_charset_t *mbcset, Idx *char_class_alloc,
+		 const char *class_name, reg_syntax_t syntax)
 #else /* not RE_ENABLE_I18N */
 build_charclass (RE_TRANSLATE_TYPE trans, bitset_t sbcset,
-		 const unsigned char *class_name, reg_syntax_t syntax)
+		 const char *class_name, reg_syntax_t syntax)
 #endif /* not RE_ENABLE_I18N */
 {
   int i;
-  const char *name = (const char *) class_name;
+  const char *name = class_name;
 
   /* In case of REG_ICASE "upper" and "lower" match the both of
      upper and lower cases.  */
@@ -3789,7 +3872,7 @@
     {
       /* Not enough, realloc it.  */
       /* +1 in case of mbcset->nchar_classes is 0.  */
-      int new_char_class_alloc = 2 * mbcset->nchar_classes + 1;
+      Idx new_char_class_alloc = 2 * mbcset->nchar_classes + 1;
       /* Use realloc since array is NULL if *alloc == 0.  */
       wctype_t *new_char_classes = re_realloc (mbcset->char_classes, wctype_t,
 					       new_char_class_alloc);
@@ -3806,13 +3889,13 @@
     if (BE (trans != NULL, 0))			\
       {						\
 	for (i = 0; i < SBC_MAX; ++i)		\
-  	  if (ctype_func (i))			\
+	  if (ctype_func (i))			\
 	    bitset_set (sbcset, trans[i]);	\
       }						\
     else					\
       {						\
 	for (i = 0; i < SBC_MAX; ++i)		\
-  	  if (ctype_func (i))			\
+	  if (ctype_func (i))			\
 	    bitset_set (sbcset, i);		\
       }						\
   } while (0)
@@ -3849,40 +3932,35 @@
 
 static bin_tree_t *
 build_charclass_op (re_dfa_t *dfa, RE_TRANSLATE_TYPE trans,
-		    const unsigned char *class_name,
-		    const unsigned char *extra, int non_match,
+		    const char *class_name,
+		    const char *extra, bool non_match,
 		    reg_errcode_t *err)
 {
   re_bitset_ptr_t sbcset;
 #ifdef RE_ENABLE_I18N
   re_charset_t *mbcset;
-  int alloc = 0;
+  Idx alloc = 0;
 #endif /* not RE_ENABLE_I18N */
   reg_errcode_t ret;
   re_token_t br_token;
   bin_tree_t *tree;
 
   sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);
-#ifdef RE_ENABLE_I18N
-  mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1);
-#endif /* RE_ENABLE_I18N */
-
-#ifdef RE_ENABLE_I18N
-  if (BE (sbcset == NULL || mbcset == NULL, 0))
-#else /* not RE_ENABLE_I18N */
   if (BE (sbcset == NULL, 0))
-#endif /* not RE_ENABLE_I18N */
     {
       *err = REG_ESPACE;
       return NULL;
     }
-
-  if (non_match)
-    {
 #ifdef RE_ENABLE_I18N
-      mbcset->non_match = 1;
-#endif /* not RE_ENABLE_I18N */
+  mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1);
+  if (BE (mbcset == NULL, 0))
+    {
+      re_free (sbcset);
+      *err = REG_ESPACE;
+      return NULL;
     }
+  mbcset->non_match = non_match;
+#endif /* RE_ENABLE_I18N */
 
   /* We don't care the syntax in this case.  */
   ret = build_charclass (trans, sbcset,
@@ -3915,6 +3993,9 @@
 #endif
 
   /* Build a tree for simple bracket.  */
+#if defined GCC_LINT || defined lint
+  memset (&br_token, 0, sizeof br_token);
+#endif
   br_token.type = SIMPLE_BRACKET;
   br_token.opr.sbcset = sbcset;
   tree = create_token_tree (dfa, NULL, NULL, &br_token);
@@ -3956,14 +4037,15 @@
 }
 
 /* This is intended for the expressions like "a{1,3}".
-   Fetch a number from `input', and return the number.
-   Return -1, if the number field is empty like "{,1}".
-   Return -2, If an error is occured.  */
+   Fetch a number from 'input', and return the number.
+   Return -1 if the number field is empty like "{,1}".
+   Return RE_DUP_MAX + 1 if the number field is too large.
+   Return -2 if an error occurred.  */
 
-static int
+static Idx
 fetch_number (re_string_t *input, re_token_t *token, reg_syntax_t syntax)
 {
-  int num = -1;
+  Idx num = -1;
   unsigned char c;
   while (1)
     {
@@ -3974,8 +4056,10 @@
       if (token->type == OP_CLOSE_DUP_NUM || c == ',')
 	break;
       num = ((token->type != CHARACTER || c < '0' || '9' < c || num == -2)
-	     ? -2 : ((num == -1) ? c - '0' : num * 10 + c - '0'));
-      num = (num > RE_DUP_MAX) ? -2 : num;
+	     ? -2
+	     : num == -1
+	     ? c - '0'
+	     : MIN (RE_DUP_MAX + 1, num * 10 + c - '0'));
     }
   return num;
 }
@@ -4005,6 +4089,9 @@
 	     re_token_type_t type)
 {
   re_token_t t;
+#if defined GCC_LINT || defined lint
+  memset (&t, 0, sizeof t);
+#endif
   t.type = type;
   return create_token_tree (dfa, left, right, &t);
 }
@@ -4049,7 +4136,7 @@
 static reg_errcode_t
 mark_opt_subexp (void *extra, bin_tree_t *node)
 {
-  int idx = (int) (long) extra;
+  Idx idx = (uintptr_t) extra;
   if (node->token.type == SUBEXP && node->token.opr.idx == idx)
     node->token.opt_subexp = 1;
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/posix/regex.c b/google3/third_party/grte/v5_src/glibc-2.27/posix/regex.c
index 68b5ef1..d6591e8 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/posix/regex.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/posix/regex.c
@@ -15,14 +15,22 @@
 
    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
+   <https://www.gnu.org/licenses/>.  */
 
-#ifdef HAVE_CONFIG_H
-#include "config.h"
+#ifndef _LIBC
+# include <config.h>
+
+# if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__
+#  pragma GCC diagnostic ignored "-Wsuggest-attribute=pure"
+# endif
+# if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__
+#  pragma GCC diagnostic ignored "-Wold-style-definition"
+#  pragma GCC diagnostic ignored "-Wtype-limits"
+# endif
 #endif
 
-/* Make sure noone compiles this code with a C++ compiler.  */
-#ifdef __cplusplus
+/* Make sure no one compiles this code with a C++ compiler.  */
+#if defined __cplusplus && defined _LIBC
 # error "This is C code, use a C compiler"
 #endif
 
@@ -56,9 +64,6 @@
    #undefs RE_DUP_MAX and sets it to the right value.  */
 #include <limits.h>
 
-/* This header defines the MIN and MAX macros.  */
-#include <sys/param.h>
-
 #include <regex.h>
 #include "regex_internal.h"
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/posix/regex.h b/google3/third_party/grte/v5_src/glibc-2.27/posix/regex.h
index e0b8915..32933bc 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/posix/regex.h
+++ b/google3/third_party/grte/v5_src/glibc-2.27/posix/regex.h
@@ -15,7 +15,7 @@
 
    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
+   <https://www.gnu.org/licenses/>.  */
 
 #ifndef _REGEX_H
 #define _REGEX_H 1
@@ -27,6 +27,36 @@
 extern "C" {
 #endif
 
+/* Define __USE_GNU to declare GNU extensions that violate the
+   POSIX name space rules.  */
+#ifdef _GNU_SOURCE
+# define __USE_GNU 1
+#endif
+
+#ifdef _REGEX_LARGE_OFFSETS
+
+/* Use types and values that are wide enough to represent signed and
+   unsigned byte offsets in memory.  This currently works only when
+   the regex code is used outside of the GNU C library; it is not yet
+   supported within glibc itself, and glibc users should not define
+   _REGEX_LARGE_OFFSETS.  */
+
+/* The type of object sizes.  */
+typedef size_t __re_size_t;
+
+/* The type of object sizes, in places where the traditional code
+   uses unsigned long int.  */
+typedef size_t __re_long_size_t;
+
+#else
+
+/* The traditional GNU regex implementation mishandles strings longer
+   than INT_MAX.  */
+typedef unsigned int __re_size_t;
+typedef unsigned long int __re_long_size_t;
+
+#endif
+
 /* The following two types have to be signed and unsigned integer type
    wide enough to hold a value of a pointer.  For most ANSI compilers
    ptrdiff_t and size_t should be likely OK.  Still size of these two
@@ -108,9 +138,9 @@
    If not set, newline is literal.  */
 # define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1)
 
-/* If this bit is set, then `{...}' defines an interval, and \{ and \}
+/* If this bit is set, then '{...}' defines an interval, and \{ and \}
      are literals.
-  If not set, then `\{...\}' defines an interval.  */
+  If not set, then '\{...\}' defines an interval.  */
 # define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
 
 /* If this bit is set, (...) defines a group, and \( and \) are literals.
@@ -165,8 +195,8 @@
    whether ^ should be special.  */
 # define RE_CARET_ANCHORS_HERE (RE_ICASE << 1)
 
-/* If this bit is set, then \{ cannot be first in an bre or
-   immediately after an alternation or begin-group operator.  */
+/* If this bit is set, then \{ cannot be first in a regex or
+   immediately after an alternation, open-group or \} operator.  */
 # define RE_CONTEXT_INVALID_DUP (RE_CARET_ANCHORS_HERE << 1)
 
 /* If this bit is set, then no_sub will be set to 1 during
@@ -185,9 +215,9 @@
    (The [[[ comments delimit what gets put into the Texinfo file, so
    don't delete them!)  */
 /* [[[begin syntaxes]]] */
-#define RE_SYNTAX_EMACS 0
+# define RE_SYNTAX_EMACS 0
 
-#define RE_SYNTAX_AWK							\
+# define RE_SYNTAX_AWK							\
   (RE_BACKSLASH_ESCAPE_IN_LISTS   | RE_DOT_NOT_NULL			\
    | RE_NO_BK_PARENS              | RE_NO_BK_REFS			\
    | RE_NO_BK_VBAR                | RE_NO_EMPTY_RANGES			\
@@ -195,52 +225,49 @@
    | RE_CHAR_CLASSES							\
    | RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS)
 
-#define RE_SYNTAX_GNU_AWK						\
+# define RE_SYNTAX_GNU_AWK						\
   ((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS		\
     | RE_INVALID_INTERVAL_ORD)						\
    & ~(RE_DOT_NOT_NULL | RE_CONTEXT_INDEP_OPS				\
       | RE_CONTEXT_INVALID_OPS ))
 
-#define RE_SYNTAX_POSIX_AWK						\
+# define RE_SYNTAX_POSIX_AWK						\
   (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS		\
    | RE_INTERVALS	    | RE_NO_GNU_OPS				\
    | RE_INVALID_INTERVAL_ORD)
 
-#define RE_SYNTAX_GREP							\
-  (RE_BK_PLUS_QM              | RE_CHAR_CLASSES				\
-   | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS				\
-   | RE_NEWLINE_ALT)
+# define RE_SYNTAX_GREP							\
+  ((RE_SYNTAX_POSIX_BASIC | RE_NEWLINE_ALT)				\
+   & ~(RE_CONTEXT_INVALID_DUP | RE_DOT_NOT_NULL))
 
-#define RE_SYNTAX_EGREP							\
-  (RE_CHAR_CLASSES        | RE_CONTEXT_INDEP_ANCHORS			\
-   | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE			\
-   | RE_NEWLINE_ALT       | RE_NO_BK_PARENS				\
-   | RE_NO_BK_VBAR)
+# define RE_SYNTAX_EGREP						\
+  ((RE_SYNTAX_POSIX_EXTENDED | RE_INVALID_INTERVAL_ORD | RE_NEWLINE_ALT) \
+   & ~(RE_CONTEXT_INVALID_OPS | RE_DOT_NOT_NULL))
 
-#define RE_SYNTAX_POSIX_EGREP						\
-  (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES			\
-   | RE_INVALID_INTERVAL_ORD)
+/* POSIX grep -E behavior is no longer incompatible with GNU.  */
+# define RE_SYNTAX_POSIX_EGREP						\
+  RE_SYNTAX_EGREP
 
 /* P1003.2/D11.2, section 4.20.7.1, lines 5078ff.  */
-#define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
+# define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
 
-#define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
+# define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
 
 /* Syntax bits common to both basic and extended POSIX regex syntax.  */
-#define _RE_SYNTAX_POSIX_COMMON						\
+# define _RE_SYNTAX_POSIX_COMMON					\
   (RE_CHAR_CLASSES | RE_DOT_NEWLINE      | RE_DOT_NOT_NULL		\
    | RE_INTERVALS  | RE_NO_EMPTY_RANGES)
 
-#define RE_SYNTAX_POSIX_BASIC						\
+# define RE_SYNTAX_POSIX_BASIC						\
   (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM | RE_CONTEXT_INVALID_DUP)
 
 /* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
    RE_LIMITED_OPS, i.e., \? \+ \| are not recognized.  Actually, this
    isn't minimal, since other operators, such as \`, aren't disabled.  */
-#define RE_SYNTAX_POSIX_MINIMAL_BASIC					\
+# define RE_SYNTAX_POSIX_MINIMAL_BASIC					\
   (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)
 
-#define RE_SYNTAX_POSIX_EXTENDED					\
+# define RE_SYNTAX_POSIX_EXTENDED					\
   (_RE_SYNTAX_POSIX_COMMON  | RE_CONTEXT_INDEP_ANCHORS			\
    | RE_CONTEXT_INDEP_OPS   | RE_NO_BK_BRACES				\
    | RE_NO_BK_PARENS        | RE_NO_BK_VBAR				\
@@ -248,25 +275,35 @@
 
 /* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INDEP_OPS is
    removed and RE_NO_BK_REFS is added.  */
-#define RE_SYNTAX_POSIX_MINIMAL_EXTENDED				\
+# define RE_SYNTAX_POSIX_MINIMAL_EXTENDED				\
   (_RE_SYNTAX_POSIX_COMMON  | RE_CONTEXT_INDEP_ANCHORS			\
    | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES				\
    | RE_NO_BK_PARENS        | RE_NO_BK_REFS				\
    | RE_NO_BK_VBAR	    | RE_UNMATCHED_RIGHT_PAREN_ORD)
 /* [[[end syntaxes]]] */
-
-/* Maximum number of duplicates an interval can allow.  Some systems
-   (erroneously) define this in other header files, but we want our
+
+/* Maximum number of duplicates an interval can allow.  POSIX-conforming
+   systems might define this in <limits.h>, but we want our
    value, so remove any previous define.  */
+# ifdef _REGEX_INCLUDE_LIMITS_H
+#  include <limits.h>
+# endif
 # ifdef RE_DUP_MAX
 #  undef RE_DUP_MAX
 # endif
-/* If sizeof(int) == 2, then ((1 << 15) - 1) overflows.  */
+
+/* RE_DUP_MAX is 2**15 - 1 because an earlier implementation stored
+   the counter as a 2-byte signed integer.  This is no longer true, so
+   RE_DUP_MAX could be increased to (INT_MAX / 10 - 1), or to
+   ((SIZE_MAX - 9) / 10) if _REGEX_LARGE_OFFSETS is defined.
+   However, there would be a huge performance problem if someone
+   actually used a pattern like a\{214748363\}, so RE_DUP_MAX retains
+   its historical value.  */
 # define RE_DUP_MAX (0x7fff)
 #endif
 
 
-/* POSIX `cflags' bits (i.e., information for `regcomp').  */
+/* POSIX 'cflags' bits (i.e., information for 'regcomp').  */
 
 /* If this bit is set, then use extended regular expression syntax.
    If not set, then use basic regular expression syntax.  */
@@ -274,19 +311,19 @@
 
 /* If this bit is set, then ignore case when matching.
    If not set, then case is significant.  */
-#define REG_ICASE (REG_EXTENDED << 1)
+#define REG_ICASE (1 << 1)
 
 /* If this bit is set, then anchors do not match at newline
      characters in the string.
    If not set, then anchors do match at newlines.  */
-#define REG_NEWLINE (REG_ICASE << 1)
+#define REG_NEWLINE (1 << 2)
 
 /* If this bit is set, then report only success or fail in regexec.
    If not set, then returns differ between not matching and errors.  */
-#define REG_NOSUB (REG_NEWLINE << 1)
+#define REG_NOSUB (1 << 3)
 
 
-/* POSIX `eflags' bits (i.e., information for regexec).  */
+/* POSIX 'eflags' bits (i.e., information for regexec).  */
 
 /* If this bit is set, then the beginning-of-line operator doesn't match
      the beginning of the string (presumably because it's not the
@@ -304,41 +341,60 @@
 
 
 /* If any error codes are removed, changed, or added, update the
-   `re_error_msg' table in regex.c.  */
+   '__re_error_msgid' table in regcomp.c.  */
+
 typedef enum
 {
-#if defined _XOPEN_SOURCE || defined __USE_XOPEN2K
-  REG_ENOSYS = -1,	/* This will never happen for this implementation.  */
-#endif
-
-  REG_NOERROR = 0,	/* Success.  */
-  REG_NOMATCH,		/* Didn't find a match (for regexec).  */
+  _REG_ENOSYS = -1,	/* This will never happen for this implementation.  */
+  _REG_NOERROR = 0,	/* Success.  */
+  _REG_NOMATCH,		/* Didn't find a match (for regexec).  */
 
   /* POSIX regcomp return error codes.  (In the order listed in the
      standard.)  */
-  REG_BADPAT,		/* Invalid pattern.  */
-  REG_ECOLLATE,		/* Invalid collating element.  */
-  REG_ECTYPE,		/* Invalid character class name.  */
-  REG_EESCAPE,		/* Trailing backslash.  */
-  REG_ESUBREG,		/* Invalid back reference.  */
-  REG_EBRACK,		/* Unmatched left bracket.  */
-  REG_EPAREN,		/* Parenthesis imbalance.  */
-  REG_EBRACE,		/* Unmatched \{.  */
-  REG_BADBR,		/* Invalid contents of \{\}.  */
-  REG_ERANGE,		/* Invalid range end.  */
-  REG_ESPACE,		/* Ran out of memory.  */
-  REG_BADRPT,		/* No preceding re for repetition op.  */
+  _REG_BADPAT,		/* Invalid pattern.  */
+  _REG_ECOLLATE,	/* Invalid collating element.  */
+  _REG_ECTYPE,		/* Invalid character class name.  */
+  _REG_EESCAPE,		/* Trailing backslash.  */
+  _REG_ESUBREG,		/* Invalid back reference.  */
+  _REG_EBRACK,		/* Unmatched left bracket.  */
+  _REG_EPAREN,		/* Parenthesis imbalance.  */
+  _REG_EBRACE,		/* Unmatched \{.  */
+  _REG_BADBR,		/* Invalid contents of \{\}.  */
+  _REG_ERANGE,		/* Invalid range end.  */
+  _REG_ESPACE,		/* Ran out of memory.  */
+  _REG_BADRPT,		/* No preceding re for repetition op.  */
 
   /* Error codes we've added.  */
-  REG_EEND,		/* Premature end.  */
-  REG_ESIZE,		/* Compiled pattern bigger than 2^16 bytes.  */
-  REG_ERPAREN		/* Unmatched ) or \); not returned from regcomp.  */
+  _REG_EEND,		/* Premature end.  */
+  _REG_ESIZE,		/* Too large (e.g., repeat count too large).  */
+  _REG_ERPAREN		/* Unmatched ) or \); not returned from regcomp.  */
 } reg_errcode_t;
+
+#if defined _XOPEN_SOURCE || defined __USE_XOPEN2K
+# define REG_ENOSYS	_REG_ENOSYS
+#endif
+#define REG_NOERROR	_REG_NOERROR
+#define REG_NOMATCH	_REG_NOMATCH
+#define REG_BADPAT	_REG_BADPAT
+#define REG_ECOLLATE	_REG_ECOLLATE
+#define REG_ECTYPE	_REG_ECTYPE
+#define REG_EESCAPE	_REG_EESCAPE
+#define REG_ESUBREG	_REG_ESUBREG
+#define REG_EBRACK	_REG_EBRACK
+#define REG_EPAREN	_REG_EPAREN
+#define REG_EBRACE	_REG_EBRACE
+#define REG_BADBR	_REG_BADBR
+#define REG_ERANGE	_REG_ERANGE
+#define REG_ESPACE	_REG_ESPACE
+#define REG_BADRPT	_REG_BADRPT
+#define REG_EEND	_REG_EEND
+#define REG_ESIZE	_REG_ESIZE
+#define REG_ERPAREN	_REG_ERPAREN
 
 /* This data structure represents a compiled pattern.  Before calling
-   the pattern compiler, the fields `buffer', `allocated', `fastmap',
-   and `translate' can be set.  After the pattern has been compiled,
-   the fields `re_nsub', `not_bol' and `not_eol' are available.  All
+   the pattern compiler, the fields 'buffer', 'allocated', 'fastmap',
+   and 'translate' can be set.  After the pattern has been compiled,
+   the fields 're_nsub', 'not_bol' and 'not_eol' are available.  All
    other fields are private to the regex routines.  */
 
 #ifndef RE_TRANSLATE_TYPE
@@ -356,16 +412,15 @@
 
 struct re_pattern_buffer
 {
-  /* Space that holds the compiled pattern.  It is declared as
-     `unsigned char *' because its elements are sometimes used as
-     array indexes.  */
-  unsigned char *__REPB_PREFIX(buffer);
+  /* Space that holds the compiled pattern.  The type
+     'struct re_dfa_t' is private and is not declared here.  */
+  struct re_dfa_t *__REPB_PREFIX(buffer);
 
-  /* Number of bytes to which `buffer' points.  */
-  unsigned long int __REPB_PREFIX(allocated);
+  /* Number of bytes to which 'buffer' points.  */
+  __re_long_size_t __REPB_PREFIX(allocated);
 
-  /* Number of bytes actually used in `buffer'.  */
-  unsigned long int __REPB_PREFIX(used);
+  /* Number of bytes actually used in 'buffer'.  */
+  __re_long_size_t __REPB_PREFIX(used);
 
   /* Syntax setting with which the pattern was compiled.  */
   reg_syntax_t __REPB_PREFIX(syntax);
@@ -385,13 +440,13 @@
   size_t re_nsub;
 
   /* Zero if this pattern cannot match the empty string, one else.
-     Well, in truth it's used only in `re_search_2', to see whether or
+     Well, in truth it's used only in 're_search_2', to see whether or
      not we should use the fastmap, so we don't set this absolutely
-     perfectly; see `re_compile_fastmap' (the `duplicate' case).  */
+     perfectly; see 're_compile_fastmap' (the "duplicate" case).  */
   unsigned __REPB_PREFIX(can_be_null) : 1;
 
-  /* If REGS_UNALLOCATED, allocate space in the `regs' structure
-     for `max (RE_NREGS, re_nsub + 1)' groups.
+  /* If REGS_UNALLOCATED, allocate space in the 'regs' structure
+     for 'max (RE_NREGS, re_nsub + 1)' groups.
      If REGS_REALLOCATE, reallocate space if necessary.
      If REGS_FIXED, use what's there.  */
 #ifdef __USE_GNU
@@ -401,11 +456,11 @@
 #endif
   unsigned __REPB_PREFIX(regs_allocated) : 2;
 
-  /* Set to zero when `regex_compile' compiles a pattern; set to one
-     by `re_compile_fastmap' if it updates the fastmap.  */
+  /* Set to zero when 're_compile_pattern' compiles a pattern; set to
+     one by 're_compile_fastmap' if it updates the fastmap.  */
   unsigned __REPB_PREFIX(fastmap_accurate) : 1;
 
-  /* If set, `re_match_2' does not return information about
+  /* If set, 're_match_2' does not return information about
      subexpressions.  */
   unsigned __REPB_PREFIX(no_sub) : 1;
 
@@ -423,7 +478,17 @@
 typedef struct re_pattern_buffer regex_t;
 
 /* Type for byte offsets within the string.  POSIX mandates this.  */
+#ifdef _REGEX_LARGE_OFFSETS
+/* POSIX 1003.1-2008 requires that regoff_t be at least as wide as
+   ptrdiff_t and ssize_t.  We don't know of any hosts where ptrdiff_t
+   is wider than ssize_t, so ssize_t is safe.  ptrdiff_t is not
+   visible here, so use ssize_t.  */
+typedef ssize_t regoff_t;
+#else
+/* The traditional GNU regex implementation mishandles strings longer
+   than INT_MAX.  */
 typedef int regoff_t;
+#endif
 
 
 #ifdef __USE_GNU
@@ -431,15 +496,15 @@
    regex.texinfo for a full description of what registers match.  */
 struct re_registers
 {
-  unsigned num_regs;
+  __re_size_t num_regs;
   regoff_t *start;
   regoff_t *end;
 };
 
 
-/* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer,
-   `re_match_2' returns information about at least this many registers
-   the first time a `regs' structure is passed.  */
+/* If 'regs_allocated' is REGS_UNALLOCATED in the pattern buffer,
+   're_match_2' returns information about at least this many registers
+   the first time a 'regs' structure is passed.  */
 # ifndef RE_NREGS
 #  define RE_NREGS 30
 # endif
@@ -447,7 +512,7 @@
 
 
 /* POSIX specification for registers.  Aside from the different names than
-   `re_registers', POSIX uses an array of structures, instead of a
+   're_registers', POSIX uses an array of structures, instead of a
    structure of arrays.  */
 typedef struct
 {
@@ -459,17 +524,17 @@
 
 #ifdef __USE_GNU
 /* Sets the current default syntax to SYNTAX, and return the old syntax.
-   You can also simply assign to the `re_syntax_options' variable.  */
+   You can also simply assign to the 're_syntax_options' variable.  */
 extern reg_syntax_t re_set_syntax (reg_syntax_t __syntax);
 
 /* Compile the regular expression PATTERN, with length LENGTH
-   and syntax given by the global `re_syntax_options', into the buffer
+   and syntax given by the global 're_syntax_options', into the buffer
    BUFFER.  Return NULL if successful, and an error string if not.
 
-   To free the allocated storage, you must call `regfree' on BUFFER.
-   Note that the translate table must either have been initialised by
-   `regcomp', with a malloc'ed value, or set to NULL before calling
-   `regfree'.  */
+   To free the allocated storage, you must call 'regfree' on BUFFER.
+   Note that the translate table must either have been initialized by
+   'regcomp', with a malloc'ed value, or set to NULL before calling
+   'regfree'.  */
 extern const char *re_compile_pattern (const char *__pattern, size_t __length,
 				       struct re_pattern_buffer *__buffer);
 
@@ -485,47 +550,52 @@
    characters.  Return the starting position of the match, -1 for no
    match, or -2 for an internal error.  Also return register
    information in REGS (if REGS and BUFFER->no_sub are nonzero).  */
-extern int re_search (struct re_pattern_buffer *__buffer, const char *__string,
-		      int __length, int __start, int __range,
-		      struct re_registers *__regs);
+extern regoff_t re_search (struct re_pattern_buffer *__buffer,
+			   const char *__String, regoff_t __length,
+			   regoff_t __start, regoff_t __range,
+			   struct re_registers *__regs);
 
 
-/* Like `re_search', but search in the concatenation of STRING1 and
+/* Like 're_search', but search in the concatenation of STRING1 and
    STRING2.  Also, stop searching at index START + STOP.  */
-extern int re_search_2 (struct re_pattern_buffer *__buffer,
-			const char *__string1, int __length1,
-			const char *__string2, int __length2, int __start,
-			int __range, struct re_registers *__regs, int __stop);
+extern regoff_t re_search_2 (struct re_pattern_buffer *__buffer,
+			     const char *__string1, regoff_t __length1,
+			     const char *__string2, regoff_t __length2,
+			     regoff_t __start, regoff_t __range,
+			     struct re_registers *__regs,
+			     regoff_t __stop);
 
 
-/* Like `re_search', but return how many characters in STRING the regexp
+/* Like 're_search', but return how many characters in STRING the regexp
    in BUFFER matched, starting at position START.  */
-extern int re_match (struct re_pattern_buffer *__buffer, const char *__string,
-		     int __length, int __start, struct re_registers *__regs);
+extern regoff_t re_match (struct re_pattern_buffer *__buffer,
+			  const char *__String, regoff_t __length,
+			  regoff_t __start, struct re_registers *__regs);
 
 
-/* Relates to `re_match' as `re_search_2' relates to `re_search'.  */
-extern int re_match_2 (struct re_pattern_buffer *__buffer,
-		       const char *__string1, int __length1,
-		       const char *__string2, int __length2, int __start,
-		       struct re_registers *__regs, int __stop);
+/* Relates to 're_match' as 're_search_2' relates to 're_search'.  */
+extern regoff_t re_match_2 (struct re_pattern_buffer *__buffer,
+			    const char *__string1, regoff_t __length1,
+			    const char *__string2, regoff_t __length2,
+			    regoff_t __start, struct re_registers *__regs,
+			    regoff_t __stop);
 
 
 /* Set REGS to hold NUM_REGS registers, storing them in STARTS and
    ENDS.  Subsequent matches using BUFFER and REGS will use this memory
    for recording register information.  STARTS and ENDS must be
-   allocated with malloc, and must each be at least `NUM_REGS * sizeof
+   allocated with malloc, and must each be at least 'NUM_REGS * sizeof
    (regoff_t)' bytes long.
 
    If NUM_REGS == 0, then subsequent matches should allocate their own
    register data.
 
    Unless this function is called, the first search or match using
-   PATTERN_BUFFER will allocate its own register data, without
+   BUFFER will allocate its own register data, without
    freeing the old data.  */
 extern void re_set_registers (struct re_pattern_buffer *__buffer,
 			      struct re_registers *__regs,
-			      unsigned int __num_regs,
+			      __re_size_t __num_regs,
 			      regoff_t *__starts, regoff_t *__ends);
 #endif	/* Use GNU */
 
@@ -537,39 +607,46 @@
 # endif
 #endif
 
-/* GCC 2.95 and later have "__restrict"; C99 compilers have
-   "restrict", and "configure" may have defined "restrict".  */
-#ifndef __restrict
-# if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__))
-#  if defined restrict || 199901L <= __STDC_VERSION__
-#   define __restrict restrict
-#  else
-#   define __restrict
-#  endif
+/* For plain 'restrict', use glibc's __restrict if defined.
+   Otherwise, GCC 2.95 and later have "__restrict"; C99 compilers have
+   "restrict", and "configure" may have defined "restrict".
+   Other compilers use __restrict, __restrict__, and _Restrict, and
+   'configure' might #define 'restrict' to those words, so pick a
+   different name.  */
+#ifndef _Restrict_
+# if defined __restrict || 2 < __GNUC__ + (95 <= __GNUC_MINOR__)
+#  define _Restrict_ __restrict
+# elif 199901L <= __STDC_VERSION__ || defined restrict
+#  define _Restrict_ restrict
+# else
+#  define _Restrict_
 # endif
 #endif
-/* gcc 3.1 and up support the [restrict] syntax.  */
-#ifndef __restrict_arr
-# if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) \
-     && !defined __GNUG__
-#  define __restrict_arr __restrict
+/* For [restrict], use glibc's __restrict_arr if available.
+   Otherwise, GCC 3.1 (not in C++ mode) and C99 support [restrict].  */
+#ifndef _Restrict_arr_
+# ifdef __restrict_arr
+#  define _Restrict_arr_ __restrict_arr
+# elif ((199901L <= __STDC_VERSION__ || 3 < __GNUC__ + (1 <= __GNUC_MINOR__)) \
+        && !defined __GNUG__)
+#  define _Restrict_arr_ _Restrict_
 # else
-#  define __restrict_arr
+#  define _Restrict_arr_
 # endif
 #endif
 
 /* POSIX compatibility.  */
-extern int regcomp (regex_t *__restrict __preg,
-		    const char *__restrict __pattern,
+extern int regcomp (regex_t *_Restrict_ __preg,
+		    const char *_Restrict_ __pattern,
 		    int __cflags);
 
-extern int regexec (const regex_t *__restrict __preg,
-		    const char *__restrict __string, size_t __nmatch,
-		    regmatch_t __pmatch[__restrict_arr],
+extern int regexec (const regex_t *_Restrict_ __preg,
+		    const char *_Restrict_ __String, size_t __nmatch,
+		    regmatch_t __pmatch[_Restrict_arr_],
 		    int __eflags);
 
-extern size_t regerror (int __errcode, const regex_t *__restrict __preg,
-			char *__restrict __errbuf, size_t __errbuf_size);
+extern size_t regerror (int __errcode, const regex_t *_Restrict_ __preg,
+			char *_Restrict_ __errbuf, size_t __errbuf_size);
 
 extern void regfree (regex_t *__preg);
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/posix/regex_internal.c b/google3/third_party/grte/v5_src/glibc-2.27/posix/regex_internal.c
index 9062083..7f0083b 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/posix/regex_internal.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/posix/regex_internal.c
@@ -15,19 +15,29 @@
 
    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
+   <https://www.gnu.org/licenses/>.  */
 
-static void re_string_construct_common (const char *str, int len,
+static void re_string_construct_common (const char *str, Idx len,
 					re_string_t *pstr,
-					RE_TRANSLATE_TYPE trans, int icase,
+					RE_TRANSLATE_TYPE trans, bool icase,
 					const re_dfa_t *dfa);
 static re_dfastate_t *create_ci_newstate (const re_dfa_t *dfa,
 					  const re_node_set *nodes,
-					  unsigned int hash);
+					  re_hashval_t hash);
 static re_dfastate_t *create_cd_newstate (const re_dfa_t *dfa,
 					  const re_node_set *nodes,
 					  unsigned int context,
-					  unsigned int hash);
+					  re_hashval_t hash);
+static reg_errcode_t re_string_realloc_buffers (re_string_t *pstr,
+						Idx new_buf_len);
+#ifdef RE_ENABLE_I18N
+static void build_wcs_buffer (re_string_t *pstr);
+static reg_errcode_t build_wcs_upper_buffer (re_string_t *pstr);
+#endif /* RE_ENABLE_I18N */
+static void build_upper_buffer (re_string_t *pstr);
+static void re_string_translate_buffer (re_string_t *pstr);
+static unsigned int re_string_context_at (const re_string_t *input, Idx idx,
+					  int eflags) __attribute__ ((pure));
 
 /* Functions for string operation.  */
 
@@ -36,11 +46,11 @@
 
 static reg_errcode_t
 __attribute_warn_unused_result__
-re_string_allocate (re_string_t *pstr, const char *str, int len, int init_len,
-		    RE_TRANSLATE_TYPE trans, int icase, const re_dfa_t *dfa)
+re_string_allocate (re_string_t *pstr, const char *str, Idx len, Idx init_len,
+		    RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa)
 {
   reg_errcode_t ret;
-  int init_buf_len;
+  Idx init_buf_len;
 
   /* Ensure at least one character fits into the buffers.  */
   if (init_len < dfa->mb_cur_max)
@@ -64,8 +74,8 @@
 
 static reg_errcode_t
 __attribute_warn_unused_result__
-re_string_construct (re_string_t *pstr, const char *str, int len,
-		     RE_TRANSLATE_TYPE trans, int icase, const re_dfa_t *dfa)
+re_string_construct (re_string_t *pstr, const char *str, Idx len,
+		     RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa)
 {
   reg_errcode_t ret;
   memset (pstr, '\0', sizeof (re_string_t));
@@ -127,7 +137,7 @@
 
 static reg_errcode_t
 __attribute_warn_unused_result__
-re_string_realloc_buffers (re_string_t *pstr, int new_buf_len)
+re_string_realloc_buffers (re_string_t *pstr, Idx new_buf_len)
 {
 #ifdef RE_ENABLE_I18N
   if (pstr->mb_cur_max > 1)
@@ -135,8 +145,8 @@
       wint_t *new_wcs;
 
       /* Avoid overflow in realloc.  */
-      const size_t max_object_size = MAX (sizeof (wint_t), sizeof (int));
-      if (BE (SIZE_MAX / max_object_size < new_buf_len, 0))
+      const size_t max_object_size = MAX (sizeof (wint_t), sizeof (Idx));
+      if (BE (MIN (IDX_MAX, SIZE_MAX / max_object_size) < new_buf_len, 0))
 	return REG_ESPACE;
 
       new_wcs = re_realloc (pstr->wcs, wint_t, new_buf_len);
@@ -145,7 +155,7 @@
       pstr->wcs = new_wcs;
       if (pstr->offsets != NULL)
 	{
-	  int *new_offsets = re_realloc (pstr->offsets, int, new_buf_len);
+	  Idx *new_offsets = re_realloc (pstr->offsets, Idx, new_buf_len);
 	  if (BE (new_offsets == NULL, 0))
 	    return REG_ESPACE;
 	  pstr->offsets = new_offsets;
@@ -166,15 +176,15 @@
 
 
 static void
-re_string_construct_common (const char *str, int len, re_string_t *pstr,
-			    RE_TRANSLATE_TYPE trans, int icase,
+re_string_construct_common (const char *str, Idx len, re_string_t *pstr,
+			    RE_TRANSLATE_TYPE trans, bool icase,
 			    const re_dfa_t *dfa)
 {
   pstr->raw_mbs = (const unsigned char *) str;
   pstr->len = len;
   pstr->raw_len = len;
   pstr->trans = trans;
-  pstr->icase = icase ? 1 : 0;
+  pstr->icase = icase;
   pstr->mbs_allocated = (trans != NULL || icase);
   pstr->mb_cur_max = dfa->mb_cur_max;
   pstr->is_utf8 = dfa->is_utf8;
@@ -206,7 +216,7 @@
   unsigned char buf[64];
 #endif
   mbstate_t prev_st;
-  int byte_idx, end_idx, remain_len;
+  Idx byte_idx, end_idx, remain_len;
   size_t mbclen;
 
   /* Build the buffers from pstr->valid_len to either pstr->len or
@@ -269,7 +279,7 @@
 build_wcs_upper_buffer (re_string_t *pstr)
 {
   mbstate_t prev_st;
-  int src_idx, byte_idx, end_idx, remain_len;
+  Idx src_idx, byte_idx, end_idx, remain_len;
   size_t mbclen;
 #ifdef _LIBC
   char buf[MB_LEN_MAX];
@@ -307,14 +317,13 @@
 	  mbclen = __mbrtowc (&wc,
 			      ((const char *) pstr->raw_mbs + pstr->raw_mbs_idx
 			       + byte_idx), remain_len, &pstr->cur_state);
-	  if (BE (mbclen + 2 > 2, 1))
+	  if (BE (mbclen < (size_t) -2, 1))
 	    {
-	      wchar_t wcu = wc;
-	      if (__iswlower (wc))
+	      wchar_t wcu = __towupper (wc);
+	      if (wcu != wc)
 		{
 		  size_t mbcdlen;
 
-		  wcu = __towupper (wc);
 		  mbcdlen = __wcrtomb (buf, wcu, &prev_st);
 		  if (BE (mbclen == mbcdlen, 1))
 		    memcpy (pstr->mbs + byte_idx, buf, mbclen);
@@ -377,14 +386,13 @@
 	else
 	  p = (const char *) pstr->raw_mbs + pstr->raw_mbs_idx + src_idx;
 	mbclen = __mbrtowc (&wc, p, remain_len, &pstr->cur_state);
-	if (BE (mbclen + 2 > 2, 1))
+	if (BE (mbclen < (size_t) -2, 1))
 	  {
-	    wchar_t wcu = wc;
-	    if (__iswlower (wc))
+	    wchar_t wcu = __towupper (wc);
+	    if (wcu != wc)
 	      {
 		size_t mbcdlen;
 
-		wcu = __towupper (wc);
 		mbcdlen = __wcrtomb ((char *) buf, wcu, &prev_st);
 		if (BE (mbclen == mbcdlen, 1))
 		  memcpy (pstr->mbs + byte_idx, buf, mbclen);
@@ -400,7 +408,7 @@
 
 		    if (pstr->offsets == NULL)
 		      {
-			pstr->offsets = re_malloc (int, pstr->bufs_len);
+			pstr->offsets = re_malloc (Idx, pstr->bufs_len);
 
 			if (pstr->offsets == NULL)
 			  return REG_ESPACE;
@@ -483,11 +491,11 @@
 /* Skip characters until the index becomes greater than NEW_RAW_IDX.
    Return the index.  */
 
-static int
-re_string_skip_chars (re_string_t *pstr, int new_raw_idx, wint_t *last_wc)
+static Idx
+re_string_skip_chars (re_string_t *pstr, Idx new_raw_idx, wint_t *last_wc)
 {
   mbstate_t prev_st;
-  int rawbuf_idx;
+  Idx rawbuf_idx;
   size_t mbclen;
   wint_t wc = WEOF;
 
@@ -496,11 +504,11 @@
        rawbuf_idx < new_raw_idx;)
     {
       wchar_t wc2;
-      int remain_len = pstr->raw_len - rawbuf_idx;
+      Idx remain_len = pstr->raw_len - rawbuf_idx;
       prev_st = pstr->cur_state;
       mbclen = __mbrtowc (&wc2, (const char *) pstr->raw_mbs + rawbuf_idx,
 			  remain_len, &pstr->cur_state);
-      if (BE ((ssize_t) mbclen <= 0, 0))
+      if (BE (mbclen == (size_t) -2 || mbclen == (size_t) -1 || mbclen == 0, 0))
 	{
 	  /* We treat these cases as a single byte character.  */
 	  if (mbclen == 0 || remain_len == 0)
@@ -511,7 +519,7 @@
 	  pstr->cur_state = prev_st;
 	}
       else
-	wc = (wint_t) wc2;
+	wc = wc2;
       /* Then proceed the next character.  */
       rawbuf_idx += mbclen;
     }
@@ -526,7 +534,7 @@
 static void
 build_upper_buffer (re_string_t *pstr)
 {
-  int char_idx, end_idx;
+  Idx char_idx, end_idx;
   end_idx = (pstr->bufs_len > pstr->len) ? pstr->len : pstr->bufs_len;
 
   for (char_idx = pstr->valid_len; char_idx < end_idx; ++char_idx)
@@ -534,10 +542,7 @@
       int ch = pstr->raw_mbs[pstr->raw_mbs_idx + char_idx];
       if (BE (pstr->trans != NULL, 0))
 	ch = pstr->trans[ch];
-      if (islower (ch))
-	pstr->mbs[char_idx] = toupper (ch);
-      else
-	pstr->mbs[char_idx] = ch;
+      pstr->mbs[char_idx] = toupper (ch);
     }
   pstr->valid_len = char_idx;
   pstr->valid_raw_len = char_idx;
@@ -548,7 +553,7 @@
 static void
 re_string_translate_buffer (re_string_t *pstr)
 {
-  int buf_idx, end_idx;
+  Idx buf_idx, end_idx;
   end_idx = (pstr->bufs_len > pstr->len) ? pstr->len : pstr->bufs_len;
 
   for (buf_idx = pstr->valid_len; buf_idx < end_idx; ++buf_idx)
@@ -567,10 +572,13 @@
 
 static reg_errcode_t
 __attribute_warn_unused_result__
-re_string_reconstruct (re_string_t *pstr, int idx, int eflags)
+re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
 {
-  int offset = idx - pstr->raw_mbs_idx;
-  if (BE (offset < 0, 0))
+  Idx offset;
+
+  if (BE (pstr->raw_mbs_idx <= idx, 0))
+    offset = idx - pstr->raw_mbs_idx;
+  else
     {
       /* Reset buffer.  */
 #ifdef RE_ENABLE_I18N
@@ -599,7 +607,7 @@
 #ifdef RE_ENABLE_I18N
 	  if (BE (pstr->offsets_needed, 0))
 	    {
-	      int low = 0, high = pstr->valid_len, mid;
+	      Idx low = 0, high = pstr->valid_len, mid;
 	      do
 		{
 		  mid = (high + low) / 2;
@@ -683,7 +691,7 @@
 	{
 #ifdef RE_ENABLE_I18N
 	  /* No, skip all characters until IDX.  */
-	  int prev_valid_len = pstr->valid_len;
+	  Idx prev_valid_len = pstr->valid_len;
 
 	  if (BE (pstr->offsets_needed, 0))
 	    {
@@ -696,7 +704,7 @@
 #ifdef RE_ENABLE_I18N
 	  if (pstr->mb_cur_max > 1)
 	    {
-	      int wcs_idx;
+	      Idx wcs_idx;
 	      wint_t wc = WEOF;
 
 	      if (pstr->is_utf8)
@@ -726,7 +734,7 @@
 			{
 			  mbstate_t cur_state;
 			  wchar_t wc2;
-			  int mlen = raw + pstr->len - p;
+			  Idx mlen = raw + pstr->len - p;
 			  unsigned char buf[6];
 			  size_t mbclen;
 
@@ -826,10 +834,11 @@
 }
 
 static unsigned char
-__attribute ((pure))
-re_string_peek_byte_case (const re_string_t *pstr, int idx)
+__attribute__ ((pure))
+re_string_peek_byte_case (const re_string_t *pstr, Idx idx)
 {
-  int ch, off;
+  int ch;
+  Idx off;
 
   /* Handle the common (easiest) cases first.  */
   if (BE (!pstr->mbs_allocated, 1))
@@ -870,7 +879,8 @@
 #ifdef RE_ENABLE_I18N
   if (pstr->offsets_needed)
     {
-      int off, ch;
+      Idx off;
+      int ch;
 
       /* For tr_TR.UTF-8 [[:islower:]] there is
 	 [[: CAPITAL LETTER I WITH DOT lower:]] in mbs.  Skip
@@ -911,7 +921,7 @@
 /* Return the context at IDX in INPUT.  */
 
 static unsigned int
-re_string_context_at (const re_string_t *input, int idx, int eflags)
+re_string_context_at (const re_string_t *input, Idx idx, int eflags)
 {
   int c;
   if (BE (idx < 0, 0))
@@ -925,7 +935,7 @@
   if (input->mb_cur_max > 1)
     {
       wint_t wc;
-      int wc_idx = idx;
+      Idx wc_idx = idx;
       while(input->wcs[wc_idx] == WEOF)
 	{
 #if defined DEBUG && DEBUG
@@ -956,23 +966,23 @@
 
 static reg_errcode_t
 __attribute_warn_unused_result__
-re_node_set_alloc (re_node_set *set, int size)
+re_node_set_alloc (re_node_set *set, Idx size)
 {
   set->alloc = size;
   set->nelem = 0;
-  set->elems = re_malloc (int, size);
-  if (BE (set->elems == NULL, 0))
+  set->elems = re_malloc (Idx, size);
+  if (BE (set->elems == NULL, 0) && (MALLOC_0_IS_NONNULL || size != 0))
     return REG_ESPACE;
   return REG_NOERROR;
 }
 
 static reg_errcode_t
 __attribute_warn_unused_result__
-re_node_set_init_1 (re_node_set *set, int elem)
+re_node_set_init_1 (re_node_set *set, Idx elem)
 {
   set->alloc = 1;
   set->nelem = 1;
-  set->elems = re_malloc (int, 1);
+  set->elems = re_malloc (Idx, 1);
   if (BE (set->elems == NULL, 0))
     {
       set->alloc = set->nelem = 0;
@@ -984,10 +994,10 @@
 
 static reg_errcode_t
 __attribute_warn_unused_result__
-re_node_set_init_2 (re_node_set *set, int elem1, int elem2)
+re_node_set_init_2 (re_node_set *set, Idx elem1, Idx elem2)
 {
   set->alloc = 2;
-  set->elems = re_malloc (int, 2);
+  set->elems = re_malloc (Idx, 2);
   if (BE (set->elems == NULL, 0))
     return REG_ESPACE;
   if (elem1 == elem2)
@@ -1020,13 +1030,13 @@
   if (src->nelem > 0)
     {
       dest->alloc = dest->nelem;
-      dest->elems = re_malloc (int, dest->alloc);
+      dest->elems = re_malloc (Idx, dest->alloc);
       if (BE (dest->elems == NULL, 0))
 	{
 	  dest->alloc = dest->nelem = 0;
 	  return REG_ESPACE;
 	}
-      memcpy (dest->elems, src->elems, src->nelem * sizeof (int));
+      memcpy (dest->elems, src->elems, src->nelem * sizeof (Idx));
     }
   else
     re_node_set_init_empty (dest);
@@ -1042,7 +1052,7 @@
 re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1,
 			   const re_node_set *src2)
 {
-  int i1, i2, is, id, delta, sbase;
+  Idx i1, i2, is, id, delta, sbase;
   if (src1->nelem == 0 || src2->nelem == 0)
     return REG_NOERROR;
 
@@ -1050,8 +1060,8 @@
      conservative estimate.  */
   if (src1->nelem + src2->nelem + dest->nelem > dest->alloc)
     {
-      int new_alloc = src1->nelem + src2->nelem + dest->alloc;
-      int *new_elems = re_realloc (dest->elems, int, new_alloc);
+      Idx new_alloc = src1->nelem + src2->nelem + dest->alloc;
+      Idx *new_elems = re_realloc (dest->elems, Idx, new_alloc);
       if (BE (new_elems == NULL, 0))
 	return REG_ESPACE;
       dest->elems = new_elems;
@@ -1073,7 +1083,7 @@
 	    --id;
 
 	  if (id < 0 || dest->elems[id] != src1->elems[i1])
-	    dest->elems[--sbase] = src1->elems[i1];
+            dest->elems[--sbase] = src1->elems[i1];
 
 	  if (--i1 < 0 || --i2 < 0)
 	    break;
@@ -1120,7 +1130,7 @@
       }
 
   /* Copy remaining SRC elements.  */
-  memcpy (dest->elems, dest->elems + sbase, delta * sizeof (int));
+  memcpy (dest->elems, dest->elems + sbase, delta * sizeof (Idx));
 
   return REG_NOERROR;
 }
@@ -1133,11 +1143,11 @@
 re_node_set_init_union (re_node_set *dest, const re_node_set *src1,
 			const re_node_set *src2)
 {
-  int i1, i2, id;
+  Idx i1, i2, id;
   if (src1 != NULL && src1->nelem > 0 && src2 != NULL && src2->nelem > 0)
     {
       dest->alloc = src1->nelem + src2->nelem;
-      dest->elems = re_malloc (int, dest->alloc);
+      dest->elems = re_malloc (Idx, dest->alloc);
       if (BE (dest->elems == NULL, 0))
 	return REG_ESPACE;
     }
@@ -1165,13 +1175,13 @@
   if (i1 < src1->nelem)
     {
       memcpy (dest->elems + id, src1->elems + i1,
-	     (src1->nelem - i1) * sizeof (int));
+	     (src1->nelem - i1) * sizeof (Idx));
       id += src1->nelem - i1;
     }
   else if (i2 < src2->nelem)
     {
       memcpy (dest->elems + id, src2->elems + i2,
-	     (src2->nelem - i2) * sizeof (int));
+	     (src2->nelem - i2) * sizeof (Idx));
       id += src2->nelem - i2;
     }
   dest->nelem = id;
@@ -1185,13 +1195,13 @@
 __attribute_warn_unused_result__
 re_node_set_merge (re_node_set *dest, const re_node_set *src)
 {
-  int is, id, sbase, delta;
+  Idx is, id, sbase, delta;
   if (src == NULL || src->nelem == 0)
     return REG_NOERROR;
   if (dest->alloc < 2 * src->nelem + dest->nelem)
     {
-      int new_alloc = 2 * (src->nelem + dest->alloc);
-      int *new_buffer = re_realloc (dest->elems, int, new_alloc);
+      Idx new_alloc = 2 * (src->nelem + dest->alloc);
+      Idx *new_buffer = re_realloc (dest->elems, Idx, new_alloc);
       if (BE (new_buffer == NULL, 0))
 	return REG_ESPACE;
       dest->elems = new_buffer;
@@ -1201,7 +1211,7 @@
   if (BE (dest->nelem == 0, 0))
     {
       dest->nelem = src->nelem;
-      memcpy (dest->elems, src->elems, src->nelem * sizeof (int));
+      memcpy (dest->elems, src->elems, src->nelem * sizeof (Idx));
       return REG_NOERROR;
     }
 
@@ -1222,7 +1232,7 @@
     {
       /* If DEST is exhausted, the remaining items of SRC must be unique.  */
       sbase -= is + 1;
-      memcpy (dest->elems + sbase, src->elems, (is + 1) * sizeof (int));
+      memcpy (dest->elems + sbase, src->elems, (is + 1) * sizeof (Idx));
     }
 
   id = dest->nelem - 1;
@@ -1251,7 +1261,7 @@
 	    {
 	      /* Copy remaining SRC elements.  */
 	      memcpy (dest->elems, dest->elems + sbase,
-		      delta * sizeof (int));
+		      delta * sizeof (Idx));
 	      break;
 	    }
 	}
@@ -1262,38 +1272,33 @@
 
 /* Insert the new element ELEM to the re_node_set* SET.
    SET should not already have ELEM.
-   return -1 if an error is occured, return 1 otherwise.  */
+   Return true if successful.  */
 
-static int
+static bool
 __attribute_warn_unused_result__
-re_node_set_insert (re_node_set *set, int elem)
+re_node_set_insert (re_node_set *set, Idx elem)
 {
-  int idx;
+  Idx idx;
   /* In case the set is empty.  */
   if (set->alloc == 0)
-    {
-      if (BE (re_node_set_init_1 (set, elem) == REG_NOERROR, 1))
-	return 1;
-      else
-	return -1;
-    }
+    return BE (re_node_set_init_1 (set, elem) == REG_NOERROR, 1);
 
   if (BE (set->nelem, 0) == 0)
     {
       /* We already guaranteed above that set->alloc != 0.  */
       set->elems[0] = elem;
       ++set->nelem;
-      return 1;
+      return true;
     }
 
   /* Realloc if we need.  */
   if (set->alloc == set->nelem)
     {
-      int *new_elems;
+      Idx *new_elems;
       set->alloc = set->alloc * 2;
-      new_elems = re_realloc (set->elems, int, set->alloc);
+      new_elems = re_realloc (set->elems, Idx, set->alloc);
       if (BE (new_elems == NULL, 0))
-	return -1;
+	return false;
       set->elems = new_elems;
     }
 
@@ -1314,56 +1319,56 @@
   /* Insert the new element.  */
   set->elems[idx] = elem;
   ++set->nelem;
-  return 1;
+  return true;
 }
 
 /* Insert the new element ELEM to the re_node_set* SET.
    SET should not already have any element greater than or equal to ELEM.
-   Return -1 if an error is occured, return 1 otherwise.  */
+   Return true if successful.  */
 
-static int
+static bool
 __attribute_warn_unused_result__
-re_node_set_insert_last (re_node_set *set, int elem)
+re_node_set_insert_last (re_node_set *set, Idx elem)
 {
   /* Realloc if we need.  */
   if (set->alloc == set->nelem)
     {
-      int *new_elems;
+      Idx *new_elems;
       set->alloc = (set->alloc + 1) * 2;
-      new_elems = re_realloc (set->elems, int, set->alloc);
+      new_elems = re_realloc (set->elems, Idx, set->alloc);
       if (BE (new_elems == NULL, 0))
-	return -1;
+	return false;
       set->elems = new_elems;
     }
 
   /* Insert the new element.  */
   set->elems[set->nelem++] = elem;
-  return 1;
+  return true;
 }
 
 /* Compare two node sets SET1 and SET2.
-   return 1 if SET1 and SET2 are equivalent, return 0 otherwise.  */
+   Return true if SET1 and SET2 are equivalent.  */
 
-static int
-__attribute ((pure))
+static bool
+__attribute__ ((pure))
 re_node_set_compare (const re_node_set *set1, const re_node_set *set2)
 {
-  int i;
+  Idx i;
   if (set1 == NULL || set2 == NULL || set1->nelem != set2->nelem)
-    return 0;
+    return false;
   for (i = set1->nelem ; --i >= 0 ; )
     if (set1->elems[i] != set2->elems[i])
-      return 0;
-  return 1;
+      return false;
+  return true;
 }
 
 /* Return (idx + 1) if SET contains the element ELEM, return 0 otherwise.  */
 
-static int
-__attribute ((pure))
-re_node_set_contains (const re_node_set *set, int elem)
+static Idx
+__attribute__ ((pure))
+re_node_set_contains (const re_node_set *set, Idx elem)
 {
-  unsigned int idx, right, mid;
+  __re_size_t idx, right, mid;
   if (set->nelem <= 0)
     return 0;
 
@@ -1382,7 +1387,7 @@
 }
 
 static void
-re_node_set_remove_at (re_node_set *set, int idx)
+re_node_set_remove_at (re_node_set *set, Idx idx)
 {
   if (idx < 0 || idx >= set->nelem)
     return;
@@ -1393,37 +1398,42 @@
 
 
 /* Add the token TOKEN to dfa->nodes, and return the index of the token.
-   Or return -1, if an error will be occured.  */
+   Or return -1 if an error occurred.  */
 
-static int
+static Idx
 re_dfa_add_node (re_dfa_t *dfa, re_token_t token)
 {
-  int type = token.type;
   if (BE (dfa->nodes_len >= dfa->nodes_alloc, 0))
     {
       size_t new_nodes_alloc = dfa->nodes_alloc * 2;
-      int *new_nexts, *new_indices;
+      Idx *new_nexts, *new_indices;
       re_node_set *new_edests, *new_eclosures;
       re_token_t *new_nodes;
 
       /* Avoid overflows in realloc.  */
       const size_t max_object_size = MAX (sizeof (re_token_t),
 					  MAX (sizeof (re_node_set),
-					       sizeof (int)));
-      if (BE (SIZE_MAX / max_object_size < new_nodes_alloc, 0))
+					       sizeof (Idx)));
+      if (BE (MIN (IDX_MAX, SIZE_MAX / max_object_size) < new_nodes_alloc, 0))
 	return -1;
 
       new_nodes = re_realloc (dfa->nodes, re_token_t, new_nodes_alloc);
       if (BE (new_nodes == NULL, 0))
 	return -1;
       dfa->nodes = new_nodes;
-      new_nexts = re_realloc (dfa->nexts, int, new_nodes_alloc);
-      new_indices = re_realloc (dfa->org_indices, int, new_nodes_alloc);
+      new_nexts = re_realloc (dfa->nexts, Idx, new_nodes_alloc);
+      new_indices = re_realloc (dfa->org_indices, Idx, new_nodes_alloc);
       new_edests = re_realloc (dfa->edests, re_node_set, new_nodes_alloc);
       new_eclosures = re_realloc (dfa->eclosures, re_node_set, new_nodes_alloc);
       if (BE (new_nexts == NULL || new_indices == NULL
 	      || new_edests == NULL || new_eclosures == NULL, 0))
-	return -1;
+	{
+	   re_free (new_nexts);
+	   re_free (new_indices);
+	   re_free (new_edests);
+	   re_free (new_eclosures);
+	   return -1;
+	}
       dfa->nexts = new_nexts;
       dfa->org_indices = new_indices;
       dfa->edests = new_edests;
@@ -1434,7 +1444,8 @@
   dfa->nodes[dfa->nodes_len].constraint = 0;
 #ifdef RE_ENABLE_I18N
   dfa->nodes[dfa->nodes_len].accept_mb =
-    (type == OP_PERIOD && dfa->mb_cur_max > 1) || type == COMPLEX_BRACKET;
+    ((token.type == OP_PERIOD && dfa->mb_cur_max > 1)
+     || token.type == COMPLEX_BRACKET);
 #endif
   dfa->nexts[dfa->nodes_len] = -1;
   re_node_set_init_empty (dfa->edests + dfa->nodes_len);
@@ -1442,11 +1453,11 @@
   return dfa->nodes_len++;
 }
 
-static inline unsigned int
+static re_hashval_t
 calc_state_hash (const re_node_set *nodes, unsigned int context)
 {
-  unsigned int hash = nodes->nelem + context;
-  int i;
+  re_hashval_t hash = nodes->nelem + context;
+  Idx i;
   for (i = 0 ; i < nodes->nelem ; i++)
     hash += nodes->elems[i];
   return hash;
@@ -1466,10 +1477,14 @@
 re_acquire_state (reg_errcode_t *err, const re_dfa_t *dfa,
 		  const re_node_set *nodes)
 {
-  unsigned int hash;
+  re_hashval_t hash;
   re_dfastate_t *new_state;
   struct re_state_table_entry *spot;
-  int i;
+  Idx i;
+#if defined GCC_LINT || defined lint
+  /* Suppress bogus uninitialized-variable warnings.  */
+  *err = REG_NOERROR;
+#endif
   if (BE (nodes->nelem == 0, 0))
     {
       *err = REG_NOERROR;
@@ -1510,10 +1525,14 @@
 re_acquire_state_context (reg_errcode_t *err, const re_dfa_t *dfa,
 			  const re_node_set *nodes, unsigned int context)
 {
-  unsigned int hash;
+  re_hashval_t hash;
   re_dfastate_t *new_state;
   struct re_state_table_entry *spot;
-  int i;
+  Idx i;
+#if defined GCC_LINT || defined lint
+  /* Suppress bogus uninitialized-variable warnings.  */
+  *err = REG_NOERROR;
+#endif
   if (nodes->nelem == 0)
     {
       *err = REG_NOERROR;
@@ -1530,7 +1549,7 @@
 	  && re_node_set_compare (state->entrance_nodes, nodes))
 	return state;
     }
-  /* There are no appropriate state in `dfa', create the new one.  */
+  /* There are no appropriate state in 'dfa', create the new one.  */
   new_state = create_cd_newstate (dfa, nodes, context, hash);
   if (BE (new_state == NULL, 0))
     *err = REG_ESPACE;
@@ -1545,11 +1564,11 @@
 static reg_errcode_t
 __attribute_warn_unused_result__
 register_state (const re_dfa_t *dfa, re_dfastate_t *newstate,
-		unsigned int hash)
+		re_hashval_t hash)
 {
   struct re_state_table_entry *spot;
   reg_errcode_t err;
-  int i;
+  Idx i;
 
   newstate->hash = hash;
   err = re_node_set_alloc (&newstate->non_eps_nodes, newstate->nodes.nelem);
@@ -1557,16 +1576,16 @@
     return REG_ESPACE;
   for (i = 0; i < newstate->nodes.nelem; i++)
     {
-      int elem = newstate->nodes.elems[i];
+      Idx elem = newstate->nodes.elems[i];
       if (!IS_EPSILON_NODE (dfa->nodes[elem].type))
-	if (re_node_set_insert_last (&newstate->non_eps_nodes, elem) < 0)
+	if (! re_node_set_insert_last (&newstate->non_eps_nodes, elem))
 	  return REG_ESPACE;
     }
 
   spot = dfa->state_table + (hash & dfa->state_hash_mask);
   if (BE (spot->alloc <= spot->num, 0))
     {
-      int new_alloc = 2 * spot->num + 2;
+      Idx new_alloc = 2 * spot->num + 2;
       re_dfastate_t **new_array = re_realloc (spot->array, re_dfastate_t *,
 					      new_alloc);
       if (BE (new_array == NULL, 0))
@@ -1600,9 +1619,9 @@
 static re_dfastate_t *
 __attribute_warn_unused_result__
 create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
-		    unsigned int hash)
+		    re_hashval_t hash)
 {
-  int i;
+  Idx i;
   reg_errcode_t err;
   re_dfastate_t *newstate;
 
@@ -1650,9 +1669,9 @@
 static re_dfastate_t *
 __attribute_warn_unused_result__
 create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
-		    unsigned int context, unsigned int hash)
+		    unsigned int context, re_hashval_t hash)
 {
-  int i, nctx_nodes = 0;
+  Idx i, nctx_nodes = 0;
   reg_errcode_t err;
   re_dfastate_t *newstate;
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/posix/regex_internal.h b/google3/third_party/grte/v5_src/glibc-2.27/posix/regex_internal.h
index 41bf2d3..3b836ed 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/posix/regex_internal.h
+++ b/google3/third_party/grte/v5_src/glibc-2.27/posix/regex_internal.h
@@ -15,7 +15,7 @@
 
    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
+   <https://www.gnu.org/licenses/>.  */
 
 #ifndef _REGEX_INTERNAL_H
 #define _REGEX_INTERNAL_H 1
@@ -26,35 +26,78 @@
 #include <stdlib.h>
 #include <string.h>
 
-#if defined HAVE_LANGINFO_H || defined HAVE_LANGINFO_CODESET || defined _LIBC
-# include <langinfo.h>
-#endif
-#if defined HAVE_LOCALE_H || defined _LIBC
-# include <locale.h>
-#endif
-#if defined HAVE_WCHAR_H || defined _LIBC
-# include <wchar.h>
-#endif /* HAVE_WCHAR_H || _LIBC */
-#if defined HAVE_WCTYPE_H || defined _LIBC
-# include <wctype.h>
-#endif /* HAVE_WCTYPE_H || _LIBC */
-#if defined HAVE_STDBOOL_H || defined _LIBC
-# include <stdbool.h>
-#endif /* HAVE_STDBOOL_H || _LIBC */
-#if defined HAVE_STDINT_H || defined _LIBC
-# include <stdint.h>
-#endif /* HAVE_STDINT_H || _LIBC */
-#if defined _LIBC
-# include <libc-lock.h>
+#include <langinfo.h>
+#include <locale.h>
+#include <wchar.h>
+#include <wctype.h>
+#include <stdbool.h>
+#include <stdint.h>
+
+/* Properties of integers.  Although Gnulib has intprops.h, glibc does
+   without for now.  */
+#ifndef _LIBC
+# include "intprops.h"
 #else
-# define __libc_lock_define(CLASS,NAME)
-# define __libc_lock_init(NAME) do { } while (0)
-# define __libc_lock_lock(NAME) do { } while (0)
-# define __libc_lock_unlock(NAME) do { } while (0)
+/* True if the real type T is signed.  */
+# define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
+
+/* True if adding the nonnegative Idx values A and B would overflow.
+   If false, set *R to A + B.  A, B, and R may be evaluated more than
+   once, or zero times.  Although this is not a full implementation of
+   Gnulib INT_ADD_WRAPV, it is good enough for glibc regex code.
+   FIXME: This implementation is a fragile stopgap, and this file would
+   be simpler and more robust if intprops.h were migrated into glibc.  */
+# define INT_ADD_WRAPV(a, b, r) \
+   (IDX_MAX - (a) < (b) ? true : (*(r) = (a) + (b), false))
+#endif
+
+#ifdef _LIBC
+# include <libc-lock.h>
+# define lock_define(name) __libc_lock_define (, name)
+# define lock_init(lock) (__libc_lock_init (lock), 0)
+# define lock_fini(lock) ((void) 0)
+# define lock_lock(lock) __libc_lock_lock (lock)
+# define lock_unlock(lock) __libc_lock_unlock (lock)
+#elif defined GNULIB_LOCK && !defined USE_UNLOCKED_IO
+# include "glthread/lock.h"
+  /* Use gl_lock_define if empty macro arguments are known to work.
+     Otherwise, fall back on less-portable substitutes.  */
+# if ((defined __GNUC__ && !defined __STRICT_ANSI__) \
+      || (defined __STDC_VERSION__ && 199901L <= __STDC_VERSION__))
+#  define lock_define(name) gl_lock_define (, name)
+# elif USE_POSIX_THREADS
+#  define lock_define(name) pthread_mutex_t name;
+# elif USE_PTH_THREADS
+#  define lock_define(name) pth_mutex_t name;
+# elif USE_SOLARIS_THREADS
+#  define lock_define(name) mutex_t name;
+# elif USE_WINDOWS_THREADS
+#  define lock_define(name) gl_lock_t name;
+# else
+#  define lock_define(name)
+# endif
+# define lock_init(lock) glthread_lock_init (&(lock))
+# define lock_fini(lock) glthread_lock_destroy (&(lock))
+# define lock_lock(lock) glthread_lock_lock (&(lock))
+# define lock_unlock(lock) glthread_lock_unlock (&(lock))
+#elif defined GNULIB_PTHREAD && !defined USE_UNLOCKED_IO
+# include <pthread.h>
+# define lock_define(name) pthread_mutex_t name;
+# define lock_init(lock) pthread_mutex_init (&(lock), 0)
+# define lock_fini(lock) pthread_mutex_destroy (&(lock))
+# define lock_lock(lock) pthread_mutex_lock (&(lock))
+# define lock_unlock(lock) pthread_mutex_unlock (&(lock))
+#else
+# define lock_define(name)
+# define lock_init(lock) 0
+# define lock_fini(lock) ((void) 0)
+  /* The 'dfa' avoids an "unused variable 'dfa'" warning from GCC.  */
+# define lock_lock(lock) ((void) dfa)
+# define lock_unlock(lock) ((void) 0)
 #endif
 
 /* In case that the system doesn't have isblank().  */
-#if !defined _LIBC && !defined HAVE_ISBLANK && !defined isblank
+#if !defined _LIBC && ! (defined isblank || (HAVE_ISBLANK && HAVE_DECL_ISBLANK))
 # define isblank(ch) ((ch) == ' ' || (ch) == '\t')
 #endif
 
@@ -75,6 +118,7 @@
   __dcgettext (_libc_intl_domainname, msgid, LC_MESSAGES)
 # endif
 #else
+# undef gettext
 # define gettext(msgid) (msgid)
 #endif
 
@@ -84,23 +128,17 @@
 # define gettext_noop(String) String
 #endif
 
-/* For loser systems without the definition.  */
-#ifndef SIZE_MAX
-# define SIZE_MAX ((size_t) -1)
-#endif
-
 #if (defined MB_CUR_MAX && HAVE_WCTYPE_H && HAVE_ISWCTYPE) || _LIBC
 # define RE_ENABLE_I18N
 #endif
 
-#if __GNUC__ >= 3
-# define BE(expr, val) __builtin_expect (expr, val)
-#else
-# define BE(expr, val) (expr)
-#endif
+#define BE(expr, val) __builtin_expect (expr, val)
 
-/* Number of single byte character.  */
-#define SBC_MAX 256
+/* Number of ASCII characters.  */
+#define ASCII_CHARS 0x80
+
+/* Number of single byte characters.  */
+#define SBC_MAX (UCHAR_MAX + 1)
 
 #define COLL_ELEM_LEN_MAX 8
 
@@ -110,11 +148,15 @@
 
 /* Rename to standard API for using out of glibc.  */
 #ifndef _LIBC
+# undef __wctype
+# undef __iswctype
 # define __wctype wctype
+# define __iswalnum iswalnum
 # define __iswctype iswctype
+# define __towlower towlower
+# define __towupper towupper
 # define __btowc btowc
 # define __mbrtowc mbrtowc
-# define __mempcpy mempcpy
 # define __wcrtomb wcrtomb
 # define __regfree regfree
 # define attribute_hidden
@@ -124,32 +166,70 @@
 # define __attribute__(arg)
 #endif
 
-extern const char __re_error_msgid[] attribute_hidden;
-extern const size_t __re_error_msgid_idx[] attribute_hidden;
+#ifndef SSIZE_MAX
+# define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
+#endif
+
+/* The type of indexes into strings.  This is signed, not size_t,
+   since the API requires indexes to fit in regoff_t anyway, and using
+   signed integers makes the code a bit smaller and presumably faster.
+   The traditional GNU regex implementation uses int for indexes.
+   The POSIX-compatible implementation uses a possibly-wider type.
+   The name 'Idx' is three letters to minimize the hassle of
+   reindenting a lot of regex code that formerly used 'int'.  */
+typedef regoff_t Idx;
+#ifdef _REGEX_LARGE_OFFSETS
+# define IDX_MAX SSIZE_MAX
+#else
+# define IDX_MAX INT_MAX
+#endif
+
+/* A hash value, suitable for computing hash tables.  */
+typedef __re_size_t re_hashval_t;
 
 /* An integer used to represent a set of bits.  It must be unsigned,
    and must be at least as wide as unsigned int.  */
 typedef unsigned long int bitset_word_t;
 /* All bits set in a bitset_word_t.  */
 #define BITSET_WORD_MAX ULONG_MAX
-/* Number of bits in a bitset_word_t.  */
-#define BITSET_WORD_BITS (sizeof (bitset_word_t) * CHAR_BIT)
-/* Number of bitset_word_t in a bit_set.  */
-#define BITSET_WORDS (SBC_MAX / BITSET_WORD_BITS)
+
+/* Number of bits in a bitset_word_t.  For portability to hosts with
+   padding bits, do not use '(sizeof (bitset_word_t) * CHAR_BIT)';
+   instead, deduce it directly from BITSET_WORD_MAX.  Avoid
+   greater-than-32-bit integers and unconditional shifts by more than
+   31 bits, as they're not portable.  */
+#if BITSET_WORD_MAX == 0xffffffffUL
+# define BITSET_WORD_BITS 32
+#elif BITSET_WORD_MAX >> 31 >> 4 == 1
+# define BITSET_WORD_BITS 36
+#elif BITSET_WORD_MAX >> 31 >> 16 == 1
+# define BITSET_WORD_BITS 48
+#elif BITSET_WORD_MAX >> 31 >> 28 == 1
+# define BITSET_WORD_BITS 60
+#elif BITSET_WORD_MAX >> 31 >> 31 >> 1 == 1
+# define BITSET_WORD_BITS 64
+#elif BITSET_WORD_MAX >> 31 >> 31 >> 9 == 1
+# define BITSET_WORD_BITS 72
+#elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 3 == 1
+# define BITSET_WORD_BITS 128
+#elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 7 == 1
+# define BITSET_WORD_BITS 256
+#elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 7 > 1
+# define BITSET_WORD_BITS 257 /* any value > SBC_MAX will do here */
+# if BITSET_WORD_BITS <= SBC_MAX
+#  error "Invalid SBC_MAX"
+# endif
+#else
+# error "Add case for new bitset_word_t size"
+#endif
+
+/* Number of bitset_word_t values in a bitset_t.  */
+#define BITSET_WORDS ((SBC_MAX + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS)
+
 typedef bitset_word_t bitset_t[BITSET_WORDS];
 typedef bitset_word_t *re_bitset_ptr_t;
 typedef const bitset_word_t *re_const_bitset_ptr_t;
 
-#define bitset_set(set,i) \
-  (set[i / BITSET_WORD_BITS] |= (bitset_word_t) 1 << i % BITSET_WORD_BITS)
-#define bitset_clear(set,i) \
-  (set[i / BITSET_WORD_BITS] &= ~((bitset_word_t) 1 << i % BITSET_WORD_BITS))
-#define bitset_contain(set,i) \
-  (set[i / BITSET_WORD_BITS] & ((bitset_word_t) 1 << i % BITSET_WORD_BITS))
-#define bitset_empty(set) memset (set, '\0', sizeof (bitset_t))
-#define bitset_set_all(set) memset (set, '\xff', sizeof (bitset_t))
-#define bitset_copy(dest,src) memcpy (dest, src, sizeof (bitset_t))
-
 #define PREV_WORD_CONSTRAINT 0x0001
 #define PREV_NOTWORD_CONSTRAINT 0x0002
 #define NEXT_WORD_CONSTRAINT 0x0004
@@ -177,9 +257,9 @@
 
 typedef struct
 {
-  int alloc;
-  int nelem;
-  int *elems;
+  Idx alloc;
+  Idx nelem;
+  Idx *elems;
 } re_node_set;
 
 typedef enum
@@ -265,19 +345,19 @@
   unsigned int non_match : 1;
 
   /* # of multibyte characters.  */
-  int nmbchars;
+  Idx nmbchars;
 
   /* # of collating symbols.  */
-  int ncoll_syms;
+  Idx ncoll_syms;
 
   /* # of equivalence classes. */
-  int nequiv_classes;
+  Idx nequiv_classes;
 
   /* # of range expressions. */
-  int nranges;
+  Idx nranges;
 
   /* # of character classes. */
-  int nchar_classes;
+  Idx nchar_classes;
 } re_charset_t;
 #endif /* RE_ENABLE_I18N */
 
@@ -290,10 +370,10 @@
 #ifdef RE_ENABLE_I18N
     re_charset_t *mbcset;	/* for COMPLEX_BRACKET */
 #endif /* RE_ENABLE_I18N */
-    int idx;			/* for BACK_REF */
+    Idx idx;			/* for BACK_REF */
     re_context_type ctx_type;	/* for ANCHOR */
   } opr;
-#if __GNUC__ >= 2
+#if __GNUC__ >= 2 && !defined __STRICT_ANSI__
   re_token_type_t type : 8;
 #else
   re_token_type_t type;
@@ -324,30 +404,30 @@
 #ifdef RE_ENABLE_I18N
   /* Store the wide character string which is corresponding to MBS.  */
   wint_t *wcs;
-  int *offsets;
+  Idx *offsets;
   mbstate_t cur_state;
 #endif
   /* Index in RAW_MBS.  Each character mbs[i] corresponds to
      raw_mbs[raw_mbs_idx + i].  */
-  int raw_mbs_idx;
+  Idx raw_mbs_idx;
   /* The length of the valid characters in the buffers.  */
-  int valid_len;
+  Idx valid_len;
   /* The corresponding number of bytes in raw_mbs array.  */
-  int valid_raw_len;
+  Idx valid_raw_len;
   /* The length of the buffers MBS and WCS.  */
-  int bufs_len;
+  Idx bufs_len;
   /* The index in MBS, which is updated by re_string_fetch_byte.  */
-  int cur_idx;
+  Idx cur_idx;
   /* length of RAW_MBS array.  */
-  int raw_len;
+  Idx raw_len;
   /* This is RAW_LEN - RAW_MBS_IDX + VALID_LEN - VALID_RAW_LEN.  */
-  int len;
+  Idx len;
   /* End of the buffer may be shorter than its length in the cases such
      as re_match_2, re_search_2.  Then, we use STOP for end of the buffer
      instead of LEN.  */
-  int raw_stop;
+  Idx raw_stop;
   /* This is RAW_STOP - RAW_MBS_IDX adjusted through OFFSETS.  */
-  int stop;
+  Idx stop;
 
   /* The context of mbs[0].  We store the context independently, since
      the context of mbs[0] may be different from raw_mbs[0], which is
@@ -357,7 +437,7 @@
   RE_TRANSLATE_TYPE trans;
   /* Copy of re_dfa_t's word_char.  */
   re_const_bitset_ptr_t word_char;
-  /* 1 if REG_ICASE.  */
+  /* true if REG_ICASE.  */
   unsigned char icase;
   unsigned char is_utf8;
   unsigned char map_notascii;
@@ -373,18 +453,10 @@
 struct re_dfa_t;
 typedef struct re_dfa_t re_dfa_t;
 
-#if IS_IN (libc)
-static reg_errcode_t re_string_realloc_buffers (re_string_t *pstr,
-						int new_buf_len);
-# ifdef RE_ENABLE_I18N
-static void build_wcs_buffer (re_string_t *pstr);
-static reg_errcode_t build_wcs_upper_buffer (re_string_t *pstr);
-# endif /* RE_ENABLE_I18N */
-static void build_upper_buffer (re_string_t *pstr);
-static void re_string_translate_buffer (re_string_t *pstr);
-static unsigned int re_string_context_at (const re_string_t *input, int idx,
-					  int eflags) __attribute__ ((pure));
+#ifndef _LIBC
+# define IS_IN(libc) false
 #endif
+
 #define re_string_peek_byte(pstr, offset) \
   ((pstr)->mbs[(pstr)->cur_idx + offset])
 #define re_string_fetch_byte(pstr) \
@@ -402,7 +474,9 @@
 #define re_string_skip_bytes(pstr,idx) ((pstr)->cur_idx += (idx))
 #define re_string_set_index(pstr,idx) ((pstr)->cur_idx = (idx))
 
-#include <alloca.h>
+#if defined _LIBC || HAVE_ALLOCA
+# include <alloca.h>
+#endif
 
 #ifndef _LIBC
 # if HAVE_ALLOCA
@@ -414,9 +488,24 @@
 # else
 /* alloca is implemented with malloc, so just use malloc.  */
 #  define __libc_use_alloca(n) 0
+#  undef alloca
+#  define alloca(n) malloc (n)
 # endif
 #endif
 
+#ifdef _LIBC
+# define MALLOC_0_IS_NONNULL 1
+#elif !defined MALLOC_0_IS_NONNULL
+# define MALLOC_0_IS_NONNULL 0
+#endif
+
+#ifndef MAX
+# define MAX(a,b) ((a) < (b) ? (b) : (a))
+#endif
+#ifndef MIN
+# define MIN(a,b) ((a) < (b) ? (a) : (b))
+#endif
+
 #define re_malloc(t,n) ((t *) malloc ((n) * sizeof (t)))
 #define re_realloc(p,t,n) ((t *) realloc (p, (n) * sizeof (t)))
 #define re_free(p) free (p)
@@ -431,9 +520,9 @@
 
   re_token_t token;
 
-  /* `node_idx' is the index in dfa->nodes, if `type' == 0.
-     Otherwise `type' indicate the type of this node.  */
-  int node_idx;
+  /* 'node_idx' is the index in dfa->nodes, if 'type' == 0.
+     Otherwise 'type' indicate the type of this node.  */
+  Idx node_idx;
 };
 typedef struct bin_tree_t bin_tree_t;
 
@@ -477,7 +566,7 @@
 
 struct re_dfastate_t
 {
-  unsigned int hash;
+  re_hashval_t hash;
   re_node_set nodes;
   re_node_set non_eps_nodes;
   re_node_set inveclosure;
@@ -485,9 +574,9 @@
   struct re_dfastate_t **trtable, **word_trtable;
   unsigned int context : 4;
   unsigned int halt : 1;
-  /* If this state can accept `multi byte'.
+  /* If this state can accept "multi byte".
      Note that we refer to multibyte characters, and multi character
-     collating elements as `multi byte'.  */
+     collating elements as "multi byte".  */
   unsigned int accept_mb : 1;
   /* If this state has backreference node(s).  */
   unsigned int has_backref : 1;
@@ -497,8 +586,8 @@
 
 struct re_state_table_entry
 {
-  int num;
-  int alloc;
+  Idx num;
+  Idx alloc;
   re_dfastate_t **array;
 };
 
@@ -506,8 +595,8 @@
 
 typedef struct
 {
-  int next_idx;
-  int alloc;
+  Idx next_idx;
+  Idx alloc;
   re_dfastate_t **array;
 } state_array_t;
 
@@ -515,8 +604,8 @@
 
 typedef struct
 {
-  int node;
-  int str_idx; /* The position NODE match at.  */
+  Idx node;
+  Idx str_idx; /* The position NODE match at.  */
   state_array_t path;
 } re_sub_match_last_t;
 
@@ -526,20 +615,20 @@
 
 typedef struct
 {
-  int str_idx;
-  int node;
+  Idx str_idx;
+  Idx node;
   state_array_t *path;
-  int alasts; /* Allocation size of LASTS.  */
-  int nlasts; /* The number of LASTS.  */
+  Idx alasts; /* Allocation size of LASTS.  */
+  Idx nlasts; /* The number of LASTS.  */
   re_sub_match_last_t **lasts;
 } re_sub_match_top_t;
 
 struct re_backref_cache_entry
 {
-  int node;
-  int str_idx;
-  int subexp_from;
-  int subexp_to;
+  Idx node;
+  Idx str_idx;
+  Idx subexp_from;
+  Idx subexp_to;
   char more;
   char unused;
   unsigned short int eps_reachable_subexps_map;
@@ -557,18 +646,18 @@
   /* EFLAGS of the argument of regexec.  */
   int eflags;
   /* Where the matching ends.  */
-  int match_last;
-  int last_node;
+  Idx match_last;
+  Idx last_node;
   /* The state log used by the matcher.  */
   re_dfastate_t **state_log;
-  int state_log_top;
+  Idx state_log_top;
   /* Back reference cache.  */
-  int nbkref_ents;
-  int abkref_ents;
+  Idx nbkref_ents;
+  Idx abkref_ents;
   struct re_backref_cache_entry *bkref_ents;
   int max_mb_elem_len;
-  int nsub_tops;
-  int asub_tops;
+  Idx nsub_tops;
+  Idx asub_tops;
   re_sub_match_top_t **sub_tops;
 } re_match_context_t;
 
@@ -576,23 +665,23 @@
 {
   re_dfastate_t **sifted_states;
   re_dfastate_t **limited_states;
-  int last_node;
-  int last_str_idx;
+  Idx last_node;
+  Idx last_str_idx;
   re_node_set limits;
 } re_sift_context_t;
 
 struct re_fail_stack_ent_t
 {
-  int idx;
-  int node;
+  Idx idx;
+  Idx node;
   regmatch_t *regs;
   re_node_set eps_via_nodes;
 };
 
 struct re_fail_stack_t
 {
-  int num;
-  int alloc;
+  Idx num;
+  Idx alloc;
   struct re_fail_stack_ent_t *stack;
 };
 
@@ -601,8 +690,8 @@
   re_token_t *nodes;
   size_t nodes_alloc;
   size_t nodes_len;
-  int *nexts;
-  int *org_indices;
+  Idx *nexts;
+  Idx *org_indices;
   re_node_set *edests;
   re_node_set *eclosures;
   re_node_set *inveclosures;
@@ -616,10 +705,10 @@
   re_bitset_ptr_t sb_char;
   int str_tree_storage_idx;
 
-  /* number of subexpressions `re_nsub' is in regex_t.  */
-  unsigned int state_hash_mask;
-  int init_node;
-  int nbackref; /* The number of backreference in this dfa.  */
+  /* number of subexpressions 're_nsub' is in regex_t.  */
+  re_hashval_t state_hash_mask;
+  Idx init_node;
+  Idx nbackref; /* The number of backreference in this dfa.  */
 
   /* Bitmap expressing which backreference is used.  */
   bitset_word_t used_bkref_map;
@@ -636,11 +725,11 @@
   int mb_cur_max;
   bitset_t word_char;
   reg_syntax_t syntax;
-  int *subexp_map;
+  Idx *subexp_map;
 #ifdef DEBUG
   char* re_str;
 #endif
-  __libc_lock_define (, lock)
+  lock_define (lock)
 };
 
 #define re_node_set_init_empty(set) memset (set, '\0', sizeof (re_node_set))
@@ -671,16 +760,60 @@
 } bracket_elem_t;
 
 
-/* Inline functions for bitset operation.  */
-static void __attribute__ ((unused))
+/* Functions for bitset_t operation.  */
+
+static inline void
+bitset_set (bitset_t set, Idx i)
+{
+  set[i / BITSET_WORD_BITS] |= (bitset_word_t) 1 << i % BITSET_WORD_BITS;
+}
+
+static inline void
+bitset_clear (bitset_t set, Idx i)
+{
+  set[i / BITSET_WORD_BITS] &= ~ ((bitset_word_t) 1 << i % BITSET_WORD_BITS);
+}
+
+static inline bool
+bitset_contain (const bitset_t set, Idx i)
+{
+  return (set[i / BITSET_WORD_BITS] >> i % BITSET_WORD_BITS) & 1;
+}
+
+static inline void
+bitset_empty (bitset_t set)
+{
+  memset (set, '\0', sizeof (bitset_t));
+}
+
+static inline void
+bitset_set_all (bitset_t set)
+{
+  memset (set, -1, sizeof (bitset_word_t) * (SBC_MAX / BITSET_WORD_BITS));
+  if (SBC_MAX % BITSET_WORD_BITS != 0)
+    set[BITSET_WORDS - 1] =
+      ((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1;
+}
+
+static inline void
+bitset_copy (bitset_t dest, const bitset_t src)
+{
+  memcpy (dest, src, sizeof (bitset_t));
+}
+
+static inline void
 bitset_not (bitset_t set)
 {
   int bitset_i;
-  for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i)
+  for (bitset_i = 0; bitset_i < SBC_MAX / BITSET_WORD_BITS; ++bitset_i)
     set[bitset_i] = ~set[bitset_i];
+  if (SBC_MAX % BITSET_WORD_BITS != 0)
+    set[BITSET_WORDS - 1] =
+      ((((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1)
+       & ~set[BITSET_WORDS - 1]);
 }
 
-static void __attribute__ ((unused))
+static inline void
 bitset_merge (bitset_t dest, const bitset_t src)
 {
   int bitset_i;
@@ -688,7 +821,7 @@
     dest[bitset_i] |= src[bitset_i];
 }
 
-static void __attribute__ ((unused))
+static inline void
 bitset_mask (bitset_t dest, const bitset_t src)
 {
   int bitset_i;
@@ -697,10 +830,10 @@
 }
 
 #ifdef RE_ENABLE_I18N
-/* Inline functions for re_string.  */
+/* Functions for re_string.  */
 static int
 __attribute__ ((pure, unused))
-re_string_char_size_at (const re_string_t *pstr, int idx)
+re_string_char_size_at (const re_string_t *pstr, Idx idx)
 {
   int byte_idx;
   if (pstr->mb_cur_max == 1)
@@ -713,23 +846,22 @@
 
 static wint_t
 __attribute__ ((pure, unused))
-re_string_wchar_at (const re_string_t *pstr, int idx)
+re_string_wchar_at (const re_string_t *pstr, Idx idx)
 {
   if (pstr->mb_cur_max == 1)
     return (wint_t) pstr->mbs[idx];
   return (wint_t) pstr->wcs[idx];
 }
 
-# if IS_IN (libc)
-#  ifdef _LIBC
-#   include <locale/weight.h>
-#  endif
+# ifdef _LIBC
+#  include <locale/weight.h>
+# endif
 
 static int
 __attribute__ ((pure, unused))
-re_string_elem_size_at (const re_string_t *pstr, int idx)
+re_string_elem_size_at (const re_string_t *pstr, Idx idx)
 {
-#  ifdef _LIBC
+# ifdef _LIBC
   const unsigned char *p, *extra;
   const int32_t *table, *indirect;
   uint_fast32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
@@ -746,10 +878,34 @@
       return p - pstr->mbs - idx;
     }
   else
-#  endif /* _LIBC */
+# endif /* _LIBC */
     return 1;
 }
-# endif
 #endif /* RE_ENABLE_I18N */
 
+#ifndef __GNUC_PREREQ
+# if defined __GNUC__ && defined __GNUC_MINOR__
+#  define __GNUC_PREREQ(maj, min) \
+         ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
+# else
+#  define __GNUC_PREREQ(maj, min) 0
+# endif
+#endif
+
+#if __GNUC_PREREQ (3,4)
+# undef __attribute_warn_unused_result__
+# define __attribute_warn_unused_result__ \
+   __attribute__ ((__warn_unused_result__))
+#else
+# define __attribute_warn_unused_result__ /* empty */
+#endif
+
+#ifndef FALLTHROUGH
+# if __GNUC__ < 7
+#  define FALLTHROUGH ((void) 0)
+# else
+#  define FALLTHROUGH __attribute__ ((__fallthrough__))
+# endif
+#endif
+
 #endif /*  _REGEX_INTERNAL_H */
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/posix/regexec.c b/google3/third_party/grte/v5_src/glibc-2.27/posix/regexec.c
index 4b1ab4e..63aef97 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/posix/regexec.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/posix/regexec.c
@@ -15,100 +15,98 @@
 
    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <stdint.h>
+   <https://www.gnu.org/licenses/>.  */
 
 static reg_errcode_t match_ctx_init (re_match_context_t *cache, int eflags,
-				     int n);
+				     Idx n);
 static void match_ctx_clean (re_match_context_t *mctx);
 static void match_ctx_free (re_match_context_t *cache);
-static reg_errcode_t match_ctx_add_entry (re_match_context_t *cache, int node,
-					  int str_idx, int from, int to);
-static int search_cur_bkref_entry (const re_match_context_t *mctx,
-				   int str_idx);
-static reg_errcode_t match_ctx_add_subtop (re_match_context_t *mctx, int node,
-					   int str_idx);
+static reg_errcode_t match_ctx_add_entry (re_match_context_t *cache, Idx node,
+					  Idx str_idx, Idx from, Idx to);
+static Idx search_cur_bkref_entry (const re_match_context_t *mctx, Idx str_idx);
+static reg_errcode_t match_ctx_add_subtop (re_match_context_t *mctx, Idx node,
+					   Idx str_idx);
 static re_sub_match_last_t * match_ctx_add_sublast (re_sub_match_top_t *subtop,
-						   int node, int str_idx);
+						    Idx node, Idx str_idx);
 static void sift_ctx_init (re_sift_context_t *sctx, re_dfastate_t **sifted_sts,
-			   re_dfastate_t **limited_sts, int last_node,
-			   int last_str_idx);
+			   re_dfastate_t **limited_sts, Idx last_node,
+			   Idx last_str_idx);
 static reg_errcode_t re_search_internal (const regex_t *preg,
-					 const char *string, int length,
-					 int start, int range, int stop,
+					 const char *string, Idx length,
+					 Idx start, Idx last_start, Idx stop,
 					 size_t nmatch, regmatch_t pmatch[],
 					 int eflags);
-static int re_search_2_stub (struct re_pattern_buffer *bufp,
-			     const char *string1, int length1,
-			     const char *string2, int length2,
-			     int start, int range, struct re_registers *regs,
-			     int stop, int ret_len);
-static int re_search_stub (struct re_pattern_buffer *bufp,
-			   const char *string, int length, int start,
-			   int range, int stop, struct re_registers *regs,
-			   int ret_len);
+static regoff_t re_search_2_stub (struct re_pattern_buffer *bufp,
+				  const char *string1, Idx length1,
+				  const char *string2, Idx length2,
+				  Idx start, regoff_t range,
+				  struct re_registers *regs,
+				  Idx stop, bool ret_len);
+static regoff_t re_search_stub (struct re_pattern_buffer *bufp,
+				const char *string, Idx length, Idx start,
+				regoff_t range, Idx stop,
+				struct re_registers *regs,
+				bool ret_len);
 static unsigned re_copy_regs (struct re_registers *regs, regmatch_t *pmatch,
-			      int nregs, int regs_allocated);
+                              Idx nregs, int regs_allocated);
 static reg_errcode_t prune_impossible_nodes (re_match_context_t *mctx);
-static int check_matching (re_match_context_t *mctx, int fl_longest_match,
-			   int *p_match_first);
-static int check_halt_state_context (const re_match_context_t *mctx,
-				     const re_dfastate_t *state, int idx);
+static Idx check_matching (re_match_context_t *mctx, bool fl_longest_match,
+			   Idx *p_match_first);
+static Idx check_halt_state_context (const re_match_context_t *mctx,
+				     const re_dfastate_t *state, Idx idx);
 static void update_regs (const re_dfa_t *dfa, regmatch_t *pmatch,
-			 regmatch_t *prev_idx_match, int cur_node,
-			 int cur_idx, int nmatch);
+			 regmatch_t *prev_idx_match, Idx cur_node,
+			 Idx cur_idx, Idx nmatch);
 static reg_errcode_t push_fail_stack (struct re_fail_stack_t *fs,
-				      int str_idx, int dest_node, int nregs,
+				      Idx str_idx, Idx dest_node, Idx nregs,
 				      regmatch_t *regs,
 				      re_node_set *eps_via_nodes);
 static reg_errcode_t set_regs (const regex_t *preg,
 			       const re_match_context_t *mctx,
 			       size_t nmatch, regmatch_t *pmatch,
-			       int fl_backtrack);
+			       bool fl_backtrack);
 static reg_errcode_t free_fail_stack_return (struct re_fail_stack_t *fs);
 
 #ifdef RE_ENABLE_I18N
 static int sift_states_iter_mb (const re_match_context_t *mctx,
 				re_sift_context_t *sctx,
-				int node_idx, int str_idx, int max_str_idx);
+				Idx node_idx, Idx str_idx, Idx max_str_idx);
 #endif /* RE_ENABLE_I18N */
 static reg_errcode_t sift_states_backward (const re_match_context_t *mctx,
 					   re_sift_context_t *sctx);
 static reg_errcode_t build_sifted_states (const re_match_context_t *mctx,
-					  re_sift_context_t *sctx, int str_idx,
+					  re_sift_context_t *sctx, Idx str_idx,
 					  re_node_set *cur_dest);
 static reg_errcode_t update_cur_sifted_state (const re_match_context_t *mctx,
 					      re_sift_context_t *sctx,
-					      int str_idx,
+					      Idx str_idx,
 					      re_node_set *dest_nodes);
 static reg_errcode_t add_epsilon_src_nodes (const re_dfa_t *dfa,
 					    re_node_set *dest_nodes,
 					    const re_node_set *candidates);
-static int check_dst_limits (const re_match_context_t *mctx,
-			     re_node_set *limits,
-			     int dst_node, int dst_idx, int src_node,
-			     int src_idx);
+static bool check_dst_limits (const re_match_context_t *mctx,
+			      const re_node_set *limits,
+			      Idx dst_node, Idx dst_idx, Idx src_node,
+			      Idx src_idx);
 static int check_dst_limits_calc_pos_1 (const re_match_context_t *mctx,
-					int boundaries, int subexp_idx,
-					int from_node, int bkref_idx);
+					int boundaries, Idx subexp_idx,
+					Idx from_node, Idx bkref_idx);
 static int check_dst_limits_calc_pos (const re_match_context_t *mctx,
-				      int limit, int subexp_idx,
-				      int node, int str_idx,
-				      int bkref_idx);
+				      Idx limit, Idx subexp_idx,
+				      Idx node, Idx str_idx,
+				      Idx bkref_idx);
 static reg_errcode_t check_subexp_limits (const re_dfa_t *dfa,
 					  re_node_set *dest_nodes,
 					  const re_node_set *candidates,
 					  re_node_set *limits,
 					  struct re_backref_cache_entry *bkref_ents,
-					  int str_idx);
+					  Idx str_idx);
 static reg_errcode_t sift_states_bkref (const re_match_context_t *mctx,
 					re_sift_context_t *sctx,
-					int str_idx,
-					const re_node_set *candidates);
+					Idx str_idx, const re_node_set *candidates);
 static reg_errcode_t merge_state_array (const re_dfa_t *dfa,
 					re_dfastate_t **dst,
-					re_dfastate_t **src, int num);
+					re_dfastate_t **src, Idx num);
 static re_dfastate_t *find_recover_state (reg_errcode_t *err,
 					 re_match_context_t *mctx);
 static re_dfastate_t *transit_state (reg_errcode_t *err,
@@ -119,7 +117,7 @@
 					    re_dfastate_t *next_state);
 static reg_errcode_t check_subexp_matching_top (re_match_context_t *mctx,
 						re_node_set *cur_nodes,
-						int str_idx);
+						Idx str_idx);
 #if 0
 static re_dfastate_t *transit_state_sb (reg_errcode_t *err,
 					re_match_context_t *mctx,
@@ -132,46 +130,46 @@
 static reg_errcode_t transit_state_bkref (re_match_context_t *mctx,
 					  const re_node_set *nodes);
 static reg_errcode_t get_subexp (re_match_context_t *mctx,
-				 int bkref_node, int bkref_str_idx);
+				 Idx bkref_node, Idx bkref_str_idx);
 static reg_errcode_t get_subexp_sub (re_match_context_t *mctx,
 				     const re_sub_match_top_t *sub_top,
 				     re_sub_match_last_t *sub_last,
-				     int bkref_node, int bkref_str);
-static int find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes,
-			     int subexp_idx, int type);
+				     Idx bkref_node, Idx bkref_str);
+static Idx find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes,
+			     Idx subexp_idx, int type);
 static reg_errcode_t check_arrival (re_match_context_t *mctx,
-				    state_array_t *path, int top_node,
-				    int top_str, int last_node, int last_str,
+				    state_array_t *path, Idx top_node,
+				    Idx top_str, Idx last_node, Idx last_str,
 				    int type);
 static reg_errcode_t check_arrival_add_next_nodes (re_match_context_t *mctx,
-						   int str_idx,
+						   Idx str_idx,
 						   re_node_set *cur_nodes,
 						   re_node_set *next_nodes);
 static reg_errcode_t check_arrival_expand_ecl (const re_dfa_t *dfa,
 					       re_node_set *cur_nodes,
-					       int ex_subexp, int type);
+					       Idx ex_subexp, int type);
 static reg_errcode_t check_arrival_expand_ecl_sub (const re_dfa_t *dfa,
 						   re_node_set *dst_nodes,
-						   int target, int ex_subexp,
+						   Idx target, Idx ex_subexp,
 						   int type);
 static reg_errcode_t expand_bkref_cache (re_match_context_t *mctx,
-					 re_node_set *cur_nodes, int cur_str,
-					 int subexp_num, int type);
-static int build_trtable (const re_dfa_t *dfa, re_dfastate_t *state);
+					 re_node_set *cur_nodes, Idx cur_str,
+					 Idx subexp_num, int type);
+static bool build_trtable (const re_dfa_t *dfa, re_dfastate_t *state);
 #ifdef RE_ENABLE_I18N
-static int check_node_accept_bytes (const re_dfa_t *dfa, int node_idx,
-				    const re_string_t *input, int idx);
+static int check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
+				    const re_string_t *input, Idx idx);
 # ifdef _LIBC
 static unsigned int find_collation_sequence_value (const unsigned char *mbs,
 						   size_t name_len);
 # endif /* _LIBC */
 #endif /* RE_ENABLE_I18N */
-static int group_nodes_into_DFAstates (const re_dfa_t *dfa,
+static Idx group_nodes_into_DFAstates (const re_dfa_t *dfa,
 				       const re_dfastate_t *state,
 				       re_node_set *states_node,
 				       bitset_t *states_ch);
-static int check_node_accept (const re_match_context_t *mctx,
-			      const re_token_t *node, int idx);
+static bool check_node_accept (const re_match_context_t *mctx,
+			       const re_token_t *node, Idx idx);
 static reg_errcode_t extend_buffers (re_match_context_t *mctx, int min_len);
 
 /* Entry point for POSIX code.  */
@@ -180,23 +178,23 @@
    string STRING.
 
    If NMATCH is zero or REG_NOSUB was set in the cflags argument to
-   `regcomp', we ignore PMATCH.  Otherwise, we assume PMATCH has at
+   'regcomp', we ignore PMATCH.  Otherwise, we assume PMATCH has at
    least NMATCH elements, and we set them to the offsets of the
    corresponding matched substrings.
 
-   EFLAGS specifies `execution flags' which affect matching: if
+   EFLAGS specifies "execution flags" which affect matching: if
    REG_NOTBOL is set, then ^ does not match at the beginning of the
    string; if REG_NOTEOL is set, then $ does not match at the end.
 
    We return 0 if we find a match and REG_NOMATCH if not.  */
 
 int
-regexec (const regex_t *__restrict preg, const char *__restrict string,
+regexec (const regex_t *_Restrict_ preg, const char *_Restrict_ string,
 	 size_t nmatch, regmatch_t pmatch[], int eflags)
 {
   reg_errcode_t err;
-  int start, length;
-  re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+  Idx start, length;
+  re_dfa_t *dfa = preg->buffer;
 
   if (eflags & ~(REG_NOTBOL | REG_NOTEOL | REG_STARTEND))
     return REG_BADPAT;
@@ -212,14 +210,14 @@
       length = strlen (string);
     }
 
-  __libc_lock_lock (dfa->lock);
+  lock_lock (dfa->lock);
   if (preg->no_sub)
-    err = re_search_internal (preg, string, length, start, length - start,
+    err = re_search_internal (preg, string, length, start, length,
 			      length, 0, NULL, eflags);
   else
-    err = re_search_internal (preg, string, length, start, length - start,
+    err = re_search_internal (preg, string, length, start, length,
 			      length, nmatch, pmatch, eflags);
-  __libc_lock_unlock (dfa->lock);
+  lock_unlock (dfa->lock);
   return err != REG_NOERROR;
 }
 
@@ -234,8 +232,8 @@
 
 int
 attribute_compat_text_section
-__compat_regexec (const regex_t *__restrict preg,
-		  const char *__restrict string, size_t nmatch,
+__compat_regexec (const regex_t *_Restrict_ preg,
+		  const char *_Restrict_ string, size_t nmatch,
 		  regmatch_t pmatch[], int eflags)
 {
   return regexec (preg, string, nmatch, pmatch,
@@ -274,62 +272,65 @@
    return the position of the start of the match.  Return value -1 means no
    match was found and -2 indicates an internal error.  */
 
-int
-re_match (struct re_pattern_buffer *bufp, const char *string, int length,
-	  int start, struct re_registers *regs)
+regoff_t
+re_match (struct re_pattern_buffer *bufp, const char *string, Idx length,
+	  Idx start, struct re_registers *regs)
 {
-  return re_search_stub (bufp, string, length, start, 0, length, regs, 1);
+  return re_search_stub (bufp, string, length, start, 0, length, regs, true);
 }
 #ifdef _LIBC
 weak_alias (__re_match, re_match)
 #endif
 
-int
-re_search (struct re_pattern_buffer *bufp, const char *string, int length,
-	   int start, int range, struct re_registers *regs)
+regoff_t
+re_search (struct re_pattern_buffer *bufp, const char *string, Idx length,
+	   Idx start, regoff_t range, struct re_registers *regs)
 {
-  return re_search_stub (bufp, string, length, start, range, length, regs, 0);
+  return re_search_stub (bufp, string, length, start, range, length, regs,
+			 false);
 }
 #ifdef _LIBC
 weak_alias (__re_search, re_search)
 #endif
 
-int
-re_match_2 (struct re_pattern_buffer *bufp, const char *string1, int length1,
-	    const char *string2, int length2, int start,
-	    struct re_registers *regs, int stop)
+regoff_t
+re_match_2 (struct re_pattern_buffer *bufp, const char *string1, Idx length1,
+	    const char *string2, Idx length2, Idx start,
+	    struct re_registers *regs, Idx stop)
 {
   return re_search_2_stub (bufp, string1, length1, string2, length2,
-			   start, 0, regs, stop, 1);
+			   start, 0, regs, stop, true);
 }
 #ifdef _LIBC
 weak_alias (__re_match_2, re_match_2)
 #endif
 
-int
-re_search_2 (struct re_pattern_buffer *bufp, const char *string1, int length1,
-	     const char *string2, int length2, int start, int range,
-	     struct re_registers *regs, int stop)
+regoff_t
+re_search_2 (struct re_pattern_buffer *bufp, const char *string1, Idx length1,
+	     const char *string2, Idx length2, Idx start, regoff_t range,
+	     struct re_registers *regs, Idx stop)
 {
   return re_search_2_stub (bufp, string1, length1, string2, length2,
-			   start, range, regs, stop, 0);
+			   start, range, regs, stop, false);
 }
 #ifdef _LIBC
 weak_alias (__re_search_2, re_search_2)
 #endif
 
-static int
+static regoff_t
 re_search_2_stub (struct re_pattern_buffer *bufp, const char *string1,
-		  int length1, const char *string2, int length2, int start,
-		  int range, struct re_registers *regs,
-		  int stop, int ret_len)
+		  Idx length1, const char *string2, Idx length2, Idx start,
+		  regoff_t range, struct re_registers *regs,
+		  Idx stop, bool ret_len)
 {
   const char *str;
-  int rval;
-  int len = length1 + length2;
+  regoff_t rval;
+  Idx len;
   char *s = NULL;
 
-  if (BE (length1 < 0 || length2 < 0 || stop < 0 || len < length1, 0))
+  if (BE ((length1 < 0 || length2 < 0 || stop < 0
+           || INT_ADD_WRAPV (length1, length2, &len)),
+          0))
     return -2;
 
   /* Concatenate the strings.  */
@@ -353,42 +354,45 @@
   else
     str = string1;
 
-  rval = re_search_stub (bufp, str, len, start, range, stop, regs, ret_len);
+  rval = re_search_stub (bufp, str, len, start, range, stop, regs,
+			 ret_len);
   re_free (s);
   return rval;
 }
 
 /* The parameters have the same meaning as those of re_search.
    Additional parameters:
-   If RET_LEN is nonzero the length of the match is returned (re_match style);
+   If RET_LEN is true the length of the match is returned (re_match style);
    otherwise the position of the match is returned.  */
 
-static int
-re_search_stub (struct re_pattern_buffer *bufp, const char *string, int length,
-		int start, int range, int stop, struct re_registers *regs,
-		int ret_len)
+static regoff_t
+re_search_stub (struct re_pattern_buffer *bufp, const char *string, Idx length,
+		Idx start, regoff_t range, Idx stop, struct re_registers *regs,
+		bool ret_len)
 {
   reg_errcode_t result;
   regmatch_t *pmatch;
-  int nregs, rval;
+  Idx nregs;
+  regoff_t rval;
   int eflags = 0;
-  re_dfa_t *dfa = (re_dfa_t *) bufp->buffer;
+  re_dfa_t *dfa = bufp->buffer;
+  Idx last_start = start + range;
 
   /* Check for out-of-range.  */
   if (BE (start < 0 || start > length, 0))
     return -1;
-  if (BE (start + range > length, 0))
-    range = length - start;
-  else if (BE (start + range < 0, 0))
-    range = -start;
+  if (BE (length < last_start || (0 <= range && last_start < start), 0))
+    last_start = length;
+  else if (BE (last_start < 0 || (range < 0 && start <= last_start), 0))
+    last_start = 0;
 
-  __libc_lock_lock (dfa->lock);
+  lock_lock (dfa->lock);
 
   eflags |= (bufp->not_bol) ? REG_NOTBOL : 0;
   eflags |= (bufp->not_eol) ? REG_NOTEOL : 0;
 
   /* Compile fastmap if we haven't yet.  */
-  if (range > 0 && bufp->fastmap != NULL && !bufp->fastmap_accurate)
+  if (start < last_start && bufp->fastmap != NULL && !bufp->fastmap_accurate)
     re_compile_fastmap (bufp);
 
   if (BE (bufp->no_sub, 0))
@@ -397,8 +401,8 @@
   /* We need at least 1 register.  */
   if (regs == NULL)
     nregs = 1;
-  else if (BE (bufp->regs_allocated == REGS_FIXED &&
-	       regs->num_regs < bufp->re_nsub + 1, 0))
+  else if (BE (bufp->regs_allocated == REGS_FIXED
+	       && regs->num_regs <= bufp->re_nsub, 0))
     {
       nregs = regs->num_regs;
       if (BE (nregs < 1, 0))
@@ -417,14 +421,14 @@
       goto out;
     }
 
-  result = re_search_internal (bufp, string, length, start, range, stop,
+  result = re_search_internal (bufp, string, length, start, last_start, stop,
 			       nregs, pmatch, eflags);
 
   rval = 0;
 
-  /* I hope we needn't fill ther regs with -1's when no match was found.  */
+  /* I hope we needn't fill their regs with -1's when no match was found.  */
   if (result != REG_NOERROR)
-    rval = -1;
+    rval = result == REG_NOMATCH ? -1 : -2;
   else if (regs != NULL)
     {
       /* If caller wants register contents data back, copy them.  */
@@ -446,18 +450,18 @@
     }
   re_free (pmatch);
  out:
-  __libc_lock_unlock (dfa->lock);
+  lock_unlock (dfa->lock);
   return rval;
 }
 
 static unsigned
-re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, int nregs,
+re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, Idx nregs,
 	      int regs_allocated)
 {
   int rval = REGS_REALLOCATE;
-  int i;
-  int need_regs = nregs + 1;
-  /* We need one extra element beyond `num_regs' for the `-1' marker GNU code
+  Idx i;
+  Idx need_regs = nregs + 1;
+  /* We need one extra element beyond 'num_regs' for the '-1' marker GNU code
      uses.  */
 
   /* Have the register data arrays been allocated?  */
@@ -530,7 +534,7 @@
 
 void
 re_set_registers (struct re_pattern_buffer *bufp, struct re_registers *regs,
-		  unsigned num_regs, regoff_t *starts, regoff_t *ends)
+		  __re_size_t num_regs, regoff_t *starts, regoff_t *ends)
 {
   if (num_regs)
     {
@@ -543,7 +547,7 @@
     {
       bufp->regs_allocated = REGS_UNALLOCATED;
       regs->num_regs = 0;
-      regs->start = regs->end = (regoff_t *) 0;
+      regs->start = regs->end = NULL;
     }
 }
 #ifdef _LIBC
@@ -568,32 +572,38 @@
 
 /* Searches for a compiled pattern PREG in the string STRING, whose
    length is LENGTH.  NMATCH, PMATCH, and EFLAGS have the same
-   meaning as with regexec.  START, and RANGE have the same meanings
-   with re_search.
+   meaning as with regexec.  LAST_START is START + RANGE, where
+   START and RANGE have the same meaning as with re_search.
    Return REG_NOERROR if we find a match, and REG_NOMATCH if not,
    otherwise return the error code.
    Note: We assume front end functions already check ranges.
-   (START + RANGE >= 0 && START + RANGE <= LENGTH)  */
+   (0 <= LAST_START && LAST_START <= LENGTH)  */
 
 static reg_errcode_t
 __attribute_warn_unused_result__
-re_search_internal (const regex_t *preg, const char *string, int length,
-		    int start, int range, int stop, size_t nmatch,
+re_search_internal (const regex_t *preg, const char *string, Idx length,
+		    Idx start, Idx last_start, Idx stop, size_t nmatch,
 		    regmatch_t pmatch[], int eflags)
 {
   reg_errcode_t err;
-  const re_dfa_t *dfa = (const re_dfa_t *) preg->buffer;
-  int left_lim, right_lim, incr;
-  int fl_longest_match, match_first, match_kind, match_last = -1;
-  int extra_nmatch;
-  int sb, ch;
+  const re_dfa_t *dfa = preg->buffer;
+  Idx left_lim, right_lim;
+  int incr;
+  bool fl_longest_match;
+  int match_kind;
+  Idx match_first;
+  Idx match_last = -1;
+  Idx extra_nmatch;
+  bool sb;
+  int ch;
 #if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
   re_match_context_t mctx = { .dfa = dfa };
 #else
   re_match_context_t mctx;
 #endif
-  char *fastmap = (preg->fastmap != NULL && preg->fastmap_accurate
-		   && range && !preg->can_be_null) ? preg->fastmap : NULL;
+  char *fastmap = ((preg->fastmap != NULL && preg->fastmap_accurate
+		    && start != last_start && !preg->can_be_null)
+		   ? preg->fastmap : NULL);
   RE_TRANSLATE_TYPE t = preg->translate;
 
 #if !(defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L))
@@ -612,7 +622,7 @@
 
 #ifdef DEBUG
   /* We assume front-end functions already check them.  */
-  assert (start + range >= 0 && start + range <= length);
+  assert (0 <= last_start && last_start <= length);
 #endif
 
   /* If initial states with non-begbuf contexts have no elements,
@@ -623,16 +633,17 @@
       && (dfa->init_state_nl->nodes.nelem == 0
 	  || !preg->newline_anchor))
     {
-      if (start != 0 && start + range != 0)
-	return REG_NOMATCH;
-      start = range = 0;
+      if (start != 0 && last_start != 0)
+        return REG_NOMATCH;
+      start = last_start = 0;
     }
 
   /* We must check the longest matching, if nmatch > 0.  */
   fl_longest_match = (nmatch != 0 || dfa->nbackref);
 
   err = re_string_allocate (&mctx.input, string, length, dfa->nodes_len + 1,
-			    preg->translate, preg->syntax & RE_ICASE, dfa);
+			    preg->translate, (preg->syntax & RE_ICASE) != 0,
+			    dfa);
   if (BE (err != REG_NOERROR, 0))
     goto free_return;
   mctx.input.stop = stop;
@@ -650,7 +661,8 @@
   if (nmatch > 1 || dfa->has_mb_node)
     {
       /* Avoid overflow.  */
-      if (BE (SIZE_MAX / sizeof (re_dfastate_t *) <= mctx.input.bufs_len, 0))
+      if (BE ((MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *))
+               <= mctx.input.bufs_len), 0))
 	{
 	  err = REG_ESPACE;
 	  goto free_return;
@@ -670,15 +682,15 @@
   mctx.input.tip_context = (eflags & REG_NOTBOL) ? CONTEXT_BEGBUF
 			   : CONTEXT_NEWLINE | CONTEXT_BEGBUF;
 
-  /* Check incrementally whether of not the input string match.  */
-  incr = (range < 0) ? -1 : 1;
-  left_lim = (range < 0) ? start + range : start;
-  right_lim = (range < 0) ? start : start + range;
+  /* Check incrementally whether the input string matches.  */
+  incr = (last_start < start) ? -1 : 1;
+  left_lim = (last_start < start) ? last_start : start;
+  right_lim = (last_start < start) ? start : last_start;
   sb = dfa->mb_cur_max == 1;
   match_kind =
     (fastmap
      ? ((sb || !(preg->syntax & RE_ICASE || t) ? 4 : 0)
-	| (range >= 0 ? 2 : 0)
+	| (start <= last_start ? 2 : 0)
 	| (t != NULL ? 1 : 0))
      : 8);
 
@@ -745,8 +757,8 @@
 	    {
 	      /* If MATCH_FIRST is out of the valid range, reconstruct the
 		 buffers.  */
-	      unsigned int offset = match_first - mctx.input.raw_mbs_idx;
-	      if (BE (offset >= (unsigned int) mctx.input.valid_raw_len, 0))
+	      __re_size_t offset = match_first - mctx.input.raw_mbs_idx;
+	      if (BE (offset >= (__re_size_t) mctx.input.valid_raw_len, 0))
 		{
 		  err = re_string_reconstruct (&mctx.input, match_first,
 					       eflags);
@@ -788,7 +800,7 @@
       /* We assume that the matching starts from 0.  */
       mctx.state_log_top = mctx.nbkref_ents = mctx.max_mb_elem_len = 0;
       match_last = check_matching (&mctx, fl_longest_match,
-				   range >= 0 ? &match_first : NULL);
+				   start <= last_start ? &match_first : NULL);
       if (match_last != -1)
 	{
 	  if (BE (match_last == -2, 0))
@@ -831,7 +843,7 @@
   /* Set pmatch[] if we need.  */
   if (nmatch > 0)
     {
-      int reg_idx;
+      Idx reg_idx;
 
       /* Initialize registers.  */
       for (reg_idx = 1; reg_idx < nmatch; ++reg_idx)
@@ -840,6 +852,9 @@
       /* Set the points where matching start/end.  */
       pmatch[0].rm_so = 0;
       pmatch[0].rm_eo = mctx.match_last;
+      /* FIXME: This function should fail if mctx.match_last exceeds
+	 the maximum possible regoff_t value.  We need a new error
+	 code REG_OVERFLOW.  */
 
       if (!preg->no_sub && nmatch > 1)
 	{
@@ -903,7 +918,7 @@
 prune_impossible_nodes (re_match_context_t *mctx)
 {
   const re_dfa_t *const dfa = mctx->dfa;
-  int halt_node, match_last;
+  Idx halt_node, match_last;
   reg_errcode_t ret;
   re_dfastate_t **sifted_states;
   re_dfastate_t **lim_states = NULL;
@@ -915,7 +930,7 @@
   halt_node = mctx->last_node;
 
   /* Avoid overflow.  */
-  if (BE (SIZE_MAX / sizeof (re_dfastate_t *) <= match_last, 0))
+  if (BE (MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *)) <= match_last, 0))
     return REG_ESPACE;
 
   sifted_states = re_malloc (re_dfastate_t *, match_last + 1);
@@ -995,9 +1010,9 @@
    since initial states may have constraints like "\<", "^", etc..  */
 
 static inline re_dfastate_t *
-__attribute ((always_inline))
+__attribute__ ((always_inline))
 acquire_init_state_context (reg_errcode_t *err, const re_match_context_t *mctx,
-			    int idx)
+			    Idx idx)
 {
   const re_dfa_t *const dfa = mctx->dfa;
   if (dfa->init_state->has_constraint)
@@ -1028,27 +1043,27 @@
 }
 
 /* Check whether the regular expression match input string INPUT or not,
-   and return the index where the matching end, return -1 if not match,
-   or return -2 in case of an error.
+   and return the index where the matching end.  Return -1 if
+   there is no match, and return -2 in case of an error.
    FL_LONGEST_MATCH means we want the POSIX longest matching.
    If P_MATCH_FIRST is not NULL, and the match fails, it is set to the
    next place where we may want to try matching.
-   Note that the matcher assume that the maching starts from the current
+   Note that the matcher assumes that the matching starts from the current
    index of the buffer.  */
 
-static int
+static Idx
 __attribute_warn_unused_result__
-check_matching (re_match_context_t *mctx, int fl_longest_match,
-		int *p_match_first)
+check_matching (re_match_context_t *mctx, bool fl_longest_match,
+		Idx *p_match_first)
 {
   const re_dfa_t *const dfa = mctx->dfa;
   reg_errcode_t err;
-  int match = 0;
-  int match_last = -1;
-  int cur_str_idx = re_string_cur_idx (&mctx->input);
+  Idx match = 0;
+  Idx match_last = -1;
+  Idx cur_str_idx = re_string_cur_idx (&mctx->input);
   re_dfastate_t *cur_state;
-  int at_init_state = p_match_first != NULL;
-  int next_start_idx = cur_str_idx;
+  bool at_init_state = p_match_first != NULL;
+  Idx next_start_idx = cur_str_idx;
 
   err = REG_NOERROR;
   cur_state = acquire_init_state_context (&err, mctx, cur_str_idx);
@@ -1067,7 +1082,7 @@
 	 later.  E.g. Processing back references.  */
       if (BE (dfa->nbackref, 0))
 	{
-	  at_init_state = 0;
+	  at_init_state = false;
 	  err = check_subexp_matching_top (mctx, &cur_state->nodes, 0);
 	  if (BE (err != REG_NOERROR, 0))
 	    return err;
@@ -1100,7 +1115,7 @@
   while (!re_string_eoi (&mctx->input))
     {
       re_dfastate_t *old_state = cur_state;
-      int next_char_idx = re_string_cur_idx (&mctx->input) + 1;
+      Idx next_char_idx = re_string_cur_idx (&mctx->input) + 1;
 
       if ((BE (next_char_idx >= mctx->input.bufs_len, 0)
 	   && mctx->input.bufs_len < mctx->input.len)
@@ -1138,7 +1153,7 @@
 	  if (old_state == cur_state)
 	    next_start_idx = next_char_idx;
 	  else
-	    at_init_state = 0;
+	    at_init_state = false;
 	}
 
       if (cur_state->halt)
@@ -1169,29 +1184,29 @@
 
 /* Check NODE match the current context.  */
 
-static int
-check_halt_node_context (const re_dfa_t *dfa, int node, unsigned int context)
+static bool
+check_halt_node_context (const re_dfa_t *dfa, Idx node, unsigned int context)
 {
   re_token_type_t type = dfa->nodes[node].type;
   unsigned int constraint = dfa->nodes[node].constraint;
   if (type != END_OF_RE)
-    return 0;
+    return false;
   if (!constraint)
-    return 1;
+    return true;
   if (NOT_SATISFY_NEXT_CONSTRAINT (constraint, context))
-    return 0;
-  return 1;
+    return false;
+  return true;
 }
 
 /* Check the halt state STATE match the current context.
    Return 0 if not match, if the node, STATE has, is a halt node and
    match the context, return the node.  */
 
-static int
+static Idx
 check_halt_state_context (const re_match_context_t *mctx,
-			  const re_dfastate_t *state, int idx)
+			  const re_dfastate_t *state, Idx idx)
 {
-  int i;
+  Idx i;
   unsigned int context;
 #ifdef DEBUG
   assert (state->halt);
@@ -1205,31 +1220,33 @@
 
 /* Compute the next node to which "NFA" transit from NODE("NFA" is a NFA
    corresponding to the DFA).
-   Return the destination node, and update EPS_VIA_NODES, return -1 in case
-   of errors.  */
+   Return the destination node, and update EPS_VIA_NODES;
+   return -1 in case of errors.  */
 
-static int
-proceed_next_node (const re_match_context_t *mctx, int nregs, regmatch_t *regs,
-		   int *pidx, int node, re_node_set *eps_via_nodes,
+static Idx
+proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs,
+		   Idx *pidx, Idx node, re_node_set *eps_via_nodes,
 		   struct re_fail_stack_t *fs)
 {
   const re_dfa_t *const dfa = mctx->dfa;
-  int i, err;
+  Idx i;
+  bool ok;
   if (IS_EPSILON_NODE (dfa->nodes[node].type))
     {
       re_node_set *cur_nodes = &mctx->state_log[*pidx]->nodes;
       re_node_set *edests = &dfa->edests[node];
-      int dest_node;
-      err = re_node_set_insert (eps_via_nodes, node);
-      if (BE (err < 0, 0))
+      Idx dest_node;
+      ok = re_node_set_insert (eps_via_nodes, node);
+      if (BE (! ok, 0))
 	return -2;
-      /* Pick up a valid destination, or return -1 if none is found.  */
+      /* Pick up a valid destination, or return -1 if none
+	 is found.  */
       for (dest_node = -1, i = 0; i < edests->nelem; ++i)
 	{
-	  int candidate = edests->elems[i];
+	  Idx candidate = edests->elems[i];
 	  if (!re_node_set_contains (cur_nodes, candidate))
 	    continue;
-	  if (dest_node == -1)
+          if (dest_node == -1)
 	    dest_node = candidate;
 
 	  else
@@ -1253,7 +1270,7 @@
     }
   else
     {
-      int naccepted = 0;
+      Idx naccepted = 0;
       re_token_type_t type = dfa->nodes[node].type;
 
 #ifdef RE_ENABLE_I18N
@@ -1263,7 +1280,7 @@
 #endif /* RE_ENABLE_I18N */
       if (type == OP_BACK_REF)
 	{
-	  int subexp_idx = dfa->nodes[node].opr.idx + 1;
+	  Idx subexp_idx = dfa->nodes[node].opr.idx + 1;
 	  naccepted = regs[subexp_idx].rm_eo - regs[subexp_idx].rm_so;
 	  if (fs != NULL)
 	    {
@@ -1280,9 +1297,9 @@
 
 	  if (naccepted == 0)
 	    {
-	      int dest_node;
-	      err = re_node_set_insert (eps_via_nodes, node);
-	      if (BE (err < 0, 0))
+	      Idx dest_node;
+	      ok = re_node_set_insert (eps_via_nodes, node);
+	      if (BE (! ok, 0))
 		return -2;
 	      dest_node = dfa->edests[node].elems[0];
 	      if (re_node_set_contains (&mctx->state_log[*pidx]->nodes,
@@ -1294,7 +1311,7 @@
       if (naccepted != 0
 	  || check_node_accept (mctx, dfa->nodes + node, *pidx))
 	{
-	  int dest_node = dfa->nexts[node];
+	  Idx dest_node = dfa->nexts[node];
 	  *pidx = (naccepted == 0) ? *pidx + 1 : *pidx + naccepted;
 	  if (fs && (*pidx > mctx->match_last || mctx->state_log[*pidx] == NULL
 		     || !re_node_set_contains (&mctx->state_log[*pidx]->nodes,
@@ -1309,16 +1326,16 @@
 
 static reg_errcode_t
 __attribute_warn_unused_result__
-push_fail_stack (struct re_fail_stack_t *fs, int str_idx, int dest_node,
-		 int nregs, regmatch_t *regs, re_node_set *eps_via_nodes)
+push_fail_stack (struct re_fail_stack_t *fs, Idx str_idx, Idx dest_node,
+		 Idx nregs, regmatch_t *regs, re_node_set *eps_via_nodes)
 {
   reg_errcode_t err;
-  int num = fs->num++;
+  Idx num = fs->num++;
   if (fs->num == fs->alloc)
     {
       struct re_fail_stack_ent_t *new_array;
-      new_array = realloc (fs->stack, (sizeof (struct re_fail_stack_ent_t)
-				       * fs->alloc * 2));
+      new_array = re_realloc (fs->stack, struct re_fail_stack_ent_t,
+                              fs->alloc * 2);
       if (new_array == NULL)
 	return REG_ESPACE;
       fs->alloc *= 2;
@@ -1334,11 +1351,11 @@
   return err;
 }
 
-static int
-pop_fail_stack (struct re_fail_stack_t *fs, int *pidx, int nregs,
+static Idx
+pop_fail_stack (struct re_fail_stack_t *fs, Idx *pidx, Idx nregs,
 		regmatch_t *regs, re_node_set *eps_via_nodes)
 {
-  int num = --fs->num;
+  Idx num = --fs->num;
   assert (num >= 0);
   *pidx = fs->stack[num].idx;
   memcpy (regs, fs->stack[num].regs, sizeof (regmatch_t) * nregs);
@@ -1356,15 +1373,15 @@
 static reg_errcode_t
 __attribute_warn_unused_result__
 set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch,
-	  regmatch_t *pmatch, int fl_backtrack)
+	  regmatch_t *pmatch, bool fl_backtrack)
 {
-  const re_dfa_t *dfa = (const re_dfa_t *) preg->buffer;
-  int idx, cur_node;
+  const re_dfa_t *dfa = preg->buffer;
+  Idx idx, cur_node;
   re_node_set eps_via_nodes;
   struct re_fail_stack_t *fs;
   struct re_fail_stack_t fs_body = { 0, 2, NULL };
   regmatch_t *prev_idx_match;
-  int prev_idx_match_malloced = 0;
+  bool prev_idx_match_malloced = false;
 
 #ifdef DEBUG
   assert (nmatch > 1);
@@ -1393,7 +1410,7 @@
 	  free_fail_stack_return (fs);
 	  return REG_ESPACE;
 	}
-      prev_idx_match_malloced = 1;
+      prev_idx_match_malloced = true;
     }
   memcpy (prev_idx_match, pmatch, sizeof (regmatch_t) * nmatch);
 
@@ -1403,7 +1420,7 @@
 
       if (idx == pmatch[0].rm_eo && cur_node == mctx->last_node)
 	{
-	  int reg_idx;
+	  Idx reg_idx;
 	  if (fs)
 	    {
 	      for (reg_idx = 0; reg_idx < nmatch; ++reg_idx)
@@ -1465,7 +1482,7 @@
 {
   if (fs)
     {
-      int fs_idx;
+      Idx fs_idx;
       for (fs_idx = 0; fs_idx < fs->num; ++fs_idx)
 	{
 	  re_node_set_free (&fs->stack[fs_idx].eps_via_nodes);
@@ -1478,12 +1495,12 @@
 
 static void
 update_regs (const re_dfa_t *dfa, regmatch_t *pmatch,
-	     regmatch_t *prev_idx_match, int cur_node, int cur_idx, int nmatch)
+	     regmatch_t *prev_idx_match, Idx cur_node, Idx cur_idx, Idx nmatch)
 {
   int type = dfa->nodes[cur_node].type;
   if (type == OP_OPEN_SUBEXP)
     {
-      int reg_num = dfa->nodes[cur_node].opr.idx + 1;
+      Idx reg_num = dfa->nodes[cur_node].opr.idx + 1;
 
       /* We are at the first node of this sub expression.  */
       if (reg_num < nmatch)
@@ -1494,7 +1511,7 @@
     }
   else if (type == OP_CLOSE_SUBEXP)
     {
-      int reg_num = dfa->nodes[cur_node].opr.idx + 1;
+      Idx reg_num = dfa->nodes[cur_node].opr.idx + 1;
       if (reg_num < nmatch)
 	{
 	  /* We are at the last node of this sub expression.  */
@@ -1528,21 +1545,21 @@
    and sift the nodes in each states according to the following rules.
    Updated state_log will be wrote to STATE_LOG.
 
-   Rules: We throw away the Node `a' in the STATE_LOG[STR_IDX] if...
+   Rules: We throw away the Node 'a' in the STATE_LOG[STR_IDX] if...
      1. When STR_IDX == MATCH_LAST(the last index in the state_log):
-	If `a' isn't the LAST_NODE and `a' can't epsilon transit to
-	the LAST_NODE, we throw away the node `a'.
-     2. When 0 <= STR_IDX < MATCH_LAST and `a' accepts
-	string `s' and transit to `b':
+	If 'a' isn't the LAST_NODE and 'a' can't epsilon transit to
+	the LAST_NODE, we throw away the node 'a'.
+     2. When 0 <= STR_IDX < MATCH_LAST and 'a' accepts
+	string 's' and transit to 'b':
 	i. If 'b' isn't in the STATE_LOG[STR_IDX+strlen('s')], we throw
-	   away the node `a'.
+	   away the node 'a'.
 	ii. If 'b' is in the STATE_LOG[STR_IDX+strlen('s')] but 'b' is
-	    thrown away, we throw away the node `a'.
+	    thrown away, we throw away the node 'a'.
      3. When 0 <= STR_IDX < MATCH_LAST and 'a' epsilon transit to 'b':
 	i. If 'b' isn't in the STATE_LOG[STR_IDX], we throw away the
-	   node `a'.
+	   node 'a'.
 	ii. If 'b' is in the STATE_LOG[STR_IDX] but 'b' is thrown away,
-	    we throw away the node `a'.  */
+	    we throw away the node 'a'.  */
 
 #define STATE_NODE_CONTAINS(state,node) \
   ((state) != NULL && re_node_set_contains (&(state)->nodes, node))
@@ -1552,7 +1569,7 @@
 {
   reg_errcode_t err;
   int null_cnt = 0;
-  int str_idx = sctx->last_str_idx;
+  Idx str_idx = sctx->last_str_idx;
   re_node_set cur_dest;
 
 #ifdef DEBUG
@@ -1607,31 +1624,31 @@
 static reg_errcode_t
 __attribute_warn_unused_result__
 build_sifted_states (const re_match_context_t *mctx, re_sift_context_t *sctx,
-		     int str_idx, re_node_set *cur_dest)
+		     Idx str_idx, re_node_set *cur_dest)
 {
   const re_dfa_t *const dfa = mctx->dfa;
   const re_node_set *cur_src = &mctx->state_log[str_idx]->non_eps_nodes;
-  int i;
+  Idx i;
 
   /* Then build the next sifted state.
-     We build the next sifted state on `cur_dest', and update
-     `sifted_states[str_idx]' with `cur_dest'.
+     We build the next sifted state on 'cur_dest', and update
+     'sifted_states[str_idx]' with 'cur_dest'.
      Note:
-     `cur_dest' is the sifted state from `state_log[str_idx + 1]'.
-     `cur_src' points the node_set of the old `state_log[str_idx]'
+     'cur_dest' is the sifted state from 'state_log[str_idx + 1]'.
+     'cur_src' points the node_set of the old 'state_log[str_idx]'
      (with the epsilon nodes pre-filtered out).  */
   for (i = 0; i < cur_src->nelem; i++)
     {
-      int prev_node = cur_src->elems[i];
+      Idx prev_node = cur_src->elems[i];
       int naccepted = 0;
-      int ret;
+      bool ok;
 
 #ifdef DEBUG
       re_token_type_t type = dfa->nodes[prev_node].type;
       assert (!IS_EPSILON_NODE (type));
 #endif
 #ifdef RE_ENABLE_I18N
-      /* If the node may accept `multi byte'.  */
+      /* If the node may accept "multi byte".  */
       if (dfa->nodes[prev_node].accept_mb)
 	naccepted = sift_states_iter_mb (mctx, sctx, prev_node,
 					 str_idx, sctx->last_str_idx);
@@ -1650,14 +1667,14 @@
 
       if (sctx->limits.nelem)
 	{
-	  int to_idx = str_idx + naccepted;
+	  Idx to_idx = str_idx + naccepted;
 	  if (check_dst_limits (mctx, &sctx->limits,
 				dfa->nexts[prev_node], to_idx,
 				prev_node, str_idx))
 	    continue;
 	}
-      ret = re_node_set_insert (cur_dest, prev_node);
-      if (BE (ret == -1, 0))
+      ok = re_node_set_insert (cur_dest, prev_node);
+      if (BE (! ok, 0))
 	return REG_ESPACE;
     }
 
@@ -1667,9 +1684,9 @@
 /* Helper functions.  */
 
 static reg_errcode_t
-clean_state_log_if_needed (re_match_context_t *mctx, int next_state_log_idx)
+clean_state_log_if_needed (re_match_context_t *mctx, Idx next_state_log_idx)
 {
-  int top = mctx->state_log_top;
+  Idx top = mctx->state_log_top;
 
   if ((next_state_log_idx >= mctx->input.bufs_len
        && mctx->input.bufs_len < mctx->input.len)
@@ -1693,9 +1710,9 @@
 
 static reg_errcode_t
 merge_state_array (const re_dfa_t *dfa, re_dfastate_t **dst,
-		   re_dfastate_t **src, int num)
+		   re_dfastate_t **src, Idx num)
 {
-  int st_idx;
+  Idx st_idx;
   reg_errcode_t err;
   for (st_idx = 0; st_idx < num; ++st_idx)
     {
@@ -1719,7 +1736,7 @@
 
 static reg_errcode_t
 update_cur_sifted_state (const re_match_context_t *mctx,
-			 re_sift_context_t *sctx, int str_idx,
+			 re_sift_context_t *sctx, Idx str_idx,
 			 re_node_set *dest_nodes)
 {
   const re_dfa_t *const dfa = mctx->dfa;
@@ -1770,7 +1787,7 @@
 		       const re_node_set *candidates)
 {
   reg_errcode_t err = REG_NOERROR;
-  int i;
+  Idx i;
 
   re_dfastate_t *state = re_acquire_state (&err, dfa, dest_nodes);
   if (BE (err != REG_NOERROR, 0))
@@ -1794,23 +1811,23 @@
 }
 
 static reg_errcode_t
-sub_epsilon_src_nodes (const re_dfa_t *dfa, int node, re_node_set *dest_nodes,
+sub_epsilon_src_nodes (const re_dfa_t *dfa, Idx node, re_node_set *dest_nodes,
 		       const re_node_set *candidates)
 {
-    int ecl_idx;
+    Idx ecl_idx;
     reg_errcode_t err;
     re_node_set *inv_eclosure = dfa->inveclosures + node;
     re_node_set except_nodes;
     re_node_set_init_empty (&except_nodes);
     for (ecl_idx = 0; ecl_idx < inv_eclosure->nelem; ++ecl_idx)
       {
-	int cur_node = inv_eclosure->elems[ecl_idx];
+	Idx cur_node = inv_eclosure->elems[ecl_idx];
 	if (cur_node == node)
 	  continue;
 	if (IS_EPSILON_NODE (dfa->nodes[cur_node].type))
 	  {
-	    int edst1 = dfa->edests[cur_node].elems[0];
-	    int edst2 = ((dfa->edests[cur_node].nelem > 1)
+	    Idx edst1 = dfa->edests[cur_node].elems[0];
+	    Idx edst2 = ((dfa->edests[cur_node].nelem > 1)
 			 ? dfa->edests[cur_node].elems[1] : -1);
 	    if ((!re_node_set_contains (inv_eclosure, edst1)
 		 && re_node_set_contains (dest_nodes, edst1))
@@ -1830,10 +1847,10 @@
       }
     for (ecl_idx = 0; ecl_idx < inv_eclosure->nelem; ++ecl_idx)
       {
-	int cur_node = inv_eclosure->elems[ecl_idx];
+	Idx cur_node = inv_eclosure->elems[ecl_idx];
 	if (!re_node_set_contains (&except_nodes, cur_node))
 	  {
-	    int idx = re_node_set_contains (dest_nodes, cur_node) - 1;
+	    Idx idx = re_node_set_contains (dest_nodes, cur_node) - 1;
 	    re_node_set_remove_at (dest_nodes, idx);
 	  }
       }
@@ -1841,18 +1858,18 @@
     return REG_NOERROR;
 }
 
-static int
-check_dst_limits (const re_match_context_t *mctx, re_node_set *limits,
-		  int dst_node, int dst_idx, int src_node, int src_idx)
+static bool
+check_dst_limits (const re_match_context_t *mctx, const re_node_set *limits,
+		  Idx dst_node, Idx dst_idx, Idx src_node, Idx src_idx)
 {
   const re_dfa_t *const dfa = mctx->dfa;
-  int lim_idx, src_pos, dst_pos;
+  Idx lim_idx, src_pos, dst_pos;
 
-  int dst_bkref_idx = search_cur_bkref_entry (mctx, dst_idx);
-  int src_bkref_idx = search_cur_bkref_entry (mctx, src_idx);
+  Idx dst_bkref_idx = search_cur_bkref_entry (mctx, dst_idx);
+  Idx src_bkref_idx = search_cur_bkref_entry (mctx, src_idx);
   for (lim_idx = 0; lim_idx < limits->nelem; ++lim_idx)
     {
-      int subexp_idx;
+      Idx subexp_idx;
       struct re_backref_cache_entry *ent;
       ent = mctx->bkref_ents + limits->elems[lim_idx];
       subexp_idx = dfa->nodes[ent->node].opr.idx;
@@ -1871,24 +1888,24 @@
       if (src_pos == dst_pos)
 	continue; /* This is unrelated limitation.  */
       else
-	return 1;
+	return true;
     }
-  return 0;
+  return false;
 }
 
 static int
 check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries,
-			     int subexp_idx, int from_node, int bkref_idx)
+			     Idx subexp_idx, Idx from_node, Idx bkref_idx)
 {
   const re_dfa_t *const dfa = mctx->dfa;
   const re_node_set *eclosures = dfa->eclosures + from_node;
-  int node_idx;
+  Idx node_idx;
 
   /* Else, we are on the boundary: examine the nodes on the epsilon
      closure.  */
   for (node_idx = 0; node_idx < eclosures->nelem; ++node_idx)
     {
-      int node = eclosures->elems[node_idx];
+      Idx node = eclosures->elems[node_idx];
       switch (dfa->nodes[node].type)
 	{
 	case OP_BACK_REF:
@@ -1897,7 +1914,8 @@
 	      struct re_backref_cache_entry *ent = mctx->bkref_ents + bkref_idx;
 	      do
 		{
-		  int dst, cpos;
+		  Idx dst;
+		  int cpos;
 
 		  if (ent->node != node)
 		    continue;
@@ -1957,9 +1975,9 @@
 }
 
 static int
-check_dst_limits_calc_pos (const re_match_context_t *mctx, int limit,
-			   int subexp_idx, int from_node, int str_idx,
-			   int bkref_idx)
+check_dst_limits_calc_pos (const re_match_context_t *mctx, Idx limit,
+			   Idx subexp_idx, Idx from_node, Idx str_idx,
+			   Idx bkref_idx)
 {
   struct re_backref_cache_entry *lim = mctx->bkref_ents + limit;
   int boundaries;
@@ -1988,14 +2006,14 @@
 static reg_errcode_t
 check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes,
 		     const re_node_set *candidates, re_node_set *limits,
-		     struct re_backref_cache_entry *bkref_ents, int str_idx)
+		     struct re_backref_cache_entry *bkref_ents, Idx str_idx)
 {
   reg_errcode_t err;
-  int node_idx, lim_idx;
+  Idx node_idx, lim_idx;
 
   for (lim_idx = 0; lim_idx < limits->nelem; ++lim_idx)
     {
-      int subexp_idx;
+      Idx subexp_idx;
       struct re_backref_cache_entry *ent;
       ent = bkref_ents + limits->elems[lim_idx];
 
@@ -2005,11 +2023,11 @@
       subexp_idx = dfa->nodes[ent->node].opr.idx;
       if (ent->subexp_to == str_idx)
 	{
-	  int ops_node = -1;
-	  int cls_node = -1;
+	  Idx ops_node = -1;
+	  Idx cls_node = -1;
 	  for (node_idx = 0; node_idx < dest_nodes->nelem; ++node_idx)
 	    {
-	      int node = dest_nodes->elems[node_idx];
+	      Idx node = dest_nodes->elems[node_idx];
 	      re_token_type_t type = dfa->nodes[node].type;
 	      if (type == OP_OPEN_SUBEXP
 		  && subexp_idx == dfa->nodes[node].opr.idx)
@@ -2033,7 +2051,7 @@
 	  if (cls_node >= 0)
 	    for (node_idx = 0; node_idx < dest_nodes->nelem; ++node_idx)
 	      {
-		int node = dest_nodes->elems[node_idx];
+		Idx node = dest_nodes->elems[node_idx];
 		if (!re_node_set_contains (dfa->inveclosures + node,
 					   cls_node)
 		    && !re_node_set_contains (dfa->eclosures + node,
@@ -2053,7 +2071,7 @@
 	{
 	  for (node_idx = 0; node_idx < dest_nodes->nelem; ++node_idx)
 	    {
-	      int node = dest_nodes->elems[node_idx];
+	      Idx node = dest_nodes->elems[node_idx];
 	      re_token_type_t type = dfa->nodes[node].type;
 	      if (type == OP_CLOSE_SUBEXP || type == OP_OPEN_SUBEXP)
 		{
@@ -2075,13 +2093,13 @@
 static reg_errcode_t
 __attribute_warn_unused_result__
 sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx,
-		   int str_idx, const re_node_set *candidates)
+		   Idx str_idx, const re_node_set *candidates)
 {
   const re_dfa_t *const dfa = mctx->dfa;
   reg_errcode_t err;
-  int node_idx, node;
+  Idx node_idx, node;
   re_sift_context_t local_sctx;
-  int first_idx = search_cur_bkref_entry (mctx, str_idx);
+  Idx first_idx = search_cur_bkref_entry (mctx, str_idx);
 
   if (first_idx == -1)
     return REG_NOERROR;
@@ -2090,7 +2108,7 @@
 
   for (node_idx = 0; node_idx < candidates->nelem; ++node_idx)
     {
-      int enabled_idx;
+      Idx enabled_idx;
       re_token_type_t type;
       struct re_backref_cache_entry *entry;
       node = candidates->elems[node_idx];
@@ -2105,10 +2123,10 @@
       enabled_idx = first_idx;
       do
 	{
-	  int subexp_len;
-	  int to_idx;
-	  int dst_node;
-	  int ret;
+	  Idx subexp_len;
+	  Idx to_idx;
+	  Idx dst_node;
+	  bool ok;
 	  re_dfastate_t *cur_state;
 
 	  if (entry->node != node)
@@ -2134,8 +2152,8 @@
 	    }
 	  local_sctx.last_node = node;
 	  local_sctx.last_str_idx = str_idx;
-	  ret = re_node_set_insert (&local_sctx.limits, enabled_idx);
-	  if (BE (ret < 0, 0))
+	  ok = re_node_set_insert (&local_sctx.limits, enabled_idx);
+	  if (BE (! ok, 0))
 	    {
 	      err = REG_ESPACE;
 	      goto free_return;
@@ -2174,21 +2192,21 @@
 #ifdef RE_ENABLE_I18N
 static int
 sift_states_iter_mb (const re_match_context_t *mctx, re_sift_context_t *sctx,
-		     int node_idx, int str_idx, int max_str_idx)
+		     Idx node_idx, Idx str_idx, Idx max_str_idx)
 {
   const re_dfa_t *const dfa = mctx->dfa;
   int naccepted;
-  /* Check the node can accept `multi byte'.  */
+  /* Check the node can accept "multi byte".  */
   naccepted = check_node_accept_bytes (dfa, node_idx, &mctx->input, str_idx);
   if (naccepted > 0 && str_idx + naccepted <= max_str_idx &&
       !STATE_NODE_CONTAINS (sctx->sifted_states[str_idx + naccepted],
 			    dfa->nexts[node_idx]))
-    /* The node can't accept the `multi byte', or the
+    /* The node can't accept the "multi byte", or the
        destination was already thrown away, then the node
-       could't accept the current input `multi byte'.   */
+       could't accept the current input "multi byte".   */
     naccepted = 0;
   /* Otherwise, it is sure that the node could accept
-     `naccepted' bytes input.  */
+     'naccepted' bytes input.  */
   return naccepted;
 }
 #endif /* RE_ENABLE_I18N */
@@ -2259,12 +2277,12 @@
 }
 
 /* Update the state_log if we need */
-re_dfastate_t *
+static re_dfastate_t *
 merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx,
 		      re_dfastate_t *next_state)
 {
   const re_dfa_t *const dfa = mctx->dfa;
-  int cur_idx = re_string_cur_idx (&mctx->input);
+  Idx cur_idx = re_string_cur_idx (&mctx->input);
 
   if (cur_idx > mctx->state_log_top)
     {
@@ -2337,14 +2355,14 @@
 /* Skip bytes in the input that correspond to part of a
    multi-byte match, then look in the log for a state
    from which to restart matching.  */
-re_dfastate_t *
+static re_dfastate_t *
 find_recover_state (reg_errcode_t *err, re_match_context_t *mctx)
 {
   re_dfastate_t *cur_state;
   do
     {
-      int max = mctx->state_log_top;
-      int cur_str_idx = re_string_cur_idx (&mctx->input);
+      Idx max = mctx->state_log_top;
+      Idx cur_str_idx = re_string_cur_idx (&mctx->input);
 
       do
 	{
@@ -2369,10 +2387,10 @@
 
 static reg_errcode_t
 check_subexp_matching_top (re_match_context_t *mctx, re_node_set *cur_nodes,
-			   int str_idx)
+			   Idx str_idx)
 {
   const re_dfa_t *const dfa = mctx->dfa;
-  int node_idx;
+  Idx node_idx;
   reg_errcode_t err;
 
   /* TODO: This isn't efficient.
@@ -2382,7 +2400,7 @@
 	   E.g. RE: (a){2}  */
   for (node_idx = 0; node_idx < cur_nodes->nelem; ++node_idx)
     {
-      int node = cur_nodes->elems[node_idx];
+      Idx node = cur_nodes->elems[node_idx];
       if (dfa->nodes[node].type == OP_OPEN_SUBEXP
 	  && dfa->nodes[node].opr.idx < BITSET_WORD_BITS
 	  && (dfa->used_bkref_map
@@ -2407,7 +2425,7 @@
   const re_dfa_t *const dfa = mctx->dfa;
   re_node_set next_nodes;
   re_dfastate_t *next_state;
-  int node_cnt, cur_str_idx = re_string_cur_idx (&mctx->input);
+  Idx node_cnt, cur_str_idx = re_string_cur_idx (&mctx->input);
   unsigned int context;
 
   *err = re_node_set_alloc (&next_nodes, state->nodes.nelem + 1);
@@ -2415,7 +2433,7 @@
     return NULL;
   for (node_cnt = 0; node_cnt < state->nodes.nelem; ++node_cnt)
     {
-      int cur_node = state->nodes.elems[node_cnt];
+      Idx cur_node = state->nodes.elems[node_cnt];
       if (check_node_accept (mctx, dfa->nodes + cur_node, cur_str_idx))
 	{
 	  *err = re_node_set_merge (&next_nodes,
@@ -2444,13 +2462,14 @@
 {
   const re_dfa_t *const dfa = mctx->dfa;
   reg_errcode_t err;
-  int i;
+  Idx i;
 
   for (i = 0; i < pstate->nodes.nelem; ++i)
     {
       re_node_set dest_nodes, *new_nodes;
-      int cur_node_idx = pstate->nodes.elems[i];
-      int naccepted, dest_idx;
+      Idx cur_node_idx = pstate->nodes.elems[i];
+      int naccepted;
+      Idx dest_idx;
       unsigned int context;
       re_dfastate_t *dest_state;
 
@@ -2473,7 +2492,7 @@
       if (naccepted == 0)
 	continue;
 
-      /* The node can accepts `naccepted' bytes.  */
+      /* The node can accepts 'naccepted' bytes.  */
       dest_idx = re_string_cur_idx (&mctx->input) + naccepted;
       mctx->max_mb_elem_len = ((mctx->max_mb_elem_len < naccepted) ? naccepted
 			       : mctx->max_mb_elem_len);
@@ -2513,18 +2532,18 @@
 {
   const re_dfa_t *const dfa = mctx->dfa;
   reg_errcode_t err;
-  int i;
-  int cur_str_idx = re_string_cur_idx (&mctx->input);
+  Idx i;
+  Idx cur_str_idx = re_string_cur_idx (&mctx->input);
 
   for (i = 0; i < nodes->nelem; ++i)
     {
-      int dest_str_idx, prev_nelem, bkc_idx;
-      int node_idx = nodes->elems[i];
+      Idx dest_str_idx, prev_nelem, bkc_idx;
+      Idx node_idx = nodes->elems[i];
       unsigned int context;
       const re_token_t *node = dfa->nodes + node_idx;
       re_node_set *new_dest_nodes;
 
-      /* Check whether `node' is a backreference or not.  */
+      /* Check whether 'node' is a backreference or not.  */
       if (node->type != OP_BACK_REF)
 	continue;
 
@@ -2536,21 +2555,21 @@
 	    continue;
 	}
 
-      /* `node' is a backreference.
+      /* 'node' is a backreference.
 	 Check the substring which the substring matched.  */
       bkc_idx = mctx->nbkref_ents;
       err = get_subexp (mctx, node_idx, cur_str_idx);
       if (BE (err != REG_NOERROR, 0))
 	goto free_return;
 
-      /* And add the epsilon closures (which is `new_dest_nodes') of
+      /* And add the epsilon closures (which is 'new_dest_nodes') of
 	 the backreference to appropriate state_log.  */
 #ifdef DEBUG
       assert (dfa->nexts[node_idx] != -1);
 #endif
       for (; bkc_idx < mctx->nbkref_ents; ++bkc_idx)
 	{
-	  int subexp_len;
+	  Idx subexp_len;
 	  re_dfastate_t *dest_state;
 	  struct re_backref_cache_entry *bkref_ent;
 	  bkref_ent = mctx->bkref_ents + bkc_idx;
@@ -2567,7 +2586,7 @@
 	  dest_state = mctx->state_log[dest_str_idx];
 	  prev_nelem = ((mctx->state_log[cur_str_idx] == NULL) ? 0
 			: mctx->state_log[cur_str_idx]->nodes.nelem);
-	  /* Add `new_dest_node' to state_log.  */
+	  /* Add 'new_dest_node' to state_log.  */
 	  if (dest_state == NULL)
 	    {
 	      mctx->state_log[dest_str_idx]
@@ -2623,13 +2642,13 @@
 
 static reg_errcode_t
 __attribute_warn_unused_result__
-get_subexp (re_match_context_t *mctx, int bkref_node, int bkref_str_idx)
+get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx)
 {
   const re_dfa_t *const dfa = mctx->dfa;
-  int subexp_num, sub_top_idx;
+  Idx subexp_num, sub_top_idx;
   const char *buf = (const char *) re_string_get_buffer (&mctx->input);
   /* Return if we have already checked BKREF_NODE at BKREF_STR_IDX.  */
-  int cache_idx = search_cur_bkref_entry (mctx, bkref_str_idx);
+  Idx cache_idx = search_cur_bkref_entry (mctx, bkref_str_idx);
   if (cache_idx != -1)
     {
       const struct re_backref_cache_entry *entry
@@ -2648,7 +2667,7 @@
       reg_errcode_t err;
       re_sub_match_top_t *sub_top = mctx->sub_tops[sub_top_idx];
       re_sub_match_last_t *sub_last;
-      int sub_last_idx, sl_str, bkref_str_off;
+      Idx sub_last_idx, sl_str, bkref_str_off;
 
       if (dfa->nodes[sub_top->node].opr.idx != subexp_num)
 	continue; /* It isn't related.  */
@@ -2659,7 +2678,7 @@
 	 evaluated.  */
       for (sub_last_idx = 0; sub_last_idx < sub_top->nlasts; ++sub_last_idx)
 	{
-	  int sl_str_diff;
+	  regoff_t sl_str_diff;
 	  sub_last = sub_top->lasts[sub_last_idx];
 	  sl_str_diff = sub_last->str_idx - sl_str;
 	  /* The matched string by the sub expression match with the substring
@@ -2705,7 +2724,8 @@
       /* Then, search for the other last nodes of the sub expression.  */
       for (; sl_str <= bkref_str_idx; ++sl_str)
 	{
-	  int cls_node, sl_str_off;
+	  Idx cls_node;
+	  regoff_t sl_str_off;
 	  const re_node_set *nodes;
 	  sl_str_off = sl_str - sub_top->str_idx;
 	  /* The matched string by the sub expression match with the substring
@@ -2772,10 +2792,10 @@
 
 static reg_errcode_t
 get_subexp_sub (re_match_context_t *mctx, const re_sub_match_top_t *sub_top,
-		re_sub_match_last_t *sub_last, int bkref_node, int bkref_str)
+		re_sub_match_last_t *sub_last, Idx bkref_node, Idx bkref_str)
 {
   reg_errcode_t err;
-  int to_idx;
+  Idx to_idx;
   /* Can the subexpression arrive the back reference?  */
   err = check_arrival (mctx, &sub_last->path, sub_last->node,
 		       sub_last->str_idx, bkref_node, bkref_str,
@@ -2798,14 +2818,14 @@
 	 nodes.
 	 E.g. RE: (a){2}  */
 
-static int
+static Idx
 find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes,
-		  int subexp_idx, int type)
+		  Idx subexp_idx, int type)
 {
-  int cls_idx;
+  Idx cls_idx;
   for (cls_idx = 0; cls_idx < nodes->nelem; ++cls_idx)
     {
-      int cls_node = nodes->elems[cls_idx];
+      Idx cls_node = nodes->elems[cls_idx];
       const re_token_t *node = dfa->nodes + cls_node;
       if (node->type == type
 	  && node->opr.idx == subexp_idx)
@@ -2821,12 +2841,12 @@
 
 static reg_errcode_t
 __attribute_warn_unused_result__
-check_arrival (re_match_context_t *mctx, state_array_t *path, int top_node,
-	       int top_str, int last_node, int last_str, int type)
+check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node,
+	       Idx top_str, Idx last_node, Idx last_str, int type)
 {
   const re_dfa_t *const dfa = mctx->dfa;
   reg_errcode_t err = REG_NOERROR;
-  int subexp_num, backup_cur_idx, str_idx, null_cnt;
+  Idx subexp_num, backup_cur_idx, str_idx, null_cnt;
   re_dfastate_t *cur_state = NULL;
   re_node_set *cur_nodes, next_nodes;
   re_dfastate_t **backup_state_log;
@@ -2837,20 +2857,24 @@
   if (BE (path->alloc < last_str + mctx->max_mb_elem_len + 1, 0))
     {
       re_dfastate_t **new_array;
-      int old_alloc = path->alloc;
-      path->alloc += last_str + mctx->max_mb_elem_len + 1;
-      new_array = re_realloc (path->array, re_dfastate_t *, path->alloc);
+      Idx old_alloc = path->alloc;
+      Idx incr_alloc = last_str + mctx->max_mb_elem_len + 1;
+      Idx new_alloc;
+      if (BE (IDX_MAX - old_alloc < incr_alloc, 0))
+	return REG_ESPACE;
+      new_alloc = old_alloc + incr_alloc;
+      if (BE (SIZE_MAX / sizeof (re_dfastate_t *) < new_alloc, 0))
+	return REG_ESPACE;
+      new_array = re_realloc (path->array, re_dfastate_t *, new_alloc);
       if (BE (new_array == NULL, 0))
-	{
-	  path->alloc = old_alloc;
-	  return REG_ESPACE;
-	}
+	return REG_ESPACE;
       path->array = new_array;
+      path->alloc = new_alloc;
       memset (new_array + old_alloc, '\0',
 	      sizeof (re_dfastate_t *) * (path->alloc - old_alloc));
     }
 
-  str_idx = path->next_idx ?: top_str;
+  str_idx = path->next_idx ? path->next_idx : top_str;
 
   /* Temporary modify MCTX.  */
   backup_state_log = mctx->state_log;
@@ -2982,12 +3006,12 @@
 
 static reg_errcode_t
 __attribute_warn_unused_result__
-check_arrival_add_next_nodes (re_match_context_t *mctx, int str_idx,
+check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx,
 			      re_node_set *cur_nodes, re_node_set *next_nodes)
 {
   const re_dfa_t *const dfa = mctx->dfa;
-  int result;
-  int cur_idx;
+  bool ok;
+  Idx cur_idx;
 #ifdef RE_ENABLE_I18N
   reg_errcode_t err = REG_NOERROR;
 #endif
@@ -2996,13 +3020,13 @@
   for (cur_idx = 0; cur_idx < cur_nodes->nelem; ++cur_idx)
     {
       int naccepted = 0;
-      int cur_node = cur_nodes->elems[cur_idx];
+      Idx cur_node = cur_nodes->elems[cur_idx];
 #ifdef DEBUG
       re_token_type_t type = dfa->nodes[cur_node].type;
       assert (!IS_EPSILON_NODE (type));
 #endif
 #ifdef RE_ENABLE_I18N
-      /* If the node may accept `multi byte'.  */
+      /* If the node may accept "multi byte".  */
       if (dfa->nodes[cur_node].accept_mb)
 	{
 	  naccepted = check_node_accept_bytes (dfa, cur_node, &mctx->input,
@@ -3010,8 +3034,8 @@
 	  if (naccepted > 1)
 	    {
 	      re_dfastate_t *dest_state;
-	      int next_node = dfa->nexts[cur_node];
-	      int next_idx = str_idx + naccepted;
+	      Idx next_node = dfa->nexts[cur_node];
+	      Idx next_idx = str_idx + naccepted;
 	      dest_state = mctx->state_log[next_idx];
 	      re_node_set_empty (&union_set);
 	      if (dest_state)
@@ -3023,8 +3047,8 @@
 		      return err;
 		    }
 		}
-	      result = re_node_set_insert (&union_set, next_node);
-	      if (BE (result < 0, 0))
+	      ok = re_node_set_insert (&union_set, next_node);
+	      if (BE (! ok, 0))
 		{
 		  re_node_set_free (&union_set);
 		  return REG_ESPACE;
@@ -3043,8 +3067,8 @@
       if (naccepted
 	  || check_node_accept (mctx, dfa->nodes + cur_node, str_idx))
 	{
-	  result = re_node_set_insert (next_nodes, dfa->nexts[cur_node]);
-	  if (BE (result < 0, 0))
+	  ok = re_node_set_insert (next_nodes, dfa->nexts[cur_node]);
+	  if (BE (! ok, 0))
 	    {
 	      re_node_set_free (&union_set);
 	      return REG_ESPACE;
@@ -3063,10 +3087,10 @@
 
 static reg_errcode_t
 check_arrival_expand_ecl (const re_dfa_t *dfa, re_node_set *cur_nodes,
-			  int ex_subexp, int type)
+			  Idx ex_subexp, int type)
 {
   reg_errcode_t err;
-  int idx, outside_node;
+  Idx idx, outside_node;
   re_node_set new_nodes;
 #ifdef DEBUG
   assert (cur_nodes->nelem);
@@ -3079,7 +3103,7 @@
 
   for (idx = 0; idx < cur_nodes->nelem; ++idx)
     {
-      int cur_node = cur_nodes->elems[idx];
+      Idx cur_node = cur_nodes->elems[idx];
       const re_node_set *eclosure = dfa->eclosures + cur_node;
       outside_node = find_subexp_node (dfa, eclosure, ex_subexp, type);
       if (outside_node == -1)
@@ -3116,31 +3140,32 @@
 static reg_errcode_t
 __attribute_warn_unused_result__
 check_arrival_expand_ecl_sub (const re_dfa_t *dfa, re_node_set *dst_nodes,
-			      int target, int ex_subexp, int type)
+			      Idx target, Idx ex_subexp, int type)
 {
-  int cur_node;
+  Idx cur_node;
   for (cur_node = target; !re_node_set_contains (dst_nodes, cur_node);)
     {
-      int err;
+      bool ok;
 
       if (dfa->nodes[cur_node].type == type
 	  && dfa->nodes[cur_node].opr.idx == ex_subexp)
 	{
 	  if (type == OP_CLOSE_SUBEXP)
 	    {
-	      err = re_node_set_insert (dst_nodes, cur_node);
-	      if (BE (err == -1, 0))
+	      ok = re_node_set_insert (dst_nodes, cur_node);
+	      if (BE (! ok, 0))
 		return REG_ESPACE;
 	    }
 	  break;
 	}
-      err = re_node_set_insert (dst_nodes, cur_node);
-      if (BE (err == -1, 0))
+      ok = re_node_set_insert (dst_nodes, cur_node);
+      if (BE (! ok, 0))
 	return REG_ESPACE;
       if (dfa->edests[cur_node].nelem == 0)
 	break;
       if (dfa->edests[cur_node].nelem == 2)
 	{
+	  reg_errcode_t err;
 	  err = check_arrival_expand_ecl_sub (dfa, dst_nodes,
 					      dfa->edests[cur_node].elems[1],
 					      ex_subexp, type);
@@ -3160,11 +3185,11 @@
 static reg_errcode_t
 __attribute_warn_unused_result__
 expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes,
-		    int cur_str, int subexp_num, int type)
+		    Idx cur_str, Idx subexp_num, int type)
 {
   const re_dfa_t *const dfa = mctx->dfa;
   reg_errcode_t err;
-  int cache_idx_start = search_cur_bkref_entry (mctx, cur_str);
+  Idx cache_idx_start = search_cur_bkref_entry (mctx, cur_str);
   struct re_backref_cache_entry *ent;
 
   if (cache_idx_start == -1)
@@ -3174,7 +3199,7 @@
   ent = mctx->bkref_ents + cache_idx_start;
   do
     {
-      int to_idx, next_node;
+      Idx to_idx, next_node;
 
       /* Is this entry ENT is appropriate?  */
       if (!re_node_set_contains (cur_nodes, ent->node))
@@ -3212,14 +3237,14 @@
 	  next_node = dfa->nexts[ent->node];
 	  if (mctx->state_log[to_idx])
 	    {
-	      int ret;
+	      bool ok;
 	      if (re_node_set_contains (&mctx->state_log[to_idx]->nodes,
 					next_node))
 		continue;
 	      err = re_node_set_init_copy (&union_set,
 					   &mctx->state_log[to_idx]->nodes);
-	      ret = re_node_set_insert (&union_set, next_node);
-	      if (BE (err != REG_NOERROR || ret < 0, 0))
+	      ok = re_node_set_insert (&union_set, next_node);
+	      if (BE (err != REG_NOERROR || ! ok, 0))
 		{
 		  re_node_set_free (&union_set);
 		  err = err != REG_NOERROR ? err : REG_ESPACE;
@@ -3244,17 +3269,19 @@
 }
 
 /* Build transition table for the state.
-   Return 1 if succeeded, otherwise return NULL.  */
+   Return true if successful.  */
 
-static int
+static bool
 build_trtable (const re_dfa_t *dfa, re_dfastate_t *state)
 {
   reg_errcode_t err;
-  int i, j, ch, need_word_trtable = 0;
+  Idx i, j;
+  int ch;
+  bool need_word_trtable = false;
   bitset_word_t elem, mask;
   bool dests_node_malloced = false;
   bool dest_states_malloced = false;
-  int ndests; /* Number of the destination states from `state'.  */
+  Idx ndests; /* Number of the destination states from 'state'.  */
   re_dfastate_t **trtable;
   re_dfastate_t **dest_states = NULL, **dest_states_word, **dest_states_nl;
   re_node_set follows, *dests_node;
@@ -3268,8 +3295,8 @@
   } *dests_alloc;
 
   /* We build DFA states which corresponds to the destination nodes
-     from `state'.  `dests_node[i]' represents the nodes which i-th
-     destination state contains, and `dests_ch[i]' represents the
+     from 'state'.  'dests_node[i]' represents the nodes which i-th
+     destination state contains, and 'dests_ch[i]' represents the
      characters which i-th destination state accepts.  */
   if (__libc_use_alloca (sizeof (struct dests_alloc)))
     dests_alloc = (struct dests_alloc *) alloca (sizeof (struct dests_alloc));
@@ -3277,32 +3304,32 @@
     {
       dests_alloc = re_malloc (struct dests_alloc, 1);
       if (BE (dests_alloc == NULL, 0))
-	return 0;
+	return false;
       dests_node_malloced = true;
     }
   dests_node = dests_alloc->dests_node;
   dests_ch = dests_alloc->dests_ch;
 
-  /* Initialize transiton table.  */
+  /* Initialize transition table.  */
   state->word_trtable = state->trtable = NULL;
 
-  /* At first, group all nodes belonging to `state' into several
+  /* At first, group all nodes belonging to 'state' into several
      destinations.  */
   ndests = group_nodes_into_DFAstates (dfa, state, dests_node, dests_ch);
   if (BE (ndests <= 0, 0))
     {
       if (dests_node_malloced)
-	free (dests_alloc);
-      /* Return 0 in case of an error, 1 otherwise.  */
+	re_free (dests_alloc);
+      /* Return false in case of an error, true otherwise.  */
       if (ndests == 0)
 	{
 	  state->trtable = (re_dfastate_t **)
 	    calloc (sizeof (re_dfastate_t *), SBC_MAX);
-	  if (BE (state->trtable == NULL, 0))
-	    return 0;
-	  return 1;
+          if (BE (state->trtable == NULL, 0))
+            return false;
+	  return true;
 	}
-      return 0;
+      return false;
     }
 
   err = re_node_set_alloc (&follows, ndests + 1);
@@ -3322,19 +3349,18 @@
       alloca (ndests * 3 * sizeof (re_dfastate_t *));
   else
     {
-      dest_states = (re_dfastate_t **)
-	malloc (ndests * 3 * sizeof (re_dfastate_t *));
+      dest_states = re_malloc (re_dfastate_t *, ndests * 3);
       if (BE (dest_states == NULL, 0))
 	{
 out_free:
 	  if (dest_states_malloced)
-	    free (dest_states);
+	    re_free (dest_states);
 	  re_node_set_free (&follows);
 	  for (i = 0; i < ndests; ++i)
 	    re_node_set_free (dests_node + i);
 	  if (dests_node_malloced)
-	    free (dests_alloc);
-	  return 0;
+	    re_free (dests_alloc);
+	  return false;
 	}
       dest_states_malloced = true;
     }
@@ -3345,7 +3371,7 @@
   /* Then build the states for all destinations.  */
   for (i = 0; i < ndests; ++i)
     {
-      int next_node;
+      Idx next_node;
       re_node_set_empty (&follows);
       /* Merge the follows of this destination states.  */
       for (j = 0; j < dests_node[i].nelem; ++j)
@@ -3371,13 +3397,13 @@
 	    goto out_free;
 
 	  if (dest_states[i] != dest_states_word[i] && dfa->mb_cur_max > 1)
-	    need_word_trtable = 1;
+	    need_word_trtable = true;
 
 	  dest_states_nl[i] = re_acquire_state_context (&err, dfa, &follows,
 							CONTEXT_NEWLINE);
 	  if (BE (dest_states_nl[i] == NULL && err != REG_NOERROR, 0))
 	    goto out_free;
- 	}
+	}
       else
 	{
 	  dest_states_word[i] = dest_states[i];
@@ -3464,16 +3490,16 @@
     }
 
   if (dest_states_malloced)
-    free (dest_states);
+    re_free (dest_states);
 
   re_node_set_free (&follows);
   for (i = 0; i < ndests; ++i)
     re_node_set_free (dests_node + i);
 
   if (dests_node_malloced)
-    free (dests_alloc);
+    re_free (dests_alloc);
 
-  return 1;
+  return true;
 }
 
 /* Group all nodes belonging to STATE into several destinations.
@@ -3481,20 +3507,20 @@
    to DESTS_NODE[i] and set the characters accepted by the destination
    to DEST_CH[i].  This function return the number of destinations.  */
 
-static int
+static Idx
 group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state,
 			    re_node_set *dests_node, bitset_t *dests_ch)
 {
   reg_errcode_t err;
-  int result;
-  int i, j, k;
-  int ndests; /* Number of the destinations from `state'.  */
+  bool ok;
+  Idx i, j, k;
+  Idx ndests; /* Number of the destinations from 'state'.  */
   bitset_t accepts; /* Characters a node can accept.  */
   const re_node_set *cur_nodes = &state->nodes;
   bitset_empty (accepts);
   ndests = 0;
 
-  /* For all the nodes belonging to `state',  */
+  /* For all the nodes belonging to 'state',  */
   for (i = 0; i < cur_nodes->nelem; ++i)
     {
       re_token_t *node = &dfa->nodes[cur_nodes->elems[i]];
@@ -3524,7 +3550,10 @@
 #ifdef RE_ENABLE_I18N
       else if (type == OP_UTF8_PERIOD)
 	{
-	  memset (accepts, '\xff', sizeof (bitset_t) / 2);
+	  if (ASCII_CHARS % BITSET_WORD_BITS == 0)
+	    memset (accepts, -1, ASCII_CHARS / CHAR_BIT);
+	  else
+	    bitset_merge (accepts, utf8_sb_map);
 	  if (!(dfa->syntax & RE_DOT_NEWLINE))
 	    bitset_clear (accepts, '\n');
 	  if (dfa->syntax & RE_DOT_NOT_NULL)
@@ -3534,7 +3563,7 @@
       else
 	continue;
 
-      /* Check the `accepts' and sift the characters which are not
+      /* Check the 'accepts' and sift the characters which are not
 	 match it the context.  */
       if (constraint)
 	{
@@ -3593,7 +3622,7 @@
 	    }
 	}
 
-      /* Then divide `accepts' into DFA states, or create a new
+      /* Then divide 'accepts' into DFA states, or create a new
 	 state.  Above, we make sure that accepts is not empty.  */
       for (j = 0; j < ndests; ++j)
 	{
@@ -3606,7 +3635,7 @@
 	  if (type == CHARACTER && !bitset_contain (dests_ch[j], node->opr.c))
 	    continue;
 
-	  /* Enumerate the intersection set of this state and `accepts'.  */
+	  /* Enumerate the intersection set of this state and 'accepts'.  */
 	  has_intersec = 0;
 	  for (k = 0; k < BITSET_WORDS; ++k)
 	    has_intersec |= intersec[k] = accepts[k] & dests_ch[j][k];
@@ -3614,7 +3643,7 @@
 	  if (!has_intersec)
 	    continue;
 
-	  /* Then check if this state is a subset of `accepts'.  */
+	  /* Then check if this state is a subset of 'accepts'.  */
 	  not_subset = not_consumed = 0;
 	  for (k = 0; k < BITSET_WORDS; ++k)
 	    {
@@ -3622,8 +3651,8 @@
 	      not_consumed |= accepts[k] = accepts[k] & ~dests_ch[j][k];
 	    }
 
-	  /* If this state isn't a subset of `accepts', create a
-	     new group state, which has the `remains'. */
+	  /* If this state isn't a subset of 'accepts', create a
+	     new group state, which has the 'remains'. */
 	  if (not_subset)
 	    {
 	      bitset_copy (dests_ch[ndests], remains);
@@ -3635,8 +3664,8 @@
 	    }
 
 	  /* Put the position in the current group. */
-	  result = re_node_set_insert (&dests_node[j], cur_nodes->elems[i]);
-	  if (BE (result < 0, 0))
+	  ok = re_node_set_insert (&dests_node[j], cur_nodes->elems[i]);
+	  if (BE (! ok, 0))
 	    goto error_return;
 
 	  /* If all characters are consumed, go to next node. */
@@ -3662,7 +3691,7 @@
 }
 
 #ifdef RE_ENABLE_I18N
-/* Check how many bytes the node `dfa->nodes[node_idx]' accepts.
+/* Check how many bytes the node 'dfa->nodes[node_idx]' accepts.
    Return the number of the bytes the node accepts.
    STR_IDX is the current index of the input string.
 
@@ -3675,12 +3704,12 @@
 # endif
 
 static int
-check_node_accept_bytes (const re_dfa_t *dfa, int node_idx,
-			 const re_string_t *input, int str_idx)
+check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
+			 const re_string_t *input, Idx str_idx)
 {
   const re_token_t *node = dfa->nodes + node_idx;
   int char_len, elem_len;
-  int i;
+  Idx i;
 
   if (BE (node->type == OP_UTF8_PERIOD, 0))
     {
@@ -3759,7 +3788,7 @@
 # ifdef _LIBC
       const unsigned char *pin
 	= ((const unsigned char *) re_string_get_buffer (input) + str_idx);
-      int j;
+      Idx j;
       uint32_t nrules;
 # endif /* _LIBC */
       int match_len = 0;
@@ -3827,6 +3856,7 @@
 		in_collseq = find_collation_sequence_value (pin, elem_len);
 	    }
 	  /* match with range expression?  */
+	  /* FIXME: Implement rational ranges here, too.  */
 	  for (i = 0; i < cset->nranges; ++i)
 	    if (cset->range_starts[i] <= in_collseq
 		&& in_collseq <= cset->range_ends[i])
@@ -3856,7 +3886,7 @@
 		    if (weight_len == weights[equiv_class_idx & 0xffffff]
 			&& (idx >> 24) == (equiv_class_idx >> 24))
 		      {
-			int cnt = 0;
+			Idx cnt = 0;
 
 			idx &= 0xffffff;
 			equiv_class_idx &= 0xffffff;
@@ -3878,18 +3908,9 @@
 # endif /* _LIBC */
 	{
 	  /* match with range expression?  */
-#if __GNUC__ >= 2
-	  wchar_t cmp_buf[] = {L'\0', L'\0', wc, L'\0', L'\0', L'\0'};
-#else
-	  wchar_t cmp_buf[] = {L'\0', L'\0', L'\0', L'\0', L'\0', L'\0'};
-	  cmp_buf[2] = wc;
-#endif
 	  for (i = 0; i < cset->nranges; ++i)
 	    {
-	      cmp_buf[0] = cset->range_starts[i];
-	      cmp_buf[4] = cset->range_ends[i];
-	      if (__wcscoll (cmp_buf, cmp_buf + 2) <= 0
-		  && __wcscoll (cmp_buf + 2, cmp_buf + 4) <= 0)
+	      if (cset->range_starts[i] <= wc && wc <= cset->range_ends[i])
 		{
 		  match_len = char_len;
 		  goto check_node_accept_bytes_match;
@@ -3936,7 +3957,8 @@
 
       for (idx = 0; idx < extrasize;)
 	{
-	  int mbs_cnt, found = 0;
+	  int mbs_cnt;
+	  bool found = false;
 	  int32_t elem_mbs_len;
 	  /* Skip the name of collating element name.  */
 	  idx = idx + extra[idx] + 1;
@@ -3948,7 +3970,7 @@
 		  break;
 	      if (mbs_cnt == elem_mbs_len)
 		/* Found the entry.  */
-		found = 1;
+		found = true;
 	    }
 	  /* Skip the byte sequence of the collating element.  */
 	  idx += elem_mbs_len;
@@ -3973,9 +3995,9 @@
 /* Check whether the node accepts the byte which is IDX-th
    byte of the INPUT.  */
 
-static int
+static bool
 check_node_accept (const re_match_context_t *mctx, const re_token_t *node,
-		   int idx)
+		   Idx idx)
 {
   unsigned char ch;
   ch = re_string_byte_at (&mctx->input, idx);
@@ -3983,28 +4005,28 @@
     {
     case CHARACTER:
       if (node->opr.c != ch)
-	return 0;
+        return false;
       break;
 
     case SIMPLE_BRACKET:
       if (!bitset_contain (node->opr.sbcset, ch))
-	return 0;
+        return false;
       break;
 
 #ifdef RE_ENABLE_I18N
     case OP_UTF8_PERIOD:
-      if (ch >= 0x80)
-	return 0;
-      /* FALLTHROUGH */
+      if (ch >= ASCII_CHARS)
+        return false;
+      FALLTHROUGH;
 #endif
     case OP_PERIOD:
       if ((ch == '\n' && !(mctx->dfa->syntax & RE_DOT_NEWLINE))
 	  || (ch == '\0' && (mctx->dfa->syntax & RE_DOT_NOT_NULL)))
-	return 0;
+	return false;
       break;
 
     default:
-      return 0;
+      return false;
     }
 
   if (node->constraint)
@@ -4014,10 +4036,10 @@
       unsigned int context = re_string_context_at (&mctx->input, idx,
 						   mctx->eflags);
       if (NOT_SATISFY_NEXT_CONSTRAINT (node->constraint, context))
-	return 0;
+	return false;
     }
 
-  return 1;
+  return true;
 }
 
 /* Extend the buffers, if the buffers have run out.  */
@@ -4030,10 +4052,11 @@
   re_string_t *pstr = &mctx->input;
 
   /* Avoid overflow.  */
-  if (BE (INT_MAX / 2 / sizeof (re_dfastate_t *) <= pstr->bufs_len, 0))
+  if (BE (MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *)) / 2
+          <= pstr->bufs_len, 0))
     return REG_ESPACE;
 
-  /* Double the lengthes of the buffers, but allocate at least MIN_LEN.  */
+  /* Double the lengths of the buffers, but allocate at least MIN_LEN.  */
   ret = re_string_realloc_buffers (pstr,
 				   MAX (min_len,
 					MIN (pstr->len, pstr->bufs_len * 2)));
@@ -4089,12 +4112,19 @@
 
 static reg_errcode_t
 __attribute_warn_unused_result__
-match_ctx_init (re_match_context_t *mctx, int eflags, int n)
+match_ctx_init (re_match_context_t *mctx, int eflags, Idx n)
 {
   mctx->eflags = eflags;
   mctx->match_last = -1;
   if (n > 0)
     {
+      /* Avoid overflow.  */
+      size_t max_object_size =
+	MAX (sizeof (struct re_backref_cache_entry),
+	     sizeof (re_sub_match_top_t *));
+      if (BE (MIN (IDX_MAX, SIZE_MAX / max_object_size) < n, 0))
+	return REG_ESPACE;
+
       mctx->bkref_ents = re_malloc (struct re_backref_cache_entry, n);
       mctx->sub_tops = re_malloc (re_sub_match_top_t *, n);
       if (BE (mctx->bkref_ents == NULL || mctx->sub_tops == NULL, 0))
@@ -4118,10 +4148,10 @@
 static void
 match_ctx_clean (re_match_context_t *mctx)
 {
-  int st_idx;
+  Idx st_idx;
   for (st_idx = 0; st_idx < mctx->nsub_tops; ++st_idx)
     {
-      int sl_idx;
+      Idx sl_idx;
       re_sub_match_top_t *top = mctx->sub_tops[st_idx];
       for (sl_idx = 0; sl_idx < top->nlasts; ++sl_idx)
 	{
@@ -4135,7 +4165,7 @@
 	  re_free (top->path->array);
 	  re_free (top->path);
 	}
-      free (top);
+      re_free (top);
     }
 
   mctx->nsub_tops = 0;
@@ -4160,8 +4190,8 @@
 
 static reg_errcode_t
 __attribute_warn_unused_result__
-match_ctx_add_entry (re_match_context_t *mctx, int node, int str_idx, int from,
-		     int to)
+match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, Idx from,
+		     Idx to)
 {
   if (mctx->nbkref_ents >= mctx->abkref_ents)
     {
@@ -4196,7 +4226,7 @@
      A backreference does not epsilon-transition unless it is empty, so set
      to all zeros if FROM != TO.  */
   mctx->bkref_ents[mctx->nbkref_ents].eps_reachable_subexps_map
-    = (from == to ? ~0 : 0);
+    = (from == to ? -1 : 0);
 
   mctx->bkref_ents[mctx->nbkref_ents++].more = 0;
   if (mctx->max_mb_elem_len < to - from)
@@ -4204,13 +4234,13 @@
   return REG_NOERROR;
 }
 
-/* Search for the first entry which has the same str_idx, or -1 if none is
+/* Return the first entry with the same str_idx, or -1 if none is
    found.  Note that MCTX->BKREF_ENTS is already sorted by MCTX->STR_IDX.  */
 
-static int
-search_cur_bkref_entry (const re_match_context_t *mctx, int str_idx)
+static Idx
+search_cur_bkref_entry (const re_match_context_t *mctx, Idx str_idx)
 {
-  int left, right, mid, last;
+  Idx left, right, mid, last;
   last = right = mctx->nbkref_ents;
   for (left = 0; left < right;)
     {
@@ -4231,7 +4261,7 @@
 
 static reg_errcode_t
 __attribute_warn_unused_result__
-match_ctx_add_subtop (re_match_context_t *mctx, int node, int str_idx)
+match_ctx_add_subtop (re_match_context_t *mctx, Idx node, Idx str_idx)
 {
 #ifdef DEBUG
   assert (mctx->sub_tops != NULL);
@@ -4239,7 +4269,7 @@
 #endif
   if (BE (mctx->nsub_tops == mctx->asub_tops, 0))
     {
-      int new_asub_tops = mctx->asub_tops * 2;
+      Idx new_asub_tops = mctx->asub_tops * 2;
       re_sub_match_top_t **new_array = re_realloc (mctx->sub_tops,
 						   re_sub_match_top_t *,
 						   new_asub_tops);
@@ -4260,12 +4290,12 @@
    at STR_IDX, whose corresponding OP_OPEN_SUBEXP is SUB_TOP.  */
 
 static re_sub_match_last_t *
-match_ctx_add_sublast (re_sub_match_top_t *subtop, int node, int str_idx)
+match_ctx_add_sublast (re_sub_match_top_t *subtop, Idx node, Idx str_idx)
 {
   re_sub_match_last_t *new_entry;
   if (BE (subtop->nlasts == subtop->alasts, 0))
     {
-      int new_alasts = 2 * subtop->alasts + 1;
+      Idx new_alasts = 2 * subtop->alasts + 1;
       re_sub_match_last_t **new_array = re_realloc (subtop->lasts,
 						    re_sub_match_last_t *,
 						    new_alasts);
@@ -4287,7 +4317,7 @@
 
 static void
 sift_ctx_init (re_sift_context_t *sctx, re_dfastate_t **sifted_sts,
-	       re_dfastate_t **limited_sts, int last_node, int last_str_idx)
+	       re_dfastate_t **limited_sts, Idx last_node, Idx last_str_idx)
 {
   sctx->sifted_states = sifted_sts;
   sctx->limited_states = limited_sts;
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/posix/wordexp-test.c b/google3/third_party/grte/v5_src/glibc-2.27/posix/wordexp-test.c
index cc29840..30c1dd6 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/posix/wordexp-test.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/posix/wordexp-test.c
@@ -200,6 +200,7 @@
     { 0, NULL, "$var", 0, 0, { NULL, }, IFS },
     { 0, NULL, "\"\\n\"", 0, 1, { "\\n", }, IFS },
     { 0, NULL, "", 0, 0, { NULL, }, IFS },
+    { 0, NULL, "${1234567890123456789012}", 0, 0, { NULL, }, IFS },
 
     /* Flags not already covered (testit() has special handling for these) */
     { 0, NULL, "one two", WRDE_DOOFFS, 2, { "one", "two", }, IFS },
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/posix/wordexp.c b/google3/third_party/grte/v5_src/glibc-2.27/posix/wordexp.c
index 8e33ad9..081f9cb 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/posix/wordexp.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/posix/wordexp.c
@@ -837,7 +837,7 @@
       if (__builtin_expect (__fxstat64 (_STAT_VER, STDERR_FILENO, &st), 0) != 0
 	  || __builtin_expect (S_ISCHR (st.st_mode), 1) == 0
 #if defined DEV_NULL_MAJOR && defined DEV_NULL_MINOR
-	  || st.st_rdev != makedev (DEV_NULL_MAJOR, DEV_NULL_MINOR)
+	  || st.st_rdev != __gnu_dev_makedev (DEV_NULL_MAJOR, DEV_NULL_MINOR)
 #endif
 	  )
 	/* It's not the /dev/null device.  Stop right here.  The
@@ -1407,7 +1407,7 @@
   /* Is it a numeric parameter? */
   else if (isdigit (env[0]))
     {
-      int n = atoi (env);
+      unsigned long n = strtoul (env, NULL, 10);
 
       if (n >= __libc_argc)
 	/* Substitute NULL. */
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/scripts/output-format.sed b/google3/third_party/grte/v5_src/glibc-2.27/scripts/output-format.sed
deleted file mode 100644
index 364f520..0000000
--- a/google3/third_party/grte/v5_src/glibc-2.27/scripts/output-format.sed
+++ /dev/null
@@ -1,35 +0,0 @@
-/ld.*[ 	]-E[BL]/b f
-/collect.*[ 	]-E[BL]/b f
-/OUTPUT_FORMAT[^)]*$/{N
-s/\n[	 ]*/ /
-}
-t o
-: o
-s/^.*OUTPUT_FORMAT(\([^,]*\), \1, \1).*$/OUTPUT_FORMAT(\1)/
-t q
-s/^.*OUTPUT_FORMAT(\([^,]*\), \([^,]*\), \([^,]*\)).*$/\1,\2,\3/
-t s
-s/^.*OUTPUT_FORMAT(\([^,)]*\).*$)/OUTPUT_FORMAT(\1)/
-t q
-d
-: s
-s/"//g
-G
-s/\n//
-s/^\([^,]*\),\([^,]*\),\([^,]*\),B/OUTPUT_FORMAT(\2)/p
-s/^\([^,]*\),\([^,]*\),\([^,]*\),L/OUTPUT_FORMAT(\3)/p
-s/^\([^,]*\),\([^,]*\),\([^,]*\)/OUTPUT_FORMAT(\1)/p
-/,/s|^|*** BUG in libc/scripts/output-format.sed *** |p
-q
-: q
-s/"//g
-p
-q
-: f
-s/^.*[ 	]-E\([BL]\)[ 	].*$/,\1/
-t h
-s/^.*[ 	]-E\([BL]\)$/,\1/
-t h
-d
-: h
-h
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/scripts/versions.awk b/google3/third_party/grte/v5_src/glibc-2.27/scripts/versions.awk
index a3df316..f4a63f3 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/scripts/versions.awk
+++ b/google3/third_party/grte/v5_src/glibc-2.27/scripts/versions.awk
@@ -132,8 +132,13 @@
 	closeversion(oldver, veryoldver);
 	veryoldver = oldver;
       }
-      printf("%s {\n  global:\n", $2) > outfile;
       oldver = $2;
+      # Skip the placeholder symbol used only for empty version map.
+      if ($3 == "__placeholder_only_for_empty_version_map;") {
+	printf("%s {\n", $2) > outfile;
+	continue;
+      }
+      printf("%s {\n  global:\n", $2) > outfile;
     }
     printf("   ") > outfile;
     for (n = 3; n <= NF; ++n) {
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/stdlib/atoi.c b/google3/third_party/grte/v5_src/glibc-2.27/stdlib/atoi.c
index a6c3f1d..c428584 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/stdlib/atoi.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/stdlib/atoi.c
@@ -26,3 +26,4 @@
 {
   return (int) strtol (nptr, (char **) NULL, 10);
 }
+libc_hidden_def (atoi)
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/string/argz-next.c b/google3/third_party/grte/v5_src/glibc-2.27/string/argz-next.c
index abce451..9200eda 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/string/argz-next.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/string/argz-next.c
@@ -36,4 +36,6 @@
     else
       return NULL;
 }
+libc_hidden_def (__argz_next)
 weak_alias (__argz_next, argz_next)
+libc_hidden_weak (argz_next)
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/string/string.h b/google3/third_party/grte/v5_src/glibc-2.27/string/string.h
index 150cfd8..22cd0fa 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/string/string.h
+++ b/google3/third_party/grte/v5_src/glibc-2.27/string/string.h
@@ -33,7 +33,8 @@
 #include <stddef.h>
 
 /* Tell the caller that we provide correct C++ prototypes.  */
-#if defined __cplusplus && __GNUC_PREREQ (4, 4)
+#if defined __cplusplus && (__GNUC_PREREQ (4, 4) \
+			    || __glibc_clang_prereq (3, 5))
 # define __CORRECT_ISO_CPP_STRING_H_PROTO
 #endif
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/string/tst-xbzero-opt.c b/google3/third_party/grte/v5_src/glibc-2.27/string/tst-xbzero-opt.c
index e9c411b..4f16c4d 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/string/tst-xbzero-opt.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/string/tst-xbzero-opt.c
@@ -119,17 +119,17 @@
 setup_no_clear (void)
 {
   unsigned char buf[TEST_BUFFER_SIZE];
-  prepare_test_buffer (buf);
   vol_glob = buf;
+  prepare_test_buffer (buf);
 }
 
 static void
 setup_ordinary_clear (void)
 {
   unsigned char buf[TEST_BUFFER_SIZE];
+  vol_glob = buf;
   prepare_test_buffer (buf);
   memset (buf, 0, TEST_BUFFER_SIZE);
-  vol_glob = buf;
 }
 
 static void
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/aarch64/dl-machine.h b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/aarch64/dl-machine.h
index db67301..c5d8e27 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/aarch64/dl-machine.h
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/aarch64/dl-machine.h
@@ -34,28 +34,22 @@
   return ehdr->e_machine == EM_AARCH64;
 }
 
-/* Return the link-time address of _DYNAMIC.  Conveniently, this is the
-   first element of the GOT. */
-static inline ElfW(Addr) __attribute__ ((unused))
-elf_machine_dynamic (void)
-{
-  extern const ElfW(Addr) _GLOBAL_OFFSET_TABLE_[] attribute_hidden;
-  return _GLOBAL_OFFSET_TABLE_[0];
-}
-
 /* Return the run-time load address of the shared object.  */
 
 static inline ElfW(Addr) __attribute__ ((unused))
 elf_machine_load_address (void)
 {
-  /* To figure out the load address we use the definition that for any symbol:
-     dynamic_addr(symbol) = static_addr(symbol) + load_addr
+  extern const ElfW(Ehdr) __ehdr_start attribute_hidden;
+  return (ElfW(Addr)) &__ehdr_start;
+}
 
-    _DYNAMIC sysmbol is used here as its link-time address stored in
-    the special unrelocated first GOT entry.  */
+/* Return the link-time address of _DYNAMIC.  */
 
-    extern ElfW(Dyn) _DYNAMIC[] attribute_hidden;
-    return (ElfW(Addr)) &_DYNAMIC - elf_machine_dynamic ();
+static inline ElfW(Addr) __attribute__ ((unused))
+elf_machine_dynamic (void)
+{
+  extern ElfW(Dyn) _DYNAMIC[] attribute_hidden;
+  return (ElfW(Addr)) _DYNAMIC - elf_machine_load_address ();
 }
 
 /* Set up the loaded object described by L so its unrelocated PLT
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/aarch64/libm-test-ulps b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/aarch64/libm-test-ulps
index 5603f2e..d9850c8 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/aarch64/libm-test-ulps
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/aarch64/libm-test-ulps
@@ -1012,7 +1012,9 @@
 ldouble: 2
 
 Function: "cos":
+double: 1
 float: 1
+idouble: 1
 ifloat: 1
 ildouble: 1
 ldouble: 1
@@ -1968,7 +1970,9 @@
 ldouble: 2
 
 Function: "sin":
+double: 1
 float: 1
+idouble: 1
 ifloat: 1
 ildouble: 1
 ldouble: 1
@@ -1998,7 +2002,9 @@
 ldouble: 3
 
 Function: "sincos":
+double: 1
 float: 1
+idouble: 1
 ifloat: 1
 ildouble: 1
 ldouble: 1
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/generic/ldsodefs.h b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/generic/ldsodefs.h
index a36d664..8759f6e 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/generic/ldsodefs.h
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/generic/ldsodefs.h
@@ -744,15 +744,26 @@
      __attribute__ ((__format__ (__printf__, 2, 3)))
      attribute_hidden;
 #else
+#if defined(__clang__)
+#include <stdarg.h>
+#endif
 __attribute__ ((always_inline, __format__ (__printf__, 2, 3)))
 static inline void
 _dl_dprintf (int fd, const char *fmt, ...)
 {
+#if defined(__clang__)
+  /* In the absence of __builtin_va_arg_pack, use varargs macros to construct a
+     direct call to the stdio function that __dprintf eventually gets to.  This
+     is not a robust hack, will break if stdio changes much.  */
+  extern int _IO_vdprintf (int d, const char *format, va_list arg);
+  va_list arg;
+
+  va_start (arg, fmt);
+  _IO_vdprintf (fd, fmt, arg);
+  va_end (arg);
+#else
   /* Use local declaration to avoid includign <stdio.h>.  */
   extern int __dprintf(int fd, const char *format, ...) attribute_hidden;
-#if defined(__clang__)
-  __dprintf (fd, fmt);
-#else
   __dprintf (fd, fmt, __builtin_va_arg_pack ());
 #endif
 }
@@ -1113,13 +1124,13 @@
 
 # if ENABLE_STATIC_PIE
 /* Relocate static executable with PIE.  */
-extern int _dl_relocate_static_pie (void) attribute_hidden;
+extern void _dl_relocate_static_pie (void) attribute_hidden;
 
 /* Get a pointer to _dl_main_map.  */
 extern struct link_map * _dl_get_dl_main_map (void)
   __attribute__ ((visibility ("hidden")));
 # else
-#  define _dl_relocate_static_pie() 0
+#  define _dl_relocate_static_pie()
 # endif
 
 /* Initialization of libpthread for statically linked applications.
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/ieee754/dbl-64/s_sin.c b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/ieee754/dbl-64/s_sin.c
index 8c589cb..ba1dbe2 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/ieee754/dbl-64/s_sin.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/ieee754/dbl-64/s_sin.c
@@ -22,22 +22,11 @@
 /*                                                                          */
 /* FUNCTIONS: usin                                                          */
 /*            ucos                                                          */
-/*            slow                                                          */
-/*            slow1                                                         */
-/*            slow2                                                         */
-/*            sloww                                                         */
-/*            sloww1                                                        */
-/*            sloww2                                                        */
-/*            bsloww                                                        */
-/*            bsloww1                                                       */
-/*            bsloww2                                                       */
-/*            cslow2                                                        */
 /* FILES NEEDED: dla.h endian.h mpa.h mydefs.h  usncs.h                     */
-/*               branred.c sincos32.c dosincos.c mpa.c                      */
-/*               sincos.tbl                                                 */
+/*		 branred.c sincos.tbl					    */
 /*                                                                          */
-/* An ultimate sin and  routine. Given an IEEE double machine number x       */
-/* it computes the correctly rounded (to nearest) value of sin(x) or cos(x) */
+/* An ultimate sin and cos routine. Given an IEEE double machine number x   */
+/* it computes sin(x) or cos(x) with ~0.55 ULP.				    */
 /* Assumption: Machine arithmetic operations are performed in               */
 /* round to nearest mode of IEEE 754 standard.                              */
 /*                                                                          */
@@ -66,35 +55,11 @@
    a - a^3/3! + a^5/5! - a^7/7! + a^9/9! + (1 - a^2) * da / 2
 
    The constants s1, s2, s3, etc. are pre-computed values of 1/3!, 1/5! and so
-   on.  The result is returned to LHS and correction in COR.  */
-#define TAYLOR_SIN(xx, a, da, cor) \
+   on.  The result is returned to LHS.  */
+#define TAYLOR_SIN(xx, a, da) \
 ({									      \
   double t = ((POLYNOMIAL (xx)  * (a) - 0.5 * (da))  * (xx) + (da));	      \
   double res = (a) + t;							      \
-  (cor) = ((a) - res) + t;						      \
-  res;									      \
-})
-
-/* This is again a variation of the Taylor series expansion with the term
-   x^3/3! expanded into the following for better accuracy:
-
-   bb * x ^ 3 + 3 * aa * x * x1 * x2 + aa * x1 ^ 3 + aa * x2 ^ 3
-
-   The correction term is dx and bb + aa = -1/3!
-   */
-#define TAYLOR_SLOW(x0, dx, cor) \
-({									      \
-  static const double th2_36 = 206158430208.0;	/*    1.5*2**37   */	      \
-  double xx = (x0) * (x0);						      \
-  double x1 = ((x0) + th2_36) - th2_36;					      \
-  double y = aa * x1 * x1 * x1;						      \
-  double r = (x0) + y;							      \
-  double x2 = ((x0) - x1) + (dx);					      \
-  double t = (((POLYNOMIAL2 (xx) + bb) * xx + 3.0 * aa * x1 * x2)	      \
-	      * (x0)  + aa * x2 * x2 * x2 + (dx));			      \
-  t = (((x0) - r) + y) + t;						      \
-  double res = r + t;							      \
-  (cor) = (r - res) + t;						      \
   res;									      \
 })
 
@@ -124,31 +89,15 @@
   cs4 = -4.16666666666664434524222570944589E-02,
   cs6 = 1.38888874007937613028114285595617E-03;
 
-static const double t22 = 0x1.8p22;
-
-void __dubsin (double x, double dx, double w[]);
-void __docos (double x, double dx, double w[]);
-double __mpsin (double x, double dx, bool reduce_range);
-double __mpcos (double x, double dx, bool reduce_range);
-static double slow (double x);
-static double slow1 (double x);
-static double slow2 (double x);
-static double sloww (double x, double dx, double orig, bool shift_quadrant);
-static double sloww1 (double x, double dx, double orig, bool shift_quadrant);
-static double sloww2 (double x, double dx, double orig, int n);
-static double bsloww (double x, double dx, double orig, int n);
-static double bsloww1 (double x, double dx, double orig, int n);
-static double bsloww2 (double x, double dx, double orig, int n);
 int __branred (double x, double *a, double *aa);
-static double cslow2 (double x);
 
 /* Given a number partitioned into X and DX, this function computes the cosine
    of the number by combining the sin and cos of X (as computed by a variation
    of the Taylor series) with the values looked up from the sin/cos table to
-   get the result in RES and a correction value in COR.  */
+   get the result.  */
 static inline double
 __always_inline
-do_cos (double x, double dx, double *corp)
+do_cos (double x, double dx)
 {
   mynumber u;
 
@@ -158,60 +107,28 @@
   u.x = big + fabs (x);
   x = fabs (x) - (u.x - big) + dx;
 
-  double xx, s, sn, ssn, c, cs, ccs, res, cor;
+  double xx, s, sn, ssn, c, cs, ccs, cor;
   xx = x * x;
   s = x + x * xx * (sn3 + xx * sn5);
   c = xx * (cs2 + xx * (cs4 + xx * cs6));
   SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
   cor = (ccs - s * ssn - cs * c) - sn * s;
-  res = cs + cor;
-  cor = (cs - res) + cor;
-  *corp = cor;
-  return res;
-}
-
-/* A more precise variant of DO_COS.  EPS is the adjustment to the correction
-   COR.  */
-static inline double
-__always_inline
-do_cos_slow (double x, double dx, double eps, double *corp)
-{
-  mynumber u;
-
-  if (x <= 0)
-    dx = -dx;
-
-  u.x = big + fabs (x);
-  x = fabs (x) - (u.x - big);
-
-  double xx, y, x1, x2, e1, e2, res, cor;
-  double s, sn, ssn, c, cs, ccs;
-  xx = x * x;
-  s = x * xx * (sn3 + xx * sn5);
-  c = x * dx + xx * (cs2 + xx * (cs4 + xx * cs6));
-  SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
-  x1 = (x + t22) - t22;
-  x2 = (x - x1) + dx;
-  e1 = (sn + t22) - t22;
-  e2 = (sn - e1) + ssn;
-  cor = (ccs - cs * c - e1 * x2 - e2 * x) - sn * s;
-  y = cs - e1 * x1;
-  cor = cor + ((cs - y) - e1 * x1);
-  res = y + cor;
-  cor = (y - res) + cor;
-  cor = 1.0005 * cor + __copysign (eps, cor);
-  *corp = cor;
-  return res;
+  return cs + cor;
 }
 
 /* Given a number partitioned into X and DX, this function computes the sine of
    the number by combining the sin and cos of X (as computed by a variation of
    the Taylor series) with the values looked up from the sin/cos table to get
-   the result in RES and a correction value in COR.  */
+   the result.  */
 static inline double
 __always_inline
-do_sin (double x, double dx, double *corp)
+do_sin (double x, double dx)
 {
+  double xold = x;
+  /* Max ULP is 0.501 if |x| < 0.126, otherwise ULP is 0.518.  */
+  if (fabs (x) < 0.126)
+    return TAYLOR_SIN (x * x, x, dx);
+
   mynumber u;
 
   if (x <= 0)
@@ -219,85 +136,22 @@
   u.x = big + fabs (x);
   x = fabs (x) - (u.x - big);
 
-  double xx, s, sn, ssn, c, cs, ccs, cor, res;
+  double xx, s, sn, ssn, c, cs, ccs, cor;
   xx = x * x;
   s = x + (dx + x * xx * (sn3 + xx * sn5));
   c = x * dx + xx * (cs2 + xx * (cs4 + xx * cs6));
   SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
   cor = (ssn + s * ccs - sn * c) + cs * s;
-  res = sn + cor;
-  cor = (sn - res) + cor;
-  *corp = cor;
-  return res;
+  return __copysign (sn + cor, xold);
 }
 
-/* A more precise variant of DO_SIN.  EPS is the adjustment to the correction
-   COR.  */
-static inline double
-__always_inline
-do_sin_slow (double x, double dx, double eps, double *corp)
-{
-  mynumber u;
-
-  if (x <= 0)
-    dx = -dx;
-  u.x = big + fabs (x);
-  x = fabs (x) - (u.x - big);
-
-  double xx, y, x1, x2, c1, c2, res, cor;
-  double s, sn, ssn, c, cs, ccs;
-  xx = x * x;
-  s = x * xx * (sn3 + xx * sn5);
-  c = xx * (cs2 + xx * (cs4 + xx * cs6));
-  SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs);
-  x1 = (x + t22) - t22;
-  x2 = (x - x1) + dx;
-  c1 = (cs + t22) - t22;
-  c2 = (cs - c1) + ccs;
-  cor = (ssn + s * ccs + cs * s + c2 * x + c1 * x2 - sn * x * dx) - sn * c;
-  y = sn + c1 * x1;
-  cor = cor + ((sn - y) + c1 * x1);
-  res = y + cor;
-  cor = (y - res) + cor;
-  cor = 1.0005 * cor + __copysign (eps, cor);
-  *corp = cor;
-  return res;
-}
-
-/* Reduce range of X and compute sin of a + da. When SHIFT_QUADRANT is true,
-   the routine returns the cosine of a + da by rotating the quadrant once and
-   computing the sine of the result.  */
-static inline double
-__always_inline
-reduce_and_compute (double x, bool shift_quadrant)
-{
-  double retval = 0, a, da;
-  unsigned int n = __branred (x, &a, &da);
-  int4 k = (n + shift_quadrant) % 4;
-  switch (k)
-    {
-    case 2:
-      a = -a;
-      da = -da;
-      /* Fall through.  */
-    case 0:
-      if (a * a < 0.01588)
-	retval = bsloww (a, da, x, n);
-      else
-	retval = bsloww1 (a, da, x, n);
-      break;
-
-    case 1:
-    case 3:
-      retval = bsloww2 (a, da, x, n);
-      break;
-    }
-  return retval;
-}
-
+/* Reduce range of x to within PI/2 with abs (x) < 105414350.  The high part
+   is written to *a, the low part to *da.  Range reduction is accurate to 136
+   bits so that when x is large and *a very close to zero, all 53 bits of *a
+   are correct.  */
 static inline int4
 __always_inline
-reduce_sincos_1 (double x, double *a, double *da)
+reduce_sincos (double x, double *a, double *da)
 {
   mynumber v;
 
@@ -306,156 +160,54 @@
   v.x = t;
   double y = (x - xn * mp1) - xn * mp2;
   int4 n = v.i[LOW_HALF] & 3;
-  double db = xn * mp3;
-  double b = y - db;
-  db = (y - b) - db;
+
+  double b, db, t1, t2;
+  t1 = xn * pp3;
+  t2 = y - t1;
+  db = (y - t2) - t1;
+
+  t1 = xn * pp4;
+  b = t2 - t1;
+  db += (t2 - b) - t1;
 
   *a = b;
   *da = db;
-
   return n;
 }
 
-/* Compute sin (A + DA).  cos can be computed by passing SHIFT_QUADRANT as
-   true, which results in shifting the quadrant N clockwise.  */
+/* Compute sin or cos (A + DA) for the given quadrant N.  */
 static double
 __always_inline
-do_sincos_1 (double a, double da, double x, int4 n, bool shift_quadrant)
+do_sincos (double a, double da, int4 n)
 {
-  double xx, retval, res, cor;
-  double eps = fabs (x) * 1.2e-30;
+  double retval;
 
-  int k1 = (n + shift_quadrant) & 3;
-  switch (k1)
-    {			/* quarter of unit circle */
-    case 2:
-      a = -a;
-      da = -da;
-      /* Fall through.  */
-    case 0:
-      xx = a * a;
-      if (xx < 0.01588)
-	{
-	  /* Taylor series.  */
-	  res = TAYLOR_SIN (xx, a, da, cor);
-	  cor = 1.02 * cor + __copysign (eps, cor);
-	  retval = (res == res + cor) ? res : sloww (a, da, x, shift_quadrant);
-	}
-      else
-	{
-	  res = do_sin (a, da, &cor);
-	  cor = 1.035 * cor + __copysign (eps, cor);
-	  retval = ((res == res + cor) ? __copysign (res, a)
-		    : sloww1 (a, da, x, shift_quadrant));
-	}
-      break;
+  if (n & 1)
+    /* Max ULP is 0.513.  */
+    retval = do_cos (a, da);
+  else
+    /* Max ULP is 0.501 if xx < 0.01588, otherwise ULP is 0.518.  */
+    retval = do_sin (a, da);
 
-    case 1:
-    case 3:
-      res = do_cos (a, da, &cor);
-      cor = 1.025 * cor + __copysign (eps, cor);
-      retval = ((res == res + cor) ? ((n & 2) ? -res : res)
-		: sloww2 (a, da, x, n));
-      break;
-    }
-
-  return retval;
+  return (n & 2) ? -retval : retval;
 }
 
-static inline int4
-__always_inline
-reduce_sincos_2 (double x, double *a, double *da)
-{
-  mynumber v;
-
-  double t = (x * hpinv + toint);
-  double xn = t - toint;
-  v.x = t;
-  double xn1 = (xn + 8.0e22) - 8.0e22;
-  double xn2 = xn - xn1;
-  double y = ((((x - xn1 * mp1) - xn1 * mp2) - xn2 * mp1) - xn2 * mp2);
-  int4 n = v.i[LOW_HALF] & 3;
-  double db = xn1 * pp3;
-  t = y - db;
-  db = (y - t) - db;
-  db = (db - xn2 * pp3) - xn * pp4;
-  double b = t + db;
-  db = (t - b) + db;
-
-  *a = b;
-  *da = db;
-
-  return n;
-}
-
-/* Compute sin (A + DA).  cos can be computed by passing SHIFT_QUADRANT as
-   true, which results in shifting the quadrant N clockwise.  */
-static double
-__always_inline
-do_sincos_2 (double a, double da, double x, int4 n, bool shift_quadrant)
-{
-  double res, retval, cor, xx;
-
-  double eps = 1.0e-24;
-
-  int4 k = (n + shift_quadrant) & 3;
-
-  switch (k)
-    {
-    case 2:
-      a = -a;
-      da = -da;
-      /* Fall through.  */
-    case 0:
-      xx = a * a;
-      if (xx < 0.01588)
-	{
-	  /* Taylor series.  */
-	  res = TAYLOR_SIN (xx, a, da, cor);
-	  cor = 1.02 * cor + __copysign (eps, cor);
-	  retval = (res == res + cor) ? res : bsloww (a, da, x, n);
-	}
-      else
-	{
-	  res = do_sin (a, da, &cor);
-	  cor = 1.035 * cor + __copysign (eps, cor);
-	  retval = ((res == res + cor) ? __copysign (res, a)
-		    : bsloww1 (a, da, x, n));
-	}
-      break;
-
-    case 1:
-    case 3:
-      res = do_cos (a, da, &cor);
-      cor = 1.025 * cor + __copysign (eps, cor);
-      retval = ((res == res + cor) ? ((n & 2) ? -res : res)
-		: bsloww2 (a, da, x, n));
-      break;
-    }
-
-  return retval;
-}
 
 /*******************************************************************/
 /* An ultimate sin routine. Given an IEEE double machine number x   */
 /* it computes the correctly rounded (to nearest) value of sin(x)  */
 /*******************************************************************/
-#ifdef IN_SINCOS
-static double
-#else
+#ifndef IN_SINCOS
 double
 SECTION
-#endif
 __sin (double x)
 {
-  double xx, res, t, cor;
+  double t, a, da;
   mynumber u;
-  int4 k, m;
+  int4 k, m, n;
   double retval = 0;
 
-#ifndef IN_SINCOS
   SET_RESTORE_ROUND_53BIT (FE_TONEAREST);
-#endif
 
   u.x = x;
   m = u.i[HIGH_HALF];
@@ -465,56 +217,34 @@
       math_check_force_underflow (x);
       retval = x;
     }
- /*---------------------------- 2^-26 < |x|< 0.25 ----------------------*/
-  else if (k < 0x3fd00000)
-    {
-      xx = x * x;
-      /* Taylor series.  */
-      t = POLYNOMIAL (xx) * (xx * x);
-      res = x + t;
-      cor = (x - res) + t;
-      retval = (res == res + 1.07 * cor) ? res : slow (x);
-    }				/*  else  if (k < 0x3fd00000)    */
-/*---------------------------- 0.25<|x|< 0.855469---------------------- */
+/*--------------------------- 2^-26<|x|< 0.855469---------------------- */
   else if (k < 0x3feb6000)
     {
-      res = do_sin (x, 0, &cor);
-      retval = (res == res + 1.096 * cor) ? res : slow1 (x);
-      retval = __copysign (retval, x);
+      /* Max ULP is 0.548.  */
+      retval = do_sin (x, 0);
     }				/*   else  if (k < 0x3feb6000)    */
 
 /*----------------------- 0.855469  <|x|<2.426265  ----------------------*/
   else if (k < 0x400368fd)
     {
-
       t = hp0 - fabs (x);
-      res = do_cos (t, hp1, &cor);
-      retval = (res == res + 1.020 * cor) ? res : slow2 (x);
-      retval = __copysign (retval, x);
+      /* Max ULP is 0.51.  */
+      retval = __copysign (do_cos (t, hp1), x);
     }				/*   else  if (k < 0x400368fd)    */
 
-#ifndef IN_SINCOS
 /*-------------------------- 2.426265<|x|< 105414350 ----------------------*/
   else if (k < 0x419921FB)
     {
-      double a, da;
-      int4 n = reduce_sincos_1 (x, &a, &da);
-      retval = do_sincos_1 (a, da, x, n, false);
+      n = reduce_sincos (x, &a, &da);
+      retval = do_sincos (a, da, n);
     }				/*   else  if (k <  0x419921FB )    */
 
-/*---------------------105414350 <|x|< 281474976710656 --------------------*/
-  else if (k < 0x42F00000)
-    {
-      double a, da;
-
-      int4 n = reduce_sincos_2 (x, &a, &da);
-      retval = do_sincos_2 (a, da, x, n, false);
-    }				/*   else  if (k <  0x42F00000 )   */
-
-/* -----------------281474976710656 <|x| <2^1024----------------------------*/
+/* --------------------105414350 <|x| <2^1024------------------------------*/
   else if (k < 0x7ff00000)
-    retval = reduce_and_compute (x, false);
-
+    {
+      n = __branred (x, &a, &da);
+      retval = do_sincos (a, da, n);
+    }
 /*--------------------- |x| > 2^1024 ----------------------------------*/
   else
     {
@@ -522,7 +252,6 @@
 	__set_errno (EDOM);
       retval = x / x;
     }
-#endif
 
   return retval;
 }
@@ -533,23 +262,17 @@
 /* it computes the correctly rounded (to nearest) value of cos(x)  */
 /*******************************************************************/
 
-#ifdef IN_SINCOS
-static double
-#else
 double
 SECTION
-#endif
 __cos (double x)
 {
-  double y, xx, res, cor, a, da;
+  double y, a, da;
   mynumber u;
-  int4 k, m;
+  int4 k, m, n;
 
   double retval = 0;
 
-#ifndef IN_SINCOS
   SET_RESTORE_ROUND_53BIT (FE_TONEAREST);
-#endif
 
   u.x = x;
   m = u.i[HIGH_HALF];
@@ -561,8 +284,8 @@
 
   else if (k < 0x3feb6000)
     {				/* 2^-27 < |x| < 0.855469 */
-      res = do_cos (x, 0, &cor);
-      retval = (res == res + 1.020 * cor) ? res : cslow2 (x);
+      /* Max ULP is 0.51.  */
+      retval = do_cos (x, 0);
     }				/*   else  if (k < 0x3feb6000)    */
 
   else if (k < 0x400368fd)
@@ -570,43 +293,23 @@
       y = hp0 - fabs (x);
       a = y + hp1;
       da = (y - a) + hp1;
-      xx = a * a;
-      if (xx < 0.01588)
-	{
-	  res = TAYLOR_SIN (xx, a, da, cor);
-	  cor = 1.02 * cor + __copysign (1.0e-31, cor);
-	  retval = (res == res + cor) ? res : sloww (a, da, x, true);
-	}
-      else
-	{
-	  res = do_sin (a, da, &cor);
-	  cor = 1.035 * cor + __copysign (1.0e-31, cor);
-	  retval = ((res == res + cor) ? __copysign (res, a)
-		    : sloww1 (a, da, x, true));
-	}
-
+      /* Max ULP is 0.501 if xx < 0.01588 or 0.518 otherwise.
+	 Range reduction uses 106 bits here which is sufficient.  */
+      retval = do_sin (a, da);
     }				/*   else  if (k < 0x400368fd)    */
 
-
-#ifndef IN_SINCOS
   else if (k < 0x419921FB)
     {				/* 2.426265<|x|< 105414350 */
-      double a, da;
-      int4 n = reduce_sincos_1 (x, &a, &da);
-      retval = do_sincos_1 (a, da, x, n, true);
+      n = reduce_sincos (x, &a, &da);
+      retval = do_sincos (a, da, n + 1);
     }				/*   else  if (k <  0x419921FB )    */
 
-  else if (k < 0x42F00000)
-    {
-      double a, da;
-
-      int4 n = reduce_sincos_2 (x, &a, &da);
-      retval = do_sincos_2 (a, da, x, n, true);
-    }				/*   else  if (k <  0x42F00000 )    */
-
-  /* 281474976710656 <|x| <2^1024 */
+  /* 105414350 <|x| <2^1024 */
   else if (k < 0x7ff00000)
-    retval = reduce_and_compute (x, true);
+    {
+      n = __branred (x, &a, &da);
+      retval = do_sincos (a, da, n + 1);
+    }
 
   else
     {
@@ -614,307 +317,15 @@
 	__set_errno (EDOM);
       retval = x / x;		/* |x| > 2^1024 */
     }
-#endif
 
   return retval;
 }
 
-/************************************************************************/
-/*  Routine compute sin(x) for  2^-26 < |x|< 0.25 by  Taylor with more   */
-/* precision  and if still doesn't accurate enough by mpsin   or dubsin */
-/************************************************************************/
-
-static inline double
-__always_inline
-slow (double x)
-{
-  double res, cor, w[2];
-  res = TAYLOR_SLOW (x, 0, cor);
-  if (res == res + 1.0007 * cor)
-    return res;
-
-  __dubsin (fabs (x), 0, w);
-  if (w[0] == w[0] + 1.000000001 * w[1])
-    return __copysign (w[0], x);
-
-  return __copysign (__mpsin (fabs (x), 0, false), x);
-}
-
-/*******************************************************************************/
-/* Routine compute sin(x) for 0.25<|x|< 0.855469 by __sincostab.tbl and Taylor */
-/* and if result still doesn't accurate enough by mpsin   or dubsin            */
-/*******************************************************************************/
-
-static inline double
-__always_inline
-slow1 (double x)
-{
-  double w[2], cor, res;
-
-  res = do_sin_slow (x, 0, 0, &cor);
-  if (res == res + cor)
-    return res;
-
-  __dubsin (fabs (x), 0, w);
-  if (w[0] == w[0] + 1.000000005 * w[1])
-    return w[0];
-
-  return __mpsin (fabs (x), 0, false);
-}
-
-/**************************************************************************/
-/*  Routine compute sin(x) for   0.855469  <|x|<2.426265  by  __sincostab.tbl  */
-/* and if result still doesn't accurate enough by mpsin   or dubsin       */
-/**************************************************************************/
-static inline double
-__always_inline
-slow2 (double x)
-{
-  double w[2], y, y1, y2, cor, res;
-
-  double t = hp0 - fabs (x);
-  res = do_cos_slow (t, hp1, 0, &cor);
-  if (res == res + cor)
-    return res;
-
-  y = fabs (x) - hp0;
-  y1 = y - hp1;
-  y2 = (y - y1) - hp1;
-  __docos (y1, y2, w);
-  if (w[0] == w[0] + 1.000000005 * w[1])
-    return w[0];
-
-  return __mpsin (fabs (x), 0, false);
-}
-
-/* Compute sin(x + dx) where X is small enough to use Taylor series around zero
-   and (x + dx) in the first or third quarter of the unit circle.  ORIG is the
-   original value of X for computing error of the result.  If the result is not
-   accurate enough, the routine calls mpsin or dubsin.  SHIFT_QUADRANT rotates
-   the unit circle by 1 to compute the cosine instead of sine.  */
-static inline double
-__always_inline
-sloww (double x, double dx, double orig, bool shift_quadrant)
-{
-  double y, t, res, cor, w[2], a, da, xn;
-  mynumber v;
-  int4 n;
-  res = TAYLOR_SLOW (x, dx, cor);
-
-  double eps = fabs (orig) * 3.1e-30;
-
-  cor = 1.0005 * cor + __copysign (eps, cor);
-
-  if (res == res + cor)
-    return res;
-
-  a = fabs (x);
-  da = (x > 0) ? dx : -dx;
-  __dubsin (a, da, w);
-  eps = fabs (orig) * 1.1e-30;
-  cor = 1.000000001 * w[1] + __copysign (eps, w[1]);
-
-  if (w[0] == w[0] + cor)
-    return __copysign (w[0], x);
-
-  t = (orig * hpinv + toint);
-  xn = t - toint;
-  v.x = t;
-  y = (orig - xn * mp1) - xn * mp2;
-  n = (v.i[LOW_HALF] + shift_quadrant) & 3;
-  da = xn * pp3;
-  t = y - da;
-  da = (y - t) - da;
-  y = xn * pp4;
-  a = t - y;
-  da = ((t - a) - y) + da;
-
-  if (n & 2)
-    {
-      a = -a;
-      da = -da;
-    }
-  x = fabs (a);
-  dx = (a > 0) ? da : -da;
-  __dubsin (x, dx, w);
-  eps = fabs (orig) * 1.1e-40;
-  cor = 1.000000001 * w[1] + __copysign (eps, w[1]);
-
-  if (w[0] == w[0] + cor)
-    return __copysign (w[0], a);
-
-  return shift_quadrant ? __mpcos (orig, 0, true) : __mpsin (orig, 0, true);
-}
-
-/* Compute sin(x + dx) where X is in the first or third quarter of the unit
-   circle.  ORIG is the original value of X for computing error of the result.
-   If the result is not accurate enough, the routine calls mpsin or dubsin.
-   SHIFT_QUADRANT rotates the unit circle by 1 to compute the cosine instead of
-   sine.  */
-static inline double
-__always_inline
-sloww1 (double x, double dx, double orig, bool shift_quadrant)
-{
-  double w[2], cor, res;
-
-  res = do_sin_slow (x, dx, 3.1e-30 * fabs (orig), &cor);
-
-  if (res == res + cor)
-    return __copysign (res, x);
-
-  dx = (x > 0 ? dx : -dx);
-  __dubsin (fabs (x), dx, w);
-
-  double eps = 1.1e-30 * fabs (orig);
-  cor = 1.000000005 * w[1] + __copysign (eps, w[1]);
-
-  if (w[0] == w[0] + cor)
-    return __copysign (w[0], x);
-
-  return shift_quadrant ? __mpcos (orig, 0, true) : __mpsin (orig, 0, true);
-}
-
-/***************************************************************************/
-/*  Routine compute sin(x+dx)   (Double-Length number) where x in second or */
-/*  fourth quarter of unit circle.Routine receive also  the  original value */
-/* and quarter(n= 1or 3)of x for computing error of result.And if result not*/
-/* accurate enough routine calls  mpsin1   or dubsin                       */
-/***************************************************************************/
-
-static inline double
-__always_inline
-sloww2 (double x, double dx, double orig, int n)
-{
-  double w[2], cor, res;
-
-  res = do_cos_slow (x, dx, 3.1e-30 * fabs (orig), &cor);
-
-  if (res == res + cor)
-    return (n & 2) ? -res : res;
-
-  dx = x > 0 ? dx : -dx;
-  __docos (fabs (x), dx, w);
-
-  double eps = 1.1e-30 * fabs (orig);
-  cor = 1.000000005 * w[1] + __copysign (eps, w[1]);
-
-  if (w[0] == w[0] + cor)
-    return (n & 2) ? -w[0] : w[0];
-
-  return (n & 1) ? __mpsin (orig, 0, true) : __mpcos (orig, 0, true);
-}
-
-/***************************************************************************/
-/*  Routine compute sin(x+dx) or cos(x+dx) (Double-Length number) where x   */
-/* is small enough to use Taylor series around zero and   (x+dx)            */
-/* in first or third quarter of unit circle.Routine receive also            */
-/* (right argument) the  original   value of x for computing error of      */
-/* result.And if result not accurate enough routine calls other routines    */
-/***************************************************************************/
-
-static inline double
-__always_inline
-bsloww (double x, double dx, double orig, int n)
-{
-  double res, cor, w[2], a, da;
-
-  res = TAYLOR_SLOW (x, dx, cor);
-  cor = 1.0005 * cor + __copysign (1.1e-24, cor);
-  if (res == res + cor)
-    return res;
-
-  a = fabs (x);
-  da = (x > 0) ? dx : -dx;
-  __dubsin (a, da, w);
-  cor = 1.000000001 * w[1] + __copysign (1.1e-24, w[1]);
-
-  if (w[0] == w[0] + cor)
-    return __copysign (w[0], x);
-
-  return (n & 1) ? __mpcos (orig, 0, true) : __mpsin (orig, 0, true);
-}
-
-/***************************************************************************/
-/*  Routine compute sin(x+dx)  or cos(x+dx) (Double-Length number) where x  */
-/* in first or third quarter of unit circle.Routine receive also            */
-/* (right argument) the original  value of x for computing error of result.*/
-/* And if result not  accurate enough routine calls  other routines         */
-/***************************************************************************/
-
-static inline double
-__always_inline
-bsloww1 (double x, double dx, double orig, int n)
-{
-  double w[2], cor, res;
-
-  res = do_sin_slow (x, dx, 1.1e-24, &cor);
-  if (res == res + cor)
-    return (x > 0) ? res : -res;
-
-  dx = (x > 0) ? dx : -dx;
-  __dubsin (fabs (x), dx, w);
-
-  cor = 1.000000005 * w[1] + __copysign (1.1e-24, w[1]);
-
-  if (w[0] == w[0] + cor)
-    return __copysign (w[0], x);
-
-  return (n & 1) ? __mpcos (orig, 0, true) : __mpsin (orig, 0, true);
-}
-
-/***************************************************************************/
-/*  Routine compute sin(x+dx)  or cos(x+dx) (Double-Length number) where x  */
-/* in second or fourth quarter of unit circle.Routine receive also  the     */
-/* original value and quarter(n= 1or 3)of x for computing error of result.  */
-/* And if result not accurate enough routine calls  other routines          */
-/***************************************************************************/
-
-static inline double
-__always_inline
-bsloww2 (double x, double dx, double orig, int n)
-{
-  double w[2], cor, res;
-
-  res = do_cos_slow (x, dx, 1.1e-24, &cor);
-  if (res == res + cor)
-    return (n & 2) ? -res : res;
-
-  dx = (x > 0) ? dx : -dx;
-  __docos (fabs (x), dx, w);
-
-  cor = 1.000000005 * w[1] + __copysign (1.1e-24, w[1]);
-
-  if (w[0] == w[0] + cor)
-    return (n & 2) ? -w[0] : w[0];
-
-  return (n & 1) ? __mpsin (orig, 0, true) : __mpcos (orig, 0, true);
-}
-
-/************************************************************************/
-/*  Routine compute cos(x) for  2^-27 < |x|< 0.25 by  Taylor with more   */
-/* precision  and if still doesn't accurate enough by mpcos   or docos  */
-/************************************************************************/
-
-static inline double
-__always_inline
-cslow2 (double x)
-{
-  double w[2], cor, res;
-
-  res = do_cos_slow (x, 0, 0, &cor);
-  if (res == res + cor)
-    return res;
-
-  __docos (fabs (x), 0, w);
-  if (w[0] == w[0] + 1.000000005 * w[1])
-    return w[0];
-
-  return __mpcos (x, 0, false);
-}
-
 #ifndef __cos
 libm_alias_double (__cos, cos)
 #endif
 #ifndef __sin
 libm_alias_double (__sin, sin)
 #endif
+
+#endif
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/ieee754/dbl-64/s_sincos.c b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/ieee754/dbl-64/s_sincos.c
index e1977ea..c746037 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/ieee754/dbl-64/s_sincos.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/ieee754/dbl-64/s_sincos.c
@@ -23,42 +23,9 @@
 #include <math_private.h>
 #include <libm-alias-double.h>
 
-#define __sin __sin_local
-#define __cos __cos_local
-#define IN_SINCOS 1
+#define IN_SINCOS
 #include "s_sin.c"
 
-/* Consolidated version of reduce_and_compute in s_sin.c that does range
-   reduction only once and computes sin and cos together.  */
-static inline void
-__always_inline
-reduce_and_compute_sincos (double x, double *sinx, double *cosx)
-{
-  double a, da;
-  unsigned int n = __branred (x, &a, &da);
-
-  n = n & 3;
-
-  if (n == 1 || n == 2)
-    {
-      a = -a;
-      da = -da;
-    }
-
-  if (n & 1)
-    {
-      double *temp = cosx;
-      cosx = sinx;
-      sinx = temp;
-    }
-
-  if (a * a < 0.01588)
-    *sinx = bsloww (a, da, x, n);
-  else
-    *sinx = bsloww1 (a, da, x, n);
-  *cosx = bsloww2 (a, da, x, n);
-}
-
 void
 __sincos (double x, double *sinx, double *cosx)
 {
@@ -68,37 +35,62 @@
   SET_RESTORE_ROUND_53BIT (FE_TONEAREST);
 
   u.x = x;
-  k = 0x7fffffff & u.i[HIGH_HALF];
+  k = u.i[HIGH_HALF] & 0x7fffffff;
 
   if (k < 0x400368fd)
     {
-      *sinx = __sin_local (x);
-      *cosx = __cos_local (x);
+      double a, da, y;
+      /* |x| < 2^-27 => cos (x) = 1, sin (x) = x.  */
+      if (k < 0x3e400000)
+	{
+	  if (k < 0x3e500000)
+	    math_check_force_underflow (x);
+	  *sinx = x;
+	  *cosx = 1.0;
+	  return;
+	}
+      /* |x| < 0.855469.  */
+      else if (k < 0x3feb6000)
+	{
+	  *sinx = do_sin (x, 0);
+	  *cosx = do_cos (x, 0);
+	  return;
+	}
+
+      /* |x| < 2.426265.  */
+      y = hp0 - fabs (x);
+      a = y + hp1;
+      da = (y - a) + hp1;
+      *sinx = __copysign (do_cos (a, da), x);
+      *cosx = do_sin (a, da);
       return;
     }
-  if (k < 0x419921FB)
-    {
-      double a, da;
-      int4 n = reduce_sincos_1 (x, &a, &da);
-
-      *sinx = do_sincos_1 (a, da, x, n, false);
-      *cosx = do_sincos_1 (a, da, x, n, true);
-
-      return;
-    }
-  if (k < 0x42F00000)
-    {
-      double a, da;
-      int4 n = reduce_sincos_2 (x, &a, &da);
-
-      *sinx = do_sincos_2 (a, da, x, n, false);
-      *cosx = do_sincos_2 (a, da, x, n, true);
-
-      return;
-    }
+  /* |x| < 2^1024.  */
   if (k < 0x7ff00000)
     {
-      reduce_and_compute_sincos (x, sinx, cosx);
+      double a, da, xx;
+      unsigned int n;
+
+      /* If |x| < 105414350 use simple range reduction.  */
+      n = k < 0x419921FB ? reduce_sincos (x, &a, &da) : __branred (x, &a, &da);
+      n = n & 3;
+
+      if (n == 1 || n == 2)
+	{
+	  a = -a;
+	  da = -da;
+	}
+
+      if (n & 1)
+	{
+	  double *temp = cosx;
+	  cosx = sinx;
+	  sinx = temp;
+	}
+
+      *sinx = do_sin (a, da);
+      xx = do_cos (a, da);
+      *cosx = (n & 2) ? -xx : xx;
       return;
     }
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/ieee754/ldbl-96/Makefile b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/ieee754/ldbl-96/Makefile
index 790f670..daa2753 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/ieee754/ldbl-96/Makefile
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/ieee754/ldbl-96/Makefile
@@ -17,5 +17,8 @@
 # <http://www.gnu.org/licenses/>.
 
 ifeq ($(subdir),math)
-tests += test-canonical-ldbl-96 test-totalorderl-ldbl-96
+tests += test-canonical-ldbl-96 test-totalorderl-ldbl-96 test-sinl-pseudo
+ifeq ($(have-ssp),yes)
+CFLAGS-test-sinl-pseudo.c += -fstack-protector-all
 endif
+endif # $(subdir) == math
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/ieee754/ldbl-96/e_rem_pio2l.c b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/ieee754/ldbl-96/e_rem_pio2l.c
index f67805f..c2ee56e 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/ieee754/ldbl-96/e_rem_pio2l.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/ieee754/ldbl-96/e_rem_pio2l.c
@@ -210,6 +210,18 @@
       return 0;
     }
 
+  if ((i0 & 0x80000000) == 0)
+    {
+      /* Pseudo-zero and unnormal representations are not valid
+	 representations of long double.  We need to avoid stack
+	 corruption in __kernel_rem_pio2, which expects input in a
+	 particular normal form, but those representations do not need
+	 to be consistently handled like any particular floating-point
+	 value.  */
+      y[1] = y[0] = __builtin_nanl ("");
+      return 0;
+    }
+
   /* Split the 64 bits of the mantissa into three 24-bit integers
      stored in a double array.  */
   exp = j0 - 23;
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/ieee754/ldbl-96/test-sinl-pseudo.c b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/ieee754/ldbl-96/test-sinl-pseudo.c
new file mode 100644
index 0000000..f59b977
--- /dev/null
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/ieee754/ldbl-96/test-sinl-pseudo.c
@@ -0,0 +1,41 @@
+/* Test sinl for pseudo-zeros and unnormals for ldbl-96 (bug 25487).
+   Copyright (C) 2020 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <math_ldbl.h>
+#include <stdint.h>
+
+static int
+do_test (void)
+{
+  for (int i = 0; i < 64; i++)
+    {
+      uint64_t sig = i == 63 ? 0 : 1ULL << i;
+      long double ld;
+      SET_LDOUBLE_WORDS (ld, 0x4141,
+			 sig >> 32, sig & 0xffffffffULL);
+      /* The requirement is that no stack overflow occurs when the
+	 pseudo-zero or unnormal goes through range reduction.  */
+      volatile long double ldr;
+      ldr = sinl (ld);
+      (void) ldr;
+    }
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/mach/hurd/xmknodat.c b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/mach/hurd/xmknodat.c
index 40d86aa..e4e866c 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/mach/hurd/xmknodat.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/mach/hurd/xmknodat.c
@@ -81,9 +81,9 @@
 
       bp = buf + sizeof (buf);
       *--bp = '\0';
-      bp = _itoa (minor (*dev), bp, 10, 0);
+      bp = _itoa (__gnu_dev_minor (*dev), bp, 10, 0);
       *--bp = '\0';
-      bp = _itoa (major (*dev), bp, 10, 0);
+      bp = _itoa (__gnu_dev_major (*dev), bp, 10, 0);
       memcpy (bp - len, translator, len);
       translator = bp - len;
       len = buf + sizeof (buf) - translator;
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/mod-tlsopt-powerpc.c b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/mod-tlsopt-powerpc.c
index ee0db12..2a82e53 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/mod-tlsopt-powerpc.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/mod-tlsopt-powerpc.c
@@ -1,11 +1,9 @@
 /* shared library to test for __tls_get_addr optimization.  */
 #include <stdio.h>
 
-#include "../../elf/tls-macros.h"
 #include "dl-tls.h"
 
-/* common 'int' variable in TLS.  */
-COMMON_INT_DEF(foo);
+__thread int foo __attribute__ ((tls_model("global-dynamic")));
 
 
 int
@@ -14,7 +12,7 @@
   int result = 0;
 
   /* Get variable using general dynamic model.  */
-  int *ap = TLS_GD (foo);
+  int *ap = &foo;
   if (*ap != 0)
     {
       printf ("foo = %d\n", *ap);
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/a2/memcpy.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/a2/memcpy.S
index c07621a..196b6d9 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/a2/memcpy.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/a2/memcpy.S
@@ -22,7 +22,7 @@
 #define PREFETCH_AHEAD 4        /* no cache lines SRC prefetching ahead  */
 #define ZERO_AHEAD 2            /* no cache lines DST zeroing ahead  */
 
-	DOT_MACHINE ("a2")
+	.machine  a2
 EALIGN (memcpy, 5, 0)
 	CALL_MCOUNT
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/fpu/__longjmp-common.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/fpu/__longjmp-common.S
index 575c539..7a4b068 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/fpu/__longjmp-common.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/fpu/__longjmp-common.S
@@ -25,7 +25,7 @@
 # include <jmpbuf-offsets.h>
 #endif
 
-	DOT_MACHINE ("altivec")
+	.machine	"altivec"
 ENTRY (__longjmp_symbol)
 #ifndef __NO_VMX__
 # ifdef PIC
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/fpu/s_isnan.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/fpu/s_isnan.S
index 7cae65a..c0cec82 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/fpu/s_isnan.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/fpu/s_isnan.S
@@ -20,7 +20,7 @@
 #include <math_ldbl_opt.h>
 
 /* int __isnan(x)  */
-	DOT_MACHINE ("power4")
+	.machine power4
 EALIGN (__isnan, 4, 0)
 	mffs	fp0
 	mtfsb0	4*cr6+lt /* reset_fpscr_bit (FPSCR_VE) */
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/fpu/setjmp-common.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/fpu/setjmp-common.S
index 036744e..e2d781e 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/fpu/setjmp-common.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/fpu/setjmp-common.S
@@ -25,7 +25,7 @@
 # include <jmpbuf-offsets.h>
 #endif
 
-	DOT_MACHINE ("altivec")
+	.machine	"altivec"
 ENTRY (__sigsetjmp_symbol)
 
 #ifdef PTR_MANGLE
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power4/memcmp.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power4/memcmp.S
index 9e9c941..cc4bd32 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power4/memcmp.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power4/memcmp.S
@@ -22,7 +22,7 @@
 		    const char *s2 [r4],
 		    size_t size [r5])  */
 
-	DOT_MACHINE ("power4")
+	.machine power4
 EALIGN (memcmp, 4, 0)
 	CALL_MCOUNT
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power4/memcpy.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power4/memcpy.S
index 4d1a6a4..44866d6 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power4/memcpy.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power4/memcpy.S
@@ -31,7 +31,7 @@
    possible when both source and destination are word aligned.
    Each case has an optimized unrolled loop.   */
 
-	DOT_MACHINE ("power4")
+	.machine power4
 EALIGN (memcpy, 5, 0)
 	CALL_MCOUNT
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power4/memset.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power4/memset.S
index 8d738ac..7e8249e 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power4/memset.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power4/memset.S
@@ -25,7 +25,7 @@
    cache line (1024 bits). There is a special case for setting cache lines
    to 0, to take advantage of the dcbz instruction.  */
 
-	DOT_MACHINE ("power4")
+	.machine power4
 EALIGN (memset, 5, 0)
 	CALL_MCOUNT
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_ceil.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_ceil.S
index 0f27ead..356c7a7 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_ceil.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_ceil.S
@@ -20,7 +20,7 @@
 #include <math_ldbl_opt.h>
 #include <libm-alias-double.h>
 
-	DOT_MACHINE ("power5")
+	.machine	"power5"
 EALIGN (__ceil, 4, 0)
 	frip	fp1, fp1
 	blr
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_ceilf.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_ceilf.S
index 8f86902..a0bcda1 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_ceilf.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_ceilf.S
@@ -19,7 +19,7 @@
 #include <sysdep.h>
 #include <libm-alias-float.h>
 
-	DOT_MACHINE	("power5")
+	.machine	"power5"
 EALIGN (__ceilf, 4, 0)
 	frip	fp1, fp1	/* The rounding instructions are double.  */
 	frsp	fp1, fp1	/* But we need to set ooverflow for float.  */
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_floor.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_floor.S
index b270634..e8a15f6 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_floor.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_floor.S
@@ -20,7 +20,7 @@
 #include <math_ldbl_opt.h>
 #include <libm-alias-double.h>
 
-	DOT_MACHINE ("power5")
+	.machine	"power5"
 EALIGN (__floor, 4, 0)
 	frim	fp1, fp1
 	blr
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_floorf.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_floorf.S
index 8e346f0..385c40c 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_floorf.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_floorf.S
@@ -19,7 +19,7 @@
 #include <sysdep.h>
 #include <libm-alias-float.h>
 
-	DOT_MACHINE ("power5")
+	.machine	"power5"
 EALIGN (__floorf, 4, 0)
 	frim	fp1, fp1	/* The rounding instructions are double.  */
 	frsp	fp1, fp1	/* But we need to set ooverflow for float.  */
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_llround.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_llround.S
index b9e87c3..c70c0bd 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_llround.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_llround.S
@@ -31,7 +31,7 @@
    instruction before we use the Floating Convert to Integer Word with
    round to zero instruction.  */
 
-	DOT_MACHINE ("power5")
+	.machine	"power5"
 ENTRY (__llround)
 	stwu    r1,-16(r1)
 	cfi_adjust_cfa_offset (16)
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_lround.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_lround.S
index da81b51..09fa022 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_lround.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_lround.S
@@ -30,7 +30,7 @@
    instruction before we use the Floating Convert to Integer Word with
    round to zero instruction.  */
 
-	DOT_MACHINE ("power5")
+	.machine	"power5"
 ENTRY (__lround)
 	stwu    r1,-16(r1)
 	cfi_adjust_cfa_offset (16)
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_round.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_round.S
index 522d094..36c9bd3 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_round.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_round.S
@@ -20,7 +20,7 @@
 #include <math_ldbl_opt.h>
 #include <libm-alias-double.h>
 
-	DOT_MACHINE ("power5")
+	.machine	"power5"
 EALIGN (__round, 4, 0)
 	frin	fp1, fp1
 	blr
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_roundf.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_roundf.S
index 093c86d..c720e77 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_roundf.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_roundf.S
@@ -19,7 +19,7 @@
 #include <sysdep.h>
 #include <libm-alias-float.h>
 
-	DOT_MACHINE ("power5")
+	.machine	"power5"
 EALIGN (__roundf, 4, 0)
 	frin	fp1, fp1	/* The rounding instructions are double.  */
 	frsp	fp1, fp1	/* But we need to set ooverflow for float.  */
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_trunc.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_trunc.S
index a4ee979..14007e9 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_trunc.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_trunc.S
@@ -20,7 +20,7 @@
 #include <math_ldbl_opt.h>
 #include <libm-alias-double.h>
 
-	DOT_MACHINE ("power5")
+	.machine	"power5"
 EALIGN (__trunc, 4, 0)
 	friz	fp1, fp1
 	blr
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_truncf.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_truncf.S
index 6f3a52e..092bae7 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_truncf.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5+/fpu/s_truncf.S
@@ -19,7 +19,7 @@
 #include <sysdep.h>
 #include <libm-alias-float.h>
 
-	DOT_MACHINE ("power5")
+	.machine	"power5"
 EALIGN (__truncf, 4, 0)
 	friz	fp1, fp1	/* The rounding instructions are double.  */
 	frsp	fp1, fp1	/* But we need to set ooverflow for float.  */
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5/fpu/s_isnan.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5/fpu/s_isnan.S
index 8cd4a1a..f159454 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5/fpu/s_isnan.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5/fpu/s_isnan.S
@@ -20,7 +20,7 @@
 #include <math_ldbl_opt.h>
 
 /* int __isnan(x)  */
-	DOT_MACHINE ("power5")
+	.machine power5
 EALIGN (__isnan, 4, 0)
 	stwu	r1,-32(r1)
 	cfi_adjust_cfa_offset (32)
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5/fpu/s_isnanf.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5/fpu/s_isnanf.S
index b0e0c0c..c45e456 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5/fpu/s_isnanf.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power5/fpu/s_isnanf.S
@@ -20,7 +20,7 @@
 #include <math_ldbl_opt.h>
 
 /* int __isnanf(x)  */
-	DOT_MACHINE ("power5")
+	.machine power5
 EALIGN (__isnanf, 4, 0)
 	stwu	r1,-32(r1)
 	cfi_adjust_cfa_offset (32)
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6/fpu/s_copysign.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6/fpu/s_copysign.S
index d149768..6069b29 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6/fpu/s_copysign.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6/fpu/s_copysign.S
@@ -28,7 +28,7 @@
 
 	.section    ".text"
 	.type	    __copysign, @function
-	DOT_MACHINE ("power6")
+	.machine    power6
 EALIGN (__copysign, 4, 0)
 	CALL_MCOUNT
 	fcpsgn	fp1,fp2,fp1
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6/fpu/s_isnan.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6/fpu/s_isnan.S
index 90df85f..cecc7c8 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6/fpu/s_isnan.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6/fpu/s_isnan.S
@@ -20,7 +20,7 @@
 #include <math_ldbl_opt.h>
 
 /* int __isnan(x)  */
-	DOT_MACHINE ("power6")
+	.machine power6
 EALIGN (__isnan, 4, 0)
 	stwu	r1,-32(r1)
 	cfi_adjust_cfa_offset (32)
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6/fpu/s_isnanf.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6/fpu/s_isnanf.S
index 0a57295..8faac97 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6/fpu/s_isnanf.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6/fpu/s_isnanf.S
@@ -20,7 +20,7 @@
 #include <math_ldbl_opt.h>
 
 /* int __isnanf(x)  */
-	DOT_MACHINE ("power6")
+	.machine power6
 EALIGN (__isnanf, 4, 0)
 	stwu	r1,-32(r1)
 	cfi_adjust_cfa_offset (32)
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6/fpu/s_llround.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6/fpu/s_llround.S
index dadd3a1..fc22a55 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6/fpu/s_llround.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6/fpu/s_llround.S
@@ -31,7 +31,7 @@
    instruction before we use the Floating Convert to Integer Word with
    round to zero instruction.  */
 
-	DOT_MACHINE ("power5")
+	.machine	"power5"
 ENTRY (__llround)
 	stwu    r1,-16(r1)
 	cfi_adjust_cfa_offset (16)
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6/memcpy.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6/memcpy.S
index fb7d2d4..3ca26a2 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6/memcpy.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6/memcpy.S
@@ -31,7 +31,7 @@
    possible when both source and destination are word aligned.
    Each case has an optimized unrolled loop.   */
 
-	DOT_MACHINE ("power6")
+	.machine power6
 EALIGN (memcpy, 5, 0)
 	CALL_MCOUNT
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6/memset.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6/memset.S
index cb1733c..8f5e862 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6/memset.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6/memset.S
@@ -25,7 +25,7 @@
    cache line (1024 bits). There is a special case for setting cache lines
    to 0, to take advantage of the dcbz instruction.  */
 
-	DOT_MACHINE ("power6")
+	.machine power6
 EALIGN (memset, 7, 0)
 	CALL_MCOUNT
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6x/fpu/s_lrint.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6x/fpu/s_lrint.S
index 9f11aa4..ad4a010 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6x/fpu/s_lrint.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6x/fpu/s_lrint.S
@@ -21,7 +21,7 @@
 #include <libm-alias-float.h>
 #include <libm-alias-double.h>
 
-	DOT_MACHINE ("power6")
+	.machine	"power6"
 /* long int[r3] __lrint (double x[fp1])  */
 ENTRY (__lrint)
 	fctiw	fp13,fp1
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6x/fpu/s_lround.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6x/fpu/s_lround.S
index 587852e..5131d11 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6x/fpu/s_lround.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power6x/fpu/s_lround.S
@@ -31,7 +31,7 @@
    instruction before we use the Floating Convert to Integer Word with
    round to zero instruction.  */
 
-	DOT_MACHINE ("power6")
+	.machine	"power6"
 ENTRY (__lround)
 	frin	fp2,fp1	/* Pre-round +-0.5.  */
 	fctiwz	fp3,fp2	/* Convert To Integer Word lround toward 0.  */
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/fpu/s_finite.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/fpu/s_finite.S
index 324c9e2..793cf0d 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/fpu/s_finite.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/fpu/s_finite.S
@@ -28,7 +28,7 @@
 
 	.section    ".text"
 	.type	    __finite, @function
-	DOT_MACHINE ("power7")
+	.machine    power7
 ENTRY (__finite)
 #ifdef SHARED
 	mflr	r11
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/fpu/s_isinf.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/fpu/s_isinf.S
index b883582..400fec7 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/fpu/s_isinf.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/fpu/s_isinf.S
@@ -28,7 +28,7 @@
 
 	.section    ".text"
 	.type	    __isinf, @function
-	DOT_MACHINE ("power7")
+	.machine    power7
 ENTRY (__isinf)
 #ifdef SHARED
 	mflr	r11
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/fpu/s_isnan.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/fpu/s_isnan.S
index 7de5a0c..b8bb0e6 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/fpu/s_isnan.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/fpu/s_isnan.S
@@ -28,7 +28,7 @@
 
 	.section    ".text"
 	.type	    __isnan, @function
-	DOT_MACHINE ("power7")
+	.machine    power7
 ENTRY (__isnan)
 #ifdef SHARED
 	mflr	r11
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/memchr.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/memchr.S
index 349b250..ec78709 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/memchr.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/memchr.S
@@ -20,7 +20,7 @@
 #include <sysdep.h>
 
 /* int [r3] memchr (char *s [r3], int byte [r4], int size [r5])  */
-	DOT_MACHINE ("power7")
+	.machine  power7
 ENTRY (__memchr)
 	CALL_MCOUNT
 	dcbt	0,r3
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/memcmp.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/memcmp.S
index 84cfa9a..8c1a00d 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/memcmp.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/memcmp.S
@@ -22,7 +22,7 @@
 		    const char *s2 [r4],
 		    size_t size [r5])  */
 
-	DOT_MACHINE ("power7")
+	.machine power7
 EALIGN (memcmp, 4, 0)
 	CALL_MCOUNT
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/memcpy.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/memcpy.S
index f4ca5c4..76b1c53 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/memcpy.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/memcpy.S
@@ -22,7 +22,7 @@
 /* void * [r3] memcpy (void *dst [r3], void *src [r4], size_t len [r5]);
    Returns 'dst'.  */
 
-	DOT_MACHINE ("power7")
+	.machine  power7
 EALIGN (memcpy, 5, 0)
 	CALL_MCOUNT
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/mempcpy.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/mempcpy.S
index d196e83..1a3f4eb 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/mempcpy.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/mempcpy.S
@@ -22,7 +22,7 @@
 /* void * [r3] __mempcpy (void *dst [r3], void *src [r4], size_t len [r5]);
 	Returns 'dst' + 'len'.  */
 
-	DOT_MACHINE ("power7")
+	.machine  power7
 EALIGN (__mempcpy, 5, 0)
 	CALL_MCOUNT
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/memrchr.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/memrchr.S
index 5c6ec53..aedae95 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/memrchr.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/memrchr.S
@@ -20,7 +20,7 @@
 #include <sysdep.h>
 
 /* int [r3] memrchr (char *s [r3], int byte [r4], int size [r5])  */
-	DOT_MACHINE ("power7")
+	.machine  power7
 ENTRY (__memrchr)
 	CALL_MCOUNT
 	add	r7,r3,r5      /* Calculate the last acceptable address.  */
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/memset.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/memset.S
index 8bec719..26fa736 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/memset.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/memset.S
@@ -22,7 +22,7 @@
 /* void * [r3] memset (void *s [r3], int c [r4], size_t n [r5]));
    Returns 's'.  */
 
-	DOT_MACHINE ("power7")
+	.machine  power7
 EALIGN (memset, 5, 0)
 	CALL_MCOUNT
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/rawmemchr.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/rawmemchr.S
index e42d39c..a886e13 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/rawmemchr.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/rawmemchr.S
@@ -20,7 +20,7 @@
 #include <sysdep.h>
 
 /* int [r3] rawmemchr (void *s [r3], int c [r4])  */
-	DOT_MACHINE ("power7")
+	.machine  power7
 ENTRY (__rawmemchr)
 	CALL_MCOUNT
 	dcbt	0,r3
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/strchr.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/strchr.S
index bf247f9..54bb4ad 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/strchr.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/strchr.S
@@ -20,7 +20,7 @@
 #include <sysdep.h>
 
 /* int [r3] strchr (char *s [r3], int c [r4])  */
-	DOT_MACHINE ("power7")
+	.machine  power7
 ENTRY (strchr)
 	CALL_MCOUNT
 	dcbt	0,r3
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/strchrnul.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/strchrnul.S
index 1a99b6a..634bf56 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/strchrnul.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/strchrnul.S
@@ -20,7 +20,7 @@
 #include <sysdep.h>
 
 /* int [r3] strchrnul (char *s [r3], int c [r4])  */
-	DOT_MACHINE ("power7")
+	.machine  power7
 ENTRY (__strchrnul)
 	CALL_MCOUNT
 	dcbt	0,r3
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/strlen.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/strlen.S
index 4566e51..f7d1ebb 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/strlen.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/strlen.S
@@ -20,7 +20,7 @@
 #include <sysdep.h>
 
 /* int [r3] strlen (char *s [r3])  */
-	DOT_MACHINE ("power7")
+	.machine  power7
 ENTRY (strlen)
 	CALL_MCOUNT
 	dcbt	0,r3
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/strnlen.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/strnlen.S
index 03ee9bd..2f28acc 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/strnlen.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc32/power7/strnlen.S
@@ -20,7 +20,7 @@
 #include <sysdep.h>
 
 /* int [r3] strnlen (char *s [r3], int size [r4])  */
-	DOT_MACHINE ("power7")
+	.machine  power7
 ENTRY (__strnlen)
 	CALL_MCOUNT
 	dcbt	0,r3
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/__longjmp-common.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/__longjmp-common.S
index 718d601..0e10b8d 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/__longjmp-common.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/__longjmp-common.S
@@ -43,7 +43,7 @@
 	.section ".text"
 #endif
 
-	DOT_MACHINE ("altivec")
+	.machine	"altivec"
 ENTRY (__longjmp)
 	CALL_MCOUNT 2
 #ifndef __NO_VMX__
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/a2/memcpy.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/a2/memcpy.S
index d831404..488ab6d 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/a2/memcpy.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/a2/memcpy.S
@@ -33,7 +33,7 @@
 	.align 2
 
 
-	DOT_MACHINE ("a2")
+	.machine  a2
 ENTRY (MEMCPY, 5)
 	CALL_MCOUNT 3
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/dl-trampoline.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/dl-trampoline.S
index abff3d5..aa141dc 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/dl-trampoline.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/dl-trampoline.S
@@ -189,7 +189,7 @@
 # endif
 	.section ".text"
 
-	DOT_MACHINE ("altivec")
+	.machine	"altivec"
 /* On entry r0 contains the index of the PLT entry we need to fixup
    and r11 contains the link_map (from PLT0+16).  The link_map becomes
    parm1 (r3) and the index (r0) needs to be converted to an offset
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/fpu/s_isnan.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/fpu/s_isnan.S
index e4d87f2..b7d9f08 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/fpu/s_isnan.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/fpu/s_isnan.S
@@ -20,7 +20,7 @@
 #include <math_ldbl_opt.h>
 
 /* int __isnan(x)  */
-	DOT_MACHINE ("power4")
+	.machine power4
 ENTRY_TOCLESS (__isnan, 4)
 	CALL_MCOUNT 0
 	mffs	fp0
@@ -57,4 +57,3 @@
 compat_symbol (libc, isnan, isnanl, GLIBC_2_0);
 # endif
 #endif
-
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/multiarch/memcpy-power8-cached.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/multiarch/memcpy-power8-cached.S
index 6ce79d7..6b69e57 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/multiarch/memcpy-power8-cached.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/multiarch/memcpy-power8-cached.S
@@ -22,7 +22,7 @@
 /* __ptr_t [r3] memcpy (__ptr_t dst [r3], __ptr_t src [r4], size_t len [r5]);
    Returns 'dst'.  */
 
-	DOT_MACHINE ("power8")
+	.machine power8
 ENTRY_TOCLESS (__memcpy_power8_cached, 5)
 	CALL_MCOUNT 3
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power4/memcmp.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power4/memcmp.S
index 1865778..e5319f1 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power4/memcmp.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power4/memcmp.S
@@ -26,7 +26,7 @@
 # define MEMCMP memcmp
 #endif
 
-	DOT_MACHINE ("power4")
+	.machine power4
 ENTRY_TOCLESS (MEMCMP, 4)
 	CALL_MCOUNT 3
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power4/memcpy.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power4/memcpy.S
index e3196c0..ce07494 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power4/memcpy.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power4/memcpy.S
@@ -36,7 +36,7 @@
 #ifndef MEMCPY
 # define MEMCPY memcpy
 #endif
-	DOT_MACHINE ("power4")
+	.machine power4
 ENTRY_TOCLESS (MEMCPY, 5)
 	CALL_MCOUNT 3
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power4/memset.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power4/memset.S
index b64e2f1..a8f0dfa 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power4/memset.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power4/memset.S
@@ -28,7 +28,7 @@
 #ifndef MEMSET
 # define MEMSET memset
 #endif
-	DOT_MACHINE ("power4")
+	.machine power4
 ENTRY_TOCLESS (MEMSET, 5)
 	CALL_MCOUNT 3
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_ceil.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_ceil.S
index 3e8f404..e500932 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_ceil.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_ceil.S
@@ -20,7 +20,7 @@
 #include <math_ldbl_opt.h>
 #include <libm-alias-double.h>
 
-	DOT_MACHINE ("power5")
+	.machine	"power5"
 ENTRY_TOCLESS (__ceil, 4)
 	CALL_MCOUNT 0
 	frip	fp1, fp1
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_ceilf.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_ceilf.S
index 55da0eb..d0b2118 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_ceilf.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_ceilf.S
@@ -19,7 +19,7 @@
 #include <sysdep.h>
 #include <libm-alias-float.h>
 
-	DOT_MACHINE ("power5")
+	.machine	"power5"
 ENTRY_TOCLESS (__ceilf, 4)
 	CALL_MCOUNT 0
 	frip	fp1, fp1	/* The rounding instructions are double.  */
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_floor.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_floor.S
index ae25a18..9b9eb15 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_floor.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_floor.S
@@ -20,7 +20,7 @@
 #include <math_ldbl_opt.h>
 #include <libm-alias-double.h>
 
-	DOT_MACHINE ("power5")
+	.machine	"power5"
 ENTRY_TOCLESS (__floor, 4)
 	CALL_MCOUNT 0
 	frim	fp1, fp1
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_floorf.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_floorf.S
index bc17c01..790edbd 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_floorf.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_floorf.S
@@ -19,7 +19,7 @@
 #include <sysdep.h>
 #include <libm-alias-float.h>
 
-	DOT_MACHINE ("power5")
+	.machine	"power5"
 ENTRY_TOCLESS (__floorf, 4)
 	CALL_MCOUNT 0
 	frim	fp1, fp1	/* The rounding instructions are double.  */
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_llround.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_llround.S
index c761081..9fc4ec4 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_llround.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_llround.S
@@ -31,7 +31,7 @@
    instruction before we use Floating Convert to Integer Word with
    round to zero instruction.  */
 
-	DOT_MACHINE	("power5")
+	.machine	"power5"
 ENTRY_TOCLESS (__llround, 4)
 	CALL_MCOUNT 0
 	frin	fp2, fp1	/* Round to nearest +-0.5.  */
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_round.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_round.S
index cc211fd..ed4df25 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_round.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_round.S
@@ -20,7 +20,7 @@
 #include <math_ldbl_opt.h>
 #include <libm-alias-double.h>
 
-	DOT_MACHINE	("power5")
+	.machine	"power5"
 ENTRY_TOCLESS (__round, 4)
 	CALL_MCOUNT 0
 	frin	fp1, fp1
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_roundf.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_roundf.S
index db677e7..32df460 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_roundf.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_roundf.S
@@ -19,7 +19,7 @@
 #include <sysdep.h>
 #include <libm-alias-float.h>
 
-	DOT_MACHINE ("power5")
+	.machine	"power5"
 ENTRY_TOCLESS (__roundf, 4)
 	CALL_MCOUNT 0
 	frin	fp1, fp1	/* The rounding instructions are double.  */
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_trunc.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_trunc.S
index 35c136c..a457665 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_trunc.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_trunc.S
@@ -20,7 +20,7 @@
 #include <math_ldbl_opt.h>
 #include <libm-alias-double.h>
 
-	DOT_MACHINE ("power5")
+	.machine	"power5"
 ENTRY_TOCLESS (__trunc, 4)
 	CALL_MCOUNT 0
 	friz	fp1, fp1
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_truncf.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_truncf.S
index 7581ba7..f06f54f 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_truncf.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5+/fpu/s_truncf.S
@@ -19,7 +19,7 @@
 #include <sysdep.h>
 #include <libm-alias-float.h>
 
-	DOT_MACHINE	("power5")
+	.machine	"power5"
 ENTRY_TOCLESS (__truncf, 4)
 	CALL_MCOUNT 0
 	friz	fp1, fp1	/* The rounding instructions are double.  */
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5/fpu/s_isnan.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5/fpu/s_isnan.S
index 2df644b..83b5657 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5/fpu/s_isnan.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power5/fpu/s_isnan.S
@@ -20,7 +20,7 @@
 #include <math_ldbl_opt.h>
 
 /* int __isnan(x)  */
-	DOT_MACHINE ("power5")
+	.machine power5
 ENTRY_TOCLESS (__isnan, 4)
 	CALL_MCOUNT 0
 	stfd	fp1,-8(r1)	/* copy FPR to GPR */
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power6/fpu/s_copysign.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power6/fpu/s_copysign.S
index da3f2f2..03e8bed 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power6/fpu/s_copysign.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power6/fpu/s_copysign.S
@@ -28,7 +28,7 @@
 
 	.section    ".text"
 	.type	    __copysign, @function
-	DOT_MACHINE ("power6")
+	.machine    power6
 ENTRY_TOCLESS (__copysign, 4)
 	CALL_MCOUNT 0
 	fcpsgn	fp1,fp2,fp1
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power6/fpu/s_isnan.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power6/fpu/s_isnan.S
index 26d31f3..6296c94 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power6/fpu/s_isnan.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power6/fpu/s_isnan.S
@@ -20,7 +20,7 @@
 #include <math_ldbl_opt.h>
 
 /* int __isnan(x)  */
-	DOT_MACHINE ("power6")
+	.machine power6
 ENTRY_TOCLESS (__isnan, 4)
 	CALL_MCOUNT 0
 	stfd	fp1,-8(r1)	/* copy FPR to GPR */
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power6/memcpy.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power6/memcpy.S
index 90565f1..9356867 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power6/memcpy.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power6/memcpy.S
@@ -43,7 +43,7 @@
 #ifndef MEMCPY
 # define MEMCPY memcpy
 #endif
-	DOT_MACHINE	("power6")
+	.machine	"power6"
 ENTRY_TOCLESS (MEMCPY, 7)
 	CALL_MCOUNT 3
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power6/memset.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power6/memset.S
index e08da4d..3901e33 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power6/memset.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power6/memset.S
@@ -28,7 +28,7 @@
 #ifndef MEMSET
 # define MEMSET memset
 #endif
-	DOT_MACHINE ("power6")
+	.machine power6
 ENTRY_TOCLESS (MEMSET, 7)
 	CALL_MCOUNT 3
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power6x/fpu/s_isnan.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power6x/fpu/s_isnan.S
index 7e8e7d2..96d0695 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power6x/fpu/s_isnan.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power6x/fpu/s_isnan.S
@@ -20,7 +20,7 @@
 #include <math_ldbl_opt.h>
 
 /* int __isnan(x)  */
-	DOT_MACHINE ("power6")
+	.machine power6
 ENTRY_TOCLESS (__isnan, 4)
 	CALL_MCOUNT 0
 	mftgpr	r4,fp1		/* copy FPR to GPR */
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power6x/fpu/s_llrint.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power6x/fpu/s_llrint.S
index ff61c39..36980be 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power6x/fpu/s_llrint.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power6x/fpu/s_llrint.S
@@ -21,7 +21,7 @@
 #include <libm-alias-float.h>
 #include <libm-alias-double.h>
 
-	DOT_MACHINE	("power6")
+	.machine	"power6"
 /* long long int[r3] __llrint (double x[fp1])  */
 ENTRY_TOCLESS (__llrint)
 	CALL_MCOUNT 0
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power6x/fpu/s_llround.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power6x/fpu/s_llround.S
index ca26028..605f55e 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power6x/fpu/s_llround.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power6x/fpu/s_llround.S
@@ -31,7 +31,7 @@
    instruction before we use Floating Convert to Integer Word with
    round to zero instruction.  */
 
-	DOT_MACHINE	("power6")
+	.machine	"power6"
 ENTRY_TOCLESS (__llround)
 	CALL_MCOUNT 0
 	frin	fp2,fp1	/* Round to nearest +-0.5.  */
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/fpu/s_finite.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/fpu/s_finite.S
index 2ef61cf..78e3bde 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/fpu/s_finite.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/fpu/s_finite.S
@@ -26,7 +26,7 @@
 	.tc	    FD_ONE[TC],0x3ff0000000000000
 	.section    ".text"
 	.type	    __finite, @function
-	DOT_MACHINE ("power7")
+	.machine    power7
 ENTRY (__finite, 4)
 	CALL_MCOUNT 0
 	lfd     fp0,.LC0@toc(r2)
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/fpu/s_isinf.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/fpu/s_isinf.S
index 4f91df3..0fbb99d 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/fpu/s_isinf.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/fpu/s_isinf.S
@@ -26,7 +26,7 @@
 	.tc	    FD_ONE[TC],0x3ff0000000000000
 	.section    ".text"
 	.type	    __isinf, @function
-	DOT_MACHINE ("power7")
+	.machine    power7
 ENTRY (__isinf, 4)
 	CALL_MCOUNT 0
 	lfd	fp0,.LC0@toc(r2)
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/fpu/s_isnan.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/fpu/s_isnan.S
index 7e2aea3..3f675d7 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/fpu/s_isnan.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/fpu/s_isnan.S
@@ -26,7 +26,7 @@
 	.tc	    FD_ONE[TC],0x3ff0000000000000
 	.section    ".text"
 	.type	    __isnan, @function
-	DOT_MACHINE ("power7")
+	.machine    power7
 ENTRY (__isnan, 4)
 	CALL_MCOUNT 0
 	lfd	fp0,.LC0@toc(r2)
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/memchr.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/memchr.S
index 01d3db1..9ab5ab2 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/memchr.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/memchr.S
@@ -24,7 +24,7 @@
 #ifndef MEMCHR
 # define MEMCHR __memchr
 #endif
-	DOT_MACHINE ("power7")
+	.machine  power7
 ENTRY_TOCLESS (MEMCHR)
 	CALL_MCOUNT 3
 	dcbt	0,r3
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/memcmp.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/memcmp.S
index 12d62a6..91acdfb 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/memcmp.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/memcmp.S
@@ -24,7 +24,7 @@
 #ifndef MEMCMP
 # define MEMCMP memcmp
 #endif
-	DOT_MACHINE ("power7")
+	.machine power7
 ENTRY_TOCLESS (MEMCMP, 4)
 	CALL_MCOUNT 3
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/memcpy.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/memcpy.S
index 25755b0..3d8629c 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/memcpy.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/memcpy.S
@@ -31,7 +31,7 @@
 #define src 4
 #define cnt 5
 
-	DOT_MACHINE ("power7")
+	.machine power7
 ENTRY_TOCLESS (MEMCPY, 5)
 	CALL_MCOUNT 3
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/memmove.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/memmove.S
index 941dbae..b7f3dc2 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/memmove.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/memmove.S
@@ -30,7 +30,7 @@
 #ifndef MEMMOVE
 # define MEMMOVE memmove
 #endif
-	DOT_MACHINE ("power7")
+	.machine power7
 ENTRY_TOCLESS (MEMMOVE, 5)
 	CALL_MCOUNT 3
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/mempcpy.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/mempcpy.S
index 8310ae4..7f5a474 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/mempcpy.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/mempcpy.S
@@ -26,7 +26,7 @@
 #ifndef MEMPCPY
 # define MEMPCPY __mempcpy
 #endif
-	DOT_MACHINE ("power7")
+	.machine  power7
 ENTRY_TOCLESS (MEMPCPY, 5)
 	CALL_MCOUNT 3
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/memrchr.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/memrchr.S
index 3d82a9d..583d513 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/memrchr.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/memrchr.S
@@ -24,7 +24,7 @@
 #ifndef MEMRCHR
 # define MEMRCHR __memrchr
 #endif
-	DOT_MACHINE ("power7")
+	.machine  power7
 ENTRY_TOCLESS (MEMRCHR)
 	CALL_MCOUNT 3
 	add	r7,r3,r5      /* Calculate the last acceptable address.  */
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/memset.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/memset.S
index 0433f28..acd0adf 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/memset.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/memset.S
@@ -25,7 +25,7 @@
 #ifndef MEMSET
 # define MEMSET memset
 #endif
-	DOT_MACHINE ("power7")
+	.machine power7
 ENTRY_TOCLESS (MEMSET, 5)
 	CALL_MCOUNT 3
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/rawmemchr.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/rawmemchr.S
index d99d9ec..6ada0eb 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/rawmemchr.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/rawmemchr.S
@@ -24,7 +24,7 @@
 #ifndef RAWMEMCHR
 # define RAWMEMCHR __rawmemchr
 #endif
-	DOT_MACHINE ("power7")
+	.machine  power7
 ENTRY_TOCLESS (RAWMEMCHR)
 	CALL_MCOUNT 2
 	dcbt	0,r3
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strchr.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strchr.S
index 7c42208..da648b2 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strchr.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strchr.S
@@ -24,7 +24,7 @@
 #endif
 
 /* int [r3] strchr (char *s [r3], int c [r4])  */
-	DOT_MACHINE ("power7")
+	.machine  power7
 ENTRY_TOCLESS (STRCHR)
 	CALL_MCOUNT 2
 	dcbt	0,r3
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strchrnul.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strchrnul.S
index 068c3c3..f137174 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strchrnul.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strchrnul.S
@@ -23,7 +23,7 @@
 # define STRCHRNUL __strchrnul
 #endif
 /* int [r3] strchrnul (char *s [r3], int c [r4])  */
-	DOT_MACHINE ("power7")
+	.machine  power7
 ENTRY_TOCLESS (STRCHRNUL)
 	CALL_MCOUNT 2
 	dcbt	0,r3
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strcmp.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strcmp.S
index 7f38527..c3d5ec1 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strcmp.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strcmp.S
@@ -29,7 +29,7 @@
 
 /* int [r3] strcmp (const char *s1 [r3], const char *s2 [r4])  */
 
-	DOT_MACHINE	("power7")
+	.machine	power7
 ENTRY_TOCLESS (STRCMP, 4)
 	CALL_MCOUNT 2
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strlen.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strlen.S
index 394c088..9758089 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strlen.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strlen.S
@@ -24,7 +24,7 @@
 #ifndef STRLEN
 # define STRLEN strlen
 #endif
-	DOT_MACHINE ("power7")
+	.machine  power7
 ENTRY_TOCLESS (STRLEN)
 	CALL_MCOUNT 1
 	dcbt	0,r3
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strncpy.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strncpy.S
index 989a401..1965f82 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strncpy.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strncpy.S
@@ -66,7 +66,7 @@
 # endif
 #endif
 
-	DOT_MACHINE ("power7")
+	.machine  power7
 #ifdef MEMSET_is_local
 ENTRY_TOCLESS (FUNC_NAME, 4)
 #else
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strnlen.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strnlen.S
index 197717b..3097cac 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strnlen.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strnlen.S
@@ -24,7 +24,7 @@
 #endif
 
 /* int [r3] strnlen (char *s [r3], int size [r4])  */
-	DOT_MACHINE ("power7")
+	.machine  power7
 ENTRY_TOCLESS (STRNLEN)
 	CALL_MCOUNT 2
 	dcbt	0,r3
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strrchr.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strrchr.S
index 779eaf2..e47e3d4 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strrchr.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strrchr.S
@@ -24,7 +24,7 @@
 # define STRRCHR strrchr
 #endif
 
-	DOT_MACHINE ("power7")
+	.machine  power7
 ENTRY_TOCLESS (STRRCHR)
 	CALL_MCOUNT 2
 	dcbt	0,r3
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strstr.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strstr.S
index 9d268fe..ac92f9c 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strstr.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power7/strstr.S
@@ -61,7 +61,7 @@
 #endif
 
 #define	FRAMESIZE	(FRAME_MIN_SIZE+32)
-	DOT_MACHINE ("power7")
+	.machine  power7
 /* Can't be ENTRY_TOCLESS due to calling __strstr_ppc which uses r2.  */
 ENTRY (STRSTR, 4)
 	CALL_MCOUNT 2
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/fpu/e_expf.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/fpu/e_expf.S
index 1471de8..32ee832 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/fpu/e_expf.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/fpu/e_expf.S
@@ -54,7 +54,7 @@
 
    float [fp1] expf (float [fp1] x)  */
 
-	DOT_MACHINE ("power8")
+	.machine power8
 ENTRY (__ieee754_expf, 4)
 	addis	DATA_OFFSET,r2,.Lanchor@toc@ha
 	addi	DATA_OFFSET,DATA_OFFSET,.Lanchor@toc@l
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/fpu/s_cosf.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/fpu/s_cosf.S
index e1fb094..af71382 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/fpu/s_cosf.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/fpu/s_cosf.S
@@ -39,7 +39,7 @@
 
 	   float [fp1] cosf (float [fp1] x)  */
 
-	DOT_MACHINE ("power8")
+	.machine power8
 ENTRY (__cosf, 4)
 	addis	r9,r2,L(anchor)@toc@ha
 	addi	r9,r9,L(anchor)@toc@l
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/fpu/s_sinf.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/fpu/s_sinf.S
index 3d820f8..59e613c 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/fpu/s_sinf.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/fpu/s_sinf.S
@@ -39,7 +39,7 @@
 
 	   float [fp1] sinf (float [fp1] x)  */
 
-	DOT_MACHINE ("power8")
+	.machine power8
 ENTRY (__sinf, 4)
 	addis	r9,r2,L(anchor)@toc@ha
 	addi	r9,r9,L(anchor)@toc@l
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/memchr.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/memchr.S
index 02b29da..45ba1b4 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/memchr.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/memchr.S
@@ -34,7 +34,7 @@
 #endif
 /* TODO: change this to .machine power8 when the minimum required binutils
    allows it.  */
-	DOT_MACHINE ("power7")
+	.machine  power7
 ENTRY_TOCLESS (MEMCHR)
 	CALL_MCOUNT 3
 	dcbt	0, r3
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/memcmp.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/memcmp.S
index 61c5ee6..ec4ccf3 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/memcmp.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/memcmp.S
@@ -28,7 +28,7 @@
 #ifndef MEMCMP
 # define MEMCMP memcmp
 #endif
-	DOT_MACHINE ("power7")
+	.machine power7
 ENTRY_TOCLESS (MEMCMP, 4)
 	CALL_MCOUNT 3
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/memrchr.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/memrchr.S
index 5795737..54de656 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/memrchr.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/memrchr.S
@@ -32,7 +32,7 @@
 #ifndef MEMRCHR
 # define MEMRCHR __memrchr
 #endif
-	DOT_MACHINE ("power7")
+	.machine  power7
 ENTRY_TOCLESS (MEMRCHR)
 	CALL_MCOUNT 3
 	add	r7, r3, r5      /* Calculate the last acceptable address.  */
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/memset.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/memset.S
index 007aa59..a42232b 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/memset.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/memset.S
@@ -30,7 +30,7 @@
 	/* No need to use .machine power8 since mtvsrd is already
 	   handled by the define.  It avoid breakage on binutils
 	   that does not support this machine specifier.  */
-	DOT_MACHINE ("power7")
+	.machine power7
 ENTRY_TOCLESS (MEMSET, 5)
 	CALL_MCOUNT 3
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strcasecmp.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strcasecmp.S
index 6e49d38..3a2efe2 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strcasecmp.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strcasecmp.S
@@ -105,7 +105,7 @@
 #  define VADDUQM_V7_V8	.long	0x11274100
 #endif
 
-	DOT_MACHINE ("power7")
+	.machine  power7
 
 ENTRY (__STRCASECMP)
 #ifdef USE_AS_STRNCASECMP
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strcasestr.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strcasestr.S
index b0dc7cf..9fc24c2 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strcasestr.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strcasestr.S
@@ -84,7 +84,7 @@
 #define	FRAMESIZE	(FRAME_MIN_SIZE+48)
 /* TODO: change this to .machine power8 when the minimum required binutils
    allows it.  */
-	DOT_MACHINE ("power7")
+	.machine  power7
 ENTRY (STRCASESTR, 4)
 	CALL_MCOUNT 2
 	mflr	r0			/* Load link register LR to r0.  */
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strchr.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strchr.S
index a934530..c5e28d9 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strchr.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strchr.S
@@ -43,7 +43,7 @@
 			| ((b)<<(32-21)) )
 /* TODO: change this to .machine power8 when the minimum required binutils
    allows it.  */
-	DOT_MACHINE ("power7")
+	.machine  power7
 ENTRY_TOCLESS (FUNC_NAME)
 	CALL_MCOUNT 2
 	dcbt	0,r3
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strcpy.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strcpy.S
index abfd231..956faf7 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strcpy.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strcpy.S
@@ -47,7 +47,7 @@
    64K as default, the page cross handling assumes minimum page size of
    4k.  */
 
-	DOT_MACHINE ("power8")
+	.machine  power8
 ENTRY_TOCLESS (FUNC_NAME, 4)
         li      r0,0          /* Doubleword with null chars to use
                                  with cmpb.  */
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strlen.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strlen.S
index 2d42cc1..719b5c6 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strlen.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strlen.S
@@ -35,7 +35,7 @@
 
 /* TODO: change this to .machine power8 when the minimum required binutils
    allows it.  */
-	DOT_MACHINE ("power7")
+	.machine  power7
 ENTRY_TOCLESS (STRLEN, 4)
 	CALL_MCOUNT 1
 	dcbt	0,r3
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strncmp.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strncmp.S
index e6e72b0..2eefa4a 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strncmp.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strncmp.S
@@ -31,7 +31,7 @@
    64K as default, the page cross handling assumes minimum page size of
    4k.  */
 
-	DOT_MACHINE ("power7")
+	.machine  power7
 ENTRY_TOCLESS (STRNCMP, 4)
 	/* Check if size is 0.  */
 	mr.	r10,r5
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strncpy.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strncpy.S
index df8241e..e8c5c71 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strncpy.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strncpy.S
@@ -60,7 +60,7 @@
    64K as default, the page cross handling assumes minimum page size of
    4k.  */
 
-	DOT_MACHINE ("power7")
+	.machine  power7
 #ifdef MEMSET_is_local
 ENTRY_TOCLESS (FUNC_NAME, 4)
 #else
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strnlen.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strnlen.S
index e647466..a98dfba 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strnlen.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strnlen.S
@@ -58,7 +58,7 @@
 
 /* int [r3] strnlen (char *s [r3], size_t maxlen [r4])  */
 /* TODO: change to power8 when minimum required binutils allows it.  */
-	DOT_MACHINE ("power7")
+	.machine  power7
 ENTRY_TOCLESS (__strnlen)
 	CALL_MCOUNT 2
 	dcbt	0,r3
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strrchr.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strrchr.S
index 7a9ecff..6ff8a52 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strrchr.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strrchr.S
@@ -80,7 +80,7 @@
 #ifndef STRRCHR
 # define STRRCHR strrchr
 #endif
-	DOT_MACHINE ("power7")
+	.machine  power7
 ENTRY_TOCLESS (STRRCHR)
 	CALL_MCOUNT 2
 	dcbt	0,r3
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strspn.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strspn.S
index 4bc8184..095f6d6 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strspn.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power8/strspn.S
@@ -67,7 +67,7 @@
 
 	/* This can be updated to power8 once the minimum version of
 	   binutils supports power8 and the above instructions.  */
-	DOT_MACHINE ("power7")
+	.machine power7
 ENTRY_TOCLESS (STRSPN, 4)
 	CALL_MCOUNT 2
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power9/strcmp.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power9/strcmp.S
index 9fd1fd9..98243a9 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power9/strcmp.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power9/strcmp.S
@@ -65,7 +65,7 @@
 /* TODO: change this to .machine power9 when the minimum required binutils
    allows it.  */
 
-	DOT_MACHINE ("power7")
+	.machine  power7
 ENTRY_TOCLESS (STRCMP, 4)
 	li	r0, 0
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power9/strncmp.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power9/strncmp.S
index b9dc6a2..40be98f 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power9/strncmp.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/power9/strncmp.S
@@ -67,7 +67,7 @@
 
 /* TODO: change this to .machine power9 when minimum binutils
    is upgraded to 2.27.  */
-	DOT_MACHINE ("power7")
+	.machine  power7
 ENTRY_TOCLESS (STRNCMP, 4)
 	/* Check if size is 0.  */
 	cmpdi	cr0, r5, 0
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/setjmp-common.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/setjmp-common.S
index ede37f9..ae92bb9 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/setjmp-common.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/powerpc64/setjmp-common.S
@@ -42,7 +42,7 @@
 	.section ".text"
 #endif
 
-	DOT_MACHINE ("altivec")
+	.machine	"altivec"
 ENTRY (setjmp_symbol)
 	CALL_MCOUNT 1
 	li r4,1			/* Set second argument to 1.  */
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/tst-tlsifunc.c b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/tst-tlsifunc.c
index 75cfb3e..681de40 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/tst-tlsifunc.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/powerpc/tst-tlsifunc.c
@@ -21,9 +21,9 @@
 #include <stdint.h>
 #include <inttypes.h>
 #include <libc-symbols.h>
-#include <tls-macros.h>
 
 __thread int bar;
+extern __thread int bar_gd asm ("bar") __attribute__ ((tls_model("global-dynamic")));
 static int *bar_ptr = NULL;
 
 static uint32_t resolver_platform = 0;
@@ -57,7 +57,7 @@
 void
 init_foo (void)
 {
-  bar_ptr = TLS_GD (bar);
+  bar_ptr = &bar_gd;
 }
 
 int
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/cmsg_nxthdr.c b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/cmsg_nxthdr.c
index fa0468e..bab0be6 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/cmsg_nxthdr.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/cmsg_nxthdr.c
@@ -37,3 +37,4 @@
     return NULL;
   return cmsg;
 }
+libc_hidden_def (__cmsg_nxthdr)
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/device-nrs.h b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/device-nrs.h
index 8d5558d..6fd7ad0 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/device-nrs.h
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/device-nrs.h
@@ -39,7 +39,7 @@
 
 /* Test whether given device is a tty.  */
 #define DEV_TTY_P(statp) \
-  ({ int __dev_major = major ((statp)->st_rdev);			      \
+  ({ int __dev_major = __gnu_dev_major ((statp)->st_rdev);		      \
      __dev_major >= DEV_TTY_LOW_MAJOR && __dev_major <= DEV_TTY_HIGH_MAJOR; })
 
 #endif	/* device-nrs.h */
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/pathconf.c b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/pathconf.c
index 3b8f480..59a50ce 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/pathconf.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/pathconf.c
@@ -73,7 +73,7 @@
     return EXT2_LINK_MAX;
 
   __snprintf (buf, sizeof (buf), "/sys/dev/block/%u:%u",
-	      gnu_dev_major (st.st_dev), gnu_dev_minor (st.st_dev));
+	      __gnu_dev_major (st.st_dev), __gnu_dev_minor (st.st_dev));
 
   ssize_t n = __readlink (buf, path, sizeof (path));
   if (n != -1 && n < sizeof (path))
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/powerpc/Makefile b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/powerpc/Makefile
index 8a49acf..6ff5cc2 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/powerpc/Makefile
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/powerpc/Makefile
@@ -18,9 +18,8 @@
 # This is needed for DSO loading from static binaries.
 sysdep-dl-routines += dl-static
 endif
-# lld doesn't support no-tls-get-addr-optimize option (b/73666526#comment23).
-ifeq ($(with-lld),no)
 # Otherwise tst-tls-dlinfo fails due to tst-tlsmod2.so using static tls.
+ifeq ($(have-tls-get-addr-optimize),yes)
 LDFLAGS-tst-tlsmod2.so += -Wl,--no-tls-get-addr-optimize
 endif
 endif
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/powerpc/configure b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/powerpc/configure
index 6d2465f..8691844 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/powerpc/configure
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/powerpc/configure
@@ -79,4 +79,35 @@
 
 fi # clang
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for linker that supports --no-tls-get-addr-optimize" >&5
+$as_echo_n "checking for linker that supports --no-tls-get-addr-optimize... " >&6; }
+libc_linker_feature=no
+if test x"$gnu_ld" = x"yes"; then
+  cat > conftest.c <<EOF
+int _start (void) { return 42; }
+EOF
+  if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS $no_ssp
+		    -Wl,--no-tls-get-addr-optimize -nostdlib -nostartfiles
+		    -fPIC -shared -o conftest.so conftest.c
+		    1>&5'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }
+  then
+    libc_linker_feature=yes
+  fi
+  rm -f conftest*
+fi
+if test $libc_linker_feature = yes; then
+  libc_cv_tls_get_addr_optimize=yes
+else
+  libc_cv_tls_get_addr_optimize=no
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_linker_feature" >&5
+$as_echo "$libc_linker_feature" >&6; }
+config_vars="$config_vars
+have-tls-get-addr-optimize = $libc_cv_tls_get_addr_optimize"
+
 ldd_rewrite_script=sysdeps/unix/sysv/linux/powerpc/ldd-rewrite.sed
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/powerpc/configure.ac b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/powerpc/configure.ac
index d3e1207..5f7eb3d 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/powerpc/configure.ac
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/powerpc/configure.ac
@@ -40,4 +40,8 @@
 
 fi # clang
 
+LIBC_LINKER_FEATURE([--no-tls-get-addr-optimize], [-Wl,--no-tls-get-addr-optimize],
+                    [libc_cv_tls_get_addr_optimize=yes], [libc_cv_tls_get_addr_optimize=no])
+LIBC_CONFIG_VAR([have-tls-get-addr-optimize], [$libc_cv_tls_get_addr_optimize])
+
 ldd_rewrite_script=sysdeps/unix/sysv/linux/powerpc/ldd-rewrite.sed
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/powerpc/powerpc64/getcontext.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/powerpc/powerpc64/getcontext.S
index c0ec8ea..3378e62 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/powerpc/powerpc64/getcontext.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/powerpc/powerpc64/getcontext.S
@@ -155,7 +155,7 @@
 #endif
 	.section ".text"
 
-	DOT_MACHINE ("altivec")
+	.machine	"altivec"
 ENTRY(__getcontext)
 	CALL_MCOUNT 1
   std  r0,(SIGCONTEXT_GP_REGS+(PT_R0*8))(r3)
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/powerpc/powerpc64/setcontext.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/powerpc/powerpc64/setcontext.S
index fac26e5..239af28 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/powerpc/powerpc64/setcontext.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/powerpc/powerpc64/setcontext.S
@@ -82,7 +82,7 @@
 # ifdef _ARCH_PWR6
   /* Use the extended four-operand version of the mtfsf insn.  */
   .machine push
-  DOT_MACHINE ("power6")
+  .machine "power6"
 
   mtfsf  0xff,fp0,1,0
 
@@ -93,7 +93,7 @@
   beq    5f
   /* Use the extended four-operand version of the mtfsf insn.  */
   .machine push
-  DOT_MACHINE ("power6")
+  .machine "power6"
 
   mtfsf  0xff,fp0,1,0
 
@@ -223,7 +223,7 @@
 #endif
 
 	.section ".text"
-	DOT_MACHINE ("altivec")
+	.machine	"altivec"
 ENTRY(__setcontext)
 	CALL_MCOUNT 1
   mflr  r0
@@ -374,7 +374,7 @@
 # ifdef _ARCH_PWR6
   /* Use the extended four-operand version of the mtfsf insn.  */
   .machine push
-  DOT_MACHINE ("power6")
+  .machine "power6"
 
   mtfsf  0xff,fp0,1,0
 
@@ -385,7 +385,7 @@
   beq    7f
   /* Use the extended four-operand version of the mtfsf insn.  */
   .machine push
-  DOT_MACHINE ("power6")
+  .machine "power6"
 
   mtfsf  0xff,fp0,1,0
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/powerpc/powerpc64/swapcontext.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/powerpc/powerpc64/swapcontext.S
index b52929c..4caa76b 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/powerpc/powerpc64/swapcontext.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/powerpc/powerpc64/swapcontext.S
@@ -178,7 +178,7 @@
 # ifdef _ARCH_PWR6
   /* Use the extended four-operand version of the mtfsf insn.  */
   .machine push
-  DOT_MACHINE ("power6")
+  .machine "power6"
 
   mtfsf  0xff,fp0,1,0
 
@@ -189,7 +189,7 @@
   beq    5f
 
   .machine push
-  DOT_MACHINE ("power6")
+  .machine "power6"
 
   mtfsf  0xff,fp0,1,0
 
@@ -310,7 +310,7 @@
 #endif
 
 	.section ".text"
-	DOT_MACHINE ("altivec")
+	.machine	"altivec"
 ENTRY(__swapcontext)
 	CALL_MCOUNT 2
   std  r0,(SIGCONTEXT_GP_REGS+(PT_R0*8))(r3)
@@ -667,7 +667,7 @@
 # ifdef _ARCH_PWR6
   /* Use the extended four-operand version of the mtfsf insn.  */
   .machine push
-  DOT_MACHINE ("power6")
+  .machine "power6"
 
   mtfsf  0xff,fp0,1,0
 
@@ -678,7 +678,7 @@
   beq    7f
 
   .machine push
-  DOT_MACHINE ("power6")
+  .machine "power6"
 
   mtfsf  0xff,fp0,1,0
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/ptsname.c b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/ptsname.c
index 6798dfb..a4c2336 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/ptsname.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/ptsname.c
@@ -29,16 +29,18 @@
 #include <_itoa.h>
 
 /* Check if DEV corresponds to a master pseudo terminal device.  */
-#define MASTER_P(Dev)                                                         \
-  (major ((Dev)) == 2                                                         \
-   || (major ((Dev)) == 4 && minor ((Dev)) >= 128 && minor ((Dev)) < 192)     \
-   || (major ((Dev)) >= 128 && major ((Dev)) < 136))
+#define MASTER_P(Dev)							\
+  (__gnu_dev_major ((Dev)) == 2						\
+   || (__gnu_dev_major ((Dev)) == 4					\
+       && __gnu_dev_minor ((Dev)) >= 128 && __gnu_dev_minor ((Dev)) < 192) \
+   || (__gnu_dev_major ((Dev)) >= 128 && __gnu_dev_major ((Dev)) < 136))
 
 /* Check if DEV corresponds to a slave pseudo terminal device.  */
-#define SLAVE_P(Dev)                                                          \
-  (major ((Dev)) == 3                                                         \
-   || (major ((Dev)) == 4 && minor ((Dev)) >= 192 && minor ((Dev)) < 256)     \
-   || (major ((Dev)) >= 136 && major ((Dev)) < 144))
+#define SLAVE_P(Dev)							\
+  (__gnu_dev_major ((Dev)) == 3						\
+   || (__gnu_dev_major ((Dev)) == 4					\
+       && __gnu_dev_minor ((Dev)) >= 192 && __gnu_dev_minor ((Dev)) < 256) \
+   || (__gnu_dev_major ((Dev)) >= 136 && __gnu_dev_major ((Dev)) < 144))
 
 /* Note that major number 4 corresponds to the old BSD style pseudo
    terminal devices.  As of Linux 2.1.115 these are no longer
@@ -122,7 +124,7 @@
 	  return ENOTTY;
 	}
 
-      ptyno = minor (stp->st_rdev);
+      ptyno = __gnu_dev_minor (stp->st_rdev);
 
       if (ptyno / 16 >= strlen (__libc_ptyname1))
 	{
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/ttyname.h b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/ttyname.h
index 74332d2..8ef0a16 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/ttyname.h
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/ttyname.h
@@ -28,7 +28,7 @@
 is_pty (struct stat64 *sb)
 {
 #ifdef _STATBUF_ST_RDEV
-  int m = major (sb->st_rdev);
+  int m = __gnu_dev_major (sb->st_rdev);
   return (136 <= m && m <= 143);
 #else
   return false;
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/cancellation.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/cancellation.S
deleted file mode 100644
index f3fb19d..0000000
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/cancellation.S
+++ /dev/null
@@ -1,115 +0,0 @@
-/* Copyright (C) 2009-2018 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2009.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <sysdep.h>
-#include <tcb-offsets.h>
-#include <kernel-features.h>
-#include "lowlevellock.h"
-
-#define PTHREAD_UNWIND JUMPTARGET(__pthread_unwind)
-#if IS_IN (libpthread)
-# if defined SHARED && !defined NO_HIDDEN
-#  undef PTHREAD_UNWIND
-#  define PTHREAD_UNWIND __GI___pthread_unwind
-# endif
-#else
-# ifndef SHARED
-	.weak __pthread_unwind
-# endif
-#endif
-
-
-#ifdef __ASSUME_PRIVATE_FUTEX
-# define LOAD_PRIVATE_FUTEX_WAIT(reg) \
-	movl	$(FUTEX_WAIT | FUTEX_PRIVATE_FLAG), reg
-#else
-# if FUTEX_WAIT == 0
-#  define LOAD_PRIVATE_FUTEX_WAIT(reg) \
-	movl	%fs:PRIVATE_FUTEX, reg
-# else
-#  define LOAD_PRIVATE_FUTEX_WAIT(reg) \
-	movl	%fs:PRIVATE_FUTEX, reg ; \
-	orl	$FUTEX_WAIT, reg
-# endif
-#endif
-
-/* It is crucial that the functions in this file don't modify registers
-   other than %rax and %r11.  The syscall wrapper code depends on this
-   because it doesn't explicitly save the other registers which hold
-   relevant values.  */
-	.text
-
-	.hidden __pthread_enable_asynccancel
-ENTRY(__pthread_enable_asynccancel)
-	movl	%fs:CANCELHANDLING, %eax
-2:	movl	%eax, %r11d
-	orl	$TCB_CANCELTYPE_BITMASK, %r11d
-	cmpl	%eax, %r11d
-	je	1f
-
-	lock
-	cmpxchgl %r11d, %fs:CANCELHANDLING
-	jnz	2b
-
-	andl	$(TCB_CANCELSTATE_BITMASK|TCB_CANCELTYPE_BITMASK|TCB_CANCELED_BITMASK|TCB_EXITING_BITMASK|TCB_CANCEL_RESTMASK|TCB_TERMINATED_BITMASK), %r11d
-	cmpl	$(TCB_CANCELTYPE_BITMASK|TCB_CANCELED_BITMASK), %r11d
-	je	3f
-
-1:	ret
-
-3:	subq	$8, %rsp
-	cfi_adjust_cfa_offset(8)
-	LP_OP(mov) $TCB_PTHREAD_CANCELED, %fs:RESULT
-	lock
-	orl	$TCB_EXITING_BITMASK, %fs:CANCELHANDLING
-	mov	%fs:CLEANUP_JMP_BUF, %RDI_LP
-	call	PTHREAD_UNWIND
-	hlt
-END(__pthread_enable_asynccancel)
-
-
-	.hidden __pthread_disable_asynccancel
-ENTRY(__pthread_disable_asynccancel)
-	testl	$TCB_CANCELTYPE_BITMASK, %edi
-	jnz	1f
-
-	movl	%fs:CANCELHANDLING, %eax
-2:	movl	%eax, %r11d
-	andl	$~TCB_CANCELTYPE_BITMASK, %r11d
-	lock
-	cmpxchgl %r11d, %fs:CANCELHANDLING
-	jnz	2b
-
-	movl	%r11d, %eax
-3:	andl	$(TCB_CANCELING_BITMASK|TCB_CANCELED_BITMASK), %eax
-	cmpl	$TCB_CANCELING_BITMASK, %eax
-	je	4f
-1:	ret
-
-	/* Performance doesn't matter in this loop.  We will
-	   delay until the thread is canceled.  And we will unlikely
-	   enter the loop twice.  */
-4:	mov	%fs:0, %RDI_LP
-	movl	$__NR_futex, %eax
-	xorq	%r10, %r10
-	addq	$CANCELHANDLING, %rdi
-	LOAD_PRIVATE_FUTEX_WAIT (%esi)
-	syscall
-	movl	%fs:CANCELHANDLING, %eax
-	jmp	3b
-END(__pthread_disable_asynccancel)
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/librt-cancellation.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/librt-cancellation.S
deleted file mode 100644
index d0f0ee4..0000000
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/librt-cancellation.S
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Copyright (C) 2009-2018 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2009.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#define __pthread_enable_asynccancel __librt_enable_asynccancel
-#define __pthread_disable_asynccancel __librt_disable_asynccancel
-#include "cancellation.S"
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/lll_timedlock_wait.c b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/lll_timedlock_wait.c
deleted file mode 100644
index f6875b8..0000000
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/lll_timedlock_wait.c
+++ /dev/null
@@ -1 +0,0 @@
-/* __lll_timedlock_wait is in lowlevellock.S.  */
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/lll_timedwait_tid.c b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/lll_timedwait_tid.c
deleted file mode 100644
index 43900c6..0000000
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/lll_timedwait_tid.c
+++ /dev/null
@@ -1 +0,0 @@
-/* __lll_timedwait_tid is in lowlevellock.S.  */
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
deleted file mode 100644
index 92561e1..0000000
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
+++ /dev/null
@@ -1,463 +0,0 @@
-/* Copyright (C) 2002-2018 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <sysdep.h>
-#include <pthread-errnos.h>
-#include <kernel-features.h>
-#include <lowlevellock.h>
-
-#include <stap-probe.h>
-
-	.text
-
-#ifdef __ASSUME_PRIVATE_FUTEX
-# define LOAD_PRIVATE_FUTEX_WAIT(reg) \
-	movl	$(FUTEX_WAIT | FUTEX_PRIVATE_FLAG), reg
-# define LOAD_PRIVATE_FUTEX_WAKE(reg) \
-	movl	$(FUTEX_WAKE | FUTEX_PRIVATE_FLAG), reg
-# define LOAD_FUTEX_WAIT(reg) \
-	xorl	$(FUTEX_WAIT | FUTEX_PRIVATE_FLAG), reg
-# define LOAD_FUTEX_WAIT_ABS(reg) \
-	xorl	$(FUTEX_WAIT_BITSET | FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME), reg
-# define LOAD_FUTEX_WAKE(reg) \
-	xorl	$(FUTEX_WAKE | FUTEX_PRIVATE_FLAG), reg
-#else
-# if FUTEX_WAIT == 0
-#  define LOAD_PRIVATE_FUTEX_WAIT(reg) \
-	movl    %fs:PRIVATE_FUTEX, reg
-# else
-#  define LOAD_PRIVATE_FUTEX_WAIT(reg) \
-	movl	%fs:PRIVATE_FUTEX, reg ; \
-	orl	$FUTEX_WAIT, reg
-# endif
-# define LOAD_PRIVATE_FUTEX_WAKE(reg) \
-	movl    %fs:PRIVATE_FUTEX, reg ; \
-	orl     $FUTEX_WAKE, reg
-# if FUTEX_WAIT == 0
-#  define LOAD_FUTEX_WAIT(reg) \
-	xorl	$FUTEX_PRIVATE_FLAG, reg ; \
-	andl	%fs:PRIVATE_FUTEX, reg
-# else
-#  define LOAD_FUTEX_WAIT(reg) \
-	xorl	$FUTEX_PRIVATE_FLAG, reg ; \
-	andl	%fs:PRIVATE_FUTEX, reg ; \
-	orl	$FUTEX_WAIT, reg
-# endif
-# define LOAD_FUTEX_WAIT_ABS(reg) \
-	xorl	$FUTEX_PRIVATE_FLAG, reg ; \
-	andl	%fs:PRIVATE_FUTEX, reg ; \
-	orl	$FUTEX_WAIT_BITSET | FUTEX_CLOCK_REALTIME, reg
-# define LOAD_FUTEX_WAKE(reg) \
-	xorl	$FUTEX_PRIVATE_FLAG, reg ; \
-	andl	%fs:PRIVATE_FUTEX, reg ; \
-	orl	$FUTEX_WAKE, reg
-#endif
-
-
-	.globl	__lll_lock_wait_private
-	.type	__lll_lock_wait_private,@function
-	.hidden	__lll_lock_wait_private
-	.align	16
-__lll_lock_wait_private:
-	cfi_startproc
-	pushq	%r10
-	cfi_adjust_cfa_offset(8)
-	pushq	%rdx
-	cfi_adjust_cfa_offset(8)
-	cfi_offset(%r10, -16)
-	cfi_offset(%rdx, -24)
-	xorq	%r10, %r10	/* No timeout.  */
-	movl	$2, %edx
-	LOAD_PRIVATE_FUTEX_WAIT (%esi)
-
-	cmpl	%edx, %eax	/* NB:	 %edx == 2 */
-	jne	2f
-
-1:	LIBC_PROBE (lll_lock_wait_private, 1, %rdi)
-	movl	$SYS_futex, %eax
-	syscall
-
-2:	movl	%edx, %eax
-	xchgl	%eax, (%rdi)	/* NB:	 lock is implied */
-
-	testl	%eax, %eax
-	jnz	1b
-
-	popq	%rdx
-	cfi_adjust_cfa_offset(-8)
-	cfi_restore(%rdx)
-	popq	%r10
-	cfi_adjust_cfa_offset(-8)
-	cfi_restore(%r10)
-	retq
-	cfi_endproc
-	.size	__lll_lock_wait_private,.-__lll_lock_wait_private
-
-#if !IS_IN (libc)
-	.globl	__lll_lock_wait
-	.type	__lll_lock_wait,@function
-	.hidden	__lll_lock_wait
-	.align	16
-__lll_lock_wait:
-	cfi_startproc
-	pushq	%r10
-	cfi_adjust_cfa_offset(8)
-	pushq	%rdx
-	cfi_adjust_cfa_offset(8)
-	cfi_offset(%r10, -16)
-	cfi_offset(%rdx, -24)
-	xorq	%r10, %r10	/* No timeout.  */
-	movl	$2, %edx
-	LOAD_FUTEX_WAIT (%esi)
-
-	cmpl	%edx, %eax	/* NB:	 %edx == 2 */
-	jne	2f
-
-1:	LIBC_PROBE (lll_lock_wait, 2, %rdi, %rsi)
-	movl	$SYS_futex, %eax
-	syscall
-
-2:	movl	%edx, %eax
-	xchgl	%eax, (%rdi)	/* NB:	 lock is implied */
-
-	testl	%eax, %eax
-	jnz	1b
-
-	popq	%rdx
-	cfi_adjust_cfa_offset(-8)
-	cfi_restore(%rdx)
-	popq	%r10
-	cfi_adjust_cfa_offset(-8)
-	cfi_restore(%r10)
-	retq
-	cfi_endproc
-	.size	__lll_lock_wait,.-__lll_lock_wait
-
-	/*      %rdi: futex
-		%rsi: flags
-		%rdx: timeout
-		%eax: futex value
-	*/
-	.globl	__lll_timedlock_wait
-	.type	__lll_timedlock_wait,@function
-	.hidden	__lll_timedlock_wait
-	.align	16
-__lll_timedlock_wait:
-	cfi_startproc
-# ifndef __ASSUME_FUTEX_CLOCK_REALTIME
-#  ifdef PIC
-	cmpl	$0, __have_futex_clock_realtime(%rip)
-#  else
-	cmpl	$0, __have_futex_clock_realtime
-#  endif
-	je	.Lreltmo
-# endif
-
-	cmpq	$0, (%rdx)
-	js	5f
-
-	pushq	%r9
-	cfi_adjust_cfa_offset(8)
-	cfi_rel_offset(%r9, 0)
-
-	movq	%rdx, %r10
-	movl	$0xffffffff, %r9d
-	LOAD_FUTEX_WAIT_ABS (%esi)
-
-	movl	$2, %edx
-	cmpl	%edx, %eax
-	jne	2f
-
-1:	movl	$SYS_futex, %eax
-	movl	$2, %edx
-	syscall
-
-2:	xchgl	%edx, (%rdi)	/* NB:   lock is implied */
-
-	testl	%edx, %edx
-	jz	3f
-
-	cmpl	$-ETIMEDOUT, %eax
-	je	4f
-	cmpl	$-EINVAL, %eax
-	jne	1b
-4:	movl	%eax, %edx
-	negl	%edx
-
-3:	movl	%edx, %eax
-	popq	%r9
-	cfi_adjust_cfa_offset(-8)
-	cfi_restore(%r9)
-	retq
-
-5:	movl	$ETIMEDOUT, %eax
-	retq
-
-# ifndef __ASSUME_FUTEX_CLOCK_REALTIME
-.Lreltmo:
-	/* Check for a valid timeout value.  */
-	cmpq	$1000000000, 8(%rdx)
-	jae	3f
-
-	pushq	%r8
-	cfi_adjust_cfa_offset(8)
-	pushq	%r9
-	cfi_adjust_cfa_offset(8)
-	pushq	%r12
-	cfi_adjust_cfa_offset(8)
-	pushq	%r13
-	cfi_adjust_cfa_offset(8)
-	pushq	%r14
-	cfi_adjust_cfa_offset(8)
-	cfi_offset(%r8, -16)
-	cfi_offset(%r9, -24)
-	cfi_offset(%r12, -32)
-	cfi_offset(%r13, -40)
-	cfi_offset(%r14, -48)
-	pushq	%rsi
-	cfi_adjust_cfa_offset(8)
-
-	/* Stack frame for the timespec and timeval structs.  */
-	subq	$24, %rsp
-	cfi_adjust_cfa_offset(24)
-
-	movq	%rdi, %r12
-	movq	%rdx, %r13
-
-	movl	$2, %edx
-	xchgl	%edx, (%r12)
-
-	testl	%edx, %edx
-	je	6f
-
-1:
-	/* Get current time.  */
-	movq	%rsp, %rdi
-	xorl	%esi, %esi
-	/* This call works because we directly jump to a system call entry
-	   which preserves all the registers.  */
-	call	JUMPTARGET(__gettimeofday)
-
-	/* Compute relative timeout.  */
-	movq	8(%rsp), %rax
-	movl	$1000, %edi
-	mul	%rdi		/* Milli seconds to nano seconds.  */
-	movq	(%r13), %rdi
-	movq	8(%r13), %rsi
-	subq	(%rsp), %rdi
-	subq	%rax, %rsi
-	jns	4f
-	addq	$1000000000, %rsi
-	decq	%rdi
-4:	testq	%rdi, %rdi
-	js	2f		/* Time is already up.  */
-
-	/* Store relative timeout.  */
-	movq	%rdi, (%rsp)
-	movq	%rsi, 8(%rsp)
-
-	/* Futex call.  */
-	movl	$2, %edx
-	movl	$1, %eax
-	movq	%rsp, %r10
-	movl	24(%rsp), %esi
-	LOAD_FUTEX_WAIT (%esi)
-	movq	%r12, %rdi
-	movl	$SYS_futex, %eax
-	syscall
-
-	/* NB: %edx == 2 */
-	xchgl	%edx, (%r12)
-
-	testl	%edx, %edx
-	je	6f
-
-	cmpl	$-ETIMEDOUT, %eax
-	jne	1b
-2:	movl	$ETIMEDOUT, %edx
-
-6:	addq	$32, %rsp
-	cfi_adjust_cfa_offset(-32)
-	popq	%r14
-	cfi_adjust_cfa_offset(-8)
-	cfi_restore(%r14)
-	popq	%r13
-	cfi_adjust_cfa_offset(-8)
-	cfi_restore(%r13)
-	popq	%r12
-	cfi_adjust_cfa_offset(-8)
-	cfi_restore(%r12)
-	popq	%r9
-	cfi_adjust_cfa_offset(-8)
-	cfi_restore(%r9)
-	popq	%r8
-	cfi_adjust_cfa_offset(-8)
-	cfi_restore(%r8)
-	movl	%edx, %eax
-	retq
-
-3:	movl	$EINVAL, %eax
-	retq
-# endif
-	cfi_endproc
-	.size	__lll_timedlock_wait,.-__lll_timedlock_wait
-#endif
-
-
-	.globl	__lll_unlock_wake_private
-	.type	__lll_unlock_wake_private,@function
-	.hidden	__lll_unlock_wake_private
-	.align	16
-__lll_unlock_wake_private:
-	cfi_startproc
-	pushq	%rsi
-	cfi_adjust_cfa_offset(8)
-	pushq	%rdx
-	cfi_adjust_cfa_offset(8)
-	cfi_offset(%rsi, -16)
-	cfi_offset(%rdx, -24)
-
-	movl	$0, (%rdi)
-	LOAD_PRIVATE_FUTEX_WAKE (%esi)
-	movl	$1, %edx	/* Wake one thread.  */
-	movl	$SYS_futex, %eax
-	syscall
-
-	popq	%rdx
-	cfi_adjust_cfa_offset(-8)
-	cfi_restore(%rdx)
-	popq	%rsi
-	cfi_adjust_cfa_offset(-8)
-	cfi_restore(%rsi)
-	retq
-	cfi_endproc
-	.size	__lll_unlock_wake_private,.-__lll_unlock_wake_private
-
-#if !IS_IN (libc)
-	.globl	__lll_unlock_wake
-	.type	__lll_unlock_wake,@function
-	.hidden	__lll_unlock_wake
-	.align	16
-__lll_unlock_wake:
-	cfi_startproc
-	pushq	%rsi
-	cfi_adjust_cfa_offset(8)
-	pushq	%rdx
-	cfi_adjust_cfa_offset(8)
-	cfi_offset(%rsi, -16)
-	cfi_offset(%rdx, -24)
-
-	movl	$0, (%rdi)
-	LOAD_FUTEX_WAKE (%esi)
-	movl	$1, %edx	/* Wake one thread.  */
-	movl	$SYS_futex, %eax
-	syscall
-
-	popq	%rdx
-	cfi_adjust_cfa_offset(-8)
-	cfi_restore(%rdx)
-	popq	%rsi
-	cfi_adjust_cfa_offset(-8)
-	cfi_restore(%rsi)
-	retq
-	cfi_endproc
-	.size	__lll_unlock_wake,.-__lll_unlock_wake
-
-	.globl	__lll_timedwait_tid
-	.type	__lll_timedwait_tid,@function
-	.hidden	__lll_timedwait_tid
-	.align	16
-__lll_timedwait_tid:
-	cfi_startproc
-	pushq	%r12
-	cfi_adjust_cfa_offset(8)
-	pushq	%r13
-	cfi_adjust_cfa_offset(8)
-	cfi_offset(%r12, -16)
-	cfi_offset(%r13, -24)
-
-	movq	%rdi, %r12
-	movq	%rsi, %r13
-
-	/* Align stack to 16 bytes when calling __gettimeofday.  */
-	subq	$24, %rsp
-	cfi_adjust_cfa_offset(24)
-
-	/* Get current time.  */
-2:	movq	%rsp, %rdi
-	xorl	%esi, %esi
-	/* This call works because we directly jump to a system call entry
-	   which preserves all the registers.  */
-	call	JUMPTARGET(__gettimeofday)
-
-	/* Compute relative timeout.  */
-	movq	8(%rsp), %rax
-	movl	$1000, %edi
-	mul	%rdi		/* Milli seconds to nano seconds.  */
-	movq	(%r13), %rdi
-	movq	8(%r13), %rsi
-	subq	(%rsp), %rdi
-	subq	%rax, %rsi
-	jns	5f
-	addq	$1000000000, %rsi
-	decq	%rdi
-5:	testq	%rdi, %rdi
-	js	6f		/* Time is already up.  */
-
-	movq	%rdi, (%rsp)	/* Store relative timeout.  */
-	movq	%rsi, 8(%rsp)
-
-	movl	(%r12), %edx
-	testl	%edx, %edx
-	jz	4f
-
-	movq	%rsp, %r10
-	/* XXX The kernel so far uses global futex for the wakeup at
-	   all times.  */
-#if FUTEX_WAIT == 0
-	xorl	%esi, %esi
-#else
-	movl	$FUTEX_WAIT, %esi
-#endif
-	movq	%r12, %rdi
-	movl	$SYS_futex, %eax
-	syscall
-
-	cmpl	$0, (%rdi)
-	jne	1f
-4:	xorl	%eax, %eax
-
-8:	addq	$24, %rsp
-	cfi_adjust_cfa_offset(-24)
-	popq	%r13
-	cfi_adjust_cfa_offset(-8)
-	cfi_restore(%r13)
-	popq	%r12
-	cfi_adjust_cfa_offset(-8)
-	cfi_restore(%r12)
-	retq
-
-	cfi_adjust_cfa_offset(32)
-1:	cmpq	$-ETIMEDOUT, %rax
-	jne	2b
-
-6:	movl	$ETIMEDOUT, %eax
-	jmp	8b
-	cfi_endproc
-	.size	__lll_timedwait_tid,.-__lll_timedwait_tid
-#endif
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
deleted file mode 100644
index a8bcfbe..0000000
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
+++ /dev/null
@@ -1,273 +0,0 @@
-/* Copyright (C) 2002-2018 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#ifndef _LOWLEVELLOCK_H
-#define _LOWLEVELLOCK_H	1
-
-#include <stap-probe.h>
-
-#ifndef __ASSEMBLER__
-# include <time.h>
-# include <sys/param.h>
-# include <bits/pthreadtypes.h>
-# include <kernel-features.h>
-# include <tcb-offsets.h>
-
-# ifndef LOCK_INSTR
-#  ifdef UP
-#   define LOCK_INSTR	/* nothing */
-#  else
-#   define LOCK_INSTR "lock;"
-#  endif
-# endif
-#else
-# ifndef LOCK
-#  ifdef UP
-#   define LOCK
-#  else
-#   define LOCK lock
-#  endif
-# endif
-#endif
-
-#include <lowlevellock-futex.h>
-
-/* XXX Remove when no assembler code uses futexes anymore.  */
-#define SYS_futex		__NR_futex
-
-#ifndef __ASSEMBLER__
-
-/* Initializer for lock.  */
-#define LLL_LOCK_INITIALIZER		(0)
-#define LLL_LOCK_INITIALIZER_LOCKED	(1)
-#define LLL_LOCK_INITIALIZER_WAITERS	(2)
-
-
-/* NB: in the lll_trylock macro we simply return the value in %eax
-   after the cmpxchg instruction.  In case the operation succeded this
-   value is zero.  In case the operation failed, the cmpxchg instruction
-   has loaded the current value of the memory work which is guaranteed
-   to be nonzero.  */
-#if !IS_IN (libc) || defined UP
-# define __lll_trylock_asm LOCK_INSTR "cmpxchgl %2, %1"
-#else
-# define __lll_trylock_asm "cmpl $0, __libc_multiple_threads(%%rip)\n\t"      \
-			   "je 0f\n\t"					      \
-			   "lock; cmpxchgl %2, %1\n\t"			      \
-			   "jmp 1f\n\t"					      \
-			   "0:\tcmpxchgl %2, %1\n\t"			      \
-			   "1:"
-#endif
-
-#define lll_trylock(futex) \
-  ({ int ret;								      \
-     __asm __volatile (__lll_trylock_asm				      \
-		       : "=a" (ret), "=m" (futex)			      \
-		       : "r" (LLL_LOCK_INITIALIZER_LOCKED), "m" (futex),      \
-			 "0" (LLL_LOCK_INITIALIZER)			      \
-		       : "memory");					      \
-     ret; })
-
-#define lll_cond_trylock(futex) \
-  ({ int ret;								      \
-     __asm __volatile (LOCK_INSTR "cmpxchgl %2, %1"			      \
-		       : "=a" (ret), "=m" (futex)			      \
-		       : "r" (LLL_LOCK_INITIALIZER_WAITERS),		      \
-			 "m" (futex), "0" (LLL_LOCK_INITIALIZER)	      \
-		       : "memory");					      \
-     ret; })
-
-#if !IS_IN (libc) || defined UP
-# define __lll_lock_asm_start LOCK_INSTR "cmpxchgl %4, %2\n\t"		      \
-			      "jz 24f\n\t"
-#else
-# define __lll_lock_asm_start "cmpl $0, __libc_multiple_threads(%%rip)\n\t"   \
-			      "je 0f\n\t"				      \
-			      "lock; cmpxchgl %4, %2\n\t"		      \
-			      "jnz 1f\n\t"				      \
-			      "jmp 24f\n"				      \
-			      "0:\tcmpxchgl %4, %2\n\t"			      \
-			      "jz 24f\n\t"
-#endif
-
-#define lll_lock(futex, private) \
-  (void)								      \
-    ({ int ignore1, ignore2, ignore3;					      \
-       if (__builtin_constant_p (private) && (private) == LLL_PRIVATE)	      \
-	 __asm __volatile (__lll_lock_asm_start				      \
-			   "1:\tlea %2, %%" RDI_LP "\n"			      \
-			   "2:\tsub $128, %%" RSP_LP "\n"		      \
-			   ".cfi_adjust_cfa_offset 128\n"		      \
-			   "3:\tcallq __lll_lock_wait_private\n"	      \
-			   "4:\tadd $128, %%" RSP_LP "\n"		      \
-			   ".cfi_adjust_cfa_offset -128\n"		      \
-			   "24:"					      \
-			   : "=S" (ignore1), "=&D" (ignore2), "=m" (futex),   \
-			     "=a" (ignore3)				      \
-			   : "0" (1), "m" (futex), "3" (0)		      \
-			   : "cx", "r11", "cc", "memory");		      \
-       else								      \
-	 __asm __volatile (__lll_lock_asm_start				      \
-			   "1:\tlea %2, %%" RDI_LP "\n"			      \
-			   "2:\tsub $128, %%" RSP_LP "\n"		      \
-			   ".cfi_adjust_cfa_offset 128\n"		      \
-			   "3:\tcallq __lll_lock_wait\n"		      \
-			   "4:\tadd $128, %%" RSP_LP "\n"		      \
-			   ".cfi_adjust_cfa_offset -128\n"		      \
-			   "24:"					      \
-			   : "=S" (ignore1), "=D" (ignore2), "=m" (futex),    \
-			     "=a" (ignore3)				      \
-			   : "1" (1), "m" (futex), "3" (0), "0" (private)     \
-			   : "cx", "r11", "cc", "memory");		      \
-    })									      \
-
-#define lll_cond_lock(futex, private) \
-  (void)								      \
-    ({ int ignore1, ignore2, ignore3;					      \
-       __asm __volatile (LOCK_INSTR "cmpxchgl %4, %2\n\t"		      \
-			 "jz 24f\n"					      \
-			 "1:\tlea %2, %%" RDI_LP "\n"			      \
-			 "2:\tsub $128, %%" RSP_LP "\n"			      \
-			 ".cfi_adjust_cfa_offset 128\n"			      \
-			 "3:\tcallq __lll_lock_wait\n"			      \
-			 "4:\tadd $128, %%" RSP_LP "\n"			      \
-			 ".cfi_adjust_cfa_offset -128\n"		      \
-			 "24:"						      \
-			 : "=S" (ignore1), "=D" (ignore2), "=m" (futex),      \
-			   "=a" (ignore3)				      \
-			 : "1" (2), "m" (futex), "3" (0), "0" (private)	      \
-			 : "cx", "r11", "cc", "memory");		      \
-    })
-
-#define lll_timedlock(futex, timeout, private) \
-  ({ int result, ignore1, ignore2, ignore3;				      \
-     __asm __volatile (LOCK_INSTR "cmpxchgl %1, %4\n\t"			      \
-		       "jz 24f\n"					      \
-		       "1:\tlea %4, %%" RDI_LP "\n"			      \
-		       "0:\tmov %8, %%" RDX_LP "\n"			      \
-		       "2:\tsub $128, %%" RSP_LP "\n"			      \
-		       ".cfi_adjust_cfa_offset 128\n"			      \
-		       "3:\tcallq __lll_timedlock_wait\n"		      \
-		       "4:\tadd $128, %%" RSP_LP "\n"			      \
-		       ".cfi_adjust_cfa_offset -128\n"			      \
-		       "24:"						      \
-		       : "=a" (result), "=D" (ignore1), "=S" (ignore2),	      \
-			 "=&d" (ignore3), "=m" (futex)			      \
-		       : "0" (0), "1" (1), "m" (futex), "m" (timeout),	      \
-			 "2" (private)					      \
-		       : "memory", "cx", "cc", "r10", "r11");		      \
-     result; })
-
-extern int __lll_timedlock_elision (int *futex, short *adapt_count,
-					 const struct timespec *timeout,
-					 int private) attribute_hidden;
-
-#define lll_timedlock_elision(futex, adapt_count, timeout, private)	\
-  __lll_timedlock_elision(&(futex), &(adapt_count), timeout, private)
-
-#if !IS_IN (libc) || defined UP
-# define __lll_unlock_asm_start LOCK_INSTR "decl %0\n\t"		      \
-				"je 24f\n\t"
-#else
-# define __lll_unlock_asm_start "cmpl $0, __libc_multiple_threads(%%rip)\n\t" \
-				"je 0f\n\t"				      \
-				"lock; decl %0\n\t"			      \
-				"jne 1f\n\t"				      \
-				"jmp 24f\n\t"				      \
-				"0:\tdecl %0\n\t"			      \
-				"je 24f\n\t"
-#endif
-
-#define lll_unlock(futex, private) \
-  (void)								      \
-    ({ int ignore;							      \
-       if (__builtin_constant_p (private) && (private) == LLL_PRIVATE)	      \
-	 __asm __volatile (__lll_unlock_asm_start			      \
-			   "1:\tlea %0, %%" RDI_LP "\n"			      \
-			   "2:\tsub $128, %%" RSP_LP "\n"		      \
-			   ".cfi_adjust_cfa_offset 128\n"		      \
-			   "3:\tcallq __lll_unlock_wake_private\n"	      \
-			   "4:\tadd $128, %%" RSP_LP "\n"		      \
-			   ".cfi_adjust_cfa_offset -128\n"		      \
-			   "24:"					      \
-			   : "=m" (futex), "=&D" (ignore)		      \
-			   : "m" (futex)				      \
-			   : "ax", "cx", "r11", "cc", "memory");	      \
-       else								      \
-	 __asm __volatile (__lll_unlock_asm_start			      \
-			   "1:\tlea %0, %%" RDI_LP "\n"			      \
-			   "2:\tsub $128, %%" RSP_LP "\n"		      \
-			   ".cfi_adjust_cfa_offset 128\n"		      \
-			   "3:\tcallq __lll_unlock_wake\n"		      \
-			   "4:\tadd $128, %%" RSP_LP "\n"		      \
-			   ".cfi_adjust_cfa_offset -128\n"		      \
-			   "24:"					      \
-			   : "=m" (futex), "=&D" (ignore)		      \
-			   : "m" (futex), "S" (private)			      \
-			   : "ax", "cx", "r11", "cc", "memory");	      \
-    })
-
-#define lll_islocked(futex) \
-  (futex != LLL_LOCK_INITIALIZER)
-
-
-/* The kernel notifies a process which uses CLONE_CHILD_CLEARTID via futex
-   wake-up when the clone terminates.  The memory location contains the
-   thread ID while the clone is running and is reset to zero by the kernel
-   afterwards.  The kernel up to version 3.16.3 does not use the private futex
-   operations for futex wake-up when the clone terminates.  */
-#define lll_wait_tid(tid) \
-  do {					\
-    __typeof (tid) __tid;		\
-    while ((__tid = (tid)) != 0)	\
-      lll_futex_wait (&(tid), __tid, LLL_SHARED);\
-  } while (0)
-
-extern int __lll_timedwait_tid (int *, const struct timespec *)
-     attribute_hidden;
-
-/* As lll_wait_tid, but with a timeout.  If the timeout occurs then return
-   ETIMEDOUT.  If ABSTIME is invalid, return EINVAL.
-   XXX Note that this differs from the generic version in that we do the
-   error checking here and not in __lll_timedwait_tid.  */
-#define lll_timedwait_tid(tid, abstime) \
-  ({									      \
-    int __result = 0;							      \
-    if ((tid) != 0)							      \
-      __result = __lll_timedwait_tid (&(tid), (abstime));		      \
-    __result; })
-
-extern int __lll_lock_elision (int *futex, short *adapt_count, int private)
-  attribute_hidden;
-
-extern int __lll_unlock_elision (int *lock, int private)
-  attribute_hidden;
-
-extern int __lll_trylock_elision (int *lock, short *adapt_count)
-  attribute_hidden;
-
-#define lll_lock_elision(futex, adapt_count, private) \
-  __lll_lock_elision (&(futex), &(adapt_count), private)
-#define lll_unlock_elision(futex, adapt_count, private) \
-  __lll_unlock_elision (&(futex), private)
-#define lll_trylock_elision(futex, adapt_count) \
-  __lll_trylock_elision (&(futex), &(adapt_count))
-
-#endif  /* !__ASSEMBLER__ */
-
-#endif	/* lowlevellock.h */
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/sigaction.c b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/sigaction.c
index 1a2c370..2f7459f 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/sigaction.c
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/unix/sysv/linux/x86_64/sigaction.c
@@ -122,7 +122,7 @@
    "	movq $" #syscall ", %rax\n"					\
    "	syscall\n"							\
    ".LEND_" #name ":\n"							\
-   ".section .eh_frame,\"a\",@unwind\n"					\
+   ".section .eh_frame,\"a\",@progbits\n"				\
    ".LSTARTFRAME_" #name ":\n"						\
    "	.long .LENDCIE_" #name "-.LSTARTCIE_" #name "\n"		\
    ".LSTARTCIE_" #name ":\n"						\
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/x86_64/configure b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/x86_64/configure
old mode 100644
new mode 100755
index 8674d14..efef46b
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/x86_64/configure
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/x86_64/configure
@@ -85,39 +85,6 @@
   build_mathvec=yes
 fi
 
-if test "$static_pie" = yes; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for linker static PIE support" >&5
-$as_echo_n "checking for linker static PIE support... " >&6; }
-if ${libc_cv_ld_static_pie+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  cat > conftest.s <<\EOF
-	.text
-	.global _start
-	.weak foo
-_start:
-	leaq	foo(%rip), %rax
-EOF
-  libc_cv_pie_option="-Wl,-pie"
-  if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -nostartfiles -nostdlib $no_ssp $libc_cv_pie_option -o conftest conftest.s 1>&5'
-  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; }; then
-    libc_cv_ld_static_pie=yes
-  else
-    libc_cv_ld_static_pie=no
-  fi
-rm -f conftest*
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_ld_static_pie" >&5
-$as_echo "$libc_cv_ld_static_pie" >&6; }
-  if test "$libc_cv_ld_static_pie" != yes; then
-    as_fn_error $? "linker support for static PIE needed" "$LINENO" 5
-  fi
-fi
-
 $as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
 
 
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/x86_64/configure.ac b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/x86_64/configure.ac
index b7d2c01..fa86e95 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/x86_64/configure.ac
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/x86_64/configure.ac
@@ -44,31 +44,6 @@
   build_mathvec=yes
 fi
 
-dnl Check if linker supports static PIE with the fix for
-dnl
-dnl https://sourceware.org/bugzilla/show_bug.cgi?id=21782
-dnl
-if test "$static_pie" = yes; then
-  AC_CACHE_CHECK(for linker static PIE support, libc_cv_ld_static_pie, [dnl
-cat > conftest.s <<\EOF
-	.text
-	.global _start
-	.weak foo
-_start:
-	leaq	foo(%rip), %rax
-EOF
-  libc_cv_pie_option="-Wl,-pie"
-  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
-    libc_cv_ld_static_pie=yes
-  else
-    libc_cv_ld_static_pie=no
-  fi
-rm -f conftest*])
-  if test "$libc_cv_ld_static_pie" != yes; then
-    AC_MSG_ERROR([linker support for static PIE needed])
-  fi
-fi
-
 dnl It is always possible to access static and hidden symbols in an
 dnl position independent way.
 AC_DEFINE(PI_STATIC_AND_HIDDEN)
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/x86_64/fpu/libm-test-ulps b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/x86_64/fpu/libm-test-ulps
index 85552bd..f34e91a 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/x86_64/fpu/libm-test-ulps
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/x86_64/fpu/libm-test-ulps
@@ -1262,7 +1262,9 @@
 ldouble: 1
 
 Function: "cos":
+double: 1
 float128: 1
+idouble: 1
 ifloat128: 1
 ildouble: 1
 ldouble: 1
@@ -2526,7 +2528,9 @@
 float: 3
 
 Function: "sin":
+double: 1
 float128: 1
+idouble: 1
 ifloat128: 1
 ildouble: 1
 ldouble: 1
@@ -2576,7 +2580,9 @@
 float: 1
 
 Function: "sincos":
+double: 1
 float128: 1
+idouble: 1
 ifloat128: 1
 ildouble: 1
 ldouble: 1
diff --git a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/x86_64/nptl/pthread_spin_lock.S b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/x86_64/nptl/pthread_spin_lock.S
index 730fd65..1468944 100644
--- a/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/x86_64/nptl/pthread_spin_lock.S
+++ b/google3/third_party/grte/v5_src/glibc-2.27/sysdeps/x86_64/nptl/pthread_spin_lock.S
@@ -15,7 +15,6 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <lowlevellock.h>
 #include <sysdep.h>
 
 ENTRY(pthread_spin_lock)