public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [rpms/grub2] rawhide: Use large code model on riscv64
@ 2026-08-24 16:14 Andrea Bolognani
  0 siblings, 0 replies; only message in thread
From: Andrea Bolognani @ 2026-08-24 16:14 UTC (permalink / raw)
  To: git-commits

            A new commit has been pushed.

            Repo   : rpms/grub2
            Branch : rawhide
            Commit : 0eb7960db81d587c867f7b0f8317b61b86a1049c
            Author : Andrea Bolognani <abologna@redhat.com>
            Date   : 2026-08-20T10:42:42+02:00
            Stats  : +173/-2 in 5 file(s)
            URL    : https://src.fedoraproject.org/rpms/grub2/c/0eb7960db81d587c867f7b0f8317b61b86a1049c?branch=rawhide

            Log:
            Use large code model on riscv64

Using medany as a workaround has served us well for the past
few years, but recently we're finding that on a number of
riscv64 platforms grub2 fails with

  ../../grub-core/kern/riscv/dl.c:
  grub_arch_dl_relocate_symbols:198:relocation overflow
  Aborted. Press any key to exit.

By backporting a couple fixes from upstream, we can
successfully switch back to the large code model.

This makes grub2 work on the platforms where it didn't
before, and doesn't cause regressions on those where it
already worked when using medany.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>

---
diff --git a/0449-Revert-Use-medany-instead-of-large-model-for-RISCV.patch b/0449-Revert-Use-medany-instead-of-large-model-for-RISCV.patch
new file mode 100644
index 0000000..f0a1d32
--- /dev/null
+++ b/0449-Revert-Use-medany-instead-of-large-model-for-RISCV.patch
@@ -0,0 +1,36 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Andrea Bolognani <abologna@redhat.com>
+Date: Fri, 14 Aug 2026 13:49:04 +0200
+Subject: [PATCH] Revert "Use medany instead of large model for RISCV"
+
+This reverts commit 10b82f6850b86e0ef10b50a395c37f1fa0ef6383.
+---
+ configure.ac | 6 ++----
+ 1 file changed, 2 insertions(+), 4 deletions(-)
+
+diff --git a/configure.ac b/configure.ac
+index b37914440ab..8e7945da595 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -1313,7 +1313,7 @@ AC_SUBST(TARGET_LDFLAGS_OLDMAGIC)
+ 
+ LDFLAGS="$TARGET_LDFLAGS"
+ 
+-if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 ; then
++if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 || test "$target_cpu" = riscv64 ; then
+   # Use large model to support 4G memory
+   AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [
+     CFLAGS="$TARGET_CFLAGS -mcmodel=large"
+@@ -1323,11 +1323,9 @@ if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 ; then
+   ])
+   if test "x$grub_cv_cc_mcmodel" = xyes; then
+     TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large"
+-  elif test "$target_cpu" = sparc64; then
++  elif test "$target_cpu" = sparc64 || test "$target_cpu" = riscv64; then
+     TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=medany"
+   fi
+-elif test "$target_cpu" = riscv64 ; then
+-    TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=medany"
+ fi
+ 
+ if test "$target_cpu"-"$platform" = x86_64-efi; then

diff --git a/0450-configure-Add-mno-relax-on-riscv.patch b/0450-configure-Add-mno-relax-on-riscv.patch
new file mode 100644
index 0000000..9191045
--- /dev/null
+++ b/0450-configure-Add-mno-relax-on-riscv.patch
@@ -0,0 +1,51 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Vladimir Serbinenko <phcoder@gmail.com>
+Date: Thu, 27 Mar 2025 19:32:23 +0300
+Subject: [PATCH] configure: Add -mno-relax on riscv*
+
+Without this option compiler sometimes emits R_RISCV_ALIGN relocs.
+Unlike other relocs this one requires the linker to do NOP deletions
+and we can't ignore them. Just instruct compiler not to emit them.
+
+Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
+Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
+---
+ configure.ac | 25 +++++++++++++++++++++++++
+ 1 file changed, 25 insertions(+)
+
+diff --git a/configure.ac b/configure.ac
+index 8e7945da595..bca4dc5beaa 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -939,6 +939,31 @@ else
+   with_utils=target
+ fi
+ 
++if test "x$target_cpu" = xriscv64 || test "x$target_cpu" = xriscv32; then
++  AC_CACHE_CHECK([for no-relax options], grub_cv_target_cc_mno_relax, [
++    grub_cv_target_cc_mno_relax=no
++    for cand in "-mno-relax" "-Wa,-mno-relax"; do
++      if test x"$grub_cv_target_cc_mno_relax" != xno ; then
++        break
++      fi
++      CFLAGS="$TARGET_CFLAGS $cand -Werror"
++      AC_LINK_IFELSE([AC_LANG_PROGRAM([[
++	    asm (".globl start; start:");
++	    void __main (void);
++	    void __main (void) {}
++	    int main (void);
++	    ]], [[]])], [grub_cv_target_cc_mno_relax="$cand"], [])
++    done
++  ])
++
++  CFLAGS="$TARGET_CFLAGS"
++
++  if test x"$grub_cv_target_cc_mno_relax" != xno ; then
++    TARGET_CFLAGS="$TARGET_CFLAGS $grub_cv_target_cc_mno_relax"
++    TARGET_CCASFLAGS="$TARGET_CCASFLAGS $grub_cv_target_cc_mno_relax"
++  fi
++fi
++
+ # GRUB doesn't use float or doubles at all. Yet some toolchains may decide
+ # that floats are a good fit to run instead of what's written in the code.
+ # Given that floating point unit is disabled (if present to begin with)

diff --git a/0451-configure-Defer-check-for-mcmodel-large-until-PIC-PI.patch b/0451-configure-Defer-check-for-mcmodel-large-until-PIC-PI.patch
new file mode 100644
index 0000000..f5dfa14
--- /dev/null
+++ b/0451-configure-Defer-check-for-mcmodel-large-until-PIC-PI.patch
@@ -0,0 +1,78 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Yao Zi <me@ziyao.cc>
+Date: Wed, 31 Dec 2025 09:05:53 +0000
+Subject: [PATCH] configure: Defer check for -mcmodel=large until PIC/PIE
+ checks are done
+
+On RISC-V, large code model is only compatible with position-depedent
+code. However, the configure script checks availability of -mcmodel=large
+before determining whether PIC/PIE is enabled, and disable them.
+
+This is problematic with toolchains that enable PIE by default, where
+check for -mcmodel=large will always fail with,
+
+  cc1: sorry, unimplemented: code model 'large' with '-fPIC'
+
+and -mcmodel=medany will be silently used instead, causing relocation
+failures at runtime with some memory layouts since -mcmodel=medany
+requires all data and code to stay within a contiguous 4 GiB range.
+
+Let's defer the check for -mcmodel=large until PIC/PIE is ensured disabled.
+
+Fixes: f1957dc8a334 (RISC-V: Add to build system)
+
+Reported-by: Han Gao <gaohan@iscas.ac.cn>
+Signed-off-by: Yao Zi <me@ziyao.cc>
+Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
+---
+ configure.ac | 30 +++++++++++++++---------------
+ 1 file changed, 15 insertions(+), 15 deletions(-)
+
+diff --git a/configure.ac b/configure.ac
+index bca4dc5beaa..414facb912c 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -1338,21 +1338,6 @@ AC_SUBST(TARGET_LDFLAGS_OLDMAGIC)
+ 
+ LDFLAGS="$TARGET_LDFLAGS"
+ 
+-if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 || test "$target_cpu" = riscv64 ; then
+-  # Use large model to support 4G memory
+-  AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [
+-    CFLAGS="$TARGET_CFLAGS -mcmodel=large"
+-    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
+-		      [grub_cv_cc_mcmodel=yes],
+-		      [grub_cv_cc_mcmodel=no])
+-  ])
+-  if test "x$grub_cv_cc_mcmodel" = xyes; then
+-    TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large"
+-  elif test "$target_cpu" = sparc64 || test "$target_cpu" = riscv64; then
+-    TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=medany"
+-  fi
+-fi
+-
+ if test "$target_cpu"-"$platform" = x86_64-efi; then
+   # EFI writes to stack below %rsp, we must not use the red zone
+   AC_CACHE_CHECK([whether option -mno-red-zone works], grub_cv_cc_no_red_zone, [
+@@ -1481,6 +1466,21 @@ fi]
+ 
+ CFLAGS="$TARGET_CFLAGS"
+ 
++if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 || test "$target_cpu" = riscv64 ; then
++  # Use large model to support 4G memory
++  AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [
++    CFLAGS="$TARGET_CFLAGS -mcmodel=large"
++    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
++		      [grub_cv_cc_mcmodel=yes],
++		      [grub_cv_cc_mcmodel=no])
++  ])
++  if test "x$grub_cv_cc_mcmodel" = xyes; then
++    TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large"
++  elif test "$target_cpu" = sparc64 || test "$target_cpu" = riscv64; then
++    TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=medany"
++  fi
++fi
++
+ # Stack smashing protector.
+ grub_CHECK_STACK_PROTECTOR
+ AC_ARG_ENABLE([stack-protector],

diff --git a/grub.patches b/grub.patches
index 9e91e08..7c86e08 100644
--- a/grub.patches
+++ b/grub.patches
@@ -439,4 +439,7 @@ Patch0444: 0444-ieee1275-add-support-for-NVMeoFC.patch
 Patch0445: 0445-grub-get-kernel-settings-Treate-kernel-uki-dtbloader.patch
 Patch0446: 0446-mm-try-allocating-regions-above-defined-limit-as-las.patch
 Patch0447: 0447-tpm-Only-skip-TPM-string-PCR-measurements-with-expli.patch
-Patch0448: 0448-bli-Allow-overriding-PACKAGE_STRING-via-grub-mkimage.patch
\ No newline at end of file
+Patch0448: 0448-bli-Allow-overriding-PACKAGE_STRING-via-grub-mkimage.patch
+Patch0449: 0449-Revert-Use-medany-instead-of-large-model-for-RISCV.patch
+Patch0450: 0450-configure-Add-mno-relax-on-riscv.patch
+Patch0451: 0451-configure-Defer-check-for-mcmodel-large-until-PIC-PI.patch

diff --git a/grub2.spec b/grub2.spec
index 37f7791..3a58c92 100644
--- a/grub2.spec
+++ b/grub2.spec
@@ -17,7 +17,7 @@
 Name:		grub2
 Epoch:		1
 Version:	2.12
-Release:	77%{?dist}
+Release:	78%{?dist}
 Summary:	Bootloader with support for Linux, Multiboot and more
 License:	GPL-3.0-or-later
 URL:		http://www.gnu.org/software/grub/
@@ -702,6 +702,9 @@ fi
 %endif
 
 %changelog
+* Thu Aug 20 2026 Andrea Bolognani <abologna@redhat.com> - 2.12-78
+- Use large code model on riscv64
+
 * Thu Aug 13 2026 Josue Hernandez <josherna@redhat.com> - 2.12-77
 - Fix systemd timer,service permissions - Resolves: #2512037
 

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-08-24 16:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-24 16:14 [rpms/grub2] rawhide: Use large code model on riscv64 Andrea Bolognani

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox