All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Use medany instead of large model for RISCV
@ 2026-03-20 14:44 Trevor Gamblin
  2026-03-20 18:37 ` Jason Montleon via Grub-devel
  2026-03-21  8:23 ` Yao Zi via Grub-devel
  0 siblings, 2 replies; 5+ messages in thread
From: Trevor Gamblin @ 2026-03-20 14:44 UTC (permalink / raw)
  To: grub-devel; +Cc: jason, Trevor Gamblin

From: Jason Montleon <jason@montleon.com>

Upstream-Status: Submitted [https://savannah.gnu.org/bugs/?65909]

Signed-off-by: Jason Montleon <jason@montleon.com>
Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
---
We have recently added this to the openembedded-core layer to help with RISC-V
builds on certain platforms (e.g. the VisionFive 2). I have left the patch as it
is there, including the link to the original bug submission and the author's
attribution. Jason, if you would like to change the attribution or anything
about the patch, let me know and I can re-submit.

 configure.ac | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index d19fb625d..2a070c577 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1675,7 +1675,7 @@ fi]
 
 CFLAGS="$TARGET_CFLAGS"
 
-if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 || test "$target_cpu" = riscv64 ; then
+if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 ; 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"
@@ -1685,9 +1685,11 @@ if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 || test "$target_
   ])
   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
+  elif test "$target_cpu" = sparc64; then
     TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=medany"
   fi
+elif test "$target_cpu" = riscv64 ; then
+    TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=medany"
 fi
 
 # Stack smashing protector.
-- 
2.53.0


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] Use medany instead of large model for RISCV
  2026-03-20 14:44 [PATCH] Use medany instead of large model for RISCV Trevor Gamblin
@ 2026-03-20 18:37 ` Jason Montleon via Grub-devel
  2026-03-20 21:54   ` Vladimir 'phcoder' Serbinenko
  2026-03-21  8:23 ` Yao Zi via Grub-devel
  1 sibling, 1 reply; 5+ messages in thread
From: Jason Montleon via Grub-devel @ 2026-03-20 18:37 UTC (permalink / raw)
  To: Trevor Gamblin; +Cc: Jason Montleon, grub-devel





On Friday, March 20th, 2026 at 10:44 AM, Trevor Gamblin <tgamblin@baylibre.com> wrote:

> From: Jason Montleon <jason@montleon.com>
> 
> Upstream-Status: Submitted [https://savannah.gnu.org/bugs/?65909]
> 
> Signed-off-by: Jason Montleon <jason@montleon.com>
> Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
> ---
> We have recently added this to the openembedded-core layer to help with RISC-V
> builds on certain platforms (e.g. the VisionFive 2). I have left the patch as it
> is there, including the link to the original bug submission and the author's
> attribution. Jason, if you would like to change the attribution or anything
> about the patch, let me know and I can re-submit.

Hi Trevor,
Fedora is still using this patch and it is working for us.
https://src.fedoraproject.org/rpms/grub2/blob/rawhide/f/0283-Use-medany-instead-of-large-model-for-RISCV.patch

I did want to share that we revisited building with large model and managed to get it to build. This resulted in a smaller binary with far fewer relocations. 
That work is at http://fedora.riscv.rocks:3000/rpms/grub2/commits/branch/main-riscv64-large-code

I am not sure if one approach would be preferred over the other.

>  configure.ac | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/configure.ac b/configure.ac
> index d19fb625d..2a070c577 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -1675,7 +1675,7 @@ fi]
> 
>  CFLAGS="$TARGET_CFLAGS"
> 
> -if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 || test "$target_cpu" = riscv64 ; then
> +if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 ; 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"
> @@ -1685,9 +1685,11 @@ if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 || test "$target_
>    ])
>    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
> +  elif test "$target_cpu" = sparc64; then
>      TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=medany"
>    fi
> +elif test "$target_cpu" = riscv64 ; then
> +    TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=medany"
>  fi
> 
>  # Stack smashing protector.
> --
> 2.53.0
> 
> 

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Use medany instead of large model for RISCV
  2026-03-20 18:37 ` Jason Montleon via Grub-devel
@ 2026-03-20 21:54   ` Vladimir 'phcoder' Serbinenko
  0 siblings, 0 replies; 5+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2026-03-20 21:54 UTC (permalink / raw)
  To: The development of GNU GRUB


[-- Attachment #1.1: Type: text/plain, Size: 3026 bytes --]

We prefer to use large model. Did you try my patch with using ET_DYN?
https://lists.libreplanet.org/archive/html/grub-devel/2025-04/msg00093.html

Regards
Vladimir 'phcoder' Serbinenko

Le ven. 20 mars 2026, 21:48, Jason Montleon via Grub-devel <
grub-devel@gnu.org> a écrit :

>
>
>
>
> On Friday, March 20th, 2026 at 10:44 AM, Trevor Gamblin <
> tgamblin@baylibre.com> wrote:
>
> > From: Jason Montleon <jason@montleon.com>
> >
> > Upstream-Status: Submitted [https://savannah.gnu.org/bugs/?65909]
> >
> > Signed-off-by: Jason Montleon <jason@montleon.com>
> > Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
> > ---
> > We have recently added this to the openembedded-core layer to help with
> RISC-V
> > builds on certain platforms (e.g. the VisionFive 2). I have left the
> patch as it
> > is there, including the link to the original bug submission and the
> author's
> > attribution. Jason, if you would like to change the attribution or
> anything
> > about the patch, let me know and I can re-submit.
>
> Hi Trevor,
> Fedora is still using this patch and it is working for us.
>
> https://src.fedoraproject.org/rpms/grub2/blob/rawhide/f/0283-Use-medany-instead-of-large-model-for-RISCV.patch
>
> I did want to share that we revisited building with large model and
> managed to get it to build. This resulted in a smaller binary with far
> fewer relocations.
> That work is at
> http://fedora.riscv.rocks:3000/rpms/grub2/commits/branch/main-riscv64-large-code
>
> I am not sure if one approach would be preferred over the other.
>
> >  configure.ac | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/configure.ac b/configure.ac
> > index d19fb625d..2a070c577 100644
> > --- a/configure.ac
> > +++ b/configure.ac
> > @@ -1675,7 +1675,7 @@ fi]
> >
> >  CFLAGS="$TARGET_CFLAGS"
> >
> > -if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 || test
> "$target_cpu" = riscv64 ; then
> > +if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 ; 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"
> > @@ -1685,9 +1685,11 @@ if test "$target_cpu" = x86_64 || test
> "$target_cpu" = sparc64 || test "$target_
> >    ])
> >    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
> > +  elif test "$target_cpu" = sparc64; then
> >      TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=medany"
> >    fi
> > +elif test "$target_cpu" = riscv64 ; then
> > +    TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=medany"
> >  fi
> >
> >  # Stack smashing protector.
> > --
> > 2.53.0
> >
> >
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>

[-- Attachment #1.2: Type: text/html, Size: 5218 bytes --]

[-- Attachment #2: Type: text/plain, Size: 141 bytes --]

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Use medany instead of large model for RISCV
  2026-03-20 14:44 [PATCH] Use medany instead of large model for RISCV Trevor Gamblin
  2026-03-20 18:37 ` Jason Montleon via Grub-devel
@ 2026-03-21  8:23 ` Yao Zi via Grub-devel
  2026-03-21 15:33   ` Trevor Gamblin
  1 sibling, 1 reply; 5+ messages in thread
From: Yao Zi via Grub-devel @ 2026-03-21  8:23 UTC (permalink / raw)
  To: The development of GNU GRUB; +Cc: Yao Zi, jason, Trevor Gamblin

On Fri, Mar 20, 2026 at 10:44:15AM -0400, Trevor Gamblin wrote:
> From: Jason Montleon <jason@montleon.com>
> 
> Upstream-Status: Submitted [https://savannah.gnu.org/bugs/?65909]
> 
> Signed-off-by: Jason Montleon <jason@montleon.com>
> Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
> ---
> We have recently added this to the openembedded-core layer to help with RISC-V
> builds on certain platforms (e.g. the VisionFive 2). I have left the patch as it
> is there, including the link to the original bug submission and the author's
> attribution. Jason, if you would like to change the attribution or anything
> about the patch, let me know and I can re-submit.

However on riscv64, medany memory model only allows addressing in +-2GiB
range, while large memory model could index the whole 64-bit address
space. This patch would break cases that grub core and dynamically
loaded modules (i.e. EFI memory allocated with type EFI_LOADER_CODE) are
located too far away to address each other with medany code model.

The issue reported in your link is related to handling of R_RISCV_ALIGN
relocations, which shouldn't happen anymore in Grub 2.14+ as commit
8fef533cf695 ("configure: Add -mno-relax on riscv*") is a fix for it.

Thanks,
Yao Zi

>  configure.ac | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/configure.ac b/configure.ac
> index d19fb625d..2a070c577 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -1675,7 +1675,7 @@ fi]
>  
>  CFLAGS="$TARGET_CFLAGS"
>  
> -if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 || test "$target_cpu" = riscv64 ; then
> +if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 ; 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"
> @@ -1685,9 +1685,11 @@ if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 || test "$target_
>    ])
>    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
> +  elif test "$target_cpu" = sparc64; then
>      TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=medany"
>    fi
> +elif test "$target_cpu" = riscv64 ; then
> +    TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=medany"
>  fi
>  
>  # Stack smashing protector.
> -- 
> 2.53.0
> 
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Use medany instead of large model for RISCV
  2026-03-21  8:23 ` Yao Zi via Grub-devel
@ 2026-03-21 15:33   ` Trevor Gamblin
  0 siblings, 0 replies; 5+ messages in thread
From: Trevor Gamblin @ 2026-03-21 15:33 UTC (permalink / raw)
  To: Yao Zi, The development of GNU GRUB; +Cc: jason


On 2026-03-21 04:23, Yao Zi wrote:
> On Fri, Mar 20, 2026 at 10:44:15AM -0400, Trevor Gamblin wrote:
>> From: Jason Montleon <jason@montleon.com>
>>
>> Upstream-Status: Submitted [https://savannah.gnu.org/bugs/?65909]
>>
>> Signed-off-by: Jason Montleon <jason@montleon.com>
>> Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
>> ---
>> We have recently added this to the openembedded-core layer to help with RISC-V
>> builds on certain platforms (e.g. the VisionFive 2). I have left the patch as it
>> is there, including the link to the original bug submission and the author's
>> attribution. Jason, if you would like to change the attribution or anything
>> about the patch, let me know and I can re-submit.
> However on riscv64, medany memory model only allows addressing in +-2GiB
> range, while large memory model could index the whole 64-bit address
> space. This patch would break cases that grub core and dynamically
> loaded modules (i.e. EFI memory allocated with type EFI_LOADER_CODE) are
> located too far away to address each other with medany code model.
>
> The issue reported in your link is related to handling of R_RISCV_ALIGN
> relocations, which shouldn't happen anymore in Grub 2.14+ as commit
> 8fef533cf695 ("configure: Add -mno-relax on riscv*") is a fix for it.

Thank you for clarifying. I've submitted a reversion patch in oe-core so 
we don't carry this and run into the problem later.

Trevor

>
> Thanks,
> Yao Zi
>
>>   configure.ac | 6 ++++--
>>   1 file changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/configure.ac b/configure.ac
>> index d19fb625d..2a070c577 100644
>> --- a/configure.ac
>> +++ b/configure.ac
>> @@ -1675,7 +1675,7 @@ fi]
>>   
>>   CFLAGS="$TARGET_CFLAGS"
>>   
>> -if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 || test "$target_cpu" = riscv64 ; then
>> +if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 ; 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"
>> @@ -1685,9 +1685,11 @@ if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 || test "$target_
>>     ])
>>     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
>> +  elif test "$target_cpu" = sparc64; then
>>       TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=medany"
>>     fi
>> +elif test "$target_cpu" = riscv64 ; then
>> +    TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=medany"
>>   fi
>>   
>>   # Stack smashing protector.
>> -- 
>> 2.53.0
>>
>>
>> _______________________________________________
>> Grub-devel mailing list
>> Grub-devel@gnu.org
>> https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-03-21 15:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-20 14:44 [PATCH] Use medany instead of large model for RISCV Trevor Gamblin
2026-03-20 18:37 ` Jason Montleon via Grub-devel
2026-03-20 21:54   ` Vladimir 'phcoder' Serbinenko
2026-03-21  8:23 ` Yao Zi via Grub-devel
2026-03-21 15:33   ` Trevor Gamblin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.