]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
loongarch: Disable relaxation relocations
authorXiaotian Wu <wuxiaotian@loongson.cn>
Thu, 15 Jun 2023 12:10:38 +0000 (20:10 +0800)
committerDaniel Kiper <daniel.kiper@oracle.com>
Thu, 22 Jun 2023 22:50:38 +0000 (00:50 +0200)
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 pass -mno-relax to GCC if it is supported, to disable relaxation and make
GRUB forward-compatible with new toolchains.

While similar code already exists for sparc64 in configure.ac, sparc64 sets
LDFLAGS while LoongArch requires CFLAGS to be set. If we only set LDFLAGS on
LoongArch, GCC will still generate relaxation relocations in the .o files, so
the sparc64 code cannot be reused.

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

Signed-off-by: Xiaotian Wu <wuxiaotian@loongson.cn>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
configure.ac

index d9f088d127acd09e19e4ace6ae58443d05f52644..a0ea5beae45d24108dc40cdc1824b80d28e841d0 100644 (file)
@@ -874,6 +874,29 @@ 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([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
+
   TARGET_CFLAGS="$TARGET_CFLAGS -Wa,-mla-global-with-abs"
   TARGET_CCASFLAGS="$TARGET_CCASFLAGS -Wa,-mla-global-with-abs"
 fi