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 #==========================================================================
111 # perl.h logic duplication begins
113 if ($define{USE_ITHREADS}) {
114 if (!$define{MULTIPLICITY}) {
115 $define{MULTIPLICITY} = 1;
119 $define{MULTIPLICITY} ||=
120 $define{USE_ITHREADS} ||
121 $define{PERL_IMPLICIT_CONTEXT} ;
123 if ($define{USE_ITHREADS} && $ARGS{PLATFORM} ne 'win32') {
124 $define{USE_REENTRANT_API} = 1;
127 if (! $define{NO_LOCALE}) {
128 if ( ! $define{NO_POSIX_2008_LOCALE}
129 && $define{HAS_NEWLOCALE}
130 && $define{HAS_USELOCALE}
131 && $define{HAS_DUPLOCALE}
132 && $define{HAS_FREELOCALE})
134 $define{HAS_POSIX_2008_LOCALE} = 1;
135 $define{USE_LOCALE} = 1;
137 elsif ($define{HAS_SETLOCALE}) {
138 $define{USE_LOCALE} = 1;
142 # https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B#Internal_version_numbering
143 my $cctype = $ARGS{CCTYPE} =~ s/MSVC//r;
144 if ($define{USE_ITHREADS} && ! $define{NO_LOCALE_THREADS}) {
145 $define{USE_LOCALE_THREADS} = 1;
148 if ( $define{HAS_POSIX_2008_LOCALE}
149 && ( ! $define{HAS_SETLOCALE} || ( $define{USE_LOCALE_THREADS}
150 && ! $define{NO_POSIX_2008_LOCALE})))
152 $define{USE_POSIX_2008_LOCALE} = 1;
155 if ($define{USE_LOCALE_THREADS} && ! $define{NO_THREAD_SAFE_LOCALE})
157 if ( $define{USE_POSIX_2008_LOCALE}
158 || ($ARGS{PLATFORM} eq 'win32' && ( $cctype !~ /\D/
161 $define{USE_THREAD_SAFE_LOCALE} = 1;
165 if ($define{USE_POSIX_2008_LOCALE} && $define{HAS_QUERYLOCALE})
167 $define{USE_QUERYLOCALE} = 1;
169 # Don't need glibc only code from perl.h
172 if ($define{USE_POSIX_2008_LOCALE} && ! $define{USE_QUERYLOCALE})
174 $define{USE_PL_CURLOCALES} = 1;
175 $define{USE_PL_CUR_LC_ALL} = 1;
178 if ($ARGS{PLATFORM} eq 'win32' && $define{USE_THREAD_SAFE_LOCALE})
180 $define{USE_PL_CUR_LC_ALL} = 1;
183 $define{TS_W32_BROKEN_LOCALECONV} = 1;
187 if ($define{MULTIPLICITY} && ( $define{USE_POSIX_2008_LOCALE}
189 && $define{USE_THREAD_SAFE_LOCALE})))
191 $define{USE_PERL_SWITCH_LOCALE_CONTEXT}
194 # perl.h logic duplication ends
195 #==========================================================================
197 print STDERR "Defines: (" . join(' ', sort keys %define) . ")\n"
198 unless $ARGS{PLATFORM} eq 'test';
203 if ($ARGS{PLATFORM} eq 'os2') {
204 if (open my $fh, '<', 'perl5.def') {
206 last if /^\s*EXPORTS\b/;
209 $ordinal{$1} = $2 if /^\s*"(\w+)"\s*(?:=\s*"\w+"\s*)?\@(\d+)\s*$/;
210 # This allows skipping ordinals which were used in older versions
211 $sym_ord = $1 if /^\s*;\s*LAST_ORDINAL\s*=\s*(\d+)\s*$/;
213 $sym_ord < $_ and $sym_ord = $_ for values %ordinal; # Take the max
218 # All platforms export boot_DynaLoader unconditionally.
219 my %export = ( boot_DynaLoader => 1 );
221 # d_thread_local not perl_thread_local - see hints/darwin.sh
222 ++$export{PL_current_context}
223 if defined $Config{d_thread_local} && $define{USE_ITHREADS};
226 foreach my $symbol (@_) {
227 ++$export{$symbol} unless exists $skip{$symbol};
232 # $hash is the hash that we're adding to. For one of our callers, it will
233 # actually be the skip hash but that doesn't affect the intent of what
234 # we're doing, as in that case we skip adding something to the skip hash
235 # for the second time.
237 my $file = $ARGS{TARG_DIR} . shift;
240 open my $vars, '<', $file or die "Cannot open $file: $!\n";
243 # All symbols have a Perl_ prefix because that's what embed.h sticks
244 # in front of them. The A?I?S?C? is strictly speaking wrong.
245 next unless /\bPERLVAR(A?I?S?C?)\(([IGT]),\s*(\w+)/;
248 my $symbol = $proc ? &$proc($1,$2,$3) : $var;
249 ++$hash->{$symbol} unless exists $skip{$var};
253 if ($ARGS{PLATFORM} ne 'os2') {
254 ++$skip{$_} foreach qw(
266 if ($ARGS{PLATFORM} eq 'vms') {
267 ++$skip{PL_statusvalue_posix};
268 # This is a wrapper if we have symlink, not a replacement
270 ++$skip{Perl_my_symlink} unless $Config{d_symlink};
272 ++$skip{PL_statusvalue_vms};
273 ++$skip{PL_perllib_sep};
274 if ($ARGS{PLATFORM} ne 'aix') {
275 ++$skip{$_} foreach qw(
286 if ($ARGS{PLATFORM} ne 'vms') {
287 # VMS does its own thing for these symbols.
288 ++$skip{$_} foreach qw(
289 PL_sig_handlers_initted
293 if ($ARGS{PLATFORM} ne 'win32') {
294 ++$skip{$_} foreach qw(
302 if ($ARGS{PLATFORM} ne 'win32') {
303 ++$skip{$_} foreach qw(
304 Perl_get_win32_message_utf8ness
305 Perl_Win_utf8_string_to_wstring
306 Perl_Win_wstring_to_utf8_string
310 unless ($define{UNLINK_ALL_VERSIONS}) {
314 unless ($define{'DEBUGGING'}) {
315 ++$skip{$_} foreach qw(
329 if ($define{'PERL_IMPLICIT_SYS'}) {
330 ++$skip{$_} foreach qw(
334 ++$export{$_} foreach qw(perl_get_host_info perl_alloc_override);
335 ++$export{perl_clone_host} if $define{USE_ITHREADS};
338 ++$skip{$_} foreach qw(
353 if (!$define{'PERL_COPY_ON_WRITE'} || $define{'PERL_NO_COW'}) {
354 ++$skip{Perl_sv_setsv_cow};
357 unless ($define{PERL_SAWAMPERSAND}) {
358 ++$skip{PL_sawampersand};
361 unless ($define{'USE_REENTRANT_API'}) {
362 ++$skip{PL_reentrant_buffer};
365 if ($define{'MYMALLOC'}) {
374 unless ($define{USE_ITHREADS}) {
375 ++$skip{PL_malloc_mutex}
379 ++$skip{$_} foreach qw(
388 unless ($define{'USE_ITHREADS'}) {
390 ++$skip{PL_user_prop_mutex};
391 ++$skip{PL_user_def_props_aTHX};
394 unless ($define{'USE_ITHREADS'}) {
395 ++$skip{$_} foreach qw(
396 PL_keyword_plugin_mutex
406 PL_locale_mutex_depth
412 PL_veto_switch_non_tTHX_context
415 Perl_clone_params_del
416 Perl_clone_params_new
435 Perl_stashpv_hvname_match
436 Perl_regdupe_internal
441 unless ($define{USE_POSIX_2008_LOCALE})
443 ++$skip{$_} foreach qw(
445 PL_scratch_locale_obj
446 PL_underlying_numeric_obj
449 unless ($define{USE_PL_CURLOCALES})
451 ++$skip{$_} foreach qw(
456 unless ($define{USE_PL_CUR_LC_ALL})
458 ++$skip{$_} foreach qw(
463 unless ($define{USE_PERL_SWITCH_LOCALE_CONTEXT})
465 ++$skip{$_} foreach qw(
466 Perl_switch_locale_context
470 unless ($define{'MULTIPLICITY'}) {
471 ++$skip{$_} foreach qw(
481 Perl_load_module_nocontext
484 Perl_warner_nocontext
485 Perl_newSVpvf_nocontext
486 Perl_sv_catpvf_nocontext
487 Perl_sv_setpvf_nocontext
488 Perl_sv_catpvf_mg_nocontext
489 Perl_sv_setpvf_mg_nocontext
495 unless ($define{'USE_DTRACE'}) {
496 ++$skip{$_} foreach qw(
497 Perl_dtrace_probe_call
498 Perl_dtrace_probe_load
500 Perl_dtrace_probe_phase
504 unless ($define{'DEBUG_LEAKING_SCALARS'}) {
505 ++$skip{PL_sv_serial};
508 unless ($define{'DEBUG_LEAKING_SCALARS_FORK_DUMP'}) {
509 ++$skip{PL_dumper_fd};
512 unless ($define{'PERL_DONT_CREATE_GVSV'}) {
513 ++$skip{Perl_gv_SVadd};
516 unless ($define{'PERL_USES_PL_PIDSTATUS'}) {
517 ++$skip{PL_pidstatus};
520 unless ($define{'PERL_TRACK_MEMPOOL'}) {
521 ++$skip{PL_memory_debug_header};
524 unless ($define{'PERL_MEM_LOG'}) {
525 ++$skip{$_} foreach qw(
535 unless ($define{'MULTIPLICITY'}) {
536 ++$skip{$_} foreach qw(
538 PL_interp_size_5_18_0
546 unless ($define{HAS_MMAP}) {
547 ++$skip{PL_mmap_page_size};
550 if ($define{HAS_SIGACTION}) {
551 ++$skip{PL_sig_trapped};
553 if ($ARGS{PLATFORM} eq 'vms') {
554 # FAKE_PERSISTENT_SIGNAL_HANDLERS defined as !defined(HAS_SIGACTION)
555 ++$skip{PL_sig_ignoring};
556 ++$skip{PL_sig_handlers_initted} unless $define{KILL_BY_SIGPRC};
560 if ($ARGS{PLATFORM} eq 'vms' && !$define{KILL_BY_SIGPRC}) {
561 # FAKE_DEFAULT_SIGNAL_HANDLERS defined as KILL_BY_SIGPRC
562 ++$skip{Perl_csighandler_init};
563 ++$skip{Perl_my_kill};
564 ++$skip{Perl_sig_to_vmscondition};
565 ++$skip{PL_sig_defaulting};
566 ++$skip{PL_sig_handlers_initted} unless !$define{HAS_SIGACTION};
569 if ($define{'HAS_STRNLEN'})
571 ++$skip{Perl_my_strnlen};
574 unless ($define{USE_LOCALE_COLLATE}) {
575 ++$skip{$_} foreach qw(
578 PL_collation_standard
582 Perl_sv_collxfrm_flags
583 PL_strxfrm_NUL_replacement
584 PL_strxfrm_is_behaved
586 PL_in_utf8_COLLATE_locale
590 unless ($define{USE_LOCALE_NUMERIC}) {
591 ++$skip{$_} foreach qw(
592 PL_underlying_numeric_obj
596 unless ($define{USE_LOCALE_CTYPE}) {
597 ++$skip{$_} foreach qw(
599 PL_in_utf8_CTYPE_locale
600 PL_in_utf8_turkic_locale
604 unless ($define{'USE_C_BACKTRACE'}) {
605 ++$skip{Perl_get_c_backtrace_dump};
606 ++$skip{Perl_dump_c_backtrace};
609 unless ($define{HAVE_INTERP_INTERN}) {
610 ++$skip{$_} foreach qw(
611 Perl_sys_intern_clear
618 if ($define{HAS_SIGNBIT}) {
619 ++$skip{Perl_signbit};
622 ++$skip{PL_op_exec_cnt}
623 unless $define{PERL_TRACE_OPS};
625 ++$skip{PL_hash_chars}
626 unless $define{PERL_USE_SINGLE_CHAR_HASH_CACHE};
628 # functions from *.sym files
630 my @syms = qw(globvar.sym);
632 # Symbols that are the public face of the PerlIO layers implementation
633 # These are in _addition to_ the public face of the abstraction
634 # and need to be exported to allow XS modules to implement layers
649 PerlIOBase_setlinebuf
688 Perl_PerlIO_context_layers
695 Perl_PerlIO_get_bufsiz
699 Perl_PerlIO_restore_errno
700 Perl_PerlIO_save_errno
703 Perl_PerlIO_set_ptrcnt
704 Perl_PerlIO_setlinebuf
713 # Export the symbols that make up the PerlIO abstraction, regardless
714 # of its implementation - read from a file
715 push @syms, 'perlio.sym';
717 # PerlIO with layers - export implementation
718 try_symbols(@layer_syms, 'perlsio_binmode');
721 unless ($define{'USE_QUADMATH'}) {
722 ++$skip{Perl_quadmath_format_needed};
723 ++$skip{Perl_quadmath_format_single};
726 unless ($Config{d_mbrlen}) {
727 ++$skip{PL_mbrlen_ps};
730 unless ($Config{d_mbrtowc}) {
731 ++$skip{PL_mbrtowc_ps};
734 unless ($Config{d_wcrtomb}) {
735 ++$skip{PL_wcrtomb_ps};
738 ###############################################################################
740 # At this point all skip lists should be completed, as we are about to test
741 # many symbols against them.
745 my ($embed) = setup_embed($ARGS{TARG_DIR});
746 my $excludedre = $define{'NO_MATHOMS'} ? qr/[emiIsb]/ : qr/[emiIs]/;
749 my ($flags, $retval, $func, @args) = @$_;
751 if (($flags =~ /[AXC]/ && $flags !~ $excludedre)
752 || (!$define{'NO_MATHOMS'} && $flags =~ /b/))
754 # public API, so export
756 # If a function is defined twice, for example before and after
757 # an #else, only export its name once. Important to do this test
758 # within the block, as the *first* definition may have flags which
759 # mean "don't export"
760 next if $seen{$func}++;
761 # Should we also skip adding the Perl_ prefix if $flags =~ /o/ ?
762 $func = "Perl_$func" if ($flags =~ /[psX]/ && $func !~ /^Perl_/);
763 ++$export{$func} unless exists $skip{$func};
769 my $syms = $ARGS{TARG_DIR} . $_;
770 open my $global, '<', $syms or die "failed to open $syms: $!\n";
772 next unless /^([A-Za-z].*)/;
774 ++$export{$symbol} unless exists $skip{$symbol};
780 readvar('perlvars.h', \%export);
781 unless ($define{MULTIPLICITY}) {
782 readvar('intrpvar.h', \%export);
785 # Oddities from PerlIO
786 # All have alternate implementations in perlio.c, so always exist.
787 # Should they be considered to be part of the API?
796 if ($ARGS{PLATFORM} eq 'win32') {
861 win32_getprotobynumber
961 elsif ($ARGS{PLATFORM} eq 'vms') {
966 Perl_csighandler_init
969 Perl_fileify_dirspec_ts
970 Perl_fileify_dirspec_utf8
971 Perl_fileify_dirspec_utf8_ts
1003 Perl_pathify_dirspec
1004 Perl_pathify_dirspec_ts
1005 Perl_pathify_dirspec_utf8
1006 Perl_pathify_dirspec_utf8_ts
1014 Perl_rmsexpand_utf8_ts
1016 Perl_sig_to_vmscondition
1020 Perl_tounixpath_utf8
1021 Perl_tounixpath_utf8_ts
1024 Perl_tounixspec_utf8
1025 Perl_tounixspec_utf8_ts
1029 Perl_tovmspath_utf8_ts
1033 Perl_tovmsspec_utf8_ts
1035 Perl_vms_case_tolerant
1046 elsif ($ARGS{PLATFORM} eq 'os2') {
1089 XS_Cwd_current_drive
1091 XS_Cwd_extLibpath_set
1095 XS_Cwd_sys_is_absolute
1096 XS_Cwd_sys_is_relative
1097 XS_Cwd_sys_is_rooted
1098 XS_DynaLoader_mod2fname
1099 XS_File__Copy_syscopy
1103 Perl_Process_Messages
1116 # When added this code was only run for Win32 (and WinCE at the time)
1117 # Currently only Win32 links static extensions into the shared library.
1118 # For *nix (and presumably OS/2) with a shared libperl, Makefile.SH compiles
1119 # static extensions with -fPIC, but links them to perl, not libperl.so
1120 # The VMS build scripts don't yet implement static extensions at all.
1122 if ($ARGS{PLATFORM} eq 'win32') {
1123 # records of type boot_module for statically linked modules (except Dynaloader)
1124 my $static_ext = $Config{static_ext} // "";
1125 $static_ext =~ s/\//__/g;
1126 $static_ext =~ s/\bDynaLoader\b//;
1127 try_symbols(map {"boot_$_"} grep {/\S/} split /\s+/, $static_ext);
1128 try_symbols("init_Win32CORE") if $static_ext =~ /\bWin32CORE\b/;
1131 if ($ARGS{PLATFORM} eq 'os2') {
1132 my (%mapped, @missing);
1133 open MAP, '<', 'miniperl.map' or die 'Cannot read miniperl.map';
1134 /^\s*[\da-f:]+\s+(\w+)/i and $mapped{$1}++ foreach <MAP>;
1135 close MAP or die 'Cannot close miniperl.map';
1137 @missing = grep { !exists $mapped{$_} }
1139 @missing = grep { !exists $exportperlmalloc{$_} } @missing;
1140 delete $export{$_} foreach @missing;
1143 ###############################################################################
1145 # Now all symbols should be defined because next we are going to output them.
1147 # Start with platform specific headers:
1149 if ($ARGS{PLATFORM} eq 'win32') {
1150 my $dll = $define{PERL_DLL} ? $define{PERL_DLL} =~ s/\.dll$//ir
1151 : "perl$Config{api_revision}$Config{api_version}";
1152 print "LIBRARY $dll\n";
1153 # The DESCRIPTION module definition file statement is not supported
1155 if ($ARGS{CCTYPE} eq 'GCC') {
1156 print "DESCRIPTION 'Perl interpreter'\n";
1160 elsif ($ARGS{PLATFORM} eq 'os2') {
1161 (my $v = $]) =~ s/(\d\.\d\d\d)(\d\d)$/$1_$2/;
1162 $v .= '-thread' if $Config{archname} =~ /-thread/;
1163 (my $dll = $define{PERL_DLL}) =~ s/\.dll$//i;
1164 $v .= "\@$Config{perl_patchlevel}" if $Config{perl_patchlevel};
1165 my $d = "DESCRIPTION '\@#perl5-porters\@perl.org:$v#\@ Perl interpreter, configured as $Config{config_args}'";
1166 $d = substr($d, 0, 249) . "...'" if length $d > 253;
1167 print <<"---EOP---";
1168 LIBRARY '$dll' INITINSTANCE TERMINSTANCE
1172 DATA LOADONCALL NONSHARED MULTIPLE
1176 elsif ($ARGS{PLATFORM} eq 'aix') {
1177 my $OSVER = `uname -v`;
1179 my $OSREL = `uname -r`;
1181 if ($OSVER > 4 || ($OSVER == 4 && $OSREL >= 3)) {
1190 my @symbols = $fold ? sort {lc $a cmp lc $b} keys %export : sort keys %export;
1191 foreach my $symbol (@symbols) {
1192 if (PLATFORM eq 'win32') {
1193 # Remembering the origin file of each symbol is an alternative to PL_ matching
1194 if (substr($symbol, 0, 3) eq 'PL_') {
1195 print "\t$symbol DATA\n";
1198 print "\t$symbol\n";
1201 elsif (PLATFORM eq 'os2') {
1202 printf qq( %-31s \@%s\n),
1203 qq("$symbol"), $ordinal{$symbol} || ++$sym_ord;
1204 printf qq( %-31s \@%s\n),
1205 qq("$exportperlmalloc{$symbol}" = "$symbol"),
1206 $ordinal{$exportperlmalloc{$symbol}} || ++$sym_ord
1207 if $exportperlmalloc and exists $exportperlmalloc{$symbol};
1213 # Then platform specific footers.
1215 if ($ARGS{PLATFORM} eq 'os2') {
1220 Perl_OS2_handler_install
1222 ; LAST_ORDINAL=$sym_ord