3 # Create the export list for perl.
5 # Needed by WIN32 and OS/2 for creating perl.dll,
6 # and by AIX for creating libperl.a when -Duseshrplib is in effect,
7 # and by VMS for creating perlshr.exe.
9 # Reads from information stored in
11 # %Config::Config (ie config.sh)
16 # miniperl.map (on OS/2)
17 # perl5.def (on OS/2; this is the old version of the file being made)
22 # plus long lists of function names hard-coded directly in this script.
24 # Writes the result to STDOUT.
26 # Normally this script is invoked from a makefile (e.g. win32/Makefile),
27 # which redirects STDOUT to a suitable file, such as:
42 %ARGS = (CCTYPE => 'MSVC', TARG_DIR => '');
44 sub process_cc_flags {
45 foreach (map {split /\s+/, $_} @_) {
46 $define{$1} = $2 // 1 if /^-D(\w+)(?:=(.+))?/;
52 if ($flag =~ /^(?:CC_FLAGS=)?(-D\w.*)/) {
54 } elsif ($flag =~ /^(CCTYPE|FILETYPE|PLATFORM|TARG_DIR|CONFIG_H)=(.+)$/) {
56 } elsif ($flag eq '--sort-fold') {
60 my @PLATFORM = qw(aix win32 os2 vms test);
62 @PLATFORM{@PLATFORM} = ();
64 die "PLATFORM undefined, must be one of: @PLATFORM\n"
65 unless defined $ARGS{PLATFORM};
66 die "PLATFORM must be one of: @PLATFORM\n"
67 unless exists $PLATFORM{$ARGS{PLATFORM}};
70 use constant PLATFORM => $ARGS{PLATFORM};
72 # This makes us able to use, e.g., $define{WIN32}, so you don't have to
73 # remember what things came from %ARGS.
74 $define{uc $ARGS{'PLATFORM'}} = 1;
76 require "./$ARGS{TARG_DIR}regen/embed_lib.pl";
78 # Is the following guard strictly necessary? Added during refactoring
79 # to keep the same behaviour when merging other code into here.
80 process_cc_flags(@Config{qw(ccflags optimize)})
81 if PLATFORM ne 'win32';
83 # Add the compile-time options that miniperl was built with to %define.
84 # On Win32 these are not the same options as perl itself will be built
85 # with since miniperl is built with a canned config (one of the win32/
86 # config_H.*) and none of the BUILDOPT's that are set in the makefiles,
87 # but they do include some #define's that are hard-coded in various
88 # source files and header files and don't include any BUILDOPT's that
89 # the user might have chosen to disable because the canned configs are
90 # minimal configs that don't include any of those options.
92 my @options = sort(Config::bincompat_options(), Config::non_bincompat_options());
93 print STDERR "Options: (@options)\n" unless PLATFORM eq 'test';
94 $define{$_} = 1 foreach @options;
96 my %exportperlmalloc =
98 Perl_malloc => "malloc",
100 Perl_realloc => "realloc",
101 Perl_calloc => "calloc",
104 my $exportperlmalloc = PLATFORM eq 'os2';
106 my $config_h = $ARGS{CONFIG_H} || "config.h";
107 open(CFG, '<', $config_h) || die "Cannot open $config_h: $!\n";
109 $define{$1} = 1 if /^\s*\#\s*define\s+(MYMALLOC|MULTIPLICITY
111 |(?:PERL|USE|HAS)_\w+)\b/x;
115 if ($define{WIN32_USE_FAKE_OLD_MINGW_LOCALES}) {
116 $define{NO_POSIX_2008_LOCALE} = 1;
119 #==========================================================================
120 # perl.h logic duplication begins
123 if ($define{USE_ITHREADS}) {
124 if (!$define{MULTIPLICITY}) {
125 $define{MULTIPLICITY} = 1;
129 $define{MULTIPLICITY} ||= $define{PERL_IMPLICIT_CONTEXT} ;
131 if ($define{USE_ITHREADS} && ! $define{WIN32}) {
132 $define{USE_REENTRANT_API} = 1;
135 if (! $define{NO_LOCALE}) {
136 if ( ! $define{NO_POSIX_2008_LOCALE}
137 && $define{HAS_NEWLOCALE}
138 && $define{HAS_USELOCALE}
139 && $define{HAS_DUPLOCALE}
140 && $define{HAS_FREELOCALE})
142 $define{HAS_POSIX_2008_LOCALE} = 1;
143 $define{USE_LOCALE} = 1;
145 elsif ($define{HAS_SETLOCALE}) {
146 $define{USE_LOCALE} = 1;
150 # https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B#Internal_version_numbering
151 my $cctype = $ARGS{CCTYPE} =~ s/MSVC//r;
152 if ( $define{USE_ITHREADS}
153 && $define{USE_LOCALE}
154 && ! $define{NO_LOCALE_THREADS})
156 $define{USE_LOCALE_THREADS} = 1;
159 if ( $define{HAS_POSIX_2008_LOCALE}
160 && $define{USE_LOCALE}
161 && (! $define{HAS_SETLOCALE} || ( $define{USE_LOCALE_THREADS}
162 && ! $define{NO_POSIX_2008_LOCALE})
163 && ! $define{NO_THREAD_SAFE_LOCALE}))
165 $define{USE_POSIX_2008_LOCALE} = 1;
168 if ($define{USE_LOCALE_THREADS} && ! $define{NO_THREAD_SAFE_LOCALE}) {
169 if ( $define{USE_POSIX_2008_LOCALE}
170 || ($define{WIN32} && ( $cctype !~ /\D/
173 $define{USE_THREAD_SAFE_LOCALE} = 1;
177 if ($define{USE_POSIX_2008_LOCALE} && $define{HAS_QUERYLOCALE})
179 $define{USE_QUERYLOCALE} = 1;
181 # Don't need glibc only code from perl.h
184 if ($define{USE_POSIX_2008_LOCALE} && ! $define{USE_QUERYLOCALE})
186 $define{USE_PL_CURLOCALES} = 1;
191 if ($define{USE_THREAD_SAFE_LOCALE})
193 $define{USE_PL_CUR_LC_ALL} = 1;
197 $define{TS_W32_BROKEN_LOCALECONV} = 1;
201 if ($define{MULTIPLICITY} && ( $define{USE_POSIX_2008_LOCALE}
203 && $define{USE_THREAD_SAFE_LOCALE})))
205 $define{USE_PERL_SWITCH_LOCALE_CONTEXT} = 1;
208 # perl.h logic duplication ends
209 #==========================================================================
211 print STDERR "Defines: (" . join(' ', sort keys %define) . ")\n"
212 unless PLATFORM eq 'test';
217 if (PLATFORM eq 'os2') {
218 if (open my $fh, '<', 'perl5.def') {
220 last if /^\s*EXPORTS\b/;
223 $ordinal{$1} = $2 if /^\s*"(\w+)"\s*(?:=\s*"\w+"\s*)?\@(\d+)\s*$/;
224 # This allows skipping ordinals which were used in older versions
225 $sym_ord = $1 if /^\s*;\s*LAST_ORDINAL\s*=\s*(\d+)\s*$/;
227 $sym_ord < $_ and $sym_ord = $_ for values %ordinal; # Take the max
232 # All platforms export boot_DynaLoader unconditionally.
233 my %export = ( boot_DynaLoader => 1 );
235 # d_thread_local not perl_thread_local - see hints/darwin.sh
236 ++$export{PL_current_context}
237 if defined $Config{d_thread_local} && $define{USE_ITHREADS};
240 foreach my $symbol (@_) {
241 ++$export{$symbol} unless exists $skip{$symbol};
246 # $hash is the hash that we're adding to. For one of our callers, it will
247 # actually be the skip hash but that doesn't affect the intent of what
248 # we're doing, as in that case we skip adding something to the skip hash
249 # for the second time.
251 my $file = $ARGS{TARG_DIR} . shift;
254 open my $vars, '<', $file or die "Cannot open $file: $!\n";
257 # All symbols have a Perl_ prefix because that's what embed.h sticks
258 # in front of them. The A?I?S?C? is strictly speaking wrong.
259 next unless /\bPERLVAR(A?I?S?C?)\(([IGT]),\s*(\w+)/;
262 my $symbol = $proc ? &$proc($1,$2,$3) : $var;
263 ++$hash->{$symbol} unless exists $skip{$var};
267 if (PLATFORM ne 'os2') {
268 ++$skip{$_} foreach qw(
280 if (PLATFORM eq 'vms') {
281 ++$skip{PL_statusvalue_posix};
282 # This is a wrapper if we have symlink, not a replacement
284 ++$skip{Perl_my_symlink} unless $Config{d_symlink};
286 ++$skip{PL_statusvalue_vms};
287 ++$skip{PL_perllib_sep};
288 if (PLATFORM ne 'aix') {
289 ++$skip{$_} foreach qw(
300 if (PLATFORM ne 'vms') {
301 # VMS does its own thing for these symbols.
302 ++$skip{$_} foreach qw(
303 PL_sig_handlers_initted
307 if (PLATFORM ne 'win32') {
308 ++$skip{$_} foreach qw(
316 if (PLATFORM ne 'win32') {
317 ++$skip{$_} foreach qw(
319 Perl_get_win32_message_utf8ness
320 Perl_Win_utf8_string_to_wstring
321 Perl_Win_wstring_to_utf8_string
325 unless ($define{UNLINK_ALL_VERSIONS}) {
329 unless ($define{'DEBUGGING'}) {
330 ++$skip{$_} foreach qw(
344 if ($define{'PERL_IMPLICIT_SYS'}) {
345 ++$skip{$_} foreach qw(
349 ++$export{$_} foreach qw(perl_get_host_info perl_alloc_override);
350 ++$export{perl_clone_host} if $define{USE_ITHREADS};
353 ++$skip{$_} foreach qw(
368 if (!$define{'PERL_COPY_ON_WRITE'} || $define{'PERL_NO_COW'}) {
369 ++$skip{Perl_sv_setsv_cow};
372 unless ($define{PERL_SAWAMPERSAND}) {
373 ++$skip{PL_sawampersand};
376 unless ($define{'USE_REENTRANT_API'}) {
377 ++$skip{PL_reentrant_buffer};
380 if ($define{'MYMALLOC'}) {
389 unless ($define{USE_ITHREADS}) {
390 ++$skip{PL_malloc_mutex}
394 ++$skip{$_} foreach qw(
403 unless ($define{'USE_ITHREADS'}) {
405 ++$skip{PL_user_prop_mutex};
406 ++$skip{PL_user_def_props_aTHX};
409 unless ($define{'USE_ITHREADS'}) {
410 ++$skip{$_} foreach qw(
411 PL_keyword_plugin_mutex
421 PL_locale_mutex_depth
427 PL_veto_switch_non_tTHX_context
430 Perl_clone_params_del
431 Perl_clone_params_new
450 Perl_stashpv_hvname_match
451 Perl_regdupe_internal
456 unless ($define{USE_POSIX_2008_LOCALE})
458 ++$skip{$_} foreach qw(
460 PL_scratch_locale_obj
463 unless ($define{USE_PL_CURLOCALES})
465 ++$skip{$_} foreach qw(
470 unless ($define{USE_PL_CUR_LC_ALL})
472 ++$skip{$_} foreach qw(
477 unless ($define{USE_PERL_SWITCH_LOCALE_CONTEXT})
479 ++$skip{$_} foreach qw(
480 Perl_switch_locale_context
484 unless ($define{'MULTIPLICITY'}) {
485 ++$skip{$_} foreach qw(
495 Perl_load_module_nocontext
498 Perl_warner_nocontext
499 Perl_newSVpvf_nocontext
500 Perl_sv_catpvf_nocontext
501 Perl_sv_setpvf_nocontext
502 Perl_sv_catpvf_mg_nocontext
503 Perl_sv_setpvf_mg_nocontext
509 unless ($define{'USE_DTRACE'}) {
510 ++$skip{$_} foreach qw(
511 Perl_dtrace_probe_call
512 Perl_dtrace_probe_load
514 Perl_dtrace_probe_phase
518 unless ($define{'DEBUG_LEAKING_SCALARS'}) {
519 ++$skip{PL_sv_serial};
522 unless ($define{'DEBUG_LEAKING_SCALARS_FORK_DUMP'}) {
523 ++$skip{PL_dumper_fd};
526 unless ($define{'PERL_DONT_CREATE_GVSV'}) {
527 ++$skip{Perl_gv_SVadd};
530 unless ($define{'PERL_USES_PL_PIDSTATUS'}) {
531 ++$skip{PL_pidstatus};
534 unless ($define{'PERL_TRACK_MEMPOOL'}) {
535 ++$skip{PL_memory_debug_header};
538 unless ($define{'PERL_MEM_LOG'}) {
539 ++$skip{$_} foreach qw(
549 unless ($define{'MULTIPLICITY'}) {
550 ++$skip{$_} foreach qw(
552 PL_interp_size_5_18_0
560 unless ($define{HAS_MMAP}) {
561 ++$skip{PL_mmap_page_size};
564 if ($define{HAS_SIGACTION}) {
565 ++$skip{PL_sig_trapped};
567 if (PLATFORM eq 'vms') {
568 # FAKE_PERSISTENT_SIGNAL_HANDLERS defined as !defined(HAS_SIGACTION)
569 ++$skip{PL_sig_ignoring};
570 ++$skip{PL_sig_handlers_initted} unless $define{KILL_BY_SIGPRC};
574 if (PLATFORM eq 'vms' && !$define{KILL_BY_SIGPRC}) {
575 # FAKE_DEFAULT_SIGNAL_HANDLERS defined as KILL_BY_SIGPRC
576 ++$skip{Perl_csighandler_init};
577 ++$skip{Perl_my_kill};
578 ++$skip{Perl_sig_to_vmscondition};
579 ++$skip{PL_sig_defaulting};
580 ++$skip{PL_sig_handlers_initted} unless !$define{HAS_SIGACTION};
583 if ($define{'HAS_STRNLEN'})
585 ++$skip{Perl_my_strnlen};
588 unless ($define{USE_LOCALE_COLLATE}) {
589 ++$skip{$_} foreach qw(
592 PL_collation_standard
596 Perl_sv_collxfrm_flags
597 PL_strxfrm_NUL_replacement
598 PL_strxfrm_is_behaved
600 PL_in_utf8_COLLATE_locale
604 unless ($define{USE_LOCALE_THREADS} && ! $define{USE_THREAD_SAFE_LOCALE}) {
605 ++$skip{$_} foreach qw(
606 PL_less_dicey_locale_buf
607 PL_less_dicey_locale_bufsize
611 unless ($define{USE_LOCALE_CTYPE}) {
612 ++$skip{$_} foreach qw(
614 PL_in_utf8_CTYPE_locale
615 PL_in_utf8_turkic_locale
619 unless ( ! $define{HAS_NL_LANGINFO}
620 && $define{USE_LOCALE_CTYPE}
622 && ! $define{HAS_MBTOWC}
623 && ! $define{HAS_MBRTOWC})
625 ++$skip{$_} foreach qw(
630 unless ($define{'USE_C_BACKTRACE'}) {
631 ++$skip{Perl_get_c_backtrace_dump};
632 ++$skip{Perl_dump_c_backtrace};
635 unless ($define{HAVE_INTERP_INTERN}) {
636 ++$skip{$_} foreach qw(
637 Perl_sys_intern_clear
644 if ($define{HAS_SIGNBIT}) {
645 ++$skip{Perl_signbit};
648 ++$skip{PL_op_exec_cnt}
649 unless $define{PERL_TRACE_OPS};
651 ++$skip{PL_hash_chars}
652 unless $define{PERL_USE_SINGLE_CHAR_HASH_CACHE};
654 unless ($define{PERL_RC_STACK}) {
655 ++$skip{$_} foreach qw(
662 # functions from *.sym files
664 my @syms = qw(globvar.sym);
666 # Symbols that are the public face of the PerlIO layers implementation
667 # These are in _addition to_ the public face of the abstraction
668 # and need to be exported to allow XS modules to implement layers
683 PerlIOBase_setlinebuf
722 Perl_PerlIO_context_layers
729 Perl_PerlIO_get_bufsiz
733 Perl_PerlIO_restore_errno
734 Perl_PerlIO_save_errno
737 Perl_PerlIO_set_ptrcnt
738 Perl_PerlIO_setlinebuf
747 # Export the symbols that make up the PerlIO abstraction, regardless
748 # of its implementation - read from a file
749 push @syms, 'perlio.sym';
751 # PerlIO with layers - export implementation
752 try_symbols(@layer_syms, 'perlsio_binmode');
755 unless ($define{'USE_QUADMATH'}) {
756 ++$skip{Perl_quadmath_format_needed};
757 ++$skip{Perl_quadmath_format_single};
760 unless ($Config{d_mbrlen}) {
761 ++$skip{PL_mbrlen_ps};
764 unless ($Config{d_mbrtowc}) {
765 ++$skip{PL_mbrtowc_ps};
768 unless ($Config{d_wcrtomb}) {
769 ++$skip{PL_wcrtomb_ps};
772 ###############################################################################
774 # At this point all skip lists should be completed, as we are about to test
775 # many symbols against them.
779 my ($embed_array) = setup_embed($ARGS{TARG_DIR});
780 my $excludedre = $define{'NO_MATHOMS'} ? qr/[emiIsb]/ : qr/[emiIs]/;
782 foreach (@$embed_array) {
783 my $embed= $_->{embed}
785 my ($flags, $retval, $func, $args) = @{$embed}{qw(flags return_type name args)};
787 if (($flags =~ /[AXC]/ && $flags !~ $excludedre)
788 || (!$define{'NO_MATHOMS'} && $flags =~ /b/))
790 # public API, so export
792 # If a function is defined twice, for example before and after
793 # an #else, only export its name once. Important to do this test
794 # within the block, as the *first* definition may have flags which
795 # mean "don't export"
796 next if $seen{$func}++;
797 # Should we also skip adding the Perl_ prefix if $flags =~ /o/ ?
798 $func = "Perl_$func" if ($flags =~ /[psX]/ && $func !~ /^Perl_/);
799 ++$export{$func} unless exists $skip{$func};
805 my $syms = $ARGS{TARG_DIR} . $_;
806 open my $global, '<', $syms or die "failed to open $syms: $!\n";
808 next unless /^([A-Za-z].*)/;
810 ++$export{$symbol} unless exists $skip{$symbol};
816 readvar('perlvars.h', \%export);
817 unless ($define{MULTIPLICITY}) {
818 readvar('intrpvar.h', \%export);
821 # Oddities from PerlIO
822 # All have alternate implementations in perlio.c, so always exist.
823 # Should they be considered to be part of the API?
832 if (PLATFORM eq 'win32') {
897 win32_getprotobynumber
997 elsif (PLATFORM eq 'vms') {
1002 Perl_csighandler_init
1004 Perl_fileify_dirspec
1005 Perl_fileify_dirspec_ts
1006 Perl_fileify_dirspec_utf8
1007 Perl_fileify_dirspec_utf8_ts
1039 Perl_pathify_dirspec
1040 Perl_pathify_dirspec_ts
1041 Perl_pathify_dirspec_utf8
1042 Perl_pathify_dirspec_utf8_ts
1050 Perl_rmsexpand_utf8_ts
1052 Perl_sig_to_vmscondition
1056 Perl_tounixpath_utf8
1057 Perl_tounixpath_utf8_ts
1060 Perl_tounixspec_utf8
1061 Perl_tounixspec_utf8_ts
1065 Perl_tovmspath_utf8_ts
1069 Perl_tovmsspec_utf8_ts
1071 Perl_vms_case_tolerant
1082 elsif (PLATFORM eq 'os2') {
1125 XS_Cwd_current_drive
1127 XS_Cwd_extLibpath_set
1131 XS_Cwd_sys_is_absolute
1132 XS_Cwd_sys_is_relative
1133 XS_Cwd_sys_is_rooted
1134 XS_DynaLoader_mod2fname
1135 XS_File__Copy_syscopy
1139 Perl_Process_Messages
1152 # When added this code was only run for Win32 (and WinCE at the time)
1153 # Currently only Win32 links static extensions into the shared library.
1154 # For *nix (and presumably OS/2) with a shared libperl, Makefile.SH compiles
1155 # static extensions with -fPIC, but links them to perl, not libperl.so
1156 # The VMS build scripts don't yet implement static extensions at all.
1158 if (PLATFORM eq 'win32') {
1159 # records of type boot_module for statically linked modules (except Dynaloader)
1160 my $static_ext = $Config{static_ext} // "";
1161 $static_ext =~ s/\//__/g;
1162 $static_ext =~ s/\bDynaLoader\b//;
1163 try_symbols(map {"boot_$_"} grep {/\S/} split /\s+/, $static_ext);
1164 try_symbols("init_Win32CORE") if $static_ext =~ /\bWin32CORE\b/;
1167 if (PLATFORM eq 'os2') {
1168 my (%mapped, @missing);
1169 open MAP, '<', 'miniperl.map' or die 'Cannot read miniperl.map';
1170 /^\s*[\da-f:]+\s+(\w+)/i and $mapped{$1}++ foreach <MAP>;
1171 close MAP or die 'Cannot close miniperl.map';
1173 @missing = grep { !exists $mapped{$_} }
1175 @missing = grep { !exists $exportperlmalloc{$_} } @missing;
1176 delete $export{$_} foreach @missing;
1179 ###############################################################################
1181 # Now all symbols should be defined because next we are going to output them.
1183 # Start with platform specific headers:
1185 if (PLATFORM eq 'win32') {
1186 my $dll = $define{PERL_DLL} ? $define{PERL_DLL} =~ s/\.dll$//ir
1187 : "perl$Config{api_revision}$Config{api_version}";
1188 print "LIBRARY $dll\n";
1189 # The DESCRIPTION module definition file statement is not supported
1191 if ($ARGS{CCTYPE} eq 'GCC') {
1192 print "DESCRIPTION 'Perl interpreter'\n";
1196 elsif (PLATFORM eq 'os2') {
1197 (my $v = $]) =~ s/(\d\.\d\d\d)(\d\d)$/$1_$2/;
1198 $v .= '-thread' if $Config{archname} =~ /-thread/;
1199 (my $dll = $define{PERL_DLL}) =~ s/\.dll$//i;
1200 $v .= "\@$Config{perl_patchlevel}" if $Config{perl_patchlevel};
1201 my $d = "DESCRIPTION '\@#perl5-porters\@perl.org:$v#\@ Perl interpreter, configured as $Config{config_args}'";
1202 $d = substr($d, 0, 249) . "...'" if length $d > 253;
1203 print <<"---EOP---";
1204 LIBRARY '$dll' INITINSTANCE TERMINSTANCE
1208 DATA LOADONCALL NONSHARED MULTIPLE
1212 elsif (PLATFORM eq 'aix') {
1213 my $OSVER = `uname -v`;
1215 my $OSREL = `uname -r`;
1217 if ($OSVER > 4 || ($OSVER == 4 && $OSREL >= 3)) {
1226 my @symbols = $fold ? sort {lc $a cmp lc $b} keys %export : sort keys %export;
1227 foreach my $symbol (@symbols) {
1228 if (PLATFORM eq 'win32') {
1229 # Remembering the origin file of each symbol is an alternative to PL_ matching
1230 if (substr($symbol, 0, 3) eq 'PL_') {
1231 print "\t$symbol DATA\n";
1234 print "\t$symbol\n";
1237 elsif (PLATFORM eq 'os2') {
1238 printf qq( %-31s \@%s\n),
1239 qq("$symbol"), $ordinal{$symbol} || ++$sym_ord;
1240 printf qq( %-31s \@%s\n),
1241 qq("$exportperlmalloc{$symbol}" = "$symbol"),
1242 $ordinal{$exportperlmalloc{$symbol}} || ++$sym_ord
1243 if $exportperlmalloc and exists $exportperlmalloc{$symbol};
1249 # Then platform specific footers.
1251 if (PLATFORM eq 'os2') {
1256 Perl_OS2_handler_install
1258 ; LAST_ORDINAL=$sym_ord