Re: [PATCH v3 5/5] loongarch: Use the -mno-relax cflags for gcc

2023-06-15 Thread Daniel Kiper
On Thu, Jun 15, 2023 at 10:04:23AM +0800, Xiaotian Wu wrote:
> 在 2023-06-13星期二的 20:09 +0800,Xi Ruoyao via Grub-devel写道:
> > On Tue, 2023-06-13 at 13:39 +0200, Daniel Kiper wrote:
> > > On Tue, Jun 13, 2023 at 05:06:35PM +0800, Xiaotian Wu wrote:
> > > > Because the binutils of the loongarch architecture adds
> > > > relaxation
> > > > support [1],
> > > > the next version of binutils will not be able to build grub.
> > > >
> > > > So we use the -mno-relax cflags to disable gcc to generate
> > > > relaxation
> > > > relocations to enhance the compatibility of grub.
> > > >
> > > > [1]:
> > > > https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=56576f4a722b7398d35802ecf7d4185c27d6d69b
> > > >
> > > > Signed-off-by: Xiaotian Wu 
> > > > ---
> > > >  configure.ac | 12 
> > > >  1 file changed, 12 insertions(+)
> > > >
> > > > diff --git a/configure.ac b/configure.ac
> > > > index d9f088d12..cd3cc6ba8 100644
> > > > --- a/configure.ac
> > > > +++ b/configure.ac
> > > > @@ -874,6 +874,18 @@ if test "x$target_cpu" = xloongarch64; then
> > > >  TARGET_CFLAGS="$TARGET_CFLAGS -mno-explicit-relocs -fno-plt"
> > > >  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mno-explicit-relocs -
> > > > fno-
> > > > plt"
> > > >    fi
> > > > +
> > > > +  AC_CACHE_CHECK([whether _mno_relax works],
> > > > [grub_cv_cc_mno_relax], [
> > > > +    CFLAGS="$TARGET_CFLAGS -mno-relax -Werror"
> > > > +    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
> > > > +   [grub_cv_cc_mno_relax=yes],
> > > > +   [grub_cv_cc_mno_relax=no])
> > > > +  ])
> > > > +  if test "x$grub_cv_cc_mno_relax" = xyes; then
> > > > +    TARGET_CFLAGS="$TARGET_CFLAGS -mno-relax"
> > > > +    TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mno-relax"
> > > > +  fi
> > >
> > > Could not you reuse sparc64 code which is ~100 lines below? If not
> > > please make loongarch code as similar as possible to the sparc64
> > > one.
> >
> > More important reason is we need to try -Wa,-mno-relax along with -
> > mno-
> > relax, like SPARC64.  GCC 13 and earlier does not accept -mno-relax,
> > but
> > the assembler itself can still generate R_LARCH_RELAX etc.  So if a
> > distro uses GCC 13 alongside Binutils 2.41, we'll need -Wa,-mno-
> > relax.
> >
> > Note that Binutils 2.41 will be released in Feb 2024 but GCC 14 will
> > be
> > released in mid 2024 (Apr to Jun) so it can be expected that some
> > distros will really use Binutils 2.41 and GCC 13.
>
> Code for sparc64 cannot be reused.
> Because sparc64 sets LDFLAGS, and loongarch needs to set CFLAGS.
> If only LDFLAGS is used on loongarch, gcc still generates .o files with
> RELAX.

The v4 LGTM but please add this explanation or something like that to
the commit message and send v5.

Daniel

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


Re: [PATCH v3 5/5] loongarch: Use the -mno-relax cflags for gcc

2023-06-14 Thread Xiaotian Wu
在 2023-06-13星期二的 20:09 +0800,Xi Ruoyao via Grub-devel写道:
> On Tue, 2023-06-13 at 13:39 +0200, Daniel Kiper wrote:
> > On Tue, Jun 13, 2023 at 05:06:35PM +0800, Xiaotian Wu wrote:
> > > Because the binutils of the loongarch architecture adds
> > > relaxation
> > > support [1],
> > > the next version of binutils will not be able to build grub.
> > > 
> > > So we use the -mno-relax cflags to disable gcc to generate
> > > relaxation
> > > relocations to enhance the compatibility of grub.
> > > 
> > > [1]:
> > > https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=56576f4a722b7398d35802ecf7d4185c27d6d69b
> > > 
> > > Signed-off-by: Xiaotian Wu 
> > > ---
> > >  configure.ac | 12 
> > >  1 file changed, 12 insertions(+)
> > > 
> > > diff --git a/configure.ac b/configure.ac
> > > index d9f088d12..cd3cc6ba8 100644
> > > --- a/configure.ac
> > > +++ b/configure.ac
> > > @@ -874,6 +874,18 @@ if test "x$target_cpu" = xloongarch64; then
> > >  TARGET_CFLAGS="$TARGET_CFLAGS -mno-explicit-relocs -fno-plt"
> > >  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mno-explicit-relocs -
> > > fno-
> > > plt"
> > >    fi
> > > +
> > > +  AC_CACHE_CHECK([whether _mno_relax works],
> > > [grub_cv_cc_mno_relax], [
> > > +    CFLAGS="$TARGET_CFLAGS -mno-relax -Werror"
> > > +    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
> > > +   [grub_cv_cc_mno_relax=yes],
> > > +   [grub_cv_cc_mno_relax=no])
> > > +  ])
> > > +  if test "x$grub_cv_cc_mno_relax" = xyes; then
> > > +    TARGET_CFLAGS="$TARGET_CFLAGS -mno-relax"
> > > +    TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mno-relax"
> > > +  fi
> > 
> > Could not you reuse sparc64 code which is ~100 lines below? If not
> > please make loongarch code as similar as possible to the sparc64
> > one.
> 
> More important reason is we need to try -Wa,-mno-relax along with -
> mno-
> relax, like SPARC64.  GCC 13 and earlier does not accept -mno-relax,
> but
> the assembler itself can still generate R_LARCH_RELAX etc.  So if a
> distro uses GCC 13 alongside Binutils 2.41, we'll need -Wa,-mno-
> relax.
> 
> Note that Binutils 2.41 will be released in Feb 2024 but GCC 14 will
> be
> released in mid 2024 (Apr to Jun) so it can be expected that some
> distros will really use Binutils 2.41 and GCC 13.

Code for sparc64 cannot be reused.
Because sparc64 sets LDFLAGS, and loongarch needs to set CFLAGS.
If only LDFLAGS is used on loongarch, gcc still generates .o files with
RELAX.

This point was also mentioned in mengqinggang's email:
https://lists.gnu.org/archive/html/grub-devel/2023-06/msg00062.html

> 
> -- 
> Xi Ruoyao 
> School of Aerospace Science and Technology, Xidian University
> 

-- 
Best Regards
Xiaotian Wu


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


Re: [PATCH v3 5/5] loongarch: Use the -mno-relax cflags for gcc

2023-06-13 Thread Xi Ruoyao via Grub-devel
On Tue, 2023-06-13 at 13:39 +0200, Daniel Kiper wrote:
> On Tue, Jun 13, 2023 at 05:06:35PM +0800, Xiaotian Wu wrote:
> > Because the binutils of the loongarch architecture adds relaxation
> > support [1],
> > the next version of binutils will not be able to build grub.
> > 
> > So we use the -mno-relax cflags to disable gcc to generate
> > relaxation
> > relocations to enhance the compatibility of grub.
> > 
> > [1]:
> > https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=56576f4a722b7398d35802ecf7d4185c27d6d69b
> > 
> > Signed-off-by: Xiaotian Wu 
> > ---
> >  configure.ac | 12 
> >  1 file changed, 12 insertions(+)
> > 
> > diff --git a/configure.ac b/configure.ac
> > index d9f088d12..cd3cc6ba8 100644
> > --- a/configure.ac
> > +++ b/configure.ac
> > @@ -874,6 +874,18 @@ if test "x$target_cpu" = xloongarch64; then
> >  TARGET_CFLAGS="$TARGET_CFLAGS -mno-explicit-relocs -fno-plt"
> >  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mno-explicit-relocs -fno-
> > plt"
> >    fi
> > +
> > +  AC_CACHE_CHECK([whether _mno_relax works],
> > [grub_cv_cc_mno_relax], [
> > +    CFLAGS="$TARGET_CFLAGS -mno-relax -Werror"
> > +    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
> > +   [grub_cv_cc_mno_relax=yes],
> > +   [grub_cv_cc_mno_relax=no])
> > +  ])
> > +  if test "x$grub_cv_cc_mno_relax" = xyes; then
> > +    TARGET_CFLAGS="$TARGET_CFLAGS -mno-relax"
> > +    TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mno-relax"
> > +  fi
> 
> Could not you reuse sparc64 code which is ~100 lines below? If not
> please make loongarch code as similar as possible to the sparc64 one.

More important reason is we need to try -Wa,-mno-relax along with -mno-
relax, like SPARC64.  GCC 13 and earlier does not accept -mno-relax, but
the assembler itself can still generate R_LARCH_RELAX etc.  So if a
distro uses GCC 13 alongside Binutils 2.41, we'll need -Wa,-mno-relax.

Note that Binutils 2.41 will be released in Feb 2024 but GCC 14 will be
released in mid 2024 (Apr to Jun) so it can be expected that some
distros will really use Binutils 2.41 and GCC 13.

-- 
Xi Ruoyao 
School of Aerospace Science and Technology, Xidian University

-- 
Xi Ruoyao 
School of Aerospace Science and Technology, Xidian University

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


Re: [PATCH v3 5/5] loongarch: Use the -mno-relax cflags for gcc

2023-06-13 Thread Daniel Kiper
On Tue, Jun 13, 2023 at 05:06:35PM +0800, Xiaotian Wu wrote:
> Because the binutils of the loongarch architecture adds relaxation support 
> [1],
> the next version of binutils will not be able to build grub.
>
> So we use the -mno-relax cflags to disable gcc to generate relaxation
> relocations to enhance the compatibility of grub.
>
> [1]: 
> https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=56576f4a722b7398d35802ecf7d4185c27d6d69b
>
> Signed-off-by: Xiaotian Wu 
> ---
>  configure.ac | 12 
>  1 file changed, 12 insertions(+)
>
> diff --git a/configure.ac b/configure.ac
> index d9f088d12..cd3cc6ba8 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -874,6 +874,18 @@ if test "x$target_cpu" = xloongarch64; then
>  TARGET_CFLAGS="$TARGET_CFLAGS -mno-explicit-relocs -fno-plt"
>  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mno-explicit-relocs -fno-plt"
>fi
> +
> +  AC_CACHE_CHECK([whether _mno_relax works], [grub_cv_cc_mno_relax], [
> +CFLAGS="$TARGET_CFLAGS -mno-relax -Werror"
> +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
> + [grub_cv_cc_mno_relax=yes],
> + [grub_cv_cc_mno_relax=no])
> +  ])
> +  if test "x$grub_cv_cc_mno_relax" = xyes; then
> +TARGET_CFLAGS="$TARGET_CFLAGS -mno-relax"
> +TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mno-relax"
> +  fi

Could not you reuse sparc64 code which is ~100 lines below? If not
please make loongarch code as similar as possible to the sparc64 one.

Daniel

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


Re: [PATCH v3 5/5] loongarch: Use the -mno-relax cflags for gcc

2023-06-13 Thread WANG Xuerui



On 2023/6/13 17:06, Xiaotian Wu wrote:

Because the binutils of the loongarch architecture adds relaxation support [1],
the next version of binutils will not be able to build grub.


We can simplify the sentence a bit, like "A working grub cannot be built 
with upcoming binutils and gcc, because linker relaxation was added [1] 
causing new unsupported relocations to appear in modules".




So we use the -mno-relax cflags to disable gcc to generate relaxation
relocations to enhance the compatibility of grub.


Better mention the justification for not enabling relaxation, i.e. 
because bootloaders are not exactly performance-sensitive code.


Also we can make the sentence more natural, like "So we pass -mno-relax 
to gcc if it is supported, to disable relaxation and make grub 
forward-compatible with new toolchains".




[1]: 
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=56576f4a722b7398d35802ecf7d4185c27d6d69b

Signed-off-by: Xiaotian Wu 
---
  configure.ac | 12 
  1 file changed, 12 insertions(+)

diff --git a/configure.ac b/configure.ac
index d9f088d12..cd3cc6ba8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -874,6 +874,18 @@ if test "x$target_cpu" = xloongarch64; then
  TARGET_CFLAGS="$TARGET_CFLAGS -mno-explicit-relocs -fno-plt"
  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mno-explicit-relocs -fno-plt"
fi
+
+  AC_CACHE_CHECK([whether _mno_relax works], [grub_cv_cc_mno_relax], [


I don't have a strong opinion as to whether a justification should be 
put here above the check though.



+CFLAGS="$TARGET_CFLAGS -mno-relax -Werror"
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
+   [grub_cv_cc_mno_relax=yes],
+   [grub_cv_cc_mno_relax=no])
+  ])
+  if test "x$grub_cv_cc_mno_relax" = xyes; then
+TARGET_CFLAGS="$TARGET_CFLAGS -mno-relax"
+TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mno-relax"
+  fi
+
TARGET_CFLAGS="$TARGET_CFLAGS -Wa,-mla-global-with-abs"
TARGET_CCASFLAGS="$TARGET_CCASFLAGS -Wa,-mla-global-with-abs"
  fi


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


[PATCH v3 5/5] loongarch: Use the -mno-relax cflags for gcc

2023-06-13 Thread Xiaotian Wu
Because the binutils of the loongarch architecture adds relaxation support [1],
the next version of binutils will not be able to build grub.

So we use the -mno-relax cflags to disable gcc to generate relaxation
relocations to enhance the compatibility of grub.

[1]: 
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=56576f4a722b7398d35802ecf7d4185c27d6d69b

Signed-off-by: Xiaotian Wu 
---
 configure.ac | 12 
 1 file changed, 12 insertions(+)

diff --git a/configure.ac b/configure.ac
index d9f088d12..cd3cc6ba8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -874,6 +874,18 @@ if test "x$target_cpu" = xloongarch64; then
 TARGET_CFLAGS="$TARGET_CFLAGS -mno-explicit-relocs -fno-plt"
 TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mno-explicit-relocs -fno-plt"
   fi
+
+  AC_CACHE_CHECK([whether _mno_relax works], [grub_cv_cc_mno_relax], [
+CFLAGS="$TARGET_CFLAGS -mno-relax -Werror"
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
+   [grub_cv_cc_mno_relax=yes],
+   [grub_cv_cc_mno_relax=no])
+  ])
+  if test "x$grub_cv_cc_mno_relax" = xyes; then
+TARGET_CFLAGS="$TARGET_CFLAGS -mno-relax"
+TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mno-relax"
+  fi
+
   TARGET_CFLAGS="$TARGET_CFLAGS -Wa,-mla-global-with-abs"
   TARGET_CCASFLAGS="$TARGET_CCASFLAGS -Wa,-mla-global-with-abs"
 fi
-- 
2.40.1


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