Bug 1524429 - Move build/autoconf/arch.m4 to python configure. r=nalexander

The file is essentially limited to ARM flag tweaks, so we make the
corresponding python configure code ARM-only. In large parts, the
python code sets things up similarly, although in a few places we try to
be smarter about than the current autoconf-based code.

The resulting config.status have been verified to only have
insignificant differences on both arm and aarch64 android builds.

Depends on D24000

Differential Revision: https://phabricator.services.mozilla.com/D24001

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mike Hommey 2019-03-19 22:32:58 +00:00
Родитель fc262970ca
Коммит 80f7e86b2e
4 изменённых файлов: 259 добавлений и 269 удалений

Просмотреть файл

@ -4,269 +4,12 @@ dnl file, You can obtain one at http://mozilla.org/MPL/2.0/.
AC_DEFUN([MOZ_ARCH_OPTS],
[
dnl ========================================================
dnl = ARM toolchain tweaks
dnl ========================================================
MOZ_THUMB=toolchain-default
MOZ_THUMB_INTERWORK=toolchain-default
MOZ_FPU=toolchain-default
MOZ_FLOAT_ABI=toolchain-default
MOZ_SOFT_FLOAT=toolchain-default
MOZ_ALIGN=toolchain-default
MOZ_ARG_WITH_STRING(arch,
[ --with-arch=[[type|toolchain-default]]
Use specific CPU features (-march=type). Resets
thumb, fpu, float-abi, etc. defaults when set],
if test -z "$GNU_CC"; then
AC_MSG_ERROR([--with-arch is not supported on non-GNU toolchains])
fi
MOZ_ARCH=$withval)
if test -z "$MOZ_ARCH"; then
dnl Defaults
case "${CPU_ARCH}-${OS_TARGET}" in
arm-Android)
MOZ_THUMB=yes
MOZ_ARCH=armv7-a
MOZ_FPU=neon
MOZ_FLOAT_ABI=softfp
MOZ_ALIGN=no
;;
arm-Darwin)
MOZ_ARCH=toolchain-default
;;
esac
fi
if test "$MOZ_ARCH" = "armv6" -a "$OS_TARGET" = "Android"; then
AC_MSG_ERROR([Android/armv6 is not supported])
fi
MOZ_ARG_WITH_STRING(thumb,
[ --with-thumb[[=yes|no|toolchain-default]]]
[ Use Thumb instruction set (-mthumb)],
if test -z "$GNU_CC"; then
AC_MSG_ERROR([--with-thumb is not supported on non-GNU toolchains])
fi
MOZ_THUMB=$withval)
MOZ_ARG_WITH_STRING(thumb-interwork,
[ --with-thumb-interwork[[=yes|no|toolchain-default]]
Use Thumb/ARM instuctions interwork (-mthumb-interwork)],
if test -z "$GNU_CC"; then
AC_MSG_ERROR([--with-thumb-interwork is not supported on non-GNU toolchains])
fi
MOZ_THUMB_INTERWORK=$withval)
MOZ_ARG_WITH_STRING(fpu,
[ --with-fpu=[[type|toolchain-default]]
Use specific FPU type (-mfpu=type)],
if test -z "$GNU_CC"; then
AC_MSG_ERROR([--with-fpu is not supported on non-GNU toolchains])
fi
MOZ_FPU=$withval)
MOZ_ARG_WITH_STRING(float-abi,
[ --with-float-abi=[[type|toolchain-default]]
Use specific arm float ABI (-mfloat-abi=type)],
if test -z "$GNU_CC"; then
AC_MSG_ERROR([--with-float-abi is not supported on non-GNU toolchains])
fi
MOZ_FLOAT_ABI=$withval)
MOZ_ARG_WITH_STRING(soft-float,
[ --with-soft-float[[=yes|no|toolchain-default]]
Use soft float library (-msoft-float)],
if test -z "$GNU_CC"; then
AC_MSG_ERROR([--with-soft-float is not supported on non-GNU toolchains])
fi
MOZ_SOFT_FLOAT=$withval)
case "$MOZ_ARCH" in
toolchain-default|"")
arch_flag=""
;;
*)
arch_flag="-march=$MOZ_ARCH"
;;
esac
case "$MOZ_THUMB" in
yes)
MOZ_THUMB2=1
thumb_flag="-mthumb"
;;
no)
MOZ_THUMB2=
thumb_flag="-marm"
;;
*)
_SAVE_CFLAGS="$CFLAGS"
CFLAGS="$arch_flag"
AC_TRY_COMPILE([],[return sizeof(__thumb2__);],
MOZ_THUMB2=1,
MOZ_THUMB2=)
CFLAGS="$_SAVE_CFLAGS"
thumb_flag=""
;;
esac
if test "$MOZ_THUMB2" = 1; then
AC_DEFINE(MOZ_THUMB2)
fi
case "$MOZ_THUMB_INTERWORK" in
yes)
thumb_interwork_flag="-mthumb-interwork"
;;
no)
thumb_interwork_flag="-mno-thumb-interwork"
;;
*) # toolchain-default
thumb_interwork_flag=""
;;
esac
case "$MOZ_FPU" in
toolchain-default|"")
fpu_flag=""
;;
*)
fpu_flag="-mfpu=$MOZ_FPU"
;;
esac
case "$MOZ_FLOAT_ABI" in
toolchain-default|"")
float_abi_flag=""
;;
*)
float_abi_flag="-mfloat-abi=$MOZ_FLOAT_ABI"
;;
esac
case "$MOZ_SOFT_FLOAT" in
yes)
soft_float_flag="-msoft-float"
;;
no)
soft_float_flag="-mno-soft-float"
;;
*) # toolchain-default
soft_float_flag=""
;;
esac
case "$MOZ_ALIGN" in
no)
align_flag="-mno-unaligned-access"
;;
yes)
align_flag="-munaligned-access"
;;
*)
align_flag=""
;;
esac
if test -n "$align_flag"; then
_SAVE_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $align_flag"
AC_MSG_CHECKING(whether alignment flag ($align_flag) is supported)
AC_TRY_COMPILE([],[],,align_flag="")
CFLAGS="$_SAVE_CFLAGS"
fi
dnl Use echo to avoid accumulating space characters
all_flags=`echo $arch_flag $thumb_flag $thumb_interwork_flag $fpu_flag $float_abi_flag $soft_float_flag $align_flag`
if test -n "$all_flags"; then
_SAVE_CFLAGS="$CFLAGS"
CFLAGS="$all_flags"
AC_MSG_CHECKING(whether the chosen combination of compiler flags ($all_flags) works)
AC_TRY_COMPILE([],[return 0;],
AC_MSG_RESULT([yes]),
AC_MSG_ERROR([no]))
CFLAGS="$_SAVE_CFLAGS $all_flags"
CXXFLAGS="$CXXFLAGS $all_flags"
ASFLAGS="$ASFLAGS $all_flags"
if test -n "$thumb_flag"; then
LDFLAGS="$LDFLAGS $thumb_flag"
if test -n "$_ARM_FLAGS"; then
CFLAGS="$CFLAGS $_ARM_FLAGS"
CXXFLAGS="$CXXFLAGS $_ARM_FLAGS"
ASFLAGS="$ASFLAGS $_ARM_FLAGS"
if test -n "$_THUMB_FLAGS"; then
LDFLAGS="$LDFLAGS $_THUMB_FLAGS"
fi
fi
AC_SUBST(MOZ_THUMB2)
if test "$CPU_ARCH" = "arm"; then
NEON_FLAGS="-mfpu=neon"
AC_MSG_CHECKING(for ARM SIMD support in compiler)
# We try to link so that this also fails when
# building with LTO.
AC_TRY_LINK([],
[asm("uqadd8 r1, r1, r2");],
result="yes", result="no")
AC_MSG_RESULT("$result")
if test "$result" = "yes"; then
AC_DEFINE(HAVE_ARM_SIMD)
HAVE_ARM_SIMD=1
fi
AC_MSG_CHECKING(ARM version support in compiler)
dnl Determine the target ARM architecture (5 for ARMv5, v5T, v5E, etc.; 6 for ARMv6, v6K, etc.)
ARM_ARCH=`${CC-cc} ${CFLAGS} -dM -E - < /dev/null | sed -n 's/.*__ARM_ARCH_\([[0-9]][[0-9]]*\).*/\1/p' | head -n 1`
AC_MSG_RESULT("$ARM_ARCH")
AC_MSG_CHECKING(for ARM NEON support in compiler)
# We try to link so that this also fails when
# building with LTO.
AC_TRY_LINK([],
[asm(".fpu neon\n vadd.i8 d0, d0, d0");],
result="yes", result="no")
AC_MSG_RESULT("$result")
if test "$result" = "yes"; then
AC_DEFINE(HAVE_ARM_NEON)
HAVE_ARM_NEON=1
dnl We don't need to build NEON support if we're targetting a non-NEON device.
dnl This matches media/webrtc/trunk/webrtc/build/common.gypi.
if test -n "$ARM_ARCH"; then
if test "$ARM_ARCH" -lt 7; then
BUILD_ARM_NEON=
else
AC_DEFINE(BUILD_ARM_NEON)
BUILD_ARM_NEON=1
fi
fi
fi
dnl Building with -mfpu=neon requires either the "softfp" or the
dnl "hardfp" ABI. Depending on the compiler's default target, and the
dnl CFLAGS, the default ABI might be neither, in which case it is the
dnl "softfloat" ABI.
dnl The "softfloat" ABI is binary-compatible with the "softfp" ABI, so
dnl we can safely mix code built with both ABIs. So, if we detect
dnl that compiling uses the "softfloat" ABI, force the use of the
dnl "softfp" ABI instead.
dnl Confusingly, the __SOFTFP__ preprocessor variable indicates the
dnl "softfloat" ABI, not the "softfp" ABI.
dnl Note: VPX_ASFLAGS is also used in CFLAGS.
AC_TRY_COMPILE([],
[#ifndef __SOFTFP__
#error "compiler target supports -mfpu=neon, so we don't have to add extra flags"
#endif],
NEON_FLAGS="$NEON_FLAGS -mfloat-abi=softfp"
)
fi # CPU_ARCH = arm
AC_SUBST(HAVE_ARM_SIMD)
AC_SUBST(HAVE_ARM_NEON)
AC_SUBST(BUILD_ARM_NEON)
AC_SUBST(ARM_ARCH)
AC_SUBST_LIST(NEON_FLAGS)
AC_SUBST(MOZ_FPU)
])

Просмотреть файл

@ -0,0 +1,252 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
@depends(target.os, '--help')
def arm_option_defaults(os, _):
if os == 'Android':
arch = 'armv7-a'
thumb = 'yes'
fpu = 'neon'
float_abi = 'softfp'
else:
arch = thumb = fpu = float_abi = 'toolchain-default'
return namespace(
arch=arch,
thumb=thumb,
fpu=fpu,
float_abi=float_abi,
)
js_option('--with-arch', nargs=1,
default=arm_option_defaults.arch,
help='Use specific CPU features (-march=type). Resets thumb, fpu, '
'float-abi, etc. defaults when set')
@depends('--with-arch')
def arch_option(value):
if value:
if value[0] != 'toolchain-default':
return ['-march={}'.format(value[0])]
return []
js_option('--with-thumb', choices=('yes', 'no', 'toolchain-default'),
default=arm_option_defaults.thumb,
nargs='?', help='Use Thumb instruction set (-mthumb)')
def normalize_arm_option(value):
if value:
if len(value):
if value[0] == 'yes':
return True
elif value[0] == 'no':
return False
else:
return value[0]
return True
return False
@depends('--with-thumb')
def thumb_option(value):
value = normalize_arm_option(value)
if value is True:
return ['-mthumb']
if value is False:
return ['-marm']
return []
js_option('--with-thumb-interwork', choices=('yes', 'no', 'toolchain-default'),
default='toolchain-default',
nargs='?', help='Use Thumb/ARM instuctions interwork (-mthumb-interwork)')
@depends('--with-thumb-interwork')
def thumb_interwork_option(value):
value = normalize_arm_option(value)
if value is True:
return ['-mthumb-interwork']
if value is False:
return ['-mno-thumb-interwork']
return []
js_option('--with-fpu', nargs=1,
default=arm_option_defaults.fpu,
help='Use specific FPU type (-mfpu=type)')
@depends('--with-fpu')
def fpu_option(value):
if value:
if value[0] != 'toolchain-default':
return ['-mfpu={}'.format(value[0])]
return []
js_option('--with-float-abi', nargs=1,
default=arm_option_defaults.float_abi,
help='Use specific arm float ABI (-mfloat-abi=type)')
@depends('--with-float-abi')
def float_abi_option(value):
if value:
if value[0] != 'toolchain-default':
return ['-mfloat-abi={}'.format(value[0])]
return []
js_option('--with-soft-float', choices=('yes', 'no', 'toolchain-default'),
default='toolchain-default',
nargs='?', help='Use soft float library (-msoft-float)')
@depends('--with-soft-float')
def soft_float_option(value):
value = normalize_arm_option(value)
if value is True:
return ['-msoft-float']
if value is False:
return ['-mno-soft-float']
return []
check_and_add_gcc_flag('-mno-unaligned-access',
when=depends(target.os)(lambda os: os == 'Android'))
@depends(arch_option, thumb_option, thumb_interwork_option, fpu_option,
float_abi_option, soft_float_option)
def all_flags(arch, thumb, interwork, fpu, float_abi, soft_float):
return arch + thumb + interwork + fpu + float_abi + soft_float
add_old_configure_assignment('_ARM_FLAGS', all_flags)
add_old_configure_assignment('_THUMB_FLAGS', thumb_option)
@depends(c_compiler, all_flags)
@checking('ARM version support in compiler', lambda x: x.arm_arch)
@imports(_from='textwrap', _import='dedent')
def arm_target(compiler, all_flags):
# We're going to preprocess the following source to figure out some details
# about the arm target options we have enabled.
source = dedent('''\
%ARM_ARCH __ARM_ARCH
#if __thumb2__
%THUMB2 yes
#else
%THUMB2 no
#endif
// Confusingly, the __SOFTFP__ preprocessor variable indicates the
// "softfloat" ABI, not the "softfp" ABI.
#if __SOFTFP__
%FLOAT_ABI soft
#elif __ARM_PCS_VFP
%FLOAT_ABI hard
#else
%FLOAT_ABI softfp
#endif
// There is more subtlety to it than this preprocessor test, but MOZ_FPU doesn't
// need to be too fine-grained.
#if __ARM_NEON
%FPU neon
#elif __ARM_VFPV2__
%FPU vfpv2
#elif __ARM_VFPV3__
%FPU vfpv3
#elif __ARM_VFPV4__
%FPU vfpv4
#elif __ARM_FPV5__
%FPU fp-armv8
#endif
''')
result = try_invoke_compiler(
compiler.wrapper + [compiler.compiler] + compiler.flags,
compiler.language,
source,
['-E'] + all_flags,
)
# Metadata emitted by preprocessors such as GCC with LANG=ja_JP.utf-8 may
# have non-ASCII characters. Treat the output as bytearray.
data = {}
for line in result.splitlines():
if line.startswith(b'%'):
k, _, v = line.partition(' ')
k = k.lstrip('%').lower()
if k == 'arm_arch':
data[k] = int(v)
else:
data[k] = {
'yes': True,
'no': False,
}.get(v, v)
log.debug('%s = %s', k, data[k])
return namespace(**data)
@depends(arm_target.arm_arch, when=depends(target.os)(lambda os: os == 'Android'))
def armv7(arch):
if arch < 7:
die('Android/armv6 and earlier are not supported')
set_config('MOZ_THUMB2', True, when=arm_target.thumb2)
set_define('MOZ_THUMB2', True, when=arm_target.thumb2)
add_old_configure_assignment('MOZ_THUMB2', True, when=arm_target.thumb2)
have_arm_simd = c_compiler.try_compile(body='asm("uqadd8 r1, r1, r2");',
check_msg='for ARM SIMD support in compiler')
set_config('HAVE_ARM_SIMD', have_arm_simd)
set_define('HAVE_ARM_SIMD', have_arm_simd)
have_arm_neon = c_compiler.try_compile(body='asm(".fpu neon\\n vadd.i8 d0, d0, d0");',
check_msg='for ARM NEON support in compiler')
set_config('HAVE_ARM_NEON', have_arm_neon)
set_define('HAVE_ARM_NEON', have_arm_neon)
# We don't need to build NEON support if we're targetting a non-NEON device.
# This matches media/webrtc/trunk/webrtc/build/common.gypi.
@depends(arm_target.arm_arch, when=have_arm_neon)
def build_arm_neon(arm_arch):
return arm_arch >= 7
set_config('BUILD_ARM_NEON', build_arm_neon)
set_define('BUILD_ARM_NEON', build_arm_neon)
set_config('ARM_ARCH', depends(arm_target.arm_arch)(lambda x: str(x)))
add_old_configure_assignment('ARM_ARCH', depends(arm_target.arm_arch)(lambda x: str(x)))
set_config('MOZ_FPU', arm_target.fpu)
@depends(arm_target.float_abi)
def neon_flags(float_abi):
# Building with -mfpu=neon requires either the "softfp" or the
# "hardfp" ABI. Depending on the compiler's default target, and the
# CFLAGS, the default ABI might be neither, in which case it is the
# "softfloat" ABI.
# The "softfloat" ABI is binary-compatible with the "softfp" ABI, so
# we can safely mix code built with both ABIs. So, if we detect
# that compiling uses the "softfloat" ABI, force the use of the
# "softfp" ABI instead.
flags = ['-mfpu=neon']
if float_abi == 'soft':
flags.append('-mfloat-abi=softfp')
return tuple(flags)
set_config('NEON_FLAGS', neon_flags)

Просмотреть файл

@ -231,7 +231,6 @@ def old_configure_options(*options):
'--with-android-min-sdk',
'--with-app-basename',
'--with-app-name',
'--with-arch',
'--with-branding',
'--with-cross-lib',
'--with-debug-label',
@ -239,8 +238,6 @@ def old_configure_options(*options):
'--with-doc-include-dirs',
'--with-doc-input-dirs',
'--with-doc-output-dir',
'--with-float-abi',
'--with-fpu',
'--with-intl-api',
'--with-ios-sdk',
'--with-jitreport-granularity',
@ -253,7 +250,6 @@ def old_configure_options(*options):
'--with-nss-prefix',
'--with-qemu-exe',
'--with-sixgill',
'--with-soft-float',
'--with-system-bz2',
'--with-system-icu',
'--with-system-libevent',
@ -261,8 +257,6 @@ def old_configure_options(*options):
'--with-system-nss',
'--with-system-png',
'--with-system-zlib',
'--with-thumb',
'--with-thumb-interwork',
'--with-unify-dist',
'--with-user-appdir',
'--x-includes',

Просмотреть файл

@ -1183,6 +1183,7 @@ def msvs_version(info):
set_config('MSVS_VERSION', msvs_version)
include('compile-checks.configure')
include('arm.configure', when=depends(target.cpu)(lambda cpu: cpu == 'arm'))
@depends(have_64_bit,