Blame SOURCES/0202-Update-gnulib-version-and-drop-most-gnulib-patches.patch

fd0330
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
fd0330
From: Robbie Harwood <rharwood@redhat.com>
fd0330
Date: Wed, 15 Dec 2021 15:07:50 -0500
fd0330
Subject: [PATCH] Update gnulib version and drop most gnulib patches
fd0330
fd0330
In addition to the changes carried in our gnulib patches, several
fd0330
Coverity and code hygiene fixes that were previously downstream are also
fd0330
included in this 3-year gnulib increment.
fd0330
fd0330
Unfortunately, fix-width.patch is retained.
fd0330
fd0330
Bump minimum autoconf version from 2.63 to 2.64 and automake from 1.11
fd0330
to 1.14, as required by gnulib.
fd0330
fd0330
Sync bootstrap script itself with gnulib.
fd0330
fd0330
Update regexp module for new dynarray dependency.
fd0330
fd0330
Fix various new warnings.
fd0330
fd0330
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
fd0330
(cherry picked from commit deb18ff931c3133c2aa536a92bd92e50d6615303)
fd0330
[rharwood: backport around requirements in INSTALL]
fd0330
---
fd0330
 configure.ac                                       |   2 +-
fd0330
 grub-core/Makefile.core.def                        |   3 +
fd0330
 grub-core/disk/luks2.c                             |   4 +-
fd0330
 grub-core/lib/posix_wrap/limits.h                  |   6 +-
fd0330
 include/grub/compiler.h                            |   4 +-
fd0330
 include/grub/list.h                                |   2 +-
fd0330
 INSTALL                                            |   2 +-
fd0330
 bootstrap                                          | 291 ++++++++++++---------
fd0330
 bootstrap.conf                                     |  22 +-
fd0330
 conf/Makefile.extra-dist                           |   6 -
fd0330
 config.h.in                                        |  68 +++++
fd0330
 grub-core/lib/gnulib-patches/fix-null-deref.patch  |  13 -
fd0330
 .../lib/gnulib-patches/fix-null-state-deref.patch  |  12 -
fd0330
 .../gnulib-patches/fix-regcomp-uninit-token.patch  |  15 --
fd0330
 .../gnulib-patches/fix-regexec-null-deref.patch    |  12 -
fd0330
 .../lib/gnulib-patches/fix-uninit-structure.patch  |  11 -
fd0330
 .../lib/gnulib-patches/fix-unused-value.patch      |  14 -
fd0330
 17 files changed, 262 insertions(+), 225 deletions(-)
fd0330
 delete mode 100644 grub-core/lib/gnulib-patches/fix-null-deref.patch
fd0330
 delete mode 100644 grub-core/lib/gnulib-patches/fix-null-state-deref.patch
fd0330
 delete mode 100644 grub-core/lib/gnulib-patches/fix-regcomp-uninit-token.patch
fd0330
 delete mode 100644 grub-core/lib/gnulib-patches/fix-regexec-null-deref.patch
fd0330
 delete mode 100644 grub-core/lib/gnulib-patches/fix-uninit-structure.patch
fd0330
 delete mode 100644 grub-core/lib/gnulib-patches/fix-unused-value.patch
fd0330
fd0330
diff --git a/configure.ac b/configure.ac
fd0330
index 40c4338bce..79f45ef1e1 100644
fd0330
--- a/configure.ac
fd0330
+++ b/configure.ac
fd0330
@@ -49,7 +49,7 @@ AC_CANONICAL_TARGET
fd0330
 program_prefix="${save_program_prefix}"
fd0330
 
fd0330
 AM_INIT_AUTOMAKE([1.11])
fd0330
-AC_PREREQ(2.63)
fd0330
+AC_PREREQ(2.64)
fd0330
 AC_CONFIG_SRCDIR([include/grub/dl.h])
fd0330
 AC_CONFIG_HEADER([config-util.h])
fd0330
 
fd0330
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
fd0330
index 08ac0fb15f..ec1ec5083b 100644
fd0330
--- a/grub-core/Makefile.core.def
fd0330
+++ b/grub-core/Makefile.core.def
fd0330
@@ -762,6 +762,9 @@ module = {
fd0330
   name = regexp;
fd0330
   common = commands/regexp.c;
fd0330
   common = commands/wildcard.c;
fd0330
+  common = lib/gnulib/malloc/dynarray_finalize.c;
fd0330
+  common = lib/gnulib/malloc/dynarray_emplace_enlarge.c;
fd0330
+  common = lib/gnulib/malloc/dynarray_resize.c;
fd0330
   common = lib/gnulib/regex.c;
fd0330
   cflags = '$(CFLAGS_POSIX) $(CFLAGS_GNULIB)';
fd0330
   cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB)';
fd0330
diff --git a/grub-core/disk/luks2.c b/grub-core/disk/luks2.c
fd0330
index 371a53b837..c917a5f91e 100644
fd0330
--- a/grub-core/disk/luks2.c
fd0330
+++ b/grub-core/disk/luks2.c
fd0330
@@ -389,7 +389,7 @@ luks2_verify_key (grub_luks2_digest_t *d, grub_uint8_t *candidate_key,
fd0330
 {
fd0330
   grub_uint8_t candidate_digest[GRUB_CRYPTODISK_MAX_KEYLEN];
fd0330
   grub_uint8_t digest[GRUB_CRYPTODISK_MAX_KEYLEN], salt[GRUB_CRYPTODISK_MAX_KEYLEN];
fd0330
-  grub_size_t saltlen = sizeof (salt), digestlen = sizeof (digest);
fd0330
+  idx_t saltlen = sizeof (salt), digestlen = sizeof (digest);
fd0330
   const gcry_md_spec_t *hash;
fd0330
   gcry_err_code_t gcry_ret;
fd0330
 
fd0330
@@ -428,7 +428,7 @@ luks2_decrypt_key (grub_uint8_t *out_key,
fd0330
   grub_uint8_t area_key[GRUB_CRYPTODISK_MAX_KEYLEN];
fd0330
   grub_uint8_t salt[GRUB_CRYPTODISK_MAX_KEYLEN];
fd0330
   grub_uint8_t *split_key = NULL;
fd0330
-  grub_size_t saltlen = sizeof (salt);
fd0330
+  idx_t saltlen = sizeof (salt);
fd0330
   char cipher[32], *p;
fd0330
   const gcry_md_spec_t *hash;
fd0330
   gcry_err_code_t gcry_ret;
fd0330
diff --git a/grub-core/lib/posix_wrap/limits.h b/grub-core/lib/posix_wrap/limits.h
fd0330
index 591dbf3289..4be7b40806 100644
fd0330
--- a/grub-core/lib/posix_wrap/limits.h
fd0330
+++ b/grub-core/lib/posix_wrap/limits.h
fd0330
@@ -25,7 +25,11 @@
fd0330
 #define USHRT_MAX GRUB_USHRT_MAX
fd0330
 #define UINT_MAX GRUB_UINT_MAX
fd0330
 #define ULONG_MAX GRUB_ULONG_MAX
fd0330
-#define SIZE_MAX GRUB_SIZE_MAX
fd0330
+
fd0330
+/* gnulib also defines this type */
fd0330
+#ifndef SIZE_MAX
fd0330
+#  define SIZE_MAX GRUB_SIZE_MAX
fd0330
+#endif
fd0330
 
fd0330
 #define SCHAR_MIN GRUB_SCHAR_MIN
fd0330
 #define SCHAR_MAX GRUB_SCHAR_MAX
fd0330
diff --git a/include/grub/compiler.h b/include/grub/compiler.h
fd0330
index ebafec6895..441a9eca07 100644
fd0330
--- a/include/grub/compiler.h
fd0330
+++ b/include/grub/compiler.h
fd0330
@@ -30,10 +30,10 @@
fd0330
 
fd0330
 /* Does this compiler support compile-time error attributes? */
fd0330
 #if GNUC_PREREQ(4,3)
fd0330
-#  define ATTRIBUTE_ERROR(msg) \
fd0330
+#  define GRUB_ATTRIBUTE_ERROR(msg) \
fd0330
 	__attribute__ ((__error__ (msg)))
fd0330
 #else
fd0330
-#  define ATTRIBUTE_ERROR(msg) __attribute__ ((noreturn))
fd0330
+#  define GRUB_ATTRIBUTE_ERROR(msg) __attribute__ ((noreturn))
fd0330
 #endif
fd0330
 
fd0330
 #if GNUC_PREREQ(4,4)
fd0330
diff --git a/include/grub/list.h b/include/grub/list.h
fd0330
index b13acb9624..21f4b4b44a 100644
fd0330
--- a/include/grub/list.h
fd0330
+++ b/include/grub/list.h
fd0330
@@ -40,7 +40,7 @@ void EXPORT_FUNC(grub_list_remove) (grub_list_t item);
fd0330
 
fd0330
 static inline void *
fd0330
 grub_bad_type_cast_real (int line, const char *file)
fd0330
-     ATTRIBUTE_ERROR ("bad type cast between incompatible grub types");
fd0330
+     GRUB_ATTRIBUTE_ERROR ("bad type cast between incompatible grub types");
fd0330
 
fd0330
 static inline void *
fd0330
 grub_bad_type_cast_real (int line, const char *file)
fd0330
diff --git a/INSTALL b/INSTALL
fd0330
index 79a0af7d93..ee9f536f76 100644
fd0330
--- a/INSTALL
fd0330
+++ b/INSTALL
fd0330
@@ -42,7 +42,7 @@ If you use a development snapshot or want to hack on GRUB you may
fd0330
 need the following.
fd0330
 
fd0330
 * Python 2.6 or later
fd0330
-* Autoconf 2.63 or later
fd0330
+* Autoconf 2.64 or later
fd0330
 * Automake 1.11 or later
fd0330
 
fd0330
 Prerequisites for make-check:
fd0330
diff --git a/bootstrap b/bootstrap
fd0330
index 5b08e7e2d4..dc2238f4ad 100755
fd0330
--- a/bootstrap
fd0330
+++ b/bootstrap
fd0330
@@ -1,10 +1,10 @@
fd0330
 #! /bin/sh
fd0330
 # Print a version string.
fd0330
-scriptversion=2019-01-04.17; # UTC
fd0330
+scriptversion=2022-01-26.05; # UTC
fd0330
 
fd0330
 # Bootstrap this package from checked-out sources.
fd0330
 
fd0330
-# Copyright (C) 2003-2019 Free Software Foundation, Inc.
fd0330
+# Copyright (C) 2003-2022 Free Software Foundation, Inc.
fd0330
 
fd0330
 # This program is free software: you can redistribute it and/or modify
fd0330
 # it under the terms of the GNU General Public License as published by
fd0330
@@ -47,7 +47,7 @@ PERL="${PERL-perl}"
fd0330
 
fd0330
 me=$0
fd0330
 
fd0330
-default_gnulib_url=git://git.sv.gnu.org/gnulib
fd0330
+default_gnulib_url=https://git.savannah.gnu.org/git/gnulib.git
fd0330
 
fd0330
 usage() {
fd0330
   cat <
fd0330
@@ -71,7 +71,9 @@ Options:
fd0330
  --no-git                 do not use git to update gnulib.  Requires that
fd0330
                           --gnulib-srcdir point to a correct gnulib snapshot
fd0330
  --skip-po                do not download po files
fd0330
-
fd0330
+EOF
fd0330
+  bootstrap_print_option_usage_hook
fd0330
+  cat <
fd0330
 If the file $me.conf exists in the same directory as this script, its
fd0330
 contents are read as shell variables to configure the bootstrap.
fd0330
 
fd0330
@@ -113,6 +115,12 @@ Running without arguments will suffice in most cases.
fd0330
 EOF
fd0330
 }
fd0330
 
fd0330
+copyright_year=`echo "$scriptversion" | sed -e 's/[^0-9].*//'`
fd0330
+copyright="Copyright (C) ${copyright_year} Free Software Foundation, Inc.
fd0330
+License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
fd0330
+This is free software: you are free to change and redistribute it.
fd0330
+There is NO WARRANTY, to the extent permitted by law."
fd0330
+
fd0330
 # warnf_ FORMAT-STRING ARG1...
fd0330
 warnf_ ()
fd0330
 {
fd0330
@@ -154,6 +162,18 @@ gnulib_files=
fd0330
 : ${AUTOPOINT=autopoint}
fd0330
 : ${AUTORECONF=autoreconf}
fd0330
 
fd0330
+# A function to be called for each unrecognized option.  Returns 0 if
fd0330
+# the option in $1 has been processed by the function.  Returns 1 if
fd0330
+# the option has not been processed by the function.  Override it via
fd0330
+# your own definition in bootstrap.conf
fd0330
+
fd0330
+bootstrap_option_hook() { return 1; }
fd0330
+
fd0330
+# A function to be called in order to print the --help information
fd0330
+# corresponding to user-defined command-line options.
fd0330
+
fd0330
+bootstrap_print_option_usage_hook() { :; }
fd0330
+
fd0330
 # A function to be called right after gnulib-tool is run.
fd0330
 # Override it via your own definition in bootstrap.conf.
fd0330
 bootstrap_post_import_hook() { :; }
fd0330
@@ -166,11 +186,11 @@ bootstrap_epilogue() { :; }
fd0330
 # specified directory.  Fill in the first %s with the destination
fd0330
 # directory and the second with the domain name.
fd0330
 po_download_command_format=\
fd0330
-"wget --mirror --level=1 -nd -q -A.po -P '%s' \
fd0330
+"wget --mirror --level=1 -nd -nv -A.po -P '%s' \
fd0330
  https://translationproject.org/latest/%s/"
fd0330
 
fd0330
 # Prefer a non-empty tarname (4th argument of AC_INIT if given), else
fd0330
-# fall back to the package name (1st argument with munging)
fd0330
+# fall back to the package name (1st argument with munging).
fd0330
 extract_package_name='
fd0330
   /^AC_INIT(\[*/{
fd0330
      s///
fd0330
@@ -187,8 +207,11 @@ extract_package_name='
fd0330
      p
fd0330
   }
fd0330
 '
fd0330
-package=$(sed -n "$extract_package_name" configure.ac) \
fd0330
-  || die 'cannot find package name in configure.ac'
fd0330
+package=$(${AUTOCONF:-autoconf} --trace AC_INIT:\$4 configure.ac 2>/dev/null)
fd0330
+if test -z "$package"; then
fd0330
+  package=$(sed -n "$extract_package_name" configure.ac) \
fd0330
+      || die 'cannot find package name in configure.ac'
fd0330
+fi
fd0330
 gnulib_name=lib$package
fd0330
 
fd0330
 build_aux=build-aux
fd0330
@@ -290,6 +313,116 @@ find_tool ()
fd0330
   eval "export $find_tool_envvar"
fd0330
 }
fd0330
 
fd0330
+# Strip blank and comment lines to leave significant entries.
fd0330
+gitignore_entries() {
fd0330
+  sed '/^#/d; /^$/d' "$@"
fd0330
+}
fd0330
+
fd0330
+# If $STR is not already on a line by itself in $FILE, insert it at the start.
fd0330
+# Entries are inserted at the start of the ignore list to ensure existing
fd0330
+# entries starting with ! are not overridden.  Such entries support
fd0330
+# whitelisting exceptions after a more generic blacklist pattern.
fd0330
+insert_if_absent() {
fd0330
+  file=$1
fd0330
+  str=$2
fd0330
+  test -f $file || touch $file
fd0330
+  test -r $file || die "Error: failed to read ignore file: $file"
fd0330
+  duplicate_entries=$(gitignore_entries $file | sort | uniq -d)
fd0330
+  if [ "$duplicate_entries" ] ; then
fd0330
+    die "Error: Duplicate entries in $file: " $duplicate_entries
fd0330
+  fi
fd0330
+  linesold=$(gitignore_entries $file | wc -l)
fd0330
+  linesnew=$( { echo "$str"; cat $file; } | gitignore_entries | sort -u | wc -l)
fd0330
+  if [ $linesold != $linesnew ] ; then
fd0330
+    { echo "$str" | cat - $file > $file.bak && mv $file.bak $file; } \
fd0330
+      || die "insert_if_absent $file $str: failed"
fd0330
+  fi
fd0330
+}
fd0330
+
fd0330
+# Adjust $PATTERN for $VC_IGNORE_FILE and insert it with
fd0330
+# insert_if_absent.
fd0330
+insert_vc_ignore() {
fd0330
+  vc_ignore_file="$1"
fd0330
+  pattern="$2"
fd0330
+  case $vc_ignore_file in
fd0330
+  *.gitignore)
fd0330
+    # A .gitignore entry that does not start with '/' applies
fd0330
+    # recursively to subdirectories, so prepend '/' to every
fd0330
+    # .gitignore entry.
fd0330
+    pattern=$(echo "$pattern" | sed s,^,/,);;
fd0330
+  esac
fd0330
+  insert_if_absent "$vc_ignore_file" "$pattern"
fd0330
+}
fd0330
+
fd0330
+symlink_to_dir()
fd0330
+{
fd0330
+  src=$1/$2
fd0330
+  dst=${3-$2}
fd0330
+
fd0330
+  test -f "$src" && {
fd0330
+
fd0330
+    # If the destination directory doesn't exist, create it.
fd0330
+    # This is required at least for "lib/uniwidth/cjk.h".
fd0330
+    dst_dir=$(dirname "$dst")
fd0330
+    if ! test -d "$dst_dir"; then
fd0330
+      mkdir -p "$dst_dir"
fd0330
+
fd0330
+      # If we've just created a directory like lib/uniwidth,
fd0330
+      # tell version control system(s) it's ignorable.
fd0330
+      # FIXME: for now, this does only one level
fd0330
+      parent=$(dirname "$dst_dir")
fd0330
+      for dot_ig in x $vc_ignore; do
fd0330
+        test $dot_ig = x && continue
fd0330
+        ig=$parent/$dot_ig
fd0330
+        insert_vc_ignore $ig "${dst_dir##*/}"
fd0330
+      done
fd0330
+    fi
fd0330
+
fd0330
+    if $copy; then
fd0330
+      {
fd0330
+        test ! -h "$dst" || {
fd0330
+          echo "$me: rm -f $dst" &&
fd0330
+          rm -f "$dst"
fd0330
+        }
fd0330
+      } &&
fd0330
+      test -f "$dst" &&
fd0330
+      cmp -s "$src" "$dst" || {
fd0330
+        echo "$me: cp -fp $src $dst" &&
fd0330
+        cp -fp "$src" "$dst"
fd0330
+      }
fd0330
+    else
fd0330
+      # Leave any existing symlink alone, if it already points to the source,
fd0330
+      # so that broken build tools that care about symlink times
fd0330
+      # aren't confused into doing unnecessary builds.  Conversely, if the
fd0330
+      # existing symlink's timestamp is older than the source, make it afresh,
fd0330
+      # so that broken tools aren't confused into skipping needed builds.  See
fd0330
+      # <https://lists.gnu.org/r/bug-gnulib/2011-05/msg00326.html>.
fd0330
+      test -h "$dst" &&
fd0330
+      src_ls=$(ls -diL "$src" 2>/dev/null) && set $src_ls && src_i=$1 &&
fd0330
+      dst_ls=$(ls -diL "$dst" 2>/dev/null) && set $dst_ls && dst_i=$1 &&
fd0330
+      test "$src_i" = "$dst_i" &&
fd0330
+      both_ls=$(ls -dt "$src" "$dst") &&
fd0330
+      test "X$both_ls" = "X$dst$nl$src" || {
fd0330
+        dot_dots=
fd0330
+        case $src in
fd0330
+        /*) ;;
fd0330
+        *)
fd0330
+          case /$dst/ in
fd0330
+          *//* | */../* | */./* | /*/*/*/*/*/)
fd0330
+             die "invalid symlink calculation: $src -> $dst";;
fd0330
+          /*/*/*/*/)    dot_dots=../../../;;
fd0330
+          /*/*/*/)      dot_dots=../../;;
fd0330
+          /*/*/)        dot_dots=../;;
fd0330
+          esac;;
fd0330
+        esac
fd0330
+
fd0330
+        echo "$me: ln -fs $dot_dots$src $dst" &&
fd0330
+        ln -fs "$dot_dots$src" "$dst"
fd0330
+      }
fd0330
+    fi
fd0330
+  }
fd0330
+}
fd0330
+
fd0330
 # Override the default configuration, if necessary.
fd0330
 # Make sure that bootstrap.conf is sourced from the current directory
fd0330
 # if we were invoked as "sh bootstrap".
fd0330
@@ -320,6 +453,12 @@ do
fd0330
   --help)
fd0330
     usage
fd0330
     exit;;
fd0330
+  --version)
fd0330
+    set -e
fd0330
+    echo "bootstrap $scriptversion"
fd0330
+    echo "$copyright"
fd0330
+    exit 0
fd0330
+    ;;
fd0330
   --gnulib-srcdir=*)
fd0330
     GNULIB_SRCDIR=${option#--gnulib-srcdir=};;
fd0330
   --skip-po)
fd0330
@@ -335,7 +474,7 @@ do
fd0330
   --no-git)
fd0330
     use_git=false;;
fd0330
   *)
fd0330
-    die "$option: unknown option";;
fd0330
+    bootstrap_option_hook $option || die "$option: unknown option";;
fd0330
   esac
fd0330
 done
fd0330
 
fd0330
@@ -346,47 +485,6 @@ if test -n "$checkout_only_file" && test ! -r "$checkout_only_file"; then
fd0330
   die "Bootstrapping from a non-checked-out distribution is risky."
fd0330
 fi
fd0330
 
fd0330
-# Strip blank and comment lines to leave significant entries.
fd0330
-gitignore_entries() {
fd0330
-  sed '/^#/d; /^$/d' "$@"
fd0330
-}
fd0330
-
fd0330
-# If $STR is not already on a line by itself in $FILE, insert it at the start.
fd0330
-# Entries are inserted at the start of the ignore list to ensure existing
fd0330
-# entries starting with ! are not overridden.  Such entries support
fd0330
-# whitelisting exceptions after a more generic blacklist pattern.
fd0330
-insert_if_absent() {
fd0330
-  file=$1
fd0330
-  str=$2
fd0330
-  test -f $file || touch $file
fd0330
-  test -r $file || die "Error: failed to read ignore file: $file"
fd0330
-  duplicate_entries=$(gitignore_entries $file | sort | uniq -d)
fd0330
-  if [ "$duplicate_entries" ] ; then
fd0330
-    die "Error: Duplicate entries in $file: " $duplicate_entries
fd0330
-  fi
fd0330
-  linesold=$(gitignore_entries $file | wc -l)
fd0330
-  linesnew=$( { echo "$str"; cat $file; } | gitignore_entries | sort -u | wc -l)
fd0330
-  if [ $linesold != $linesnew ] ; then
fd0330
-    { echo "$str" | cat - $file > $file.bak && mv $file.bak $file; } \
fd0330
-      || die "insert_if_absent $file $str: failed"
fd0330
-  fi
fd0330
-}
fd0330
-
fd0330
-# Adjust $PATTERN for $VC_IGNORE_FILE and insert it with
fd0330
-# insert_if_absent.
fd0330
-insert_vc_ignore() {
fd0330
-  vc_ignore_file="$1"
fd0330
-  pattern="$2"
fd0330
-  case $vc_ignore_file in
fd0330
-  *.gitignore)
fd0330
-    # A .gitignore entry that does not start with '/' applies
fd0330
-    # recursively to subdirectories, so prepend '/' to every
fd0330
-    # .gitignore entry.
fd0330
-    pattern=$(echo "$pattern" | sed s,^,/,);;
fd0330
-  esac
fd0330
-  insert_if_absent "$vc_ignore_file" "$pattern"
fd0330
-}
fd0330
-
fd0330
 # Die if there is no AC_CONFIG_AUX_DIR($build_aux) line in configure.ac.
fd0330
 found_aux_dir=no
fd0330
 grep '^[	 ]*AC_CONFIG_AUX_DIR(\['"$build_aux"'\])' configure.ac \
fd0330
@@ -665,9 +763,25 @@ if $use_gnulib; then
fd0330
       shallow=
fd0330
       if test -z "$GNULIB_REVISION"; then
fd0330
         git clone -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2'
fd0330
+        git clone $shallow ${GNULIB_URL:-$default_gnulib_url} "$gnulib_path" \
fd0330
+          || cleanup_gnulib
fd0330
+      else
fd0330
+        git fetch -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2'
fd0330
+        mkdir -p "$gnulib_path"
fd0330
+        # Only want a shallow checkout of $GNULIB_REVISION, but git does not
fd0330
+        # support cloning by commit hash. So attempt a shallow fetch by commit
fd0330
+        # hash to minimize the amount of data downloaded and changes needed to
fd0330
+        # be processed, which can drastically reduce download and processing
fd0330
+        # time for checkout. If the fetch by commit fails, a shallow fetch can
fd0330
+        # not be performed because we do not know what the depth of the commit
fd0330
+        # is without fetching all commits. So fallback to fetching all commits.
fd0330
+        git -C "$gnulib_path" init
fd0330
+        git -C "$gnulib_path" remote add origin ${GNULIB_URL:-$default_gnulib_url}
fd0330
+        git -C "$gnulib_path" fetch $shallow origin "$GNULIB_REVISION" \
fd0330
+          || git -C "$gnulib_path" fetch origin \
fd0330
+          || cleanup_gnulib
fd0330
+        git -C "$gnulib_path" reset --hard FETCH_HEAD
fd0330
       fi
fd0330
-      git clone $shallow ${GNULIB_URL:-$default_gnulib_url} "$gnulib_path" \
fd0330
-        || cleanup_gnulib
fd0330
 
fd0330
       trap - 1 2 13 15
fd0330
     fi
fd0330
@@ -784,75 +898,6 @@ case $SKIP_PO in
fd0330
   fi;;
fd0330
 esac
fd0330
 
fd0330
-symlink_to_dir()
fd0330
-{
fd0330
-  src=$1/$2
fd0330
-  dst=${3-$2}
fd0330
-
fd0330
-  test -f "$src" && {
fd0330
-
fd0330
-    # If the destination directory doesn't exist, create it.
fd0330
-    # This is required at least for "lib/uniwidth/cjk.h".
fd0330
-    dst_dir=$(dirname "$dst")
fd0330
-    if ! test -d "$dst_dir"; then
fd0330
-      mkdir -p "$dst_dir"
fd0330
-
fd0330
-      # If we've just created a directory like lib/uniwidth,
fd0330
-      # tell version control system(s) it's ignorable.
fd0330
-      # FIXME: for now, this does only one level
fd0330
-      parent=$(dirname "$dst_dir")
fd0330
-      for dot_ig in x $vc_ignore; do
fd0330
-        test $dot_ig = x && continue
fd0330
-        ig=$parent/$dot_ig
fd0330
-        insert_vc_ignore $ig "${dst_dir##*/}"
fd0330
-      done
fd0330
-    fi
fd0330
-
fd0330
-    if $copy; then
fd0330
-      {
fd0330
-        test ! -h "$dst" || {
fd0330
-          echo "$me: rm -f $dst" &&
fd0330
-          rm -f "$dst"
fd0330
-        }
fd0330
-      } &&
fd0330
-      test -f "$dst" &&
fd0330
-      cmp -s "$src" "$dst" || {
fd0330
-        echo "$me: cp -fp $src $dst" &&
fd0330
-        cp -fp "$src" "$dst"
fd0330
-      }
fd0330
-    else
fd0330
-      # Leave any existing symlink alone, if it already points to the source,
fd0330
-      # so that broken build tools that care about symlink times
fd0330
-      # aren't confused into doing unnecessary builds.  Conversely, if the
fd0330
-      # existing symlink's timestamp is older than the source, make it afresh,
fd0330
-      # so that broken tools aren't confused into skipping needed builds.  See
fd0330
-      # <https://lists.gnu.org/r/bug-gnulib/2011-05/msg00326.html>.
fd0330
-      test -h "$dst" &&
fd0330
-      src_ls=$(ls -diL "$src" 2>/dev/null) && set $src_ls && src_i=$1 &&
fd0330
-      dst_ls=$(ls -diL "$dst" 2>/dev/null) && set $dst_ls && dst_i=$1 &&
fd0330
-      test "$src_i" = "$dst_i" &&
fd0330
-      both_ls=$(ls -dt "$src" "$dst") &&
fd0330
-      test "X$both_ls" = "X$dst$nl$src" || {
fd0330
-        dot_dots=
fd0330
-        case $src in
fd0330
-        /*) ;;
fd0330
-        *)
fd0330
-          case /$dst/ in
fd0330
-          *//* | */../* | */./* | /*/*/*/*/*/)
fd0330
-             die "invalid symlink calculation: $src -> $dst";;
fd0330
-          /*/*/*/*/)    dot_dots=../../../;;
fd0330
-          /*/*/*/)      dot_dots=../../;;
fd0330
-          /*/*/)        dot_dots=../;;
fd0330
-          esac;;
fd0330
-        esac
fd0330
-
fd0330
-        echo "$me: ln -fs $dot_dots$src $dst" &&
fd0330
-        ln -fs "$dot_dots$src" "$dst"
fd0330
-      }
fd0330
-    fi
fd0330
-  }
fd0330
-}
fd0330
-
fd0330
 version_controlled_file() {
fd0330
   parent=$1
fd0330
   file=$2
fd0330
@@ -970,7 +1015,7 @@ bootstrap_post_import_hook \
fd0330
 # Uninitialized submodules are listed with an initial dash.
fd0330
 if $use_git && git submodule | grep '^-' >/dev/null; then
fd0330
   die "some git submodules are not initialized. "     \
fd0330
-      "Run 'git submodule init' and bootstrap again."
fd0330
+      "Run 'git submodule update --init' and bootstrap again."
fd0330
 fi
fd0330
 
fd0330
 # Remove any dangling symlink matching "*.m4" or "*.[ch]" in some
fd0330
@@ -1064,7 +1109,7 @@ bootstrap_epilogue
fd0330
 
fd0330
 echo "$0: done.  Now you can run './configure'."
fd0330
 
fd0330
-# Local variables:
fd0330
+# Local Variables:
fd0330
 # eval: (add-hook 'before-save-hook 'time-stamp)
fd0330
 # time-stamp-start: "scriptversion="
fd0330
 # time-stamp-format: "%:y-%02m-%02d.%02H"
fd0330
diff --git a/bootstrap.conf b/bootstrap.conf
fd0330
index 71ce943c7d..e4e5f3750a 100644
fd0330
--- a/bootstrap.conf
fd0330
+++ b/bootstrap.conf
fd0330
@@ -1,6 +1,6 @@
fd0330
 # Bootstrap configuration.
fd0330
 
fd0330
-# Copyright (C) 2006-2019 Free Software Foundation, Inc.
fd0330
+# Copyright (C) 2006-2022 Free Software Foundation, Inc.
fd0330
 
fd0330
 # This program is free software: you can redistribute it and/or modify
fd0330
 # it under the terms of the GNU General Public License as published by
fd0330
@@ -16,11 +16,10 @@
fd0330
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
fd0330
 
fd0330
 
fd0330
-GNULIB_REVISION=d271f868a8df9bbec29049d01e056481b7a1a263
fd0330
+GNULIB_REVISION=9f48fb992a3d7e96610c4ce8be969cff2d61a01b
fd0330
 
fd0330
 # gnulib modules used by this package.
fd0330
-# mbswidth is used by gnulib-fix-width.diff's changes to argp rather than
fd0330
-# directly.
fd0330
+# mbswidth is used by fix-width.diff's changes to argp rather than directly.
fd0330
 gnulib_modules="
fd0330
   argp
fd0330
   base64
fd0330
@@ -67,8 +66,8 @@ SKIP_PO=t
fd0330
 
fd0330
 # Build prerequisites
fd0330
 buildreq="\
fd0330
-autoconf   2.63
fd0330
-automake   1.11
fd0330
+autoconf   2.64
fd0330
+automake   1.14
fd0330
 gettext    0.18.3
fd0330
 git        1.5.5
fd0330
 tar        -
fd0330
@@ -80,11 +79,12 @@ cp -a INSTALL INSTALL.grub
fd0330
 
fd0330
 bootstrap_post_import_hook () {
fd0330
   set -e
fd0330
-  for patchname in fix-null-deref fix-null-state-deref fix-regcomp-uninit-token \
fd0330
-      fix-regexec-null-deref fix-uninit-structure fix-unused-value fix-width; do
fd0330
-    patch -d grub-core/lib/gnulib -p2 \
fd0330
-      < "grub-core/lib/gnulib-patches/$patchname.patch"
fd0330
-  done
fd0330
+
fd0330
+  # Instead of patching our gnulib and therefore maintaining a fork, submit
fd0330
+  # changes to gnulib and update the hash above when they've merged.  Do not
fd0330
+  # add new patches here.
fd0330
+  patch -d grub-core/lib/gnulib -p2 < grub-core/lib/gnulib-patches/fix-width.patch
fd0330
+
fd0330
   for patchname in \
fd0330
       0001-Support-POTFILES-shell \
fd0330
       0002-Handle-gettext_printf-shell-function \
fd0330
diff --git a/conf/Makefile.extra-dist b/conf/Makefile.extra-dist
fd0330
index 5eef708338..26ac8765e3 100644
fd0330
--- a/conf/Makefile.extra-dist
fd0330
+++ b/conf/Makefile.extra-dist
fd0330
@@ -31,12 +31,6 @@ EXTRA_DIST += grub-core/gensymlist.sh
fd0330
 EXTRA_DIST += grub-core/genemuinit.sh
fd0330
 EXTRA_DIST += grub-core/genemuinitheader.sh
fd0330
 
fd0330
-EXTRA_DIST += grub-core/lib/gnulib-patches/fix-null-deref.patch
fd0330
-EXTRA_DIST += grub-core/lib/gnulib-patches/fix-null-state-deref.patch
fd0330
-EXTRA_DIST += grub-core/lib/gnulib-patches/fix-regcomp-uninit-token.patch
fd0330
-EXTRA_DIST += grub-core/lib/gnulib-patches/fix-regexec-null-deref.patch
fd0330
-EXTRA_DIST += grub-core/lib/gnulib-patches/fix-uninit-structure.patch
fd0330
-EXTRA_DIST += grub-core/lib/gnulib-patches/fix-unused-value.patch
fd0330
 EXTRA_DIST += grub-core/lib/gnulib-patches/fix-width.patch
fd0330
 
fd0330
 EXTRA_DIST += grub-core/lib/libgcrypt
fd0330
diff --git a/config.h.in b/config.h.in
fd0330
index c3134309c6..512d1bbe13 100644
fd0330
--- a/config.h.in
fd0330
+++ b/config.h.in
fd0330
@@ -67,10 +67,78 @@
fd0330
 #  define _GNU_SOURCE 1
fd0330
 
fd0330
 #  ifndef _GL_INLINE_HEADER_BEGIN
fd0330
+/* gnulib gets configured against the host, not the target, and the rest of
fd0330
+ * our buildsystem works around that.  This is difficult to avoid as gnulib's
fd0330
+ * detection requires a more capable system than our target.  Instead, we
fd0330
+ * reach in and set values appropriately - intentionally setting more than the
fd0330
+ * bare minimum.  If, when updating gnulib, something breaks, there's probably
fd0330
+ * a change needed here or in grub-core/Makefile.core.def. */
fd0330
+#    define SIZE_MAX ((size_t) -1)
fd0330
+#    define _GL_ATTRIBUTE_ALLOC_SIZE(args) \
fd0330
+    __attribute__ ((__alloc_size__ args))
fd0330
+#    define _GL_ATTRIBUTE_ALWAYS_INLINE __attribute__ ((__always_inline__))
fd0330
+#    define _GL_ATTRIBUTE_ARTIFICIAL __attribute__ ((__artificial__))
fd0330
+#    define _GL_ATTRIBUTE_COLD __attribute__ ((cold))
fd0330
 #    define _GL_ATTRIBUTE_CONST __attribute__ ((const))
fd0330
+#    define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute ((__malloc__ (f, i)))
fd0330
+#    define _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC (free, 1)
fd0330
+#    define _GL_ATTRIBUTE_DEPRECATED __attribute__ ((__deprecated__))
fd0330
+#    define _GL_ATTRIBUTE_ERROR(msg) __attribute__ ((__error__ (msg)))
fd0330
+#    define _GL_ATTRIBUTE_EXTERNALLY_VISIBLE \
fd0330
+    __attribute__ ((externally_visible))
fd0330
+#    define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
fd0330
+#    define _GL_ATTRIBUTE_LEAF __attribute__ ((__leaf__))
fd0330
+#    define _GL_ATTRIBUTE_MALLOC __attribute__ ((malloc))
fd0330
+#    define _GL_ATTRIBUTE_MAYBE_UNUSED _GL_ATTRIBUTE_UNUSED
fd0330
+#    define _GL_ATTRIBUTE_MAY_ALIAS __attribute__ ((__may_alias__))
fd0330
+#    define _GL_ATTRIBUTE_NODISCARD __attribute__ ((__warn_unused_result__))
fd0330
+#    define _GL_ATTRIBUTE_NOINLINE __attribute__ ((__noinline__))
fd0330
+#    define _GL_ATTRIBUTE_NONNULL(args) __attribute__ ((__nonnull__ args))
fd0330
+#    define _GL_ATTRIBUTE_NONSTRING __attribute__ ((__nonstring__))
fd0330
+#    define _GL_ATTRIBUTE_PACKED __attribute__ ((__packed__))
fd0330
+#    define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
fd0330
+#    define _GL_ATTRIBUTE_RETURNS_NONNULL \
fd0330
+    __attribute__ ((__returns_nonnull__))
fd0330
+#    define _GL_ATTRIBUTE_SENTINEL(pos) __attribute__ ((__sentinel__ pos))
fd0330
+#    define _GL_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
fd0330
+#    define _GL_ATTRIBUTE_WARNING(msg) __attribute__ ((__warning__ (msg)))
fd0330
+#    define _GL_CMP(n1, n2) (((n1) > (n2)) - ((n1) < (n2)))
fd0330
+#    define _GL_GNUC_PREREQ GNUC_PREREQ
fd0330
+#    define _GL_INLINE inline
fd0330
+#    define _GL_UNUSED_LABEL _GL_ATTRIBUTE_UNUSED
fd0330
+
fd0330
+/* We can't use __has_attribute for these because gcc-5.1 is too old for
fd0330
+ * that.  Everything above is present in that version, though. */
fd0330
+#    if __GNUC__ >= 7
fd0330
+#      define _GL_ATTRIBUTE_FALLTHROUGH __attribute__ ((fallthrough))
fd0330
+#    else
fd0330
+#      define _GL_ATTRIBUTE_FALLTHROUGH /* empty */
fd0330
+#    endif
fd0330
+
fd0330
+#    ifndef ASM_FILE
fd0330
+typedef __INT_FAST32_TYPE__ int_fast32_t;
fd0330
+typedef __UINT_FAST32_TYPE__ uint_fast32_t;
fd0330
+#    endif
fd0330
+
fd0330
+/* Ensure ialloc nests static/non-static inline properly. */
fd0330
+#    define IALLOC_INLINE static inline
fd0330
+
fd0330
+/* gnulib uses these for blocking out warnings they can't/won't fix.  gnulib
fd0330
+ * also makes the decision about whether to provide a declaration for
fd0330
+ * reallocarray() at compile-time, so this is a convenient place to override -
fd0330
+ * it's used by the ialloc module, which is used by base64. */
fd0330
+#    define _GL_INLINE_HEADER_BEGIN _Pragma ("GCC diagnostic push")	\
fd0330
+    void *								\
fd0330
+    reallocarray (void *ptr, unsigned int nmemb, unsigned int size);
fd0330
+#    define _GL_INLINE_HEADER_END   _Pragma ("GCC diagnostic pop")
fd0330
 
fd0330
 /* We don't have an abort() for gnulib to call in regexp. */
fd0330
 #    define abort __builtin_unreachable
fd0330
 #  endif /* !_GL_INLINE_HEADER_BEGIN */
fd0330
 
fd0330
+/* gnulib doesn't build cleanly with older compilers. */
fd0330
+#  if __GNUC__ < 11
fd0330
+_Pragma ("GCC diagnostic ignored \"-Wtype-limits\"")
fd0330
+#  endif
fd0330
+
fd0330
 #endif
fd0330
diff --git a/grub-core/lib/gnulib-patches/fix-null-deref.patch b/grub-core/lib/gnulib-patches/fix-null-deref.patch
fd0330
deleted file mode 100644
fd0330
index 8fafa153a4..0000000000
fd0330
--- a/grub-core/lib/gnulib-patches/fix-null-deref.patch
fd0330
+++ /dev/null
fd0330
@@ -1,13 +0,0 @@
fd0330
-diff --git a/lib/argp-parse.c b/lib/argp-parse.c
fd0330
-index 6dec57310..900adad54 100644
fd0330
---- a/lib/argp-parse.c
fd0330
-+++ b/lib/argp-parse.c
fd0330
-@@ -940,7 +940,7 @@ weak_alias (__argp_parse, argp_parse)
fd0330
- void *
fd0330
- __argp_input (const struct argp *argp, const struct argp_state *state)
fd0330
- {
fd0330
--  if (state)
fd0330
-+  if (state && state->pstate)
fd0330
-     {
fd0330
-       struct group *group;
fd0330
-       struct parser *parser = state->pstate;
fd0330
diff --git a/grub-core/lib/gnulib-patches/fix-null-state-deref.patch b/grub-core/lib/gnulib-patches/fix-null-state-deref.patch
fd0330
deleted file mode 100644
fd0330
index 813ec09c8a..0000000000
fd0330
--- a/grub-core/lib/gnulib-patches/fix-null-state-deref.patch
fd0330
+++ /dev/null
fd0330
@@ -1,12 +0,0 @@
fd0330
---- a/lib/argp-help.c	2020-10-28 14:32:19.189215988 +0000
fd0330
-+++ b/lib/argp-help.c	2020-10-28 14:38:21.204673940 +0000
fd0330
-@@ -145,7 +145,8 @@
fd0330
-       if (*(int *)((char *)upptr + up->uparams_offs) >= upptr->rmargin)
fd0330
-         {
fd0330
-           __argp_failure (state, 0, 0,
fd0330
--                          dgettext (state->root_argp->argp_domain,
fd0330
-+                          dgettext (state == NULL ? NULL
fd0330
-+                                    : state->root_argp->argp_domain,
fd0330
-                                     "\
fd0330
- ARGP_HELP_FMT: %s value is less than or equal to %s"),
fd0330
-                           "rmargin", up->name);
fd0330
diff --git a/grub-core/lib/gnulib-patches/fix-regcomp-uninit-token.patch b/grub-core/lib/gnulib-patches/fix-regcomp-uninit-token.patch
fd0330
deleted file mode 100644
fd0330
index 02e06315df..0000000000
fd0330
--- a/grub-core/lib/gnulib-patches/fix-regcomp-uninit-token.patch
fd0330
+++ /dev/null
fd0330
@@ -1,15 +0,0 @@
fd0330
---- a/lib/regcomp.c	2020-11-24 17:06:08.159223858 +0000
fd0330
-+++ b/lib/regcomp.c	2020-11-24 17:06:15.630253923 +0000
fd0330
-@@ -3808,11 +3808,7 @@
fd0330
- create_tree (re_dfa_t *dfa, bin_tree_t *left, bin_tree_t *right,
fd0330
- 	     re_token_type_t type)
fd0330
- {
fd0330
--  re_token_t t;
fd0330
--#if defined GCC_LINT || defined lint
fd0330
--  memset (&t, 0, sizeof t);
fd0330
--#endif
fd0330
--  t.type = type;
fd0330
-+  re_token_t t = { .type = type };
fd0330
-   return create_token_tree (dfa, left, right, &t);
fd0330
- }
fd0330
- 
fd0330
diff --git a/grub-core/lib/gnulib-patches/fix-regexec-null-deref.patch b/grub-core/lib/gnulib-patches/fix-regexec-null-deref.patch
fd0330
deleted file mode 100644
fd0330
index db6dac9c9e..0000000000
fd0330
--- a/grub-core/lib/gnulib-patches/fix-regexec-null-deref.patch
fd0330
+++ /dev/null
fd0330
@@ -1,12 +0,0 @@
fd0330
---- a/lib/regexec.c	2020-10-21 14:25:35.310195912 +0000
fd0330
-+++ b/lib/regexec.c	2020-11-05 10:55:09.621542984 +0000
fd0330
-@@ -1692,6 +1692,9 @@
fd0330
- {
fd0330
-   Idx top = mctx->state_log_top;
fd0330
-
fd0330
-+  if (mctx->state_log == NULL)
fd0330
-+    return REG_NOERROR;
fd0330
-+
fd0330
-   if ((next_state_log_idx >= mctx->input.bufs_len
fd0330
-        && mctx->input.bufs_len < mctx->input.len)
fd0330
-       || (next_state_log_idx >= mctx->input.valid_len
fd0330
diff --git a/grub-core/lib/gnulib-patches/fix-uninit-structure.patch b/grub-core/lib/gnulib-patches/fix-uninit-structure.patch
fd0330
deleted file mode 100644
fd0330
index 7b4d9f67af..0000000000
fd0330
--- a/grub-core/lib/gnulib-patches/fix-uninit-structure.patch
fd0330
+++ /dev/null
fd0330
@@ -1,11 +0,0 @@
fd0330
---- a/lib/regcomp.c	2020-10-22 13:49:06.770168928 +0000
fd0330
-+++ b/lib/regcomp.c	2020-10-22 13:50:37.026528298 +0000
fd0330
-@@ -3662,7 +3662,7 @@
fd0330
-   Idx alloc = 0;
fd0330
- #endif /* not RE_ENABLE_I18N */
fd0330
-   reg_errcode_t ret;
fd0330
--  re_token_t br_token;
fd0330
-+  re_token_t br_token = {0};
fd0330
-   bin_tree_t *tree;
fd0330
- 
fd0330
-   sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);
fd0330
diff --git a/grub-core/lib/gnulib-patches/fix-unused-value.patch b/grub-core/lib/gnulib-patches/fix-unused-value.patch
fd0330
deleted file mode 100644
fd0330
index ba51f1bf22..0000000000
fd0330
--- a/grub-core/lib/gnulib-patches/fix-unused-value.patch
fd0330
+++ /dev/null
fd0330
@@ -1,14 +0,0 @@
fd0330
---- a/lib/regexec.c	2020-10-21 14:25:35.310195912 +0000
fd0330
-+++ b/lib/regexec.c	2020-10-21 14:32:07.961765604 +0000
fd0330
-@@ -828,7 +828,11 @@
fd0330
- 		    break;
fd0330
- 		  if (__glibc_unlikely (err != REG_NOMATCH))
fd0330
- 		    goto free_return;
fd0330
-+#ifdef DEBUG
fd0330
-+		  /* Only used for assertion below when DEBUG is set, otherwise
fd0330
-+		     it will be over-written when we loop around.  */
fd0330
- 		  match_last = -1;
fd0330
-+#endif
fd0330
- 		}
fd0330
- 	      else
fd0330
- 		break; /* We found a match.  */