From: Konstantin Demin rockdrilla@gmail.com
Signed-off-by: Konstantin Demin rockdrilla@gmail.com --- tools/makedep.c | 126 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 120 insertions(+), 6 deletions(-)
diff --git a/tools/makedep.c b/tools/makedep.c index 05360bdda91..3dfd8c69e2b 100644 --- a/tools/makedep.c +++ b/tools/makedep.c @@ -178,6 +178,7 @@ static struct strarray disabled_dirs[MAX_ARCHS]; static unsigned int native_archs[MAX_ARCHS]; static unsigned int hybrid_archs[MAX_ARCHS]; static struct strarray hybrid_target_flags[MAX_ARCHS]; +static struct strarray global_lto_skip[MAX_ARCHS];
struct makefile { @@ -210,6 +211,8 @@ struct makefile int is_win16; int is_exe; int disabled[MAX_ARCHS]; + int lto_skip[MAX_ARCHS]; + struct strarray lto_skip_src[MAX_ARCHS];
/* values generated at output time */ struct strarray in_files; @@ -4561,6 +4564,25 @@ static void load_sources( struct makefile *make )
for (i = 0; i < make->delayimports.count; i++) strarray_add_uniq( &delay_import_libs, get_base_name( make->delayimports.str[i] )); + + if (with_lto) + { + for (arch = 0; arch < archs.count; arch++) + { + const char * lto_skip; + + memset( &make->lto_skip_src[arch], 0, sizeof(struct strarray) ); + + lto_skip = get_expanded_arch_var( make, "LTO_SKIP", arch ); + make->lto_skip[arch] = var_to_bool( lto_skip ); + /* no need to parse source skiplist if target is marked as non-LTO */ + if (make->lto_skip[arch]) continue; + + value = get_expanded_arch_var_array( make, "LTO_SKIP_SRC", arch ); + for (i = 0; i < value.count; i++) + strarray_add( &make->lto_skip_src[arch], xstrdup( value.str[i] )); + } + } }
@@ -4641,19 +4663,109 @@ static void output_lto_flags( int use_lto, int prefer_env ) }
+/******************************************************************* + * parse_global_lto_skip_lists + */ +static void parse_global_lto_skip_lists( void ) +{ + unsigned int arch; + char *buffer; + FILE *file; + + for (arch = 0; arch < archs.count; arch++) + { + memset( &global_lto_skip[arch], 0, sizeof(struct strarray) ); + + if (arch) + input_file_name = root_src_dir_path(strmake( "tools/lto-skip.%s.list", archs.str[arch] )); + else + input_file_name = root_src_dir_path( "tools/lto-skip.list" ); + /* skip nonexistent files */ + if (!(file = fopen( input_file_name, "r" ))) + { + input_file_name = NULL; + continue; + } + input_line = 0; + + while ((buffer = get_line( file ))) + { + if (*buffer == '#') continue; /* comment */ + buffer = skip_spaces( buffer ); + strarray_add( &global_lto_skip[arch], xstrdup( buffer )); + } + (void) fclose( file ); + input_file_name = NULL; + input_line = 0; + } +} + + +/******************************************************************* + * is_lto_enabled_source + */ +static int is_lto_enabled_source( struct makefile *make, struct incl_file *source, unsigned int arch ) +{ + if (!with_lto) return 0; + if (!make) return 0; + if (!source) return 0; + + /* target config: any arch */ + if (strarray_exists( make->lto_skip_src[0], source->name )) + return 0; + + if (arch) + { + /* target config: specific arch */ + if (strarray_exists( make->lto_skip_src[arch], source->name )) + return 0; + + /* global config: specific arch */ + if (strarray_exists( global_lto_skip[arch], source->filename )) + return 0; + } + + /* global config: any arch */ + if (strarray_exists( global_lto_skip[0], source->filename )) + return 0; + + return 1; +} + + +/******************************************************************* + * is_lto_enabled_target + */ +static int is_lto_enabled_target( struct makefile *make, unsigned int arch ) +{ + if (!with_lto) return 0; + if (!make) return 0; + + /* any arch */ + if (make->lto_skip[0]) return 0; + + /* specific arch */ + if (arch && make->lto_skip[arch]) + return 0; + + return 1; +} + + /******************************************************************* * output_lto_flags_source */ static void output_lto_flags_source( struct makefile *make, struct incl_file *source, unsigned int arch, int prefer_env ) { + int use_lto = 0; + if (!with_lto) return; if (!make) return; if (!source) return;
- (void) arch; /* mark as used */ - - output_lto_flags( with_lto, prefer_env ); + use_lto = is_lto_enabled_target( make, arch ) && is_lto_enabled_source( make, source, arch ); + output_lto_flags( use_lto, prefer_env ); }
@@ -4662,12 +4774,13 @@ static void output_lto_flags_source( struct makefile *make, struct incl_file *so */ static void output_lto_flags_target( struct makefile *make, unsigned int arch, int prefer_env ) { + int use_lto = 0; + if (!with_lto) return; if (!make) return;
- (void) arch; /* mark as used */ - - output_lto_flags( with_lto, prefer_env ); + use_lto = is_lto_enabled_target( make, arch ); + output_lto_flags( use_lto, prefer_env ); }
@@ -4797,6 +4910,7 @@ int main( int argc, char *argv[] )
for (i = 0; i < subdirs.count; i++) submakes[i] = parse_makefile( subdirs.str[i] );
+ parse_global_lto_skip_lists(); load_sources( top_makefile ); load_sources( include_makefile ); for (i = 0; i < subdirs.count; i++)