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)=(.+)$/) {
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}};
69 use constant PLATFORM => $ARGS{PLATFORM};
71 require "./$ARGS{TARG_DIR}regen/embed_lib.pl";
73 # Is the following guard strictly necessary? Added during refactoring
74 # to keep the same behaviour when merging other code into here.
75 process_cc_flags(@Config{qw(ccflags optimize)})
76 if $ARGS{PLATFORM} ne 'win32';
78 # Add the compile-time options that miniperl was built with to %define.
79 # On Win32 these are not the same options as perl itself will be built
80 # with since miniperl is built with a canned config (one of the win32/
81 # config_H.*) and none of the BUILDOPT's that are set in the makefiles,
82 # but they do include some #define's that are hard-coded in various
83 # source files and header files and don't include any BUILDOPT's that
84 # the user might have chosen to disable because the canned configs are
85 # minimal configs that don't include any of those options.
87 my @options = sort(Config::bincompat_options(), Config::non_bincompat_options());
88 print STDERR "Options: (@options)\n" unless $ARGS{PLATFORM} eq 'test';
89 $define{$_} = 1 foreach @options;
91 my %exportperlmalloc =
93 Perl_malloc => "malloc",
95 Perl_realloc => "realloc",
96 Perl_calloc => "calloc",
99 my $exportperlmalloc = $ARGS{PLATFORM} eq 'os2';
101 my $config_h = 'config.h';
102 open(CFG, '<', $config_h) || die "Cannot open $config_h: $!\n";
104 $define{$1} = 1 if /^\s*\#\s*define\s+(MYMALLOC|MULTIPLICITY
106 |(?:PERL|USE|HAS)_\w+)\b/x;
110 # perl.h logic duplication begins
112 if ($define{USE_ITHREADS}) {
113 if (!$define{MULTIPLICITY}) {
114 $define{MULTIPLICITY} = 1;
118 $define{MULTIPLICITY} ||=
119 $define{USE_ITHREADS} ||
120 $define{PERL_IMPLICIT_CONTEXT} ;
122 if ($define{USE_ITHREADS} && $ARGS{PLATFORM} ne 'win32') {
123 $define{USE_REENTRANT_API} = 1;
126 if (! $define{NO_LOCALE}) {
127 if ( ! $define{NO_POSIX_2008_LOCALE}
128 && $define{HAS_NEWLOCALE}
129 && $define{HAS_USELOCALE}
130 && $define{HAS_DUPLOCALE}
131 && $define{HAS_FREELOCALE})
133 $define{HAS_POSIX_2008_LOCALE} = 1;
134 $define{USE_LOCALE} = 1;
136 elsif ($define{HAS_SETLOCALE}) {
137 $define{USE_LOCALE} = 1;
141 # https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B#Internal_version_numbering
142 my $cctype = $ARGS{CCTYPE} =~ s/MSVC//r;
143 if ($define{USE_ITHREADS} && ! $define{NO_LOCALE_THREADS}) {
144 $define{USE_LOCALE_THREADS} = 1;
146 if (! $define{HAS_SETLOCALE} && $define{HAS_POSIX_2008_LOCALE}) {
147 $define{USE_POSIX_2008_LOCALE} = 1;
148 $define{USE_THREAD_SAFE_LOCALE} = 1;
150 elsif ( ($define{USE_LOCALE_THREADS} || $define{USE_THREAD_SAFE_LOCALE})
151 && ( $define{HAS_POSIX_2008_LOCALE}
152 || ($ARGS{PLATFORM} eq 'win32' && ( $cctype !~ /\D/
154 && ! $define{NO_THREAD_SAFE_LOCALE})
156 $define{USE_THREAD_SAFE_LOCALE} = 1 unless $define{USE_THREAD_SAFE_LOCALE};
157 $define{USE_POSIX_2008_LOCALE} = 1 if $define{HAS_POSIX_2008_LOCALE};
160 if ( $ARGS{PLATFORM} eq 'win32'
161 && $define{USE_THREAD_SAFE_LOCALE}
164 $define{TS_W32_BROKEN_LOCALECONV} = 1;
167 # perl.h logic duplication ends
169 print STDERR "Defines: (" . join(' ', sort keys %define) . ")\n"
170 unless $ARGS{PLATFORM} eq 'test';
175 if ($ARGS{PLATFORM} eq 'os2') {
176 if (open my $fh, '<', 'perl5.def') {
178 last if /^\s*EXPORTS\b/;
181 $ordinal{$1} = $2 if /^\s*"(\w+)"\s*(?:=\s*"\w+"\s*)?\@(\d+)\s*$/;
182 # This allows skipping ordinals which were used in older versions
183 $sym_ord = $1 if /^\s*;\s*LAST_ORDINAL\s*=\s*(\d+)\s*$/;
185 $sym_ord < $_ and $sym_ord = $_ for values %ordinal; # Take the max
190 # All platforms export boot_DynaLoader unconditionally.
191 my %export = ( boot_DynaLoader => 1 );
193 # d_thread_local not perl_thread_local - see hints/darwin.sh
194 ++$export{PL_current_context}
195 if defined $Config{d_thread_local} && $define{USE_ITHREADS};
198 foreach my $symbol (@_) {
199 ++$export{$symbol} unless exists $skip{$symbol};
204 # $hash is the hash that we're adding to. For one of our callers, it will
205 # actually be the skip hash but that doesn't affect the intent of what
206 # we're doing, as in that case we skip adding something to the skip hash
207 # for the second time.
209 my $file = $ARGS{TARG_DIR} . shift;
212 open my $vars, '<', $file or die "Cannot open $file: $!\n";
215 # All symbols have a Perl_ prefix because that's what embed.h sticks
216 # in front of them. The A?I?S?C? is strictly speaking wrong.
217 next unless /\bPERLVAR(A?I?S?C?)\(([IGT]),\s*(\w+)/;
220 my $symbol = $proc ? &$proc($1,$2,$3) : $var;
221 ++$hash->{$symbol} unless exists $skip{$var};
225 if ($ARGS{PLATFORM} ne 'os2') {
226 ++$skip{$_} foreach qw(
238 if ($ARGS{PLATFORM} eq 'vms') {
239 ++$skip{PL_statusvalue_posix};
240 # This is a wrapper if we have symlink, not a replacement
242 ++$skip{Perl_my_symlink} unless $Config{d_symlink};
244 ++$skip{PL_statusvalue_vms};
245 ++$skip{PL_perllib_sep};
246 if ($ARGS{PLATFORM} ne 'aix') {
247 ++$skip{$_} foreach qw(
258 if ($ARGS{PLATFORM} ne 'vms') {
259 # VMS does its own thing for these symbols.
260 ++$skip{$_} foreach qw(
261 PL_sig_handlers_initted
265 if ($ARGS{PLATFORM} ne 'win32') {
266 ++$skip{$_} foreach qw(
274 if ($ARGS{PLATFORM} ne 'win32') {
275 ++$skip{$_} foreach qw(
280 unless ($define{UNLINK_ALL_VERSIONS}) {
284 unless ($define{'DEBUGGING'}) {
285 ++$skip{$_} foreach qw(
292 Perl__setlocale_debug_string
300 if ($define{'PERL_IMPLICIT_SYS'}) {
301 ++$skip{$_} foreach qw(
305 ++$export{$_} foreach qw(perl_get_host_info perl_alloc_override);
306 ++$export{perl_clone_host} if $define{USE_ITHREADS};
309 ++$skip{$_} foreach qw(
324 if (!$define{'PERL_COPY_ON_WRITE'} || $define{'PERL_NO_COW'}) {
325 ++$skip{Perl_sv_setsv_cow};
328 unless ($define{PERL_SAWAMPERSAND}) {
329 ++$skip{PL_sawampersand};
332 unless ($define{'USE_REENTRANT_API'}) {
333 ++$skip{PL_reentrant_buffer};
336 if ($define{'MYMALLOC'}) {
345 unless ($define{USE_ITHREADS}) {
346 ++$skip{PL_malloc_mutex}
350 ++$skip{$_} foreach qw(
359 unless ($define{'USE_ITHREADS'}) {
361 ++$skip{PL_user_prop_mutex};
362 ++$skip{PL_user_def_props_aTHX};
365 unless ($define{'USE_ITHREADS'}) {
366 ++$skip{$_} foreach qw(
367 PL_keyword_plugin_mutex
377 PL_lc_numeric_mutex_depth
385 Perl_clone_params_del
386 Perl_clone_params_new
405 Perl_stashpv_hvname_match
406 Perl_regdupe_internal
411 unless ($define{USE_POSIX_2008_LOCALE})
413 ++$skip{$_} foreach qw(
415 PL_scratch_locale_obj
416 PL_underlying_numeric_obj
419 unless ($define{USE_POSIX_2008_LOCALE} && ! $define{HAS_QUERY_LOCALE})
421 ++$skip{$_} foreach qw(
426 unless ($define{'MULTIPLICITY'}) {
427 ++$skip{$_} foreach qw(
437 Perl_load_module_nocontext
440 Perl_warner_nocontext
441 Perl_newSVpvf_nocontext
442 Perl_sv_catpvf_nocontext
443 Perl_sv_setpvf_nocontext
444 Perl_sv_catpvf_mg_nocontext
445 Perl_sv_setpvf_mg_nocontext
451 if ($define{USE_THREAD_SAFE_LOCALE}) {
452 ++$skip{PL_lc_numeric_mutex};
453 ++$skip{PL_lc_numeric_mutex_depth};
456 unless ($define{'USE_DTRACE'}) {
457 ++$skip{$_} foreach qw(
458 Perl_dtrace_probe_call
459 Perl_dtrace_probe_load
461 Perl_dtrace_probe_phase
465 unless ($define{'DEBUG_LEAKING_SCALARS'}) {
466 ++$skip{PL_sv_serial};
469 unless ($define{'DEBUG_LEAKING_SCALARS_FORK_DUMP'}) {
470 ++$skip{PL_dumper_fd};
473 unless ($define{'PERL_DONT_CREATE_GVSV'}) {
474 ++$skip{Perl_gv_SVadd};
477 unless ($define{'PERL_USES_PL_PIDSTATUS'}) {
478 ++$skip{PL_pidstatus};
481 unless ($define{'PERL_TRACK_MEMPOOL'}) {
482 ++$skip{PL_memory_debug_header};
485 unless ($define{'PERL_MEM_LOG'}) {
486 ++$skip{$_} foreach qw(
496 unless ($define{'MULTIPLICITY'}) {
497 ++$skip{$_} foreach qw(
499 PL_interp_size_5_18_0
507 unless ($define{HAS_MMAP}) {
508 ++$skip{PL_mmap_page_size};
511 if ($define{HAS_SIGACTION}) {
512 ++$skip{PL_sig_trapped};
514 if ($ARGS{PLATFORM} eq 'vms') {
515 # FAKE_PERSISTENT_SIGNAL_HANDLERS defined as !defined(HAS_SIGACTION)
516 ++$skip{PL_sig_ignoring};
517 ++$skip{PL_sig_handlers_initted} unless $define{KILL_BY_SIGPRC};
521 if ($ARGS{PLATFORM} eq 'vms' && !$define{KILL_BY_SIGPRC}) {
522 # FAKE_DEFAULT_SIGNAL_HANDLERS defined as KILL_BY_SIGPRC
523 ++$skip{Perl_csighandler_init};
524 ++$skip{Perl_my_kill};
525 ++$skip{Perl_sig_to_vmscondition};
526 ++$skip{PL_sig_defaulting};
527 ++$skip{PL_sig_handlers_initted} unless !$define{HAS_SIGACTION};
530 if ($define{'HAS_STRNLEN'})
532 ++$skip{Perl_my_strnlen};
535 unless ($define{USE_LOCALE_COLLATE}) {
536 ++$skip{$_} foreach qw(
539 PL_collation_standard
543 Perl_sv_collxfrm_flags
544 PL_strxfrm_NUL_replacement
545 PL_strxfrm_is_behaved
550 unless ($define{USE_LOCALE_NUMERIC}) {
551 ++$skip{$_} foreach qw(
552 PL_underlying_numeric_obj
556 unless ($define{'USE_C_BACKTRACE'}) {
557 ++$skip{Perl_get_c_backtrace_dump};
558 ++$skip{Perl_dump_c_backtrace};
561 unless ($define{HAVE_INTERP_INTERN}) {
562 ++$skip{$_} foreach qw(
563 Perl_sys_intern_clear
570 if ($define{HAS_SIGNBIT}) {
571 ++$skip{Perl_signbit};
574 ++$skip{PL_op_exec_cnt}
575 unless $define{PERL_TRACE_OPS};
577 ++$skip{PL_hash_chars}
578 unless $define{PERL_USE_SINGLE_CHAR_HASH_CACHE};
580 # functions from *.sym files
582 my @syms = qw(globvar.sym);
584 # Symbols that are the public face of the PerlIO layers implementation
585 # These are in _addition to_ the public face of the abstraction
586 # and need to be exported to allow XS modules to implement layers
601 PerlIOBase_setlinebuf
640 Perl_PerlIO_context_layers
647 Perl_PerlIO_get_bufsiz
651 Perl_PerlIO_restore_errno
652 Perl_PerlIO_save_errno
655 Perl_PerlIO_set_ptrcnt
656 Perl_PerlIO_setlinebuf
665 # Export the symbols that make up the PerlIO abstraction, regardless
666 # of its implementation - read from a file
667 push @syms, 'perlio.sym';
669 # PerlIO with layers - export implementation
670 try_symbols(@layer_syms, 'perlsio_binmode');
673 unless ($define{'USE_QUADMATH'}) {
674 ++$skip{Perl_quadmath_format_needed};
675 ++$skip{Perl_quadmath_format_single};
678 unless ($Config{d_mbrlen}) {
679 ++$skip{PL_mbrlen_ps};
682 unless ($Config{d_mbrtowc}) {
683 ++$skip{PL_mbrtowc_ps};
686 unless ($Config{d_wcrtomb}) {
687 ++$skip{PL_wcrtomb_ps};
690 ###############################################################################
692 # At this point all skip lists should be completed, as we are about to test
693 # many symbols against them.
697 my ($embed) = setup_embed($ARGS{TARG_DIR});
698 my $excludedre = $define{'NO_MATHOMS'} ? qr/[emiIsb]/ : qr/[emiIs]/;
701 my ($flags, $retval, $func, @args) = @$_;
703 if (($flags =~ /[AXC]/ && $flags !~ $excludedre)
704 || (!$define{'NO_MATHOMS'} && $flags =~ /b/))
706 # public API, so export
708 # If a function is defined twice, for example before and after
709 # an #else, only export its name once. Important to do this test
710 # within the block, as the *first* definition may have flags which
711 # mean "don't export"
712 next if $seen{$func}++;
713 # Should we also skip adding the Perl_ prefix if $flags =~ /o/ ?
714 $func = "Perl_$func" if ($flags =~ /[psX]/ && $func !~ /^Perl_/);
715 ++$export{$func} unless exists $skip{$func};
721 my $syms = $ARGS{TARG_DIR} . $_;
722 open my $global, '<', $syms or die "failed to open $syms: $!\n";
724 next unless /^([A-Za-z].*)/;
726 ++$export{$symbol} unless exists $skip{$symbol};
732 readvar('perlvars.h', \%export);
733 unless ($define{MULTIPLICITY}) {
734 readvar('intrpvar.h', \%export);
737 # Oddities from PerlIO
738 # All have alternate implementations in perlio.c, so always exist.
739 # Should they be considered to be part of the API?
748 if ($ARGS{PLATFORM} eq 'win32') {
813 win32_getprotobynumber
913 elsif ($ARGS{PLATFORM} eq 'vms') {
918 Perl_csighandler_init
921 Perl_fileify_dirspec_ts
922 Perl_fileify_dirspec_utf8
923 Perl_fileify_dirspec_utf8_ts
956 Perl_pathify_dirspec_ts
957 Perl_pathify_dirspec_utf8
958 Perl_pathify_dirspec_utf8_ts
966 Perl_rmsexpand_utf8_ts
968 Perl_sig_to_vmscondition
973 Perl_tounixpath_utf8_ts
977 Perl_tounixspec_utf8_ts
981 Perl_tovmspath_utf8_ts
985 Perl_tovmsspec_utf8_ts
987 Perl_vms_case_tolerant
998 elsif ($ARGS{PLATFORM} eq 'os2') {
1041 XS_Cwd_current_drive
1043 XS_Cwd_extLibpath_set
1047 XS_Cwd_sys_is_absolute
1048 XS_Cwd_sys_is_relative
1049 XS_Cwd_sys_is_rooted
1050 XS_DynaLoader_mod2fname
1051 XS_File__Copy_syscopy
1055 Perl_Process_Messages
1068 # When added this code was only run for Win32 (and WinCE at the time)
1069 # Currently only Win32 links static extensions into the shared library.
1070 # For *nix (and presumably OS/2) with a shared libperl, Makefile.SH compiles
1071 # static extensions with -fPIC, but links them to perl, not libperl.so
1072 # The VMS build scripts don't yet implement static extensions at all.
1074 if ($ARGS{PLATFORM} eq 'win32') {
1075 # records of type boot_module for statically linked modules (except Dynaloader)
1076 my $static_ext = $Config{static_ext} // "";
1077 $static_ext =~ s/\//__/g;
1078 $static_ext =~ s/\bDynaLoader\b//;
1079 try_symbols(map {"boot_$_"} grep {/\S/} split /\s+/, $static_ext);
1080 try_symbols("init_Win32CORE") if $static_ext =~ /\bWin32CORE\b/;
1083 if ($ARGS{PLATFORM} eq 'os2') {
1084 my (%mapped, @missing);
1085 open MAP, '<', 'miniperl.map' or die 'Cannot read miniperl.map';
1086 /^\s*[\da-f:]+\s+(\w+)/i and $mapped{$1}++ foreach <MAP>;
1087 close MAP or die 'Cannot close miniperl.map';
1089 @missing = grep { !exists $mapped{$_} }
1091 @missing = grep { !exists $exportperlmalloc{$_} } @missing;
1092 delete $export{$_} foreach @missing;
1095 ###############################################################################
1097 # Now all symbols should be defined because next we are going to output them.
1099 # Start with platform specific headers:
1101 if ($ARGS{PLATFORM} eq 'win32') {
1102 my $dll = $define{PERL_DLL} ? $define{PERL_DLL} =~ s/\.dll$//ir
1103 : "perl$Config{api_revision}$Config{api_version}";
1104 print "LIBRARY $dll\n";
1105 # The DESCRIPTION module definition file statement is not supported
1107 if ($ARGS{CCTYPE} eq 'GCC') {
1108 print "DESCRIPTION 'Perl interpreter'\n";
1112 elsif ($ARGS{PLATFORM} eq 'os2') {
1113 (my $v = $]) =~ s/(\d\.\d\d\d)(\d\d)$/$1_$2/;
1114 $v .= '-thread' if $Config{archname} =~ /-thread/;
1115 (my $dll = $define{PERL_DLL}) =~ s/\.dll$//i;
1116 $v .= "\@$Config{perl_patchlevel}" if $Config{perl_patchlevel};
1117 my $d = "DESCRIPTION '\@#perl5-porters\@perl.org:$v#\@ Perl interpreter, configured as $Config{config_args}'";
1118 $d = substr($d, 0, 249) . "...'" if length $d > 253;
1119 print <<"---EOP---";
1120 LIBRARY '$dll' INITINSTANCE TERMINSTANCE
1124 DATA LOADONCALL NONSHARED MULTIPLE
1128 elsif ($ARGS{PLATFORM} eq 'aix') {
1129 my $OSVER = `uname -v`;
1131 my $OSREL = `uname -r`;
1133 if ($OSVER > 4 || ($OSVER == 4 && $OSREL >= 3)) {
1142 my @symbols = $fold ? sort {lc $a cmp lc $b} keys %export : sort keys %export;
1143 foreach my $symbol (@symbols) {
1144 if (PLATFORM eq 'win32') {
1145 # Remembering the origin file of each symbol is an alternative to PL_ matching
1146 if (substr($symbol, 0, 3) eq 'PL_') {
1147 print "\t$symbol DATA\n";
1150 print "\t$symbol\n";
1153 elsif (PLATFORM eq 'os2') {
1154 printf qq( %-31s \@%s\n),
1155 qq("$symbol"), $ordinal{$symbol} || ++$sym_ord;
1156 printf qq( %-31s \@%s\n),
1157 qq("$exportperlmalloc{$symbol}" = "$symbol"),
1158 $ordinal{$exportperlmalloc{$symbol}} || ++$sym_ord
1159 if $exportperlmalloc and exists $exportperlmalloc{$symbol};
1165 # Then platform specific footers.
1167 if ($ARGS{PLATFORM} eq 'os2') {
1172 Perl_OS2_handler_install
1174 ; LAST_ORDINAL=$sym_ord