]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
libgcrypt: Allow GRUB to build with Clang
authorAndrew Hamilton <adhamilt@gmail.com>
Sun, 31 Aug 2025 03:32:39 +0000 (22:32 -0500)
committerDaniel Kiper <daniel.kiper@oracle.com>
Tue, 9 Sep 2025 23:12:17 +0000 (01:12 +0200)
Attempts to build GRUB with Clang were failing due to errors such as:

  error: redefinition of typedef 'gcry_md_hd_t' is a C11 feature

Correct this by adding a compiler pragma to disable the Clang
"typedef-redefinition" warnings. This required an update to
include/grub/crypto.h and the util/import_gcry.py script to add the
pragma to libgcrypt-grub's types.h due to u16 and similar types.

Signed-off-by: Andrew Hamilton <adhamilt@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
include/grub/crypto.h
util/import_gcry.py

index b0d7add1dba4d9f5a596ec8460658cf594e763d2..6ab021cb86bc3d453fb16fcd94cb9ff4c9ae98c5 100644 (file)
@@ -245,6 +245,14 @@ typedef struct gcry_md_spec
   struct gcry_md_spec *next;
 } gcry_md_spec_t;
 
+/*
+ * Clang defaults to flagging type redefinitions as warnings.
+ * A few "forward declarations" in this file are needed due
+ * to inter-relationship complexities between GRUB and libgcrypt.
+ */
+#ifdef __clang__
+#pragma GCC diagnostic ignored "-Wtypedef-redefinition"
+#endif
 typedef struct gcry_md_handle*gcry_md_hd_t;
 
 struct gcry_mpi;
index 086bde77c786daf25f193d474b19f9554d9dfe60..1e23ee7609ba2279ead73b945e41b0dcae5ad311 100644 (file)
@@ -608,7 +608,11 @@ with codecs.open (os.path.join (cipher_dir_out, "crypto.lst"), "w", "utf-8") as
                 continue
             with codecs.open (infile, "r", "utf-8") as f:
                 if src == "types.h":
-                    fw.write (f.read ().replace ("float f;", "").replace ("double g;", ""))
+                    fw.write (f.read ().replace ("float f;", "").replace ("double g;", "") \
+                     .replace("#ifndef HAVE_BYTE",
+                              "#ifdef __clang__\n" \
+                              "#pragma GCC diagnostic ignored \"-Wtypedef-redefinition\"\n#endif\n" \
+                              "#ifndef HAVE_BYTE"))
                     continue
 
                 if src == "cipher-proto.h":