compilers: pull sanitzier args into compiler classes

This simplifies and cleans things up.
pull/5700/head
Dylan Baker 6 years ago committed by Nirbheek Chauhan
parent e0f036f3a4
commit c8a6a44850
  1. 2
      mesonbuild/compilers/__init__.py
  2. 24
      mesonbuild/compilers/compilers.py
  3. 13
      mesonbuild/compilers/mixins/gnu.py
  4. 5
      mesonbuild/modules/gnome.py

@ -33,7 +33,6 @@ __all__ = [
'is_object',
'is_source',
'lang_suffixes',
'sanitizer_compile_args',
'sort_clink',
'ArmCCompiler',
@ -116,7 +115,6 @@ from .compilers import (
is_object,
is_library,
lang_suffixes,
sanitizer_compile_args,
sort_clink,
CompilerArgs,
)

@ -254,20 +254,6 @@ base_options = {'b_pch': coredata.UserBooleanOption('Use precompiled headers', T
'from_buildtype'),
}
def sanitizer_compile_args(value):
if value == 'none':
return []
args = ['-fsanitize=' + value]
if 'address' in value: # For -fsanitize=address,undefined
args.append('-fno-omit-frame-pointer')
return args
def sanitizer_link_args(value):
if value == 'none':
return []
args = ['-fsanitize=' + value]
return args
def option_enabled(boptions, options, option):
try:
if option not in boptions:
@ -288,7 +274,7 @@ def get_base_compile_args(options, compiler):
except KeyError:
pass
try:
args += sanitizer_compile_args(options['b_sanitize'].value)
args += compiler.sanitizer_compile_args(options['b_sanitize'].value)
except KeyError:
pass
try:
@ -333,7 +319,7 @@ def get_base_link_args(options, linker, is_shared_module):
except KeyError:
pass
try:
args += sanitizer_link_args(options['b_sanitize'].value)
args += linker.sanitizer_link_args(options['b_sanitize'].value)
except KeyError:
pass
try:
@ -1201,6 +1187,12 @@ class Compiler:
def get_lto_link_args(self) -> List[str]:
return []
def sanitizer_compile_args(self, value: str) -> List[str]:
return []
def sanitizer_link_args(self, value: str) -> List[str]:
return []
@enum.unique
class CompilerType(enum.Enum):

@ -372,6 +372,19 @@ class GnuLikeCompiler(metaclass=abc.ABCMeta):
def get_lto_link_args(self) -> typing.List[str]:
return ['-flto']
def sanitizer_compile_args(self, value: str) -> typing.List[str]:
if value == 'none':
return []
args = ['-fsanitize=' + value]
if 'address' in value: # for -fsanitize=address,undefined
args.append('-fno-omit-frame-pointer')
return args
def sanitizer_link_args(self, value: str) -> typing.List[str]:
if value == 'none':
return []
return ['-fsanitize=' + value]
class GnuCompiler(GnuLikeCompiler):
"""

@ -23,7 +23,6 @@ import subprocess
from .. import build
from .. import mlog
from .. import mesonlib
from .. import compilers
from .. import interpreter
from . import GResourceTarget, GResourceHeaderTarget, GirTarget, TypelibTarget, VapiTarget
from . import get_include_args
@ -604,7 +603,7 @@ class GnomeModule(ExtensionModule):
cflags += state.project_args[lang]
if 'b_sanitize' in compiler.base_options:
sanitize = state.environment.coredata.base_options['b_sanitize'].value
cflags += compilers.sanitizer_compile_args(sanitize)
cflags += compiler.sanitizer_compile_args(sanitize)
sanitize = sanitize.split(',')
# These must be first in ldflags
if 'address' in sanitize:
@ -615,7 +614,7 @@ class GnomeModule(ExtensionModule):
internal_ldflags += ['-lubsan']
# FIXME: Linking directly to lib*san is not recommended but g-ir-scanner
# does not understand -f LDFLAGS. https://bugzilla.gnome.org/show_bug.cgi?id=783892
# ldflags += compilers.sanitizer_link_args(sanitize)
# ldflags += compiler.sanitizer_link_args(sanitize)
return cflags, internal_ldflags, external_ldflags

Loading…
Cancel
Save