public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
From: Andrea Bolognani <abologna@redhat.com>
To: git-commits@fedoraproject.org
Subject: [rpms/grub2] f45: Use large code model on riscv64
Date: Mon, 24 Aug 2026 16:16:39 GMT	[thread overview]
Message-ID: <178758819998.1.16721303010324205965.rpms-grub2-7dd6677a65e8@fedoraproject.org> (raw)

            A new commit has been pushed.

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

            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/0448-Revert-Use-medany-instead-of-large-model-for-RISCV.patch b/0448-Revert-Use-medany-instead-of-large-model-for-RISCV.patch
new file mode 100644
index 0000000..f0a1d32
--- /dev/null
+++ b/0448-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/0449-configure-Add-mno-relax-on-riscv.patch b/0449-configure-Add-mno-relax-on-riscv.patch
new file mode 100644
index 0000000..9191045
--- /dev/null
+++ b/0449-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/0450-configure-Defer-check-for-mcmodel-large-until-PIC-PI.patch b/0450-configure-Defer-check-for-mcmodel-large-until-PIC-PI.patch
new file mode 100644
index 0000000..f5dfa14
--- /dev/null
+++ b/0450-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 2eb4021..29a1fcb 100644
--- a/grub.patches
+++ b/grub.patches
@@ -438,4 +438,7 @@ Patch0443: 0443-ieee1275-support-added-for-multiple-nvme-bootpaths.patch
 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
\ No newline at end of file
+Patch0447: 0447-tpm-Only-skip-TPM-string-PCR-measurements-with-expli.patch
+Patch0448: 0448-Revert-Use-medany-instead-of-large-model-for-RISCV.patch
+Patch0449: 0449-configure-Add-mno-relax-on-riscv.patch
+Patch0450: 0450-configure-Defer-check-for-mcmodel-large-until-PIC-PI.patch

diff --git a/grub2.spec b/grub2.spec
index 2a7e5c2..8de2174 100644
--- a/grub2.spec
+++ b/grub2.spec
@@ -17,7 +17,7 @@
 Name:		grub2
 Epoch:		1
 Version:	2.12
-Release:	76%{?dist}
+Release:	77%{?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-77
+- Use large code model on riscv64
+
 * Mon Aug 17 2026 Andrea Bolognani <abologna@redhat.com> - 2.12-76
 - Only build CC variant for aarch64 and x86_64
 

                 reply	other threads:[~2026-08-24 16:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=178758819998.1.16721303010324205965.rpms-grub2-7dd6677a65e8@fedoraproject.org \
    --to=abologna@redhat.com \
    --cc=git-commits@fedoraproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox