blob: e7603aeae2b4626182a658fbfe934eaf8e04c8df [file] [log] [blame]
from __future__ import print_function
# We need to be very careful about adding imports to this function, as the
# imports will increase execution time, and this is called for every
# compiler invocation.
import os
import sys
WRAPPER_ONLY_OPTIONS = set((
'-print-cmdline',
'-nopie',
'-noccache',
'-clang-syntax',
))
X86_DISABLE_FLAGS = set(['-mno-movbe'])
# GCC flags to remove from the clang command line.
# TODO: Once clang supports GCC compatibility mode, remove
# these checks.
#
# Use of -Qunused-arguments allows this set to be small, just those
# that clang still warns about.
CLANG_UNSUPPORTED = set((
'-pass-exit-codes',
'-Wclobbered',
'-Wunsafe-loop-optimizations',
'-Wlogical-op',
'-Wmissing-parameter-type',
'-Woverride-init',
'-Wold-style-declaration',
'-Wno-psabi',
'-mno-movbe',
))
# Flags not supported by GCC.
GCC_UNSUPPORTED = set(['-Xcompiler'])
# Flags not supported by sanitizers (ASan etc.)
LINKER_UNSUPPORTED_ASAN_FLAGS = set((
'-Wl,--no-undefined',
'-Wl,-z,defs',
))
CLANG_UNSUPPORTED_PREFIXES = ('-Wstrict-aliasing=', '-finline-limit=')
# clang with '-ftrapv' generates 'call __mulodi4', which is only implemented
# in compiler-rt library. However compiler-rt library only has i386/x86_64
# backends (see '/usr/lib/clang/3.7.0/lib/linux/libclang_rt.*'). GCC, on the
# other hand, generate 'call __mulvdi3', which is implemented in libgcc. See
# bug chromium:503229.
CLANG_ARM_OPTIONS_TO_BE_DISCARDED = set(['-ftrapv'])
# Clang may use different options for the same or similar functionality.
GCC_TO_CLANG = {
'-Wno-error=unused-but-set-variable': '-Wno-error=unused-variable',
'-Wno-error=maybe-uninitialized': '-Wno-error=uninitialized',
'-Wno-unused-but-set-variable': '-Wno-unused-variable',
'-Wunused-but-set-variable': '-Wunused-variable',
'-Wno-error=cpp': '-Wno-#warnings',
}
def handle_exec_exception(exc, argv0, use_ccache, execargs):
"""Analyze compiler execution errors."""
import errno
if use_ccache and exc.errno == errno.ENOENT:
print('error: make sure you install ccache\n', file=sys.stderr)
print(
'error: execution of (%s, %s) failed' % (argv0, execargs),
file=sys.stderr)
raise
def has_sanitizer_flags(args):
"""Returns true if ASan/MSan flags are present."""
if any([x.startswith('-fsanitize') for x in args]):
return True
return False
def startswith_i86(s):
"""Returns true if s starts with i.86."""
return s[0] + s[2:4] == 'i86'
def find_source_file(arg_list):
"""Find c source file in arg list, if it exists."""
c_endings = ('.c', '.cc', '.cpp', '.C', '.cxx', '.c++')
num_args = len(arg_list)
i = 1 # Start with second arg
while i < num_args:
arg = arg_list[i]
for ext in c_endings:
if arg.endswith(ext) and arg_list[i-1] != '-o':
return arg
i += 1
return ''