Bug 1524467 - Use -m32/-m64 in more cases. r=froydnj

In upcoming changes, we're going to use the normal compiler flags for
bindgen instead of having a separate logic for essentially the same
flags (and there's not much reason not to use the same flags after all).

One hiccup, though is that for some reason, --target=i686-linux-gnu
doesn't work with bindgen while it works with clang in the same setup.
But -m32 does.

Considering -m32 and -m64 are standard flags and that we're using them
in many cases, it doesn't hurt to use them instead of --target with
clang.

While we're doing that, we might as well refactor a little to avoid the
multiple branches handling the use of -m32/-m64, and fix the theoretical
compile-x86_64-with-x86-clang-cl case, as well as the weird check for
aarch64.

And because only two cases actually require -Xclang, only one of which
requires a condition, and the control flow is not too complex to avoid
flag duplication, we just remove the append_flag function; it was too
confusing, with all the cases we skipped it when -Xclang was not wanted.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mike Hommey 2019-02-04 17:22:58 +00:00
Родитель 278743b81e
Коммит 33a69b7eea
2 изменённых файлов: 34 добавлений и 45 удалений

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

@ -587,12 +587,6 @@ def check_compiler(compiler, language, target):
flags = []
def append_flag(flag):
if flag not in flags:
if info.type == 'clang-cl':
flags.append('-Xclang')
flags.append(flag)
# Check language standards
# --------------------------------------------------------------------
if language != info.language:
@ -605,7 +599,9 @@ def check_compiler(compiler, language, target):
# example)
if info.language == 'C' and info.language_version != 199901:
if info.type in ('clang-cl', 'clang', 'gcc'):
append_flag('-std=gnu99')
if info.type == 'clang-cl':
flags.append('-Xclang')
flags.append('-std=gnu99')
# Note: MSVC, while supporting C++14, still reports 199711L for __cplusplus.
# Note: this is a strict version check because we used to always add
@ -613,48 +609,41 @@ def check_compiler(compiler, language, target):
cxx14_version = 201402
if info.language == 'C++':
if info.type == 'clang' and info.language_version != cxx14_version:
append_flag('-std=gnu++14')
flags.append('-std=gnu++14')
# MSVC headers include C++14 features, but don't guard them
# with appropriate checks.
elif info.type == 'clang-cl' and info.language_version != cxx14_version:
append_flag('-std=c++14')
flags.append('-Xclang')
flags.append('-std=c++14')
# Check compiler target
# --------------------------------------------------------------------
if not info.cpu or info.cpu != target.cpu:
if info.type == 'clang':
append_flag('--target=%s' % target.toolchain)
elif info.type == 'clang-cl':
# Ideally this would share the 'clang' branch above, but on Windows
# the --target needs additional data like ms-compatibility-version.
if (info.cpu, target.cpu) == ('x86_64', 'x86'):
# -m32 does not use -Xclang, so add it directly.
flags.append('-m32')
elif target.toolchain == 'aarch64-mingw32':
# clang-cl uses a different name for this target
flags.append('--target=aarch64-windows-msvc')
elif info.type == 'gcc':
same_arch = same_arch_different_bits()
if (target.cpu, info.cpu) in same_arch:
append_flag('-m32')
elif (info.cpu, target.cpu) in same_arch:
append_flag('-m64')
has_target = False
if info.type == 'clang':
if not info.kernel or info.kernel != target.kernel or \
not info.endianness or info.endianness != target.endianness:
flags.append('--target=%s' % target.toolchain)
has_target = True
if not info.kernel or info.kernel != target.kernel:
if info.type == 'clang':
append_flag('--target=%s' % target.toolchain)
# Add target flag when there is an OS mismatch (e.g. building for Android on
# Linux). However, only do this if the target OS is in our whitelist, to
# keep things the same on other platforms.
elif target.os in OS_preprocessor_checks and (
not info.os or info.os != target.os):
flags.append('--target=%s' % target.toolchain)
has_target = True
if not info.endianness or info.endianness != target.endianness:
if info.type == 'clang':
append_flag('--target=%s' % target.toolchain)
# Add target flag when there is an OS mismatch (e.g. building for Android on
# Linux). However, only do this if the target OS is in our whitelist, to
# keep things the same on other platforms.
if target.os in OS_preprocessor_checks and (
not info.os or info.os != target.os):
if info.type == 'clang':
append_flag('--target=%s' % target.toolchain)
if not has_target and (not info.cpu or info.cpu != target.cpu and info.type != 'msvc'):
same_arch = same_arch_different_bits()
if (target.cpu, info.cpu) in same_arch:
flags.append('-m32')
elif (info.cpu, target.cpu) in same_arch:
flags.append('-m64')
elif info.type == 'clang-cl' and target.cpu == 'aarch64':
# clang-cl uses a different name for this target
flags.append('--target=aarch64-windows-msvc')
elif info.type == 'clang':
flags.append('--target=%s' % target.toolchain)
return namespace(
type=info.type,

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

@ -748,10 +748,10 @@ class LinuxSimpleCrossToolchainTest(BaseToolchainTest):
def test_cross_clang(self):
self.do_toolchain_test(self.PATHS, {
'c_compiler': self.DEFAULT_CLANG_RESULT + {
'flags': ['--target=i686-linux-gnu'],
'flags': ['-m32']
},
'cxx_compiler': self.DEFAULT_CLANGXX_RESULT + {
'flags': ['--target=i686-linux-gnu'],
'flags': ['-m32']
},
'host_c_compiler': self.DEFAULT_CLANG_RESULT,
'host_cxx_compiler': self.DEFAULT_CLANGXX_RESULT,
@ -789,10 +789,10 @@ class LinuxX86_64CrossToolchainTest(BaseToolchainTest):
def test_cross_clang(self):
self.do_toolchain_test(self.PATHS, {
'c_compiler': self.DEFAULT_CLANG_RESULT + {
'flags': ['--target=x86_64-linux-gnu'],
'flags': ['-m64']
},
'cxx_compiler': self.DEFAULT_CLANGXX_RESULT + {
'flags': ['--target=x86_64-linux-gnu'],
'flags': ['-m64']
},
'host_c_compiler': self.DEFAULT_CLANG_RESULT,
'host_cxx_compiler': self.DEFAULT_CLANGXX_RESULT,