patch 9.1.0621: MS-Windows: startup code can be improved

Commit: 
https://github.com/vim/vim/commit/b32d0a479d18512be551a3bca6366796c47d2633
Author: Ken Takata <ken...@csc.jp>
Date:   Fri Jul 26 18:46:54 2024 +0200

    patch 9.1.0621: MS-Windows: startup code can be improved
    
    Problem:  MS-Windows: startup code can be improved
    Solution: Re-work and optimize win32 startup code
              (Ken Takata)
    
    * Revise the code and reduce #ifdefs.
    * For VIMDLL, stop using the default CRT startup code to reduce the file
      size.
      The file size becomes ~130 KB -> ~34 KB on MSVC.
    * Update comments. Make them consistent between os_w32dll.c and
      os_w32exe.c.
    
    closes: #15352
    
    Signed-off-by: Ken Takata <ken...@csc.jp>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/Make_cyg_ming.mak b/src/Make_cyg_ming.mak
index 20ed90356..911adb5ee 100644
--- a/src/Make_cyg_ming.mak
+++ b/src/Make_cyg_ming.mak
@@ -995,7 +995,7 @@ VIMDLLBASE := vim32$(DEBUG_SUFFIX)
  endif
 TARGET = $(VIMDLLBASE).dll
 LFLAGS += -shared
-EXELFLAGS += -municode
+EXELFLAGS += -municode -nostdlib
  ifneq ($(DEBUG),yes)
 EXELFLAGS += -s
  endif
@@ -1122,14 +1122,22 @@ $(EXEOBJG): | $(OUTDIR)
 $(EXEOBJC): | $(OUTDIR)
 
 ifeq ($(VIMDLL),yes)
+ ifeq ($(ARCH),x86-64)
+EXEENTRYC = -Wl,--entry=wmainCRTStartup
+EXEENTRYG = -Wl,--entry=wWinMainCRTStartup
+ else ifeq ($(ARCH),i686)
+EXEENTRYC = -Wl,--entry=_wmainCRTStartup
+EXEENTRYG = -Wl,--entry=_wWinMainCRTStartup@0
+ endif
+
 $(TARGET): $(OBJ)
        $(LINK) $(CFLAGS) $(LFLAGS) -o $@ $(OBJ) $(LIB) -lole32 -luuid -lgdi32 
$(LUA_LIB) $(MZSCHEME_LIBDIR) $(MZSCHEME_LIB) $(PYTHONLIB) $(PYTHON3LIB) 
$(RUBYLIB) $(SODIUMLIB)
 
 $(GVIMEXE): $(EXEOBJG) $(VIMDLLBASE).dll
-       $(CC) -L. $(EXELFLAGS) -mwindows -o $@ $(EXEOBJG) -l$(VIMDLLBASE)
+       $(CC) -L. $(EXELFLAGS) -mwindows -o $@ $(EXEOBJG) -l$(VIMDLLBASE) 
$(EXEENTRYG)
 
 $(VIMEXE): $(EXEOBJC) $(VIMDLLBASE).dll
-       $(CC) -L. $(EXELFLAGS) -o $@ $(EXEOBJC) -l$(VIMDLLBASE)
+       $(CC) -L. $(EXELFLAGS) -o $@ $(EXEOBJC) -l$(VIMDLLBASE) $(EXEENTRYC)
 else
 $(TARGET): $(OBJ)
        $(LINK) $(CFLAGS) $(LFLAGS) -o $@ $(OBJ) $(LIB) -lole32 -luuid 
$(LUA_LIB) $(MZSCHEME_LIBDIR) $(MZSCHEME_LIB) $(PYTHONLIB) $(PYTHON3LIB) 
$(RUBYLIB) $(SODIUMLIB)
@@ -1330,10 +1338,10 @@ $(OUTDIR)/netbeans.o:   netbeans.c $(INCL) 
$(NBDEBUG_INCL) $(NBDEBUG_SRC)
        $(CC) -c $(CFLAGS) netbeans.c -o $@
 
 $(OUTDIR)/os_w32exec.o:        os_w32exe.c $(INCL)
-       $(CC) -c $(CFLAGS) -UFEAT_GUI_MSWIN os_w32exe.c -o $@
+       $(CC) -c $(CFLAGS) -UFEAT_GUI_MSWIN -DUSE_OWNSTARTUP os_w32exe.c -o $@
 
 $(OUTDIR)/os_w32exeg.o:        os_w32exe.c $(INCL)
-       $(CC) -c $(CFLAGS) os_w32exe.c -o $@
+       $(CC) -c $(CFLAGS) -DUSE_OWNSTARTUP os_w32exe.c -o $@
 
 $(OUTDIR)/os_win32.o:  os_win32.c $(INCL) $(MZSCHEME_INCL)
        $(CC) -c $(CFLAGS) os_win32.c -o $@
diff --git a/src/Make_mvc.mak b/src/Make_mvc.mak
index adcf19a4e..c750311d2 100644
--- a/src/Make_mvc.mak
+++ b/src/Make_mvc.mak
@@ -1302,11 +1302,11 @@ $(NETBEANS_OBJ) $(CHANNEL_OBJ) $(XPM_OBJ) $(OUTDIR) 
ersion.obj $(LINKARGS2)
 
 $(GVIM).exe: $(OUTDIR) $(EXEOBJG) $(VIMDLLBASE).dll
        $(LINK) $(LINKARGS1) /subsystem:$(SUBSYSTEM) -out:$(GVIM).exe \
-               $(EXEOBJG) $(VIMDLLBASE).lib $(LIBC)
+               $(EXEOBJG) $(VIMDLLBASE).lib
 
 $(VIM).exe: $(OUTDIR) $(EXEOBJC) $(VIMDLLBASE).dll
        $(LINK) $(LINKARGS1) /subsystem:$(SUBSYSTEM_CON) -out:$(VIM).exe \
-               $(EXEOBJC) $(VIMDLLBASE).lib $(LIBC)
+               $(EXEOBJC) $(VIMDLLBASE).lib
 
 !else
 
@@ -1715,10 +1715,10 @@ $(OUTDIR)/os_w32dll.obj:        $(OUTDIR) os_w32dll.c
 $(OUTDIR)/os_w32exe.obj:       $(OUTDIR) os_w32exe.c  $(INCL)
 
 $(OUTDIR)/os_w32exec.obj:      $(OUTDIR) os_w32exe.c  $(INCL)
-       $(CC) $(CFLAGS:-DFEAT_GUI_MSWIN=) /Fo$@ os_w32exe.c
+       $(CC) $(CFLAGS:-DFEAT_GUI_MSWIN=) /DUSE_OWNSTARTUP /GS- /Fo$@ 
os_w32exe.c
 
 $(OUTDIR)/os_w32exeg.obj:      $(OUTDIR) os_w32exe.c  $(INCL)
-       $(CC) $(CFLAGS) /Fo$@ os_w32exe.c
+       $(CC) $(CFLAGS) /DUSE_OWNSTARTUP /GS- /Fo$@ os_w32exe.c
 
 $(OUTDIR)/pathdef.obj: $(OUTDIR) $(PATHDEF_SRC) $(INCL)
        $(CC) $(CFLAGS_OUTDIR) $(PATHDEF_SRC)
diff --git a/src/os_w32dll.c b/src/os_w32dll.c
index e7ba99bb9..651f96c97 100644
--- a/src/os_w32dll.c
+++ b/src/os_w32dll.c
@@ -7,7 +7,7 @@
  * See README.txt for an overview of the Vim source code.
  */
 /*
- * Windows GUI: main program (DLL) entry point:
+ * Windows GUI/Console: main program (DLL) entry point:
  *
  * Ron Aaron <ronaha...@yahoo.com> wrote this and the DLL support code.
  * Adapted by Ken Takata.
diff --git a/src/os_w32exe.c b/src/os_w32exe.c
index c4f02949d..85bbfbcd2 100644
--- a/src/os_w32exe.c
+++ b/src/os_w32exe.c
@@ -8,10 +8,10 @@
  * See README.txt for an overview of the Vim source code.
  */
 /*
- * Windows GUI: main program (EXE) entry point:
+ * Windows GUI/Console: main program (EXE) entry point:
  *
- * Ron Aaron <ronaha...@yahoo.com> wrote this and the (now deleted) DLL support
- * code.
+ * Ron Aaron <ronaha...@yahoo.com> wrote this and the DLL support code.
+ * Adapted by Ken Takata.
  */
 #include "vim.h"
 
@@ -20,32 +20,53 @@
 __declspec(dllimport)
 #endif
 int VimMain(int argc, char **argv);
-#ifndef VIMDLL
+
+#ifdef VIMDLL
+# define SaveInst(hInst)    // Do nothing
+#else
 void SaveInst(HINSTANCE hInst);
 #endif
 
-#ifndef PROTO
-# ifdef FEAT_GUI
+#ifdef FEAT_GUI
     int WINAPI
 wWinMain(
     HINSTANCE  hInstance,
     HINSTANCE  hPrevInst UNUSED,
     LPWSTR     lpszCmdLine UNUSED,
     int                nCmdShow UNUSED)
-# else
+{
+    SaveInst(hInstance);
+    return VimMain(0, NULL);
+}
+#else
     int
 wmain(int argc UNUSED, wchar_t **argv UNUSED)
-# endif
 {
-# ifndef VIMDLL
-#  ifdef FEAT_GUI
-    SaveInst(hInstance);
-#  else
     SaveInst(GetModuleHandleW(NULL));
-#  endif
-# endif
-    VimMain(0, NULL);
-
-    return 0;
+    return VimMain(0, NULL);
 }
 #endif
+
+#ifdef USE_OWNSTARTUP
+// Use our own entry point and don't use the default CRT startup code to
+// reduce the size of (g)vim.exe.  This works only when VIMDLL is defined.
+//
+// For MSVC, the /GS- compiler option is needed to avoid the undefined symbol
+// error.  (It disables the security check. However, it affects only this
+// function and doesn't have any effect on Vim itself.)
+// For MinGW, the -nostdlib compiler option and the --entry linker option are
+// needed.
+# ifdef FEAT_GUI
+    void WINAPI
+wWinMainCRTStartup(void)
+{
+    VimMain(0, NULL);
+}
+# else
+    void
+wmainCRTStartup(void)
+{
+    VimMain(0, NULL);
+}
+# endif
+#endif // USE_OWNSTARTUP
diff --git a/src/version.c b/src/version.c
index 806e3c542..a70a97812 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    621,
 /**/
     620,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1sXOIU-00CcgY-VY%40256bit.org.

Raspunde prin e-mail lui