From 90bed22eb715201de3ddde0b08d4d6b9357c7635 Mon Sep 17 00:00:00 2001
From: Jacek Caban <jacek@codeweavers.com>
Date: Tue, 6 Aug 2019 12:28:53 +0200
Subject: [PATCH] winegcc: Use -nodefaultlibs -nostartfiles for builtin DLLs.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
---
 tools/winegcc/winegcc.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/winegcc/winegcc.c b/tools/winegcc/winegcc.c
index 222c7502707..a7476dd19d7 100644
--- a/tools/winegcc/winegcc.c
+++ b/tools/winegcc/winegcc.c
@@ -383,6 +383,7 @@ static int try_link( const strarray *prefix, const strarray *link_tool, const ch
 
 static strarray *get_link_args( struct options *opts, const char *output_name )
 {
+    int use_wine_crt = opts->wine_builtin && opts->shared;
     const strarray *link_tool = get_translator( opts );
     strarray *flags = strarray_alloc();
     unsigned int i;
@@ -437,8 +438,8 @@ static strarray *get_link_args( struct options *opts, const char *output_name )
         else strarray_add( flags, opts->gui_app ? "-mwindows" : "-mconsole" );
 
         if (opts->unicode_app) strarray_add( flags, "-municode" );
-        if (opts->nodefaultlibs) strarray_add( flags, "-nodefaultlibs" );
-        if (opts->nostartfiles) strarray_add( flags, "-nostartfiles" );
+        if (opts->nodefaultlibs || use_wine_crt) strarray_add( flags, "-nodefaultlibs" );
+        if (opts->nostartfiles || use_wine_crt) strarray_add( flags, "-nostartfiles" );
 
         if (opts->subsystem)
         {
@@ -1172,7 +1173,7 @@ static void build(struct options* opts)
 	strarray_add(link_args, "-lc");
     }
 
-    if (opts->nodefaultlibs && is_pe) strarray_add( link_args, "-lgcc" );
+    if ((opts->nodefaultlibs || opts->shared) && is_pe) strarray_add( link_args, "-lgcc" );
 
     spawn(opts->prefix, link_args, 0);
     strarray_free (link_args);
-- 
GitLab