patch 9.1.0630: MS-Windows: build fails with VIMDLL and mzscheme

Problem:  MS-Windows: build fails with VIMDLL and mzscheme
Solution: define scheme_register_tls_space() inside gvim.exe
          and refer to it from the dll (Ken Takata).

`scheme_register_tls_space()` doesn't support a thread-local variable in
a DLL:
https://docs.racket-lang.org/inside/im_memoryalloc.html#%28cpp._scheme_register_tls_space%29

closes: #15363

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-27 13:25:34 +02:00
committed by Christian Brabandt
parent 4100852e09
commit f0ce176b5f
5 changed files with 62 additions and 9 deletions

View File

@ -1006,7 +1006,7 @@ EXELFLAGS += -s
endif
ifeq ($(COVERAGE),yes)
EXELFLAGS += --coverage
else
else ifndef MZSCHEME
EXELFLAGS += -nostdlib
EXECFLAGS = -DUSE_OWNSTARTUP
endif
@ -1141,12 +1141,14 @@ $(EXEOBJC): | $(OUTDIR)
ifeq ($(VIMDLL),yes)
ifneq ($(COVERAGE),yes)
ifeq ($(ARCH),x86-64)
ifndef MZSCHEME
ifeq ($(ARCH),x86-64)
EXEENTRYC = -Wl,--entry=wmainCRTStartup
EXEENTRYG = -Wl,--entry=wWinMainCRTStartup
else ifeq ($(ARCH),i686)
else ifeq ($(ARCH),i686)
EXEENTRYC = -Wl,--entry=_wmainCRTStartup
EXEENTRYG = -Wl,--entry=_wWinMainCRTStartup@0
endif
endif
endif

View File

@ -801,6 +801,13 @@ OBJ = $(OBJ) $(OUTDIR)\os_w32dll.obj $(OUTDIR)\vimd.res
EXEOBJC = $(OUTDIR)\os_w32exec.obj $(OUTDIR)\vimc.res
EXEOBJG = $(OUTDIR)\os_w32exeg.obj $(OUTDIR)\vimg.res
CFLAGS = $(CFLAGS) -DVIMDLL
! ifdef MZSCHEME
EXECFLAGS =
EXELIBC = $(LIBC)
! else
EXECFLAGS = -DUSE_OWNSTARTUP /GS-
EXELIBC =
! endif
!else
OBJ = $(OBJ) $(OUTDIR)\os_w32exe.obj $(OUTDIR)\vim.res
!endif
@ -1302,11 +1309,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
$(EXEOBJG) $(VIMDLLBASE).lib $(EXELIBC)
$(VIM).exe: $(OUTDIR) $(EXEOBJC) $(VIMDLLBASE).dll
$(LINK) $(LINKARGS1) /subsystem:$(SUBSYSTEM_CON) -out:$(VIM).exe \
$(EXEOBJC) $(VIMDLLBASE).lib
$(EXEOBJC) $(VIMDLLBASE).lib $(EXELIBC)
!else
@ -1380,12 +1387,16 @@ clean: testclean
- if exist $(OUTDIR)/nul $(DEL_TREE) $(OUTDIR)
- if exist *.obj del *.obj
- if exist $(VIM).exe del $(VIM).exe
- if exist $(VIM).exp del $(VIM).exp
- if exist $(VIM).lib del $(VIM).lib
- if exist $(VIM).ilk del $(VIM).ilk
- if exist $(VIM).pdb del $(VIM).pdb
- if exist $(VIM).map del $(VIM).map
- if exist $(VIM).ncb del $(VIM).ncb
!if "$(VIMDLL)" == "yes"
- if exist $(GVIM).exe del $(GVIM).exe
- if exist $(GVIM).exp del $(GVIM).exp
- if exist $(GVIM).lib del $(GVIM).lib
- if exist $(GVIM).map del $(GVIM).map
- if exist $(VIMDLLBASE).dll del $(VIMDLLBASE).dll
- if exist $(VIMDLLBASE).ilk del $(VIMDLLBASE).ilk
@ -1715,10 +1726,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=) /DUSE_OWNSTARTUP /GS- /Fo$@ os_w32exe.c
$(CC) $(CFLAGS:-DFEAT_GUI_MSWIN=) $(EXECFLAGS) /Fo$@ os_w32exe.c
$(OUTDIR)/os_w32exeg.obj: $(OUTDIR) os_w32exe.c $(INCL)
$(CC) $(CFLAGS) /DUSE_OWNSTARTUP /GS- /Fo$@ os_w32exe.c
$(CC) $(CFLAGS) $(EXECFLAGS) /Fo$@ os_w32exe.c
$(OUTDIR)/pathdef.obj: $(OUTDIR) $(PATHDEF_SRC) $(INCL)
$(CC) $(CFLAGS_OUTDIR) $(PATHDEF_SRC)

View File

@ -383,7 +383,7 @@ static void (*dll_scheme_set_config_path)(Scheme_Object *p);
# define scheme_null dll_scheme_null
# define scheme_true dll_scheme_true
// pointers are GetProceAddress'ed as pointers to pointer
// pointers are GetProcAddress'ed as pointers to pointer
#if !defined(USE_THREAD_LOCAL) && !defined(LINK_EXTENSIONS_BY_TABLE)
# define scheme_current_thread (*dll_scheme_current_thread_ptr)
# endif
@ -924,7 +924,7 @@ mzscheme_end(void)
#endif
}
#if HAVE_TLS_SPACE
#if HAVE_TLS_SPACE && !defined(VIMDLL)
# if defined(_MSC_VER)
static __declspec(thread) void *tls_space;
extern intptr_t _tls_index;
@ -960,7 +960,24 @@ mzscheme_main(void)
}
#endif
#ifdef HAVE_TLS_SPACE
# ifdef VIMDLL
void **ptls_space;
intptr_t tls_index;
void (*pget_tls_info)(void ***ptls_space, intptr_t *ptls_index);
// Get the address of get_tls_info() from (g)vim.exe.
pget_tls_info = (void *)GetProcAddress(
GetModuleHandle(NULL), "get_tls_info");
if (pget_tls_info == NULL)
{
disabled = TRUE;
return vim_main2();
}
pget_tls_info(&ptls_space, &tls_index);
scheme_register_tls_space(ptls_space, tls_index);
# else
scheme_register_tls_space(&tls_space, _tls_index);
# endif
#endif
#ifdef TRAMPOLINED_MZVIM_STARTUP
return scheme_main_setup(TRUE, mzscheme_env_main, argc, &argv);

View File

@ -70,3 +70,24 @@ wmainCRTStartup(void)
}
# endif
#endif // USE_OWNSTARTUP
#if defined(VIMDLL) && defined(FEAT_MZSCHEME)
# if defined(_MSC_VER)
static __declspec(thread) void *tls_space;
extern intptr_t _tls_index;
# elif defined(__MINGW32__)
static __thread void *tls_space;
extern intptr_t _tls_index;
# endif
// Get TLS information that is needed for if_mzsch.
__declspec(dllexport) void
get_tls_info(void ***ptls_space, intptr_t *ptls_index)
{
*ptls_space = &tls_space;
*ptls_index = _tls_index;
return;
}
#endif

View File

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