From a19baa613c9769701790afd2f9ebfc422a1e97e7 Mon Sep 17 00:00:00 2001 From: Daniel Dragan Date: Thu, 11 Oct 2012 01:47:19 -0400 Subject: [PATCH] stop Win32 VC miniperl from exporting functions miniperl.exe does not load XS modules. It has no reason to export anything. About 130 things are exported by VC Win32 miniperl. 90% of them are the win32_* functions. All but a couple Perl_* exports are gone in the exporting miniperl. See perl #115216 for the full list of accidentally exported items. Also stop trying to find Win32CORE's boot function in Perl_init_os_extras through the export table. It is not exported and not in the miniperl image and GetProcAddress will never return not NULL. By removing this GetProcAddress call, miniperl stops importing GetProcAddress from kernel32 and a tiny bit startup time by miniperl during the full perl build process. By removing the exports the compiler is free to use more random (not cdecl) calling conventions and/or optimizing away code than before. Also by removing the export entries, and the GetProcAddress import, RO strings are removed from the miniperl image. This commit only affects the VC miniperl. The Mingw miniperl remains unmodified except for not trying to load Win32CORE through the export table and some of the .c files being compiled with PERL_IS_MINIPERL when previously they were not. --- EXTERN.h | 22 +++++++++++++++------- win32/Makefile | 2 +- win32/makefile.mk | 2 +- win32/win32.c | 2 ++ win32/win32.h | 12 ++++++++---- 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/EXTERN.h b/EXTERN.h index 58ca37a..2fd3731 100644 --- a/EXTERN.h +++ b/EXTERN.h @@ -29,16 +29,24 @@ # define dEXTCONST globaldef {"$GLOBAL_RO_VARS"} readonly #else # if (defined(WIN32) || defined(__SYMBIAN32__)) && !defined(PERL_STATIC_SYMS) -# if defined(PERLDLL) || defined(__SYMBIAN32__) -# define EXT extern __declspec(dllexport) +/* miniperl should not export anything */ +# if defined(PERL_IS_MINIPERL) && !defined(UNDER_CE) && defined(_MSC_VER) +# define EXT extern # define dEXT -# define EXTCONST extern __declspec(dllexport) const +# define EXTCONST extern const # define dEXTCONST const # else -# define EXT extern __declspec(dllimport) -# define dEXT -# define EXTCONST extern __declspec(dllimport) const -# define dEXTCONST const +# if defined(PERLDLL) || defined(__SYMBIAN32__) +# define EXT extern __declspec(dllexport) +# define dEXT +# define EXTCONST extern __declspec(dllexport) const +# define dEXTCONST const +# else +# define EXT extern __declspec(dllimport) +# define dEXT +# define EXTCONST extern __declspec(dllimport) const +# define dEXTCONST const +# endif # endif # else # if defined(__CYGWIN__) && defined(USEIMPORTLIB) diff --git a/win32/Makefile b/win32/Makefile index f005286..cf83e9b 100644 --- a/win32/Makefile +++ b/win32/Makefile @@ -968,7 +968,7 @@ $(MINICORE_OBJ) : $(CORE_NOCFG_H) $(CC) -c $(CFLAGS) -DPERL_EXTERNAL_GLOB -DPERL_IS_MINIPERL $(OBJOUT_FLAG)$@ ..\$(*F).c $(MINIWIN32_OBJ) : $(CORE_NOCFG_H) - $(CC) -c $(CFLAGS) $(OBJOUT_FLAG)$@ $(*F).c + $(CC) -c $(CFLAGS) -DPERL_IS_MINIPERL $(OBJOUT_FLAG)$@ $(*F).c # -DPERL_IMPLICIT_SYS needs C++ for perllib.c # This is the only file that depends on perlhost.h, vmem.h, and vdir.h diff --git a/win32/makefile.mk b/win32/makefile.mk index e9d40f8..bd8e726 100644 --- a/win32/makefile.mk +++ b/win32/makefile.mk @@ -1097,7 +1097,7 @@ $(MINICORE_OBJ) : $(CORE_NOCFG_H) $(CC) -c $(CFLAGS) -DPERL_EXTERNAL_GLOB -DPERL_IS_MINIPERL $(OBJOUT_FLAG)$@ ..\$(*B).c $(MINIWIN32_OBJ) : $(CORE_NOCFG_H) - $(CC) -c $(CFLAGS) $(OBJOUT_FLAG)$@ $(*B).c + $(CC) -c $(CFLAGS) -DPERL_IS_MINIPERL $(OBJOUT_FLAG)$@ $(*B).c # -DPERL_IMPLICIT_SYS needs C++ for perllib.c # rules wrapped in .IFs break Win9X build (we end up with unbalanced []s unless diff --git a/win32/win32.c b/win32/win32.c index 4427e06..3ee85a1 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -4146,10 +4146,12 @@ Perl_init_os_extras(void) char *file = __FILE__; /* Initialize Win32CORE if it has been statically linked. */ +#ifndef PERL_IS_MINIPERL void (*pfn_init)(pTHX); pfn_init = (void (*)(pTHX))GetProcAddress((HMODULE)w32_perldll_handle, "init_Win32CORE"); if (pfn_init) pfn_init(aTHX); +#endif newXS("Win32::SetChildShowWindow", w32_SetChildShowWindow, file); } diff --git a/win32/win32.h b/win32/win32.h index 59a3052..9d229db 100644 --- a/win32/win32.h +++ b/win32/win32.h @@ -46,11 +46,15 @@ */ /* now even GCC supports __declspec() */ - -#if defined(PERLDLL) -#define DllExport __declspec(dllexport) +/* miniperl has no reason to export anything */ +#if defined(PERL_IS_MINIPERL) && !defined(UNDER_CE) && defined(_MSC_VER) +# define DllExport #else -#define DllExport __declspec(dllimport) +# if defined(PERLDLL) +# define DllExport __declspec(dllexport) +# else +# define DllExport __declspec(dllimport) +# endif #endif /* The Perl APIs can only be called directly inside the perl5xx.dll. -- 2.7.4