nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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