Skip to contentSkip to conversation

libgcrypt: Allow GRUB to Build With Clang

PATCH In review Andrew Hamilton 2 participants 2 messages Aug 31, 2025 – Sep 2, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libgcrypt: Allow GRUB to Build With Clang

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 pramga to disable the Clang "typedef-redefinition" warnings. This required an update to crypto.h and the import_gcry.py script to add the pragma to libgcrypt-grub's types.h due to "u16" and similar types.

---
 include/grub/crypto.h | 9 +++++++++
 util/import_gcry.py   | 6 +++++-
 2 files changed, 14 insertions(+), 1 deletion(-)
include/grub/crypto.h +9 -0
index b0d7add1d..55e21de6f 100644
@@ -245,6 +245,15 @@ 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;
util/import_gcry.py +5 -1
index 086bde77c..1e23ee760 100644
@@ -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":
Signature · 7 lines
2.47.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Reviewed-by Daniel Kiper on v1 1/1
#1 lore raw
Quoted 10 lines · Andrew Hamilton

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 pramga to disable the Clang "typedef-redefinition" warnings. This required an update to crypto.h and the import_gcry.py script to add the pragma to libgcrypt-grub's types.h due to "u16" and similar types.

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel