Test which flags make our asm compile.

Previously we relied on assumption that clang always needs -no-integrated-as
but it's not always true.
This commit is contained in:
Vladimir Serbinenko 2015-02-21 16:29:28 +01:00
parent 0b02bfa034
commit 065ad910f1
6 changed files with 89 additions and 27 deletions

20
asm-tests/arm.S Normal file
View file

@ -0,0 +1,20 @@
/* on arm clang doesn't support .arch directive */
.text
.syntax unified
#if !defined (__thumb2__)
.arch armv7a
.arm
#else
.arch armv7
.thumb
#endif
mcr p15, 0, r11, c7, c14, 2
/* clang restricts access to dsb/isb despite .arch */
dsb
isb

10
asm-tests/i386.S Normal file
View file

@ -0,0 +1,10 @@
/* on x86 old clang doesn't support .code16
newer clang supports it but creates 6-byte jumps instead of 3-byte ones
which makes us go over boot sector size. */
.code16
jmp far
.org 4
.space 300
far:
.byte 0

11
asm-tests/mips.S Normal file
View file

@ -0,0 +1,11 @@
/* on mips clang doesn't support privilegied instructions, doubleword store/load
and crashes with hand-written assembly
*/
.set mips3
sync
ld $t2, 0($t6)
a:
addiu $t7, $s0, (b - a)
b: nop

8
asm-tests/powerpc.S Normal file
View file

@ -0,0 +1,8 @@
/* clang <= 3.3 doesn't handle most of ppc assembly, not even inline assembly
used by gcrypt */
/* Cache invalidation loop is a fair test. */
li 5, 0
1: icbi 5, 3
addi 5, 5, 32
cmpw 5, 4
blt 1b

9
asm-tests/sparc64.S Normal file
View file

@ -0,0 +1,9 @@
.text
1:
/* A small list of examples of what clang doesn't support. */
clr %o0
lduw [%o4 + 4], %o4
and %o6, ~0xff, %o6
stw %o5, [%o3]
bne,pt %icc, 1b
nop

View file

@ -560,35 +560,39 @@ AC_COMPILE_IFELSE(
]])], ]])],
[grub_cv_cc_target_clang=no], [grub_cv_cc_target_clang=yes])]) [grub_cv_cc_target_clang=no], [grub_cv_cc_target_clang=yes])])
# on x86 clang doesn't support .code16 AC_CACHE_CHECK([for options to compile assembly], [grub_cv_cc_target_asm_compile], [
# on arm clang doesn't support .arch directive test_program=
# on mips clang doesn't support privilegied instructions, doubleword store/load case "x$target_cpu" in
# and crashes with hand-written assembly xmips | xmipsel)
if test "x$grub_cv_cc_target_clang" = xyes && ( test "x$target_cpu" = xi386 \ test_program=mips
|| test "x$target_cpu" = xx86_64 || test "x$target_cpu" = xarm \ ;;
|| test "x$target_cpu" = xmips || test "x$target_cpu" = xmipsel ); then xi386 | xx86_64)
TARGET_CCASFLAGS="$TARGET_CCASFLAGS -no-integrated-as" test_program=i386
;;
xpowerpc | xsparc64 | xarm)
test_program=$target_cpu
;;
esac
if test x"$test_program" = x ; then
grub_cv_cc_target_asm_compile=
else
found=no
for arg in "" "-no-integrated-as"; do
cmdline="$TARGET_CC -c -o /dev/null $TARGET_CCASFLAGS $arg $TARGET_CPPFLAGS $srcdir/asm-tests/$test_program.S"
echo "Running $cmdline" >&AS_MESSAGE_LOG_FD
if $cmdline >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then
grub_cv_cc_target_asm_compile="$arg"
found=yes
break
fi fi
done
if test x"$found" = xno ; then
AC_MSG_ERROR([could not compile assembly])
fi
fi
])
if test "x$grub_cv_cc_target_clang" = xyes && test "x$target_cpu" = xpowerpc; then TARGET_CCASFLAGS="$TARGET_CCASFLAGS $grub_cv_cc_target_asm_compile"
AC_CACHE_CHECK([if clang can handle ame instruction], [grub_cv_cc_target_clang_ame]
[
CFLAGS="$TARGET_CFLAGS"
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([], [[
unsigned int a = 0, b = 0;
asm volatile ("{ame|addme} %0,%1" : "=r" (a) : "r" (b));
if (a)
return 1;
]])],
[grub_cv_cc_target_clang_ame=yes], [grub_cv_cc_target_clang_ame=no])])
# clang <= 3.3 doesn't handle most of ppc assembly, not even inline assembly
# used by gcrypt
if test x$grub_cv_cc_target_clang_ame = xno ; then
TARGET_CCASFLAGS="$TARGET_CCASFLAGS -no-integrated-as"
TARGET_CFLAGS="$TARGET_CFLAGS -no-integrated-as"
fi
fi
if test "x$target_cpu" = xi386 && test "x$platform" != xemu; then if test "x$target_cpu" = xi386 && test "x$platform" != xemu; then
TARGET_CFLAGS="$TARGET_CFLAGS -march=i386" TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"