Allow compiling with clang (not really supported though).

* conf/Makefile.common (CFLAGS_PLATFORM): Don't add -mrtd -mregparm=3
	unconditionally.
	* configure.ac: Add -no-integrated-as when using clangfor asm files.
	Add -mrtd -mregparm=3 on i386 when not using clang.
	* grub-core/kern/misc.c (grub_memset): Add volatile when on clang.
This commit is contained in:
Vladimir Serbinenko 2013-11-07 11:44:40 +01:00
parent dd07e0c4cf
commit 60375a88fe
4 changed files with 61 additions and 37 deletions

View file

@ -1,3 +1,13 @@
2013-11-07 Vladimir Serbinenko <phcoder@gmail.com>
Allow compiling with clang (not really supported though).
* conf/Makefile.common (CFLAGS_PLATFORM): Don't add -mrtd -mregparm=3
unconditionally.
* configure.ac: Add -no-integrated-as when using clangfor asm files.
Add -mrtd -mregparm=3 on i386 when not using clang.
* grub-core/kern/misc.c (grub_memset): Add volatile when on clang.
2013-11-07 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/kern/ieee1275/cmain.c: Add explicit attribute on asm

View file

@ -6,18 +6,6 @@ export LC_COLLATE := C
unexport LC_ALL
# Platform specific options
if COND_i386_pc
CFLAGS_PLATFORM += -mrtd -mregparm=3
endif
if COND_i386_qemu
CFLAGS_PLATFORM += -mrtd -mregparm=3
endif
if COND_i386_coreboot
CFLAGS_PLATFORM += -mrtd -mregparm=3
endif
if COND_i386_ieee1275
CFLAGS_PLATFORM += -mrtd -mregparm=3
endif
if COND_mips_loongson
CFLAGS_PLATFORM += -mexplicit-relocs
CPPFLAGS_PLATFORM = -DUSE_ASCII_FALLBACK

View file

@ -480,6 +480,45 @@ if test "x$target_cpu" != xi386 && test "x$target_cpu" != xx86_64; then
TARGET_CFLAGS="$TARGET_CFLAGS -Wcast-align"
fi
AC_CACHE_CHECK([if compiling with clang], [grub_cv_cc_target_clang]
[AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([], [[
#ifdef __clang__
#error "is clang"
#endif
]])],
[grub_cv_cc_target_clang=no], [grub_cv_cc_target_clang=yes])])
if test "x$grub_cv_cc_target_clang" = xyes; then
TARGET_CCASFLAGS="$TARGET_CCASFLAGS -no-integrated-as"
fi
if test "x$target_cpu" = xi386 && test "x$platform" != xemu; then
TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
fi
if test "x$target_m32" = x1; then
# Force 32-bit mode.
TARGET_CFLAGS="$TARGET_CFLAGS -m32"
TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m32"
TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m32"
TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
TARGET_MODULE_FORMAT="elf32"
fi
if test "x$target_m64" = x1; then
# Force 64-bit mode.
TARGET_CFLAGS="$TARGET_CFLAGS -m64"
TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m64"
TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m64"
TARGET_LDFLAGS="$TARGET_LDFLAGS -m64"
TARGET_MODULE_FORMAT="elf64"
fi
if test "x$grub_cv_cc_target_clang" = xno && test "x$target_cpu" = xi386 && test "x$platform" != xemu && test "x$platform" != xefi; then
TARGET_CFLAGS="$TARGET_CFLAGS -mrtd -mregparm=3"
fi
# Force no alignment to save space on i386.
if test "x$target_cpu" = xi386; then
AC_CACHE_CHECK([whether -falign-loops works], [grub_cv_cc_falign_loop], [
@ -647,28 +686,6 @@ enable_efiemu=no
fi
AC_SUBST([enable_efiemu])
if test "x$target_cpu" = xi386 && test "x$platform" != xemu; then
TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
fi
if test "x$target_m32" = x1; then
# Force 32-bit mode.
TARGET_CFLAGS="$TARGET_CFLAGS -m32"
TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m32"
TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m32"
TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
TARGET_MODULE_FORMAT="elf32"
fi
if test "x$target_m64" = x1; then
# Force 64-bit mode.
TARGET_CFLAGS="$TARGET_CFLAGS -m64"
TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m64"
TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m64"
TARGET_LDFLAGS="$TARGET_LDFLAGS -m64"
TARGET_MODULE_FORMAT="elf64"
fi
case "$target_os" in
cygwin)
;;

View file

@ -454,6 +454,15 @@ grub_strndup (const char *s, grub_size_t n)
return p;
}
/* clang detects that we're implementing here a memset so it decides to
optimise and calls memset resulting in infinite recursion. With volatile
we make it not optimise in this way. */
#ifdef __clang__
#define VOLATILE_CLANG volatile
#else
#define VOLATILE_CLANG
#endif
void *
grub_memset (void *s, int c, grub_size_t len)
{
@ -470,13 +479,13 @@ grub_memset (void *s, int c, grub_size_t len)
while (len > 0 && (((grub_addr_t) p) & (sizeof (unsigned long) - 1)))
{
*(grub_uint8_t *) p = pattern8;
*(VOLATILE_CLANG grub_uint8_t *) p = pattern8;
p = (grub_uint8_t *) p + 1;
len--;
}
while (len >= sizeof (unsigned long))
{
*(unsigned long *) p = patternl;
*(VOLATILE_CLANG unsigned long *) p = patternl;
p = (unsigned long *) p + 1;
len -= sizeof (unsigned long);
}
@ -484,7 +493,7 @@ grub_memset (void *s, int c, grub_size_t len)
while (len > 0)
{
*(grub_uint8_t *) p = pattern8;
*(VOLATILE_CLANG grub_uint8_t *) p = pattern8;
p = (grub_uint8_t *) p + 1;
len--;
}