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 <kentkt@csc.jp>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Ken Takata
2024-07-26 18:46:54 +02:00
committed by Christian Brabandt
parent be82825687
commit b32d0a479d
5 changed files with 58 additions and 27 deletions

View File

@ -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 $@

View File

@ -1302,11 +1302,11 @@ $(NETBEANS_OBJ) $(CHANNEL_OBJ) $(XPM_OBJ) $(OUTDIR)\version.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)

View File

@ -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 <ronaharon@yahoo.com> wrote this and the DLL support code.
* Adapted by Ken Takata.

View File

@ -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 <ronaharon@yahoo.com> wrote this and the (now deleted) DLL support
* code.
* Ron Aaron <ronaharon@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

View File

@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
621,
/**/
620,
/**/