ieee1275: split up grub_machine_get_bootlocation
[grub.git] / acinclude.m4
index 609c4f2..78cdf6e 100644 (file)
@@ -93,7 +93,7 @@ else
 fi
 grub_cv_prog_objcopy_absolute=yes
 for link_addr in 0x2000 0x8000 0x7C00; do
-  if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -nostdlib ${TARGET_IMG_LDFLAGS_AC} ${TARGET_IMG_BASE_LDOPT},$link_addr conftest.o -o conftest.exec]); then :
+  if AC_TRY_COMMAND([${CC-cc} ${TARGET_CFLAGS} ${TARGET_LDFLAGS} -nostdlib ${TARGET_IMG_LDFLAGS_AC} ${TARGET_IMG_BASE_LDOPT},$link_addr conftest.o -o conftest.exec]); then :
   else
     AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr])
   fi
@@ -390,6 +390,58 @@ else
 [fi]
 ])
 
+AC_DEFUN([grub_CHECK_LINK_PIE],[
+[# Position independent executable.
+link_nopie_needed=no]
+AC_MSG_CHECKING([whether linker needs disabling of PIE to work])
+AC_LANG_CONFTEST([AC_LANG_SOURCE([[]])])
+
+[if eval "$ac_compile -Wl,-r,-d -nostdlib -Werror -o conftest.o" 2> /dev/null; then]
+  AC_MSG_RESULT([no])
+  [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
+  rm -f conftest.o
+else
+  link_nopie_needed=yes]
+  AC_MSG_RESULT([yes])
+[fi]
+])
+
+
+dnl Check if the Linker supports `-no-pie'.
+AC_DEFUN([grub_CHECK_NO_PIE],
+[AC_MSG_CHECKING([whether linker accepts -no-pie])
+AC_CACHE_VAL(grub_cv_cc_ld_no_pie,
+[save_LDFLAGS="$LDFLAGS"
+LDFLAGS="$LDFLAGS -no-pie -nostdlib -Werror"
+AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
+              [grub_cv_cc_ld_no_pie=yes],
+              [grub_cv_cc_ld_no_pie=no])
+LDFLAGS="$save_LDFLAGS"
+])
+AC_MSG_RESULT([$grub_cv_cc_ld_no_pie])
+nopie_possible=no
+if test "x$grub_cv_cc_ld_no_pie" = xyes ; then
+  nopie_possible=yes
+fi
+])
+
+AC_DEFUN([grub_CHECK_NO_PIE_ONEWORD],
+[AC_MSG_CHECKING([whether linker accepts -nopie])
+AC_CACHE_VAL(grub_cv_cc_ld_no_pie_oneword,
+[save_LDFLAGS="$LDFLAGS"
+LDFLAGS="$LDFLAGS -nopie -nostdlib -Werror"
+AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
+              [grub_cv_cc_ld_no_pie_oneword=yes],
+              [grub_cv_cc_ld_no_pie_oneword=no])
+LDFLAGS="$save_LDFLAGS"
+])
+AC_MSG_RESULT([$grub_cv_cc_ld_no_pie_oneword])
+nopie_oneword_possible=no
+if test "x$grub_cv_cc_ld_no_pie_oneword" = xyes ; then
+  nopie_oneword_possible=yes
+fi
+])
+
 dnl Check if the C compiler supports `-fPIC'.
 AC_DEFUN([grub_CHECK_PIC],[
 [# Position independent executable.