def SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS(conf): # we don't want any libraries or modules to rely on runtime # resolution of symbols if not sys.platform.startswith("openbsd"): conf.env.undefined_ldflags = conf.ADD_LDFLAGS('-Wl,-no-undefined', testflags=True) if not sys.platform.startswith( "openbsd") and conf.env.undefined_ignore_ldflags == []: if conf.CHECK_LDFLAGS(['-undefined', 'dynamic_lookup']): conf.env.undefined_ignore_ldflags = [ '-undefined', 'dynamic_lookup' ]
def SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS(conf): if Options.options.address_sanitizer or Options.options.enable_libfuzzer: # Sanitizers can rely on symbols undefined at library link time and the # symbols used for fuzzers are only defined by compiler wrappers. return if not sys.platform.startswith("openbsd"): # we don't want any libraries or modules to rely on runtime # resolution of symbols conf.env.undefined_ldflags = conf.ADD_LDFLAGS('-Wl,-no-undefined', testflags=True) if (conf.env.undefined_ignore_ldflags == [] and conf.CHECK_LDFLAGS(['-undefined', 'dynamic_lookup'])): conf.env.undefined_ignore_ldflags = ['-undefined', 'dynamic_lookup']
def SAMBA_CONFIG_H(conf, path=None): '''write out config.h in the right directory''' # we don't want to produce a config.h in places like lib/replace # when we are building projects that depend on lib/replace if not IN_LAUNCH_DIR(conf): return # we need to build real code that can't be optimized away to test stack_protect_list = ['-fstack-protector-strong', '-fstack-protector'] for stack_protect_flag in stack_protect_list: flag_supported = conf.check( fragment=''' #include <stdio.h> int main(void) { char t[100000]; while (fgets(t, sizeof(t), stdin)); return 0; } ''', execute=0, cflags=['-Werror', '-Wp,-D_FORTIFY_SOURCE=2', stack_protect_flag], mandatory=False, msg='Checking if compiler accepts %s' % (stack_protect_flag)) if flag_supported: conf.ADD_CFLAGS('%s' % (stack_protect_flag)) break flag_supported = conf.check( fragment=''' #include <stdio.h> int main(void) { char t[100000]; while (fgets(t, sizeof(t), stdin)); return 0; } ''', execute=0, cflags=['-Werror', '-fstack-clash-protection'], mandatory=False, msg='Checking if compiler accepts -fstack-clash-protection') if flag_supported: conf.ADD_CFLAGS('-fstack-clash-protection') if Options.options.debug: conf.ADD_CFLAGS('-g', testflags=True) if Options.options.pidl_developer: conf.env.PIDL_DEVELOPER_MODE = True if Options.options.developer: conf.env.DEVELOPER_MODE = True conf.ADD_CFLAGS('-g', testflags=True) conf.ADD_CFLAGS('-Wall', testflags=True) conf.ADD_CFLAGS('-Wshadow', testflags=True) conf.ADD_CFLAGS('-Wmissing-prototypes', testflags=True) if CHECK_CODE( conf, 'struct a { int b; }; struct c { struct a d; } e = { };', 'CHECK_C99_INIT', link=False, cflags= '-Wmissing-field-initializers -Werror=missing-field-initializers', msg="Checking C99 init of nested structs."): conf.ADD_CFLAGS('-Wmissing-field-initializers', testflags=True) conf.ADD_CFLAGS('-Wformat-overflow=2', testflags=True) conf.ADD_CFLAGS('-Wformat-zero-length', testflags=True) conf.ADD_CFLAGS('-Wcast-align -Wcast-qual', testflags=True) conf.ADD_CFLAGS('-fno-common', testflags=True) conf.ADD_CFLAGS('-Werror=address', testflags=True) # we add these here to ensure that -Wstrict-prototypes is not set during configure conf.ADD_CFLAGS('-Werror=strict-prototypes -Wstrict-prototypes', testflags=True) conf.ADD_CFLAGS('-Werror=write-strings -Wwrite-strings', testflags=True) conf.ADD_CFLAGS('-Werror-implicit-function-declaration', testflags=True) conf.ADD_CFLAGS('-Werror=pointer-arith -Wpointer-arith', testflags=True) conf.ADD_CFLAGS( '-Werror=declaration-after-statement -Wdeclaration-after-statement', testflags=True) conf.ADD_CFLAGS('-Werror=return-type -Wreturn-type', testflags=True) conf.ADD_CFLAGS('-Werror=uninitialized -Wuninitialized', testflags=True) conf.ADD_CFLAGS('-Wimplicit-fallthrough', testflags=True) conf.ADD_CFLAGS('-Werror=strict-overflow -Wstrict-overflow=2', testflags=True) conf.ADD_CFLAGS('-Wformat=2 -Wno-format-y2k', testflags=True) conf.ADD_CFLAGS('-Wno-format-zero-length', testflags=True) conf.ADD_CFLAGS('-Werror=format-security -Wformat-security', testflags=True, prereq_flags='-Wformat') # This check is because for ldb_search(), a NULL format string # is not an error, but some compilers complain about that. if CHECK_CFLAGS( conf, ["-Werror=format", "-Wformat=2"], ''' int testformat(char *format, ...) __attribute__ ((format (__printf__, 1, 2))); int main(void) { testformat(0); return 0; } '''): if not 'EXTRA_CFLAGS' in conf.env: conf.env['EXTRA_CFLAGS'] = [] conf.env['EXTRA_CFLAGS'].extend(TO_LIST("-Werror=format")) if not Options.options.disable_warnings_as_errors: conf.ADD_NAMED_CFLAGS('PICKY_CFLAGS', '-Werror -Wno-error=deprecated-declarations', testflags=True) conf.ADD_NAMED_CFLAGS('PICKY_CFLAGS', '-Wno-error=tautological-compare', testflags=True) conf.ADD_NAMED_CFLAGS('PICKY_CFLAGS', '-Wno-error=cast-align', testflags=True) if Options.options.fatal_errors: conf.ADD_CFLAGS('-Wfatal-errors', testflags=True) if Options.options.pedantic: conf.ADD_CFLAGS('-W', testflags=True) if (Options.options.address_sanitizer or Options.options.undefined_sanitizer): conf.ADD_CFLAGS('-g -O1', testflags=True) if Options.options.address_sanitizer: conf.ADD_CFLAGS('-fno-omit-frame-pointer', testflags=True) conf.ADD_CFLAGS('-fsanitize=address', testflags=True) conf.ADD_LDFLAGS('-fsanitize=address', testflags=True) conf.env['ADDRESS_SANITIZER'] = True if Options.options.undefined_sanitizer: conf.ADD_CFLAGS('-fsanitize=undefined', testflags=True) conf.ADD_CFLAGS('-fsanitize=null', testflags=True) conf.ADD_CFLAGS('-fsanitize=alignment', testflags=True) conf.ADD_LDFLAGS('-fsanitize=undefined', testflags=True) conf.env['UNDEFINED_SANITIZER'] = True # Let people pass an additional ADDITIONAL_{CFLAGS,LDFLAGS} # environment variables which are only used the for final build. # # The CFLAGS and LDFLAGS environment variables are also # used for the configure checks which might impact their results. # # If these variables don't pass a smoke test, fail the configure conf.add_os_flags('ADDITIONAL_CFLAGS') if conf.env.ADDITIONAL_CFLAGS: conf.CHECK_CFLAGS(conf.env['ADDITIONAL_CFLAGS'], mandatory=True) conf.env['EXTRA_CFLAGS'].extend(conf.env['ADDITIONAL_CFLAGS']) conf.add_os_flags('ADDITIONAL_LDFLAGS') if conf.env.ADDITIONAL_LDFLAGS: conf.CHECK_LDFLAGS(conf.env['ADDITIONAL_LDFLAGS'], mandatory=True) conf.env['EXTRA_LDFLAGS'].extend(conf.env['ADDITIONAL_LDFLAGS']) if path is None: conf.write_config_header('default/config.h', top=True, remove=False) else: conf.write_config_header(os.path.join(conf.variant, path), remove=False) for key in conf.env.define_key: conf.undefine(key, from_env=False) conf.env.define_key = [] conf.SAMBA_CROSS_CHECK_COMPLETE()