Skip to content

Commit 1aa0dd0

Browse files
ziyao233Daniel Kiper
authored andcommitted
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: f1957dc (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>
1 parent ff1edd9 commit 1aa0dd0

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

configure.ac

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,21 +1543,6 @@ AC_SUBST(TARGET_LDFLAGS_OLDMAGIC)
15431543

15441544
LDFLAGS="$TARGET_LDFLAGS"
15451545

1546-
if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 || test "$target_cpu" = riscv64 ; then
1547-
# Use large model to support 4G memory
1548-
AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [
1549-
CFLAGS="$TARGET_CFLAGS -mcmodel=large"
1550-
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
1551-
[grub_cv_cc_mcmodel=yes],
1552-
[grub_cv_cc_mcmodel=no])
1553-
])
1554-
if test "x$grub_cv_cc_mcmodel" = xyes; then
1555-
TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large"
1556-
elif test "$target_cpu" = sparc64 || test "$target_cpu" = riscv64; then
1557-
TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=medany"
1558-
fi
1559-
fi
1560-
15611546
if test "$target_cpu"-"$platform" = x86_64-efi; then
15621547
# EFI writes to stack below %rsp, we must not use the red zone
15631548
AC_CACHE_CHECK([whether option -mno-red-zone works], grub_cv_cc_no_red_zone, [
@@ -1666,6 +1651,21 @@ fi]
16661651

16671652
CFLAGS="$TARGET_CFLAGS"
16681653

1654+
if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 || test "$target_cpu" = riscv64 ; then
1655+
# Use large model to support 4G memory
1656+
AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [
1657+
CFLAGS="$TARGET_CFLAGS -mcmodel=large"
1658+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
1659+
[grub_cv_cc_mcmodel=yes],
1660+
[grub_cv_cc_mcmodel=no])
1661+
])
1662+
if test "x$grub_cv_cc_mcmodel" = xyes; then
1663+
TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large"
1664+
elif test "$target_cpu" = sparc64 || test "$target_cpu" = riscv64; then
1665+
TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=medany"
1666+
fi
1667+
fi
1668+
16691669
# Stack smashing protector.
16701670
grub_CHECK_STACK_PROTECTOR
16711671
AC_ARG_ENABLE([stack-protector],

0 commit comments

Comments
 (0)