Skip to contentSkip to conversation

Fix compilation and installation on cygwin and mingw

PATCH New Vladimir Serbinenko 1 participant 10 messages May 3, 2025

lore
Share & tools
lore
#2 lore raw

PATCH v2 2/9 compiler-rt: Add pei386_runtime_relocator stub

In reply to Vladimir Serbinenko

It's inserted by mingw and is meaningless in our environment

---
 grub-core/kern/compiler-rt.c | 4 ++++
 include/grub/compiler-rt.h   | 1 +
 2 files changed, 5 insertions(+)
grub-core/kern/compiler-rt.c +4 -0
index eda689a0c..28d3c62fe 100644
@@ -210,6 +210,10 @@ void ___chkstk_ms (void)
 void __chkstk_ms (void)
 {
 }
+
+void _pei386_runtime_relocator (void)
+{
+}
 #endif
 
 union component64
include/grub/compiler-rt.h +1 -0
index 17828b322..e139ebc87 100644
@@ -207,6 +207,7 @@ void EXPORT_FUNC (__register_frame_info) (void);
 void EXPORT_FUNC (__deregister_frame_info) (void);
 void EXPORT_FUNC (___chkstk_ms) (void);
 void EXPORT_FUNC (__chkstk_ms) (void);
+void EXPORT_FUNC (_pei386_runtime_relocator) (void);
 #endif
 
 #endif
Signature · 7 lines
2.49.0


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

PATCH v2 4/9 hostdisk: Fix cygwin compilation

In reply to Vladimir Serbinenko
---
 grub-core/osdep/windows/hostdisk.c    |  5 +++--
 include/grub/osdep/hostfile_windows.h | 10 ++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)
grub-core/osdep/windows/hostdisk.c +3 -2
index aaa6e2f8e..4d37d9db0 100644
@@ -669,13 +669,14 @@ grub_util_is_special_file (const char *name)
 
 #else
 
-void
+int
 grub_util_file_sync (FILE *f)
 {
   fflush (f);
   if (!allow_fd_syncs)
-    return;
+    return 0;
   fsync (fileno (f));
+  return 0;
 }
 
 FILE *
include/grub/osdep/hostfile_windows.h +10 -0
index bf6451b6d..a712170d1 100644
@@ -77,6 +77,16 @@ enum grub_util_fd_open_flags_t
 
 #endif
 
+#ifdef __CYGWIN__
+#include <unistd.h>
+
+static inline ssize_t
+grub_util_readlink (const char *name, char *buf, size_t bufsize)
+{
+  return readlink(name, buf, bufsize);
+}
+#endif
+
 LPTSTR
 grub_util_utf8_to_tchar (const char *in);
 char *
Signature · 7 lines
2.49.0


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

v2 cover Fix compilation and installation on cygwin and mingw

I recently borked my GRUB install, both main and fallback. I had no external media but could boot into windows via EFI menu. I discovered that our compilation and installation from windows is broken. Here is the series of patches to fix it

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

#7 lore raw

PATCH v2 7/9 mkrescue: Fix compilation under cygwin.

Cygwin is an interesting case where grub_util_fd_sync needs a handle but fileno returns an fd. Just use fsync directly in this case

---
 util/grub-mkrescue.c | 4 ++++
 1 file changed, 4 insertions(+)
util/grub-mkrescue.c +4 -0
index 6dc71a8a1..72cc693f2 100644
@@ -670,7 +670,11 @@ main (int argc, char *argv[])
 						 "i386-pc", 0);
 	      sz = ftello (sa);
 	      fflush (sa);
+#ifdef __CYGWIN__
+	      fsync (fileno (sa));
+#else
 	      grub_util_fd_sync (fileno (sa));
+#endif
 	      fclose (sa);
 
 	      if (sz > 32768)
Signature · 7 lines
2.49.0


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

PATCH v2 3/9 pe2elf: Set correct flag for relocation sections

In reply to Vladimir Serbinenko

Without this flag GRUB ignores the relocation section leading to a crash

---
 util/grub-pe2elf.c | 1 +
 1 file changed, 1 insertion(+)
util/grub-pe2elf.c +1 -0
index 11331294f..b686f0c82 100644
@@ -341,6 +341,7 @@ write_reloc_section (FILE* fp, const char *name, char *image,
       shdr[i].sh_offset = offset;
       shdr[i].sh_link = symtab_section;
       shdr[i].sh_addralign = 4;
+      shdr[i].sh_flags = SHF_INFO_LINK;
       shdr[i].sh_entsize = sizeof (elf_reloc_t);
       shdr[i].sh_size = num_rels * sizeof (elf_reloc_t);
 
Signature · 7 lines
2.49.0


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

PATCH v2 5/9 Add cygwin path to unifont

In reply to Vladimir Serbinenko
---
 configure.ac | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
configure.ac +1 -1
index e9c6ad8cc..8417ce009 100644
@@ -1925,7 +1925,7 @@ AC_ARG_WITH([unifont],
 if test "x$with_unifont" = x; then
   # search in well-known directories
   for ext in pcf pcf.gz bdf bdf.gz ttf ttf.gz otf otf.gz; do
-    for dir in . /usr/src /usr/share/fonts/X11/misc /usr/share/fonts/unifont /usr/share/fonts/uni /usr/share/fonts/truetype/unifont /usr/share/fonts/misc /usr/pkg/share/fonts/X11/misc /usr/local/share/fonts/gnu-unifont /usr/local/share/fonts/unifont; do
+    for dir in . /usr/src /usr/share/fonts/X11/misc /usr/share/fonts/unifont /usr/share/fonts/uni /usr/share/fonts/truetype/unifont /usr/share/fonts/misc /usr/pkg/share/fonts/X11/misc /usr/local/share/fonts/gnu-unifont /usr/local/share/fonts/unifont /usr/share/fonts/opentype/unifont; do
       if test -f "$dir/unifont.$ext"; then
         md5="$(md5sum "$dir/unifont.$ext"|awk '{ print $1; }')"
         # PCF and BDF from version 6.3 isn't hanled properly by libfreetype.
Signature · 7 lines
2.49.0


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

PATCH v2 9/9 render-label: Supports canonical paths not starting with /

In reply to Vladimir Serbinenko

On windows canonical path starts with drive letter

---
 util/render-label.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
util/render-label.c +1 -1
index 432a5c3d2..e78175180 100644
@@ -164,7 +164,7 @@ grub_util_render_label (const char *label_font,
 		       strerror (errno));
     }
 
-  fontfull = xasprintf ("(host)/%s", t);
+  fontfull = xasprintf ("(host)%s", t);
   free (t);
 
   grub_font_loader_init ();
Signature · 7 lines
2.49.0


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

PATCH v2 6/9 Strip extra sections generated on cygwin when creating binary images

In reply to Vladimir Serbinenko
---
 gentpl.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
gentpl.py +1 -1
index d8c6965d8..f20797228 100644
@@ -775,7 +775,7 @@ def image(defn, platform):
 if test x$(TARGET_APPLE_LINKER) = x1; then \
   $(MACHO2IMG) $< $@; \
 else \
-  $(TARGET_OBJCOPY) $(""" + cname(defn) + """_OBJCOPYFLAGS) --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .MIPS.abiflags -R .reginfo -R .rel.dyn -R .note.gnu.gold-version -R .note.gnu.property -R .ARM.exidx -R .interp $< $@; \
+  $(TARGET_OBJCOPY) $(""" + cname(defn) + """_OBJCOPYFLAGS) --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .MIPS.abiflags -R .reginfo -R .rel.dyn -R .note.gnu.gold-version -R .note.gnu.property -R .ARM.exidx -R .interp -R .reloc -R .buildid $< $@; \
 fi
 """)
 
Signature · 7 lines
2.49.0


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

PATCH v2 8/9 Discard .buildid and .reloc in cygwin script

In reply to Vladimir Serbinenko
---
 conf/i386-cygwin-img-ld.sc | 4 ++++
 1 file changed, 4 insertions(+)
conf/i386-cygwin-img-ld.sc +4 -0
index 578da91b0..aeba49f45 100644
@@ -50,6 +50,10 @@ SECTIONS
   {
     *(.stabstr)
   }
+  /DISCARD/ : {
+    *(.buildid)
+    *(.reloc)
+  }
 }
 
 ASSERT("__rdata_end__"=="edata", ".pdata not empty")
Signature · 7 lines
2.49.0


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

PATCH v2 1/9 Fix error when cross-compiling for windows from unix-like OS

In reply to Vladimir Serbinenko

In this case exeext doesn't match the expected value by autoconf and so tests fail as autoconf looks for compiled binaries under wrong name.

---
 configure.ac | 12 ++++++++++++
 1 file changed, 12 insertions(+)
configure.ac +12 -0
index 83e3ddf90..e9c6ad8cc 100644
@@ -575,12 +575,22 @@ tmp_CFLAGS="$CFLAGS"
 tmp_LDFLAGS="$LDFLAGS"
 tmp_CPPFLAGS="$CPPFLAGS"
 tmp_LIBS="$LIBS"
+tmp_EXEEXT="$EXEEXT"
+tmp_ac_exeext="$ac_exeext"
 CC="$TARGET_CC"
 CFLAGS="$TARGET_CFLAGS"
 CPPFLAGS="$TARGET_CPPFLAGS"
 LDFLAGS="$TARGET_LDFLAGS"
 LIBS=""
 
+case "$target_os" in
+  cygwin*|mingw32*|mingw64*)		TARGET_EXEEXT=.exe ;;
+  *)					TARGET_EXEEXT= ;;
+esac
+
+EXEEXT="$TARGET_EXEEXT"
+ac_exeext="$TARGET_EXEEXT"
+
 if test "x$target_m32" = x1; then
   # Force 32-bit mode.
   TARGET_CFLAGS="$TARGET_CFLAGS -m32"
@@ -1618,6 +1628,8 @@ CFLAGS="$tmp_CFLAGS"
 CPPFLAGS="$tmp_CPPFLAGS"
 LDFLAGS="$tmp_LDFLAGS"
 LIBS="$tmp_LIBS"
+EXEEXT="$tmp_EXEEXT"
+ac_exeext="$tmp_ac_exeext"
 
 #
 # Check for options.
Signature · 7 lines
2.49.0


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