From: Konstantin Demin rockdrilla@gmail.com
Signed-off-by: Konstantin Demin rockdrilla@gmail.com --- tools/winebuild/build.h | 2 ++ tools/winebuild/import.c | 55 +++++++++++++++++++++++++++++++++++++--- tools/winebuild/main.c | 6 ++++- tools/winebuild/utils.c | 31 ++++++++++++++++++++-- 4 files changed, 88 insertions(+), 6 deletions(-)
diff --git a/tools/winebuild/build.h b/tools/winebuild/build.h index e5ede93425b..e329ce4a9cc 100644 --- a/tools/winebuild/build.h +++ b/tools/winebuild/build.h @@ -26,6 +26,7 @@ #include <stdio.h> #include <stdlib.h> #include "../tools.h" +#include "../lto.h"
typedef enum { @@ -363,6 +364,7 @@ extern void put_pword( unsigned int val );
extern int current_line; extern int UsePIC; +extern int UseLTO; extern int nb_errors; extern int display_warnings; extern int kill_at; diff --git a/tools/winebuild/import.c b/tools/winebuild/import.c index eba74bb9660..8252245732f 100644 --- a/tools/winebuild/import.c +++ b/tools/winebuild/import.c @@ -1241,11 +1241,35 @@ static const char *get_target_machine(void) /* build a library from the current asm files and any additional object files in argv */ void output_static_lib( const char *output_name, struct strarray files, int create ) { - struct strarray args; + struct strarray args = empty_strarray;
if (!create || target.platform != PLATFORM_WINDOWS) { - args = find_tool( "ar", NULL ); + while (UseLTO > 0) + { + static int init_env_ar = 0; + static const char * env_ar; + const char * _cmd[2] = { 0 }; + + if (!init_env_ar) + { + if ((env_ar = getenv( "WINE_AR" ))) + { + /* duplicate string if non-empty; otherwise set to NULL */ + env_ar = (env_ar[0]) ? xstrdup( env_ar ) : NULL; + } + init_env_ar = 1; + } + if (!env_ar) break; + + _cmd[0] = env_ar; + args = find_tool( "ar", _cmd ); + break; + } + if (!args.count) + { + args = find_tool( "ar", NULL ); + } strarray_add( &args, create ? "rc" : "r" ); strarray_add( &args, output_name ); } @@ -1263,7 +1287,32 @@ void output_static_lib( const char *output_name, struct strarray files, int crea
if (target.platform != PLATFORM_WINDOWS) { - struct strarray ranlib = find_tool( "ranlib", NULL ); + struct strarray ranlib = empty_strarray; + while (UseLTO > 0) + { + static int init_env_ranlib = 0; + static const char * env_ranlib; + const char * _cmd[2] = { 0 }; + + if (!init_env_ranlib) + { + if ((env_ranlib = getenv( "WINE_RANLIB" ))) + { + /* duplicate string if non-empty; otherwise set to NULL */ + env_ranlib = (env_ranlib[0]) ? xstrdup( env_ranlib ) : NULL; + } + init_env_ranlib = 1; + } + if (!env_ranlib) break; + + _cmd[0] = env_ranlib; + args = find_tool( "ranlib", _cmd ); + break; + } + if (!ranlib.count) + { + ranlib = find_tool( "ranlib", NULL ); + } strarray_add( &ranlib, output_name ); spawn( ranlib ); } diff --git a/tools/winebuild/main.c b/tools/winebuild/main.c index 63d65e7bcd0..e48c5afb194 100644 --- a/tools/winebuild/main.c +++ b/tools/winebuild/main.c @@ -34,6 +34,7 @@ #include "build.h"
int UsePIC = 0; +int UseLTO = -1; int nb_errors = 0; int display_warnings = 0; int native_arch = -1; @@ -185,7 +186,7 @@ static const char usage_str[] = " -e, --entry=FUNC Set the DLL entry point function (default: DllMain)\n" " -E, --export=FILE Export the symbols defined in the .spec or .def file\n" " --external-symbols Allow linking to external symbols\n" -" -f FLAGS Compiler flags (-fPIC and -fasynchronous-unwind-tables are supported)\n" +" -f FLAGS Compiler flags (-fPIC, -fasynchronous-unwind-tables and -flto are supported)\n" " -F, --filename=DLLFILE Set the DLL filename (default: from input file name)\n" " --fake-module Create a fake binary module\n" " -h, --help Display this help message\n" @@ -405,6 +406,8 @@ static void option_callback( int optc, char *optarg ) if (!strcmp( optarg, "PIC") || !strcmp( optarg, "pic")) UsePIC = 1; else if (!strcmp( optarg, "asynchronous-unwind-tables")) unwind_tables = 1; else if (!strcmp( optarg, "no-asynchronous-unwind-tables")) unwind_tables = 0; + else if (!strcmp( optarg, "lto" )) UseLTO = 1; + else if (!strcmp( optarg, "no-lto" )) UseLTO = 0; /* ignore all other flags */ break; case 'h': @@ -569,6 +572,7 @@ int main(int argc, char **argv) if (is_pe()) unwind_tables = 1;
files = parse_options( argc, argv, short_options, long_options, 0, option_callback ); + verbose = adjust_verbose_lto( UseLTO, verbose );
atexit( cleanup ); /* make sure we remove the output file on exit */
diff --git a/tools/winebuild/utils.c b/tools/winebuild/utils.c index 05595f86d37..25b96dddd20 100644 --- a/tools/winebuild/utils.c +++ b/tools/winebuild/utils.c @@ -303,6 +303,8 @@ struct strarray get_as_command(void)
if (using_cc) { + /* disable LTO for assembly */ + append_lto_flags( &args, (UseLTO >= 0) ? 0 : -1, 1 /* prefer flags from env */ ); strarray_add( &args, "-xassembler" ); strarray_add( &args, "-c" ); if (force_pointer_size) @@ -345,6 +347,7 @@ struct strarray get_ld_command(void) }
strarray_addall( &args, ld_command ); + append_lto_flags( &args, UseLTO, 1 /* prefer flags from env */ );
if (force_pointer_size) { @@ -380,8 +383,32 @@ const char *get_nm_command(void) { if (!nm_command.count) { - static const char * const commands[] = { "nm", "gnm", NULL }; - nm_command = find_tool( "nm", commands ); + while (UseLTO > 0) + { + static int init_env_nm = 0; + static const char * env_nm; + const char * _cmd[2] = { 0 }; + + if (!init_env_nm) + { + if ((env_nm = getenv( "WINE_NM" ))) + { + /* duplicate string if non-empty; otherwise set to NULL */ + env_nm = (env_nm[0]) ? xstrdup( env_nm ) : NULL; + } + init_env_nm = 1; + } + if (!env_nm) break; + + _cmd[0] = env_nm; + nm_command = find_tool( "nm", _cmd ); + break; + } + if (!nm_command.count) + { + static const char * const commands[] = { "nm", "gnm", NULL }; + nm_command = find_tool( "nm", commands ); + } } if (nm_command.count > 1) fatal_error( "multiple arguments in nm command not supported yet\n" );