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_THREADS}) {
124 if (!$define{MULTIPLICITY}) {
125 $define{MULTIPLICITY} = 1;
129 $define{MULTIPLICITY} ||= $define{PERL_IMPLICIT_CONTEXT} ;
131 if ($define{MULTIPLICITY} && ! $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_THREADS}
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}
178 && ( $define{HAS_QUERYLOCALE}
179 || ( $Config{cppsymbols} =~ /__GLIBC__/
180 && ! $define{NO_USE_NL_LOCALE_NAME}
181 && $define{HAS_NL_LANGINFO_L}
182 && ! $define{SETLOCALE_ACCEPTS_ANY_LOCALE_NAME})))
184 $define{USE_QUERYLOCALE} = 1;
187 if ($define{USE_POSIX_2008_LOCALE} && ! $define{USE_QUERYLOCALE})
189 $define{USE_PL_CURLOCALES} = 1;
194 if ($define{USE_THREAD_SAFE_LOCALE})
196 $define{USE_PL_CUR_LC_ALL} = 1;
200 $define{TS_W32_BROKEN_LOCALECONV} = 1;
204 if ($define{MULTIPLICITY} && ( $define{USE_POSIX_2008_LOCALE}
206 && $define{USE_THREAD_SAFE_LOCALE})))
208 $define{USE_PERL_SWITCH_LOCALE_CONTEXT} = 1;
211 # perl.h logic duplication ends
212 #==========================================================================
214 print STDERR "Defines: (" . join(' ', sort keys %define) . ")\n"
215 unless PLATFORM eq 'test';
220 if (PLATFORM eq 'os2') {
221 if (open my $fh, '<', 'perl5.def') {
223 last if /^\s*EXPORTS\b/;
226 $ordinal{$1} = $2 if /^\s*"(\w+)"\s*(?:=\s*"\w+"\s*)?\@(\d+)\s*$/;
227 # This allows skipping ordinals which were used in older versions
228 $sym_ord = $1 if /^\s*;\s*LAST_ORDINAL\s*=\s*(\d+)\s*$/;
230 $sym_ord < $_ and $sym_ord = $_ for values %ordinal; # Take the max
235 # All platforms export boot_DynaLoader unconditionally.
236 my %export = ( boot_DynaLoader => 1 );
238 # d_thread_local not perl_thread_local - see hints/darwin.sh
239 ++$export{PL_current_context}
240 if defined $Config{d_thread_local} && $define{USE_ITHREADS};
243 foreach my $symbol (@_) {
244 ++$export{$symbol} unless exists $skip{$symbol};
249 # $hash is the hash that we're adding to. For one of our callers, it will
250 # actually be the skip hash but that doesn't affect the intent of what
251 # we're doing, as in that case we skip adding something to the skip hash
252 # for the second time.
254 my $file = $ARGS{TARG_DIR} . shift;
257 open my $vars, '<', $file or die "Cannot open $file: $!\n";
260 # All symbols have a Perl_ prefix because that's what embed.h sticks
261 # in front of them. The A?I?S?C? is strictly speaking wrong.
262 next unless /\bPERLVAR(A?I?S?C?)\(([IGT]),\s*(\w+)/;
265 my $symbol = $proc ? &$proc($1,$2,$3) : $var;
266 ++$hash->{$symbol} unless exists $skip{$var};
270 if (PLATFORM ne 'os2') {
271 ++$skip{$_} foreach qw(
283 if (PLATFORM eq 'vms') {
284 ++$skip{PL_statusvalue_posix};
285 # This is a wrapper if we have symlink, not a replacement
287 ++$skip{Perl_my_symlink} unless $Config{d_symlink};
289 ++$skip{PL_statusvalue_vms};
290 ++$skip{PL_perllib_sep};
291 if (PLATFORM ne 'aix') {
292 ++$skip{$_} foreach qw(
303 if (PLATFORM ne 'vms') {
304 # VMS does its own thing for these symbols.
305 ++$skip{$_} foreach qw(
306 PL_sig_handlers_initted
310 if (PLATFORM ne 'win32') {
311 ++$skip{$_} foreach qw(
319 if (PLATFORM ne 'win32') {
320 ++$skip{$_} foreach qw(
322 Perl_get_win32_message_utf8ness
323 Perl_Win_utf8_string_to_wstring
324 Perl_Win_wstring_to_utf8_string
328 unless ($define{UNLINK_ALL_VERSIONS}) {
332 unless ($define{'DEBUGGING'}) {
333 ++$skip{$_} foreach qw(
347 if ($define{'PERL_IMPLICIT_SYS'}) {
348 ++$skip{$_} foreach qw(
352 ++$export{$_} foreach qw(perl_get_host_info perl_alloc_override);
353 ++$export{perl_clone_host} if $define{USE_ITHREADS};
356 ++$skip{$_} foreach qw(
371 if (!$define{'PERL_COPY_ON_WRITE'} || $define{'PERL_NO_COW'}) {
372 ++$skip{Perl_sv_setsv_cow};
375 unless ($define{PERL_SAWAMPERSAND}) {
376 ++$skip{PL_sawampersand};
379 unless ($define{'USE_REENTRANT_API'}) {
380 ++$skip{PL_reentrant_buffer};
383 if ($define{'MYMALLOC'}) {
392 unless ($define{USE_ITHREADS}) {
393 ++$skip{PL_malloc_mutex}
397 ++$skip{$_} foreach qw(
406 unless ($define{'USE_ITHREADS'}) {
408 ++$skip{PL_user_prop_mutex};
409 ++$skip{PL_user_def_props_aTHX};
412 unless ($define{'USE_ITHREADS'}) {
413 ++$skip{$_} foreach qw(
414 PL_keyword_plugin_mutex
424 PL_locale_mutex_depth
430 PL_veto_switch_non_tTHX_context
433 Perl_clone_params_del
434 Perl_clone_params_new
453 Perl_stashpv_hvname_match
454 Perl_regdupe_internal
459 unless ($define{'USE_THREADS'}) {
460 ++$skip{Perl_thread_locale_init};
461 ++$skip{Perl_thread_locale_term};
464 if (!$define{USE_ITHREADS} || $define{WIN32}) {
465 ++$skip{PL_main_thread};
468 unless ($define{USE_POSIX_2008_LOCALE})
470 ++$skip{$_} foreach qw(
472 PL_scratch_locale_obj
476 unless ($define{USE_PL_CURLOCALES})
478 ++$skip{$_} foreach qw(
483 unless ($define{USE_PL_CUR_LC_ALL})
485 ++$skip{$_} foreach qw(
490 unless ($define{USE_PERL_SWITCH_LOCALE_CONTEXT})
492 ++$skip{$_} foreach qw(
493 Perl_switch_locale_context
497 unless ($define{'MULTIPLICITY'}) {
498 ++$skip{$_} foreach qw(
509 Perl_load_module_nocontext
512 Perl_warner_nocontext
513 Perl_newSVpvf_nocontext
514 Perl_sv_catpvf_nocontext
515 Perl_sv_setpvf_nocontext
516 Perl_sv_catpvf_mg_nocontext
517 Perl_sv_setpvf_mg_nocontext
523 unless ($define{'USE_DTRACE'}) {
524 ++$skip{$_} foreach qw(
525 Perl_dtrace_probe_call
526 Perl_dtrace_probe_load
528 Perl_dtrace_probe_phase
532 unless ($define{'DEBUG_LEAKING_SCALARS'}) {
533 ++$skip{PL_sv_serial};
536 unless ($define{'DEBUG_LEAKING_SCALARS_FORK_DUMP'}) {
537 ++$skip{PL_dumper_fd};
540 unless ($define{'PERL_DONT_CREATE_GVSV'}) {
541 ++$skip{Perl_gv_SVadd};
544 unless ($define{'PERL_USES_PL_PIDSTATUS'}) {
545 ++$skip{PL_pidstatus};
548 unless ($define{'PERL_TRACK_MEMPOOL'}) {
549 ++$skip{PL_memory_debug_header};
552 unless ($define{'PERL_MEM_LOG'}) {
553 ++$skip{$_} foreach qw(
563 unless ($define{'MULTIPLICITY'}) {
564 ++$skip{$_} foreach qw(
566 PL_interp_size_5_18_0
574 unless ($define{HAS_MMAP}) {
575 ++$skip{PL_mmap_page_size};
578 if ($define{HAS_SIGACTION}) {
579 ++$skip{PL_sig_trapped};
581 if (PLATFORM eq 'vms') {
582 # FAKE_PERSISTENT_SIGNAL_HANDLERS defined as !defined(HAS_SIGACTION)
583 ++$skip{PL_sig_ignoring};
584 ++$skip{PL_sig_handlers_initted} unless $define{KILL_BY_SIGPRC};
588 if (PLATFORM eq 'vms' && !$define{KILL_BY_SIGPRC}) {
589 # FAKE_DEFAULT_SIGNAL_HANDLERS defined as KILL_BY_SIGPRC
590 ++$skip{Perl_csighandler_init};
591 ++$skip{Perl_my_kill};
592 ++$skip{Perl_sig_to_vmscondition};
593 ++$skip{PL_sig_defaulting};
594 ++$skip{PL_sig_handlers_initted} unless !$define{HAS_SIGACTION};
597 if ($define{'HAS_STRNLEN'})
599 ++$skip{Perl_my_strnlen};
602 unless ($define{USE_LOCALE_COLLATE}) {
603 ++$skip{$_} foreach qw(
606 PL_collation_standard
610 Perl_sv_collxfrm_flags
611 PL_strxfrm_NUL_replacement
612 PL_strxfrm_is_behaved
614 PL_in_utf8_COLLATE_locale
618 unless ($define{USE_LOCALE_THREADS} && ! $define{USE_THREAD_SAFE_LOCALE}) {
619 ++$skip{$_} foreach qw(
620 PL_less_dicey_locale_buf
621 PL_less_dicey_locale_bufsize
625 unless ($define{USE_LOCALE_CTYPE}) {
626 ++$skip{$_} foreach qw(
628 PL_in_utf8_CTYPE_locale
629 PL_in_utf8_turkic_locale
633 unless ( ! $define{HAS_NL_LANGINFO}
634 && $define{USE_LOCALE_CTYPE}
636 && ! $define{HAS_MBTOWC}
637 && ! $define{HAS_MBRTOWC})
639 ++$skip{$_} foreach qw(
644 unless ($define{'USE_C_BACKTRACE'}) {
645 ++$skip{Perl_get_c_backtrace_dump};
646 ++$skip{Perl_dump_c_backtrace};
649 unless ($define{HAVE_INTERP_INTERN}) {
650 ++$skip{$_} foreach qw(
651 Perl_sys_intern_clear
658 if ($define{HAS_SIGNBIT}) {
659 ++$skip{Perl_signbit};
662 ++$skip{PL_op_exec_cnt}
663 unless $define{PERL_TRACE_OPS};
665 ++$skip{PL_hash_chars}
666 unless $define{PERL_USE_SINGLE_CHAR_HASH_CACHE};
668 unless ($define{PERL_RC_STACK}) {
669 ++$skip{$_} foreach qw(
676 # functions from *.sym files
678 my @syms = qw(globvar.sym);
680 # Symbols that are the public face of the PerlIO layers implementation
681 # These are in _addition to_ the public face of the abstraction
682 # and need to be exported to allow XS modules to implement layers
697 PerlIOBase_setlinebuf
736 Perl_PerlIO_context_layers
743 Perl_PerlIO_get_bufsiz
747 Perl_PerlIO_restore_errno
748 Perl_PerlIO_save_errno
751 Perl_PerlIO_set_ptrcnt
752 Perl_PerlIO_setlinebuf
761 # Export the symbols that make up the PerlIO abstraction, regardless
762 # of its implementation - read from a file
763 push @syms, 'perlio.sym';
765 # PerlIO with layers - export implementation
766 try_symbols(@layer_syms, 'perlsio_binmode');
769 unless ($define{'USE_QUADMATH'}) {
770 ++$skip{Perl_quadmath_format_needed};
771 ++$skip{Perl_quadmath_format_single};
774 unless ($Config{d_mbrlen}) {
775 ++$skip{PL_mbrlen_ps};
778 unless ($Config{d_mbrtowc}) {
779 ++$skip{PL_mbrtowc_ps};
782 unless ($Config{d_wcrtomb}) {
783 ++$skip{PL_wcrtomb_ps};
786 ###############################################################################
788 # At this point all skip lists should be completed, as we are about to test
789 # many symbols against them.
793 my ($embed_array) = setup_embed($ARGS{TARG_DIR});
794 my $excludedre = $define{'NO_MATHOMS'} ? qr/[emiIsb]/ : qr/[emiIs]/;
796 foreach (@$embed_array) {
797 my $embed= $_->{embed}
799 my ($flags, $retval, $func, $args) = @{$embed}{qw(flags return_type name args)};
801 if (($flags =~ /[AXC]/ && $flags !~ $excludedre)
802 || (!$define{'NO_MATHOMS'} && $flags =~ /b/))
804 # public API, so export
806 # If a function is defined twice, for example before and after
807 # an #else, only export its name once. Important to do this test
808 # within the block, as the *first* definition may have flags which
809 # mean "don't export"
810 next if $seen{$func}++;
811 # Should we also skip adding the Perl_ prefix if $flags =~ /o/ ?
812 $func = "Perl_$func" if ($flags =~ /[psX]/ && $func !~ /^Perl_/);
813 ++$export{$func} unless exists $skip{$func};
819 my $syms = $ARGS{TARG_DIR} . $_;
820 open my $global, '<', $syms or die "failed to open $syms: $!\n";
822 next unless /^([A-Za-z].*)/;
824 ++$export{$symbol} unless exists $skip{$symbol};
830 readvar('perlvars.h', \%export);
831 unless ($define{MULTIPLICITY}) {
832 readvar('intrpvar.h', \%export);
835 # Oddities from PerlIO
836 # All have alternate implementations in perlio.c, so always exist.
837 # Should they be considered to be part of the API?
846 if (PLATFORM eq 'win32') {
911 win32_getprotobynumber
1011 elsif (PLATFORM eq 'vms') {
1016 Perl_csighandler_init
1018 Perl_fileify_dirspec
1019 Perl_fileify_dirspec_ts
1020 Perl_fileify_dirspec_utf8
1021 Perl_fileify_dirspec_utf8_ts
1053 Perl_pathify_dirspec
1054 Perl_pathify_dirspec_ts
1055 Perl_pathify_dirspec_utf8
1056 Perl_pathify_dirspec_utf8_ts
1064 Perl_rmsexpand_utf8_ts
1066 Perl_sig_to_vmscondition
1070 Perl_tounixpath_utf8
1071 Perl_tounixpath_utf8_ts
1074 Perl_tounixspec_utf8
1075 Perl_tounixspec_utf8_ts
1079 Perl_tovmspath_utf8_ts
1083 Perl_tovmsspec_utf8_ts
1085 Perl_vms_case_tolerant
1096 elsif (PLATFORM eq 'os2') {
1139 XS_Cwd_current_drive
1141 XS_Cwd_extLibpath_set
1145 XS_Cwd_sys_is_absolute
1146 XS_Cwd_sys_is_relative
1147 XS_Cwd_sys_is_rooted
1148 XS_DynaLoader_mod2fname
1149 XS_File__Copy_syscopy
1153 Perl_Process_Messages
1166 # When added this code was only run for Win32 (and WinCE at the time)
1167 # Currently only Win32 links static extensions into the shared library.
1168 # For *nix (and presumably OS/2) with a shared libperl, Makefile.SH compiles
1169 # static extensions with -fPIC, but links them to perl, not libperl.so
1170 # The VMS build scripts don't yet implement static extensions at all.
1172 if (PLATFORM eq 'win32') {
1173 # records of type boot_module for statically linked modules (except Dynaloader)
1174 my $static_ext = $Config{static_ext} // "";
1175 $static_ext =~ s/\//__/g;
1176 $static_ext =~ s/\bDynaLoader\b//;
1177 try_symbols(map {"boot_$_"} grep {/\S/} split /\s+/, $static_ext);
1178 try_symbols("init_Win32CORE") if $static_ext =~ /\bWin32CORE\b/;
1181 if (PLATFORM eq 'os2') {
1182 my (%mapped, @missing);
1183 open MAP, '<', 'miniperl.map' or die 'Cannot read miniperl.map';
1184 /^\s*[\da-f:]+\s+(\w+)/i and $mapped{$1}++ foreach <MAP>;
1185 close MAP or die 'Cannot close miniperl.map';
1187 @missing = grep { !exists $mapped{$_} }
1189 @missing = grep { !exists $exportperlmalloc{$_} } @missing;
1190 delete $export{$_} foreach @missing;
1194 if (ord "A" != 65) {
1195 for my $symbol (qw( PL_a2e PL_e2a PL_e2utf PL_utf2e )) {
1196 try_symbols($symbol);
1201 ###############################################################################
1203 # Now all symbols should be defined because next we are going to output them.
1205 # Start with platform specific headers:
1207 if (PLATFORM eq 'win32') {
1208 my $dll = $define{PERL_DLL} ? $define{PERL_DLL} =~ s/\.dll$//ir
1209 : "perl$Config{api_revision}$Config{api_version}";
1210 print "LIBRARY $dll\n";
1211 # The DESCRIPTION module definition file statement is not supported
1213 if ($ARGS{CCTYPE} eq 'GCC') {
1214 print "DESCRIPTION 'Perl interpreter'\n";
1218 elsif (PLATFORM eq 'os2') {
1219 (my $v = $]) =~ s/(\d\.\d\d\d)(\d\d)$/$1_$2/;
1220 $v .= '-thread' if $Config{archname} =~ /-thread/;
1221 (my $dll = $define{PERL_DLL}) =~ s/\.dll$//i;
1222 $v .= "\@$Config{perl_patchlevel}" if $Config{perl_patchlevel};
1223 my $d = "DESCRIPTION '\@#perl5-porters\@perl.org:$v#\@ Perl interpreter, configured as $Config{config_args}'";
1224 $d = substr($d, 0, 249) . "...'" if length $d > 253;
1225 print <<"---EOP---";
1226 LIBRARY '$dll' INITINSTANCE TERMINSTANCE
1230 DATA LOADONCALL NONSHARED MULTIPLE
1234 elsif (PLATFORM eq 'aix') {
1235 my $OSVER = `uname -v`;
1237 my $OSREL = `uname -r`;
1239 if ($OSVER > 4 || ($OSVER == 4 && $OSREL >= 3)) {
1248 my @symbols = $fold ? sort {lc $a cmp lc $b} keys %export : sort keys %export;
1249 foreach my $symbol (@symbols) {
1250 if (PLATFORM eq 'win32') {
1251 # Remembering the origin file of each symbol is an alternative to PL_ matching
1252 if (substr($symbol, 0, 3) eq 'PL_') {
1253 print "\t$symbol DATA\n";
1256 print "\t$symbol\n";
1259 elsif (PLATFORM eq 'os2') {
1260 printf qq( %-31s \@%s\n),
1261 qq("$symbol"), $ordinal{$symbol} || ++$sym_ord;
1262 printf qq( %-31s \@%s\n),
1263 qq("$exportperlmalloc{$symbol}" = "$symbol"),
1264 $ordinal{$exportperlmalloc{$symbol}} || ++$sym_ord
1265 if $exportperlmalloc and exists $exportperlmalloc{$symbol};
1271 # Then platform specific footers.
1273 if (PLATFORM eq 'os2') {
1278 Perl_OS2_handler_install
1280 ; LAST_ORDINAL=$sym_ord