stop Win32 VC miniperl from exporting functions
authorDaniel Dragan <bulk88@hotmail.com>
Thu, 11 Oct 2012 05:47:19 +0000 (01:47 -0400)
committerSteve Hay <steve.m.hay@googlemail.com>
Thu, 11 Oct 2012 07:22:11 +0000 (08:22 +0100)
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
win32/Makefile
win32/makefile.mk
win32/win32.c
win32/win32.h

index 58ca37a..2fd3731 100644 (file)
--- a/EXTERN.h
+++ b/EXTERN.h
 #  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)
index f005286..cf83e9b 100644 (file)
@@ -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
index e9d40f8..bd8e726 100644 (file)
@@ -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
index 4427e06..3ee85a1 100644 (file)
@@ -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);
 }
index 59a3052..9d229db 100644 (file)
  */
 
 /* 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.