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:
43 %ARGS = (CCTYPE => 'MSVC', TARG_DIR => '');
45 sub process_cc_flags {
46 foreach (map {split /\s+/, $_} @_) {
47 $define{$1} = $2 // 1 if /^-D(\w+)(?:=(.+))?/;
53 if ($flag =~ /^(?:CC_FLAGS=)?(-D\w.*)/) {
55 } elsif ($flag =~ /^(CCTYPE|FILETYPE|PLATFORM|TARG_DIR)=(.+)$/) {
57 } elsif ($flag eq '--sort-fold') {
61 my @PLATFORM = qw(aix win32 os2 vms test);
63 @PLATFORM{@PLATFORM} = ();
65 die "PLATFORM undefined, must be one of: @PLATFORM\n"
66 unless defined $ARGS{PLATFORM};
67 die "PLATFORM must be one of: @PLATFORM\n"
68 unless exists $PLATFORM{$ARGS{PLATFORM}};
71 use constant PLATFORM => $ARGS{PLATFORM};
73 # This makes us able to use, e.g., $define{WIN32}, so you don't have to
74 # remember what things came from %ARGS.
75 $define{uc $ARGS{'PLATFORM'}} = 1;
77 require "./$ARGS{TARG_DIR}regen/embed_lib.pl";
79 # Is the following guard strictly necessary? Added during refactoring
80 # to keep the same behaviour when merging other code into here.
81 process_cc_flags(@Config{qw(ccflags optimize)})
82 if PLATFORM ne 'win32';
84 # Add the compile-time options that miniperl was built with to %define.
85 # On Win32 these are not the same options as perl itself will be built
86 # with since miniperl is built with a canned config (one of the win32/
87 # config_H.*) and none of the BUILDOPT's that are set in the makefiles,
88 # but they do include some #define's that are hard-coded in various
89 # source files and header files and don't include any BUILDOPT's that
90 # the user might have chosen to disable because the canned configs are
91 # minimal configs that don't include any of those options.
93 my @options = sort(Config::bincompat_options(), Config::non_bincompat_options());
94 print STDERR "Options: (@options)\n" unless PLATFORM eq 'test';
95 $define{$_} = 1 foreach @options;
97 my %exportperlmalloc =
99 Perl_malloc => "malloc",
100 Perl_mfree => "free",
101 Perl_realloc => "realloc",
102 Perl_calloc => "calloc",
105 my $exportperlmalloc = PLATFORM eq 'os2';
107 my $config_h = 'config.h';
108 open(CFG, '<', $config_h) || die "Cannot open $config_h: $!\n";
110 $define{$1} = 1 if /^\s*\#\s*define\s+(MYMALLOC|MULTIPLICITY
112 |(?:PERL|USE|HAS)_\w+)\b/x;
116 #==========================================================================
117 # perl.h logic duplication begins
120 if ($define{USE_ITHREADS}) {
121 if (!$define{MULTIPLICITY}) {
122 $define{MULTIPLICITY} = 1;
126 $define{MULTIPLICITY} ||=
127 $define{USE_ITHREADS} ||
128 $define{PERL_IMPLICIT_CONTEXT} ;
130 if ($define{USE_ITHREADS} && ! $define{WIN32}) {
131 $define{USE_REENTRANT_API} = 1;
134 if (! $define{NO_LOCALE}) {
135 if ( ! $define{NO_POSIX_2008_LOCALE}
136 && $define{HAS_NEWLOCALE}
137 && $define{HAS_USELOCALE}
138 && $define{HAS_DUPLOCALE}
139 && $define{HAS_FREELOCALE})
141 $define{HAS_POSIX_2008_LOCALE} = 1;
142 $define{USE_LOCALE} = 1;
144 elsif ($define{HAS_SETLOCALE}) {
145 $define{USE_LOCALE} = 1;
149 # https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B#Internal_version_numbering
150 my $cctype = $ARGS{CCTYPE} =~ s/MSVC//r;
151 if ($define{USE_ITHREADS} && ! $define{NO_LOCALE_THREADS}) {
152 $define{USE_LOCALE_THREADS} = 1;
155 if ( $define{HAS_POSIX_2008_LOCALE}
156 && ( ! $define{HAS_SETLOCALE} || ( $define{USE_LOCALE_THREADS}
157 && ! $define{NO_POSIX_2008_LOCALE})))
159 $define{USE_POSIX_2008_LOCALE} = 1;
162 if ($define{USE_LOCALE_THREADS} && ! $define{NO_THREAD_SAFE_LOCALE})
164 if ( $define{USE_POSIX_2008_LOCALE}
165 || ($define{WIN32} && ( $cctype !~ /\D/
168 $define{USE_THREAD_SAFE_LOCALE} = 1;
172 if ($define{USE_POSIX_2008_LOCALE} && $define{HAS_QUERYLOCALE})
174 $define{USE_QUERYLOCALE} = 1;
176 # Don't need glibc only code from perl.h
179 if ($define{USE_POSIX_2008_LOCALE} && ! $define{USE_QUERYLOCALE})
181 $define{USE_PL_CURLOCALES} = 1;
182 $define{USE_PL_CUR_LC_ALL} = 1;
185 if ($define{WIN32} && $define{USE_THREAD_SAFE_LOCALE})
187 $define{USE_PL_CUR_LC_ALL} = 1;
190 $define{TS_W32_BROKEN_LOCALECONV} = 1;
194 if ($define{MULTIPLICITY} && ( $define{USE_POSIX_2008_LOCALE}
196 && $define{USE_THREAD_SAFE_LOCALE})))
198 $define{USE_PERL_SWITCH_LOCALE_CONTEXT} = 1;
201 # perl.h logic duplication ends
202 #==========================================================================
204 print STDERR "Defines: (" . join(' ', sort keys %define) . ")\n"
205 unless PLATFORM eq 'test';
210 if (PLATFORM eq 'os2') {
211 if (open my $fh, '<', 'perl5.def') {
213 last if /^\s*EXPORTS\b/;
216 $ordinal{$1} = $2 if /^\s*"(\w+)"\s*(?:=\s*"\w+"\s*)?\@(\d+)\s*$/;
217 # This allows skipping ordinals which were used in older versions
218 $sym_ord = $1 if /^\s*;\s*LAST_ORDINAL\s*=\s*(\d+)\s*$/;
220 $sym_ord < $_ and $sym_ord = $_ for values %ordinal; # Take the max
225 # All platforms export boot_DynaLoader unconditionally.
226 my %export = ( boot_DynaLoader => 1 );
228 # d_thread_local not perl_thread_local - see hints/darwin.sh
229 ++$export{PL_current_context}
230 if defined $Config{d_thread_local} && $define{USE_ITHREADS};
233 foreach my $symbol (@_) {
234 ++$export{$symbol} unless exists $skip{$symbol};
239 # $hash is the hash that we're adding to. For one of our callers, it will
240 # actually be the skip hash but that doesn't affect the intent of what
241 # we're doing, as in that case we skip adding something to the skip hash
242 # for the second time.
244 my $file = $ARGS{TARG_DIR} . shift;
247 open my $vars, '<', $file or die "Cannot open $file: $!\n";
250 # All symbols have a Perl_ prefix because that's what embed.h sticks
251 # in front of them. The A?I?S?C? is strictly speaking wrong.
252 next unless /\bPERLVAR(A?I?S?C?)\(([IGT]),\s*(\w+)/;
255 my $symbol = $proc ? &$proc($1,$2,$3) : $var;
256 ++$hash->{$symbol} unless exists $skip{$var};
260 if (PLATFORM ne 'os2') {
261 ++$skip{$_} foreach qw(
273 if (PLATFORM eq 'vms') {
274 ++$skip{PL_statusvalue_posix};
275 # This is a wrapper if we have symlink, not a replacement
277 ++$skip{Perl_my_symlink} unless $Config{d_symlink};
279 ++$skip{PL_statusvalue_vms};
280 ++$skip{PL_perllib_sep};
281 if (PLATFORM ne 'aix') {
282 ++$skip{$_} foreach qw(
293 if (PLATFORM ne 'vms') {
294 # VMS does its own thing for these symbols.
295 ++$skip{$_} foreach qw(
296 PL_sig_handlers_initted
300 if (PLATFORM ne 'win32') {
301 ++$skip{$_} foreach qw(
309 if (PLATFORM ne 'win32') {
310 ++$skip{$_} foreach qw(
311 Perl_get_win32_message_utf8ness
312 Perl_Win_utf8_string_to_wstring
313 Perl_Win_wstring_to_utf8_string
317 unless ($define{UNLINK_ALL_VERSIONS}) {
321 unless ($define{'DEBUGGING'}) {
322 ++$skip{$_} foreach qw(
336 if ($define{'PERL_IMPLICIT_SYS'}) {
337 ++$skip{$_} foreach qw(
341 ++$export{$_} foreach qw(perl_get_host_info perl_alloc_override);
342 ++$export{perl_clone_host} if $define{USE_ITHREADS};
345 ++$skip{$_} foreach qw(
360 if (!$define{'PERL_COPY_ON_WRITE'} || $define{'PERL_NO_COW'}) {
361 ++$skip{Perl_sv_setsv_cow};
364 unless ($define{PERL_SAWAMPERSAND}) {
365 ++$skip{PL_sawampersand};
368 unless ($define{'USE_REENTRANT_API'}) {
369 ++$skip{PL_reentrant_buffer};
372 if ($define{'MYMALLOC'}) {
381 unless ($define{USE_ITHREADS}) {
382 ++$skip{PL_malloc_mutex}
386 ++$skip{$_} foreach qw(
395 unless ($define{'USE_ITHREADS'}) {
397 ++$skip{PL_user_prop_mutex};
398 ++$skip{PL_user_def_props_aTHX};
401 unless ($define{'USE_ITHREADS'}) {
402 ++$skip{$_} foreach qw(
403 PL_keyword_plugin_mutex
413 PL_locale_mutex_depth
419 PL_veto_switch_non_tTHX_context
422 Perl_clone_params_del
423 Perl_clone_params_new
442 Perl_stashpv_hvname_match
443 Perl_regdupe_internal
448 unless ($define{USE_POSIX_2008_LOCALE})
450 ++$skip{$_} foreach qw(
452 PL_scratch_locale_obj
453 PL_underlying_numeric_obj
456 unless ($define{USE_PL_CURLOCALES})
458 ++$skip{$_} foreach qw(
463 unless ($define{USE_PL_CUR_LC_ALL})
465 ++$skip{$_} foreach qw(
470 unless ($define{USE_PERL_SWITCH_LOCALE_CONTEXT})
472 ++$skip{$_} foreach qw(
473 Perl_switch_locale_context
477 unless ($define{'MULTIPLICITY'}) {
478 ++$skip{$_} foreach qw(
488 Perl_load_module_nocontext
491 Perl_warner_nocontext
492 Perl_newSVpvf_nocontext
493 Perl_sv_catpvf_nocontext
494 Perl_sv_setpvf_nocontext
495 Perl_sv_catpvf_mg_nocontext
496 Perl_sv_setpvf_mg_nocontext
502 unless ($define{'USE_DTRACE'}) {
503 ++$skip{$_} foreach qw(
504 Perl_dtrace_probe_call
505 Perl_dtrace_probe_load
507 Perl_dtrace_probe_phase
511 unless ($define{'DEBUG_LEAKING_SCALARS'}) {
512 ++$skip{PL_sv_serial};
515 unless ($define{'DEBUG_LEAKING_SCALARS_FORK_DUMP'}) {
516 ++$skip{PL_dumper_fd};
519 unless ($define{'PERL_DONT_CREATE_GVSV'}) {
520 ++$skip{Perl_gv_SVadd};
523 unless ($define{'PERL_USES_PL_PIDSTATUS'}) {
524 ++$skip{PL_pidstatus};
527 unless ($define{'PERL_TRACK_MEMPOOL'}) {
528 ++$skip{PL_memory_debug_header};
531 unless ($define{'PERL_MEM_LOG'}) {
532 ++$skip{$_} foreach qw(
542 unless ($define{'MULTIPLICITY'}) {
543 ++$skip{$_} foreach qw(
545 PL_interp_size_5_18_0
553 unless ($define{HAS_MMAP}) {
554 ++$skip{PL_mmap_page_size};
557 if ($define{HAS_SIGACTION}) {
558 ++$skip{PL_sig_trapped};
560 if (PLATFORM eq 'vms') {
561 # FAKE_PERSISTENT_SIGNAL_HANDLERS defined as !defined(HAS_SIGACTION)
562 ++$skip{PL_sig_ignoring};
563 ++$skip{PL_sig_handlers_initted} unless $define{KILL_BY_SIGPRC};
567 if (PLATFORM eq 'vms' && !$define{KILL_BY_SIGPRC}) {
568 # FAKE_DEFAULT_SIGNAL_HANDLERS defined as KILL_BY_SIGPRC
569 ++$skip{Perl_csighandler_init};
570 ++$skip{Perl_my_kill};
571 ++$skip{Perl_sig_to_vmscondition};
572 ++$skip{PL_sig_defaulting};
573 ++$skip{PL_sig_handlers_initted} unless !$define{HAS_SIGACTION};
576 if ($define{'HAS_STRNLEN'})
578 ++$skip{Perl_my_strnlen};
581 unless ($define{USE_LOCALE_COLLATE}) {
582 ++$skip{$_} foreach qw(
585 PL_collation_standard
589 Perl_sv_collxfrm_flags
590 PL_strxfrm_NUL_replacement
591 PL_strxfrm_is_behaved
593 PL_in_utf8_COLLATE_locale
597 unless ($define{USE_LOCALE_NUMERIC}) {
598 ++$skip{$_} foreach qw(
599 PL_underlying_numeric_obj
603 unless ($define{USE_LOCALE_CTYPE}) {
604 ++$skip{$_} foreach qw(
606 PL_in_utf8_CTYPE_locale
607 PL_in_utf8_turkic_locale
611 unless ($define{'USE_C_BACKTRACE'}) {
612 ++$skip{Perl_get_c_backtrace_dump};
613 ++$skip{Perl_dump_c_backtrace};
616 unless ($define{HAVE_INTERP_INTERN}) {
617 ++$skip{$_} foreach qw(
618 Perl_sys_intern_clear
625 if ($define{HAS_SIGNBIT}) {
626 ++$skip{Perl_signbit};
629 ++$skip{PL_op_exec_cnt}
630 unless $define{PERL_TRACE_OPS};
632 ++$skip{PL_hash_chars}
633 unless $define{PERL_USE_SINGLE_CHAR_HASH_CACHE};
635 # functions from *.sym files
637 my @syms = qw(globvar.sym);
639 # Symbols that are the public face of the PerlIO layers implementation
640 # These are in _addition to_ the public face of the abstraction
641 # and need to be exported to allow XS modules to implement layers
656 PerlIOBase_setlinebuf
695 Perl_PerlIO_context_layers
702 Perl_PerlIO_get_bufsiz
706 Perl_PerlIO_restore_errno
707 Perl_PerlIO_save_errno
710 Perl_PerlIO_set_ptrcnt
711 Perl_PerlIO_setlinebuf
720 # Export the symbols that make up the PerlIO abstraction, regardless
721 # of its implementation - read from a file
722 push @syms, 'perlio.sym';
724 # PerlIO with layers - export implementation
725 try_symbols(@layer_syms, 'perlsio_binmode');
728 unless ($define{'USE_QUADMATH'}) {
729 ++$skip{Perl_quadmath_format_needed};
730 ++$skip{Perl_quadmath_format_single};
733 unless ($Config{d_mbrlen}) {
734 ++$skip{PL_mbrlen_ps};
737 unless ($Config{d_mbrtowc}) {
738 ++$skip{PL_mbrtowc_ps};
741 unless ($Config{d_wcrtomb}) {
742 ++$skip{PL_wcrtomb_ps};
745 ###############################################################################
747 # At this point all skip lists should be completed, as we are about to test
748 # many symbols against them.
752 my ($embed_array) = setup_embed($ARGS{TARG_DIR});
753 my $excludedre = $define{'NO_MATHOMS'} ? qr/[emiIsb]/ : qr/[emiIs]/;
755 foreach (@$embed_array) {
756 my $embed= $_->{embed}
758 my ($flags, $retval, $func, $args) = @{$embed}{qw(flags return_type name args)};
760 if (($flags =~ /[AXC]/ && $flags !~ $excludedre)
761 || (!$define{'NO_MATHOMS'} && $flags =~ /b/))
763 # public API, so export
765 # If a function is defined twice, for example before and after
766 # an #else, only export its name once. Important to do this test
767 # within the block, as the *first* definition may have flags which
768 # mean "don't export"
769 next if $seen{$func}++;
770 # Should we also skip adding the Perl_ prefix if $flags =~ /o/ ?
771 $func = "Perl_$func" if ($flags =~ /[psX]/ && $func !~ /^Perl_/);
772 ++$export{$func} unless exists $skip{$func};
778 my $syms = $ARGS{TARG_DIR} . $_;
779 open my $global, '<', $syms or die "failed to open $syms: $!\n";
781 next unless /^([A-Za-z].*)/;
783 ++$export{$symbol} unless exists $skip{$symbol};
789 readvar('perlvars.h', \%export);
790 unless ($define{MULTIPLICITY}) {
791 readvar('intrpvar.h', \%export);
794 # Oddities from PerlIO
795 # All have alternate implementations in perlio.c, so always exist.
796 # Should they be considered to be part of the API?
805 if (PLATFORM eq 'win32') {
870 win32_getprotobynumber
970 elsif (PLATFORM eq 'vms') {
975 Perl_csighandler_init
978 Perl_fileify_dirspec_ts
979 Perl_fileify_dirspec_utf8
980 Perl_fileify_dirspec_utf8_ts
1012 Perl_pathify_dirspec
1013 Perl_pathify_dirspec_ts
1014 Perl_pathify_dirspec_utf8
1015 Perl_pathify_dirspec_utf8_ts
1023 Perl_rmsexpand_utf8_ts
1025 Perl_sig_to_vmscondition
1029 Perl_tounixpath_utf8
1030 Perl_tounixpath_utf8_ts
1033 Perl_tounixspec_utf8
1034 Perl_tounixspec_utf8_ts
1038 Perl_tovmspath_utf8_ts
1042 Perl_tovmsspec_utf8_ts
1044 Perl_vms_case_tolerant
1055 elsif (PLATFORM eq 'os2') {
1098 XS_Cwd_current_drive
1100 XS_Cwd_extLibpath_set
1104 XS_Cwd_sys_is_absolute
1105 XS_Cwd_sys_is_relative
1106 XS_Cwd_sys_is_rooted
1107 XS_DynaLoader_mod2fname
1108 XS_File__Copy_syscopy
1112 Perl_Process_Messages
1125 # When added this code was only run for Win32 (and WinCE at the time)
1126 # Currently only Win32 links static extensions into the shared library.
1127 # For *nix (and presumably OS/2) with a shared libperl, Makefile.SH compiles
1128 # static extensions with -fPIC, but links them to perl, not libperl.so
1129 # The VMS build scripts don't yet implement static extensions at all.
1131 if (PLATFORM eq 'win32') {
1132 # records of type boot_module for statically linked modules (except Dynaloader)
1133 my $static_ext = $Config{static_ext} // "";
1134 $static_ext =~ s/\//__/g;
1135 $static_ext =~ s/\bDynaLoader\b//;
1136 try_symbols(map {"boot_$_"} grep {/\S/} split /\s+/, $static_ext);
1137 try_symbols("init_Win32CORE") if $static_ext =~ /\bWin32CORE\b/;
1140 if (PLATFORM eq 'os2') {
1141 my (%mapped, @missing);
1142 open MAP, '<', 'miniperl.map' or die 'Cannot read miniperl.map';
1143 /^\s*[\da-f:]+\s+(\w+)/i and $mapped{$1}++ foreach <MAP>;
1144 close MAP or die 'Cannot close miniperl.map';
1146 @missing = grep { !exists $mapped{$_} }
1148 @missing = grep { !exists $exportperlmalloc{$_} } @missing;
1149 delete $export{$_} foreach @missing;
1152 ###############################################################################
1154 # Now all symbols should be defined because next we are going to output them.
1156 # Start with platform specific headers:
1158 if (PLATFORM eq 'win32') {
1159 my $dll = $define{PERL_DLL} ? $define{PERL_DLL} =~ s/\.dll$//ir
1160 : "perl$Config{api_revision}$Config{api_version}";
1161 print "LIBRARY $dll\n";
1162 # The DESCRIPTION module definition file statement is not supported
1164 if ($ARGS{CCTYPE} eq 'GCC') {
1165 print "DESCRIPTION 'Perl interpreter'\n";
1169 elsif (PLATFORM eq 'os2') {
1170 (my $v = $]) =~ s/(\d\.\d\d\d)(\d\d)$/$1_$2/;
1171 $v .= '-thread' if $Config{archname} =~ /-thread/;
1172 (my $dll = $define{PERL_DLL}) =~ s/\.dll$//i;
1173 $v .= "\@$Config{perl_patchlevel}" if $Config{perl_patchlevel};
1174 my $d = "DESCRIPTION '\@#perl5-porters\@perl.org:$v#\@ Perl interpreter, configured as $Config{config_args}'";
1175 $d = substr($d, 0, 249) . "...'" if length $d > 253;
1176 print <<"---EOP---";
1177 LIBRARY '$dll' INITINSTANCE TERMINSTANCE
1181 DATA LOADONCALL NONSHARED MULTIPLE
1185 elsif (PLATFORM eq 'aix') {
1186 my $OSVER = `uname -v`;
1188 my $OSREL = `uname -r`;
1190 if ($OSVER > 4 || ($OSVER == 4 && $OSREL >= 3)) {
1199 my @symbols = $fold ? sort {lc $a cmp lc $b} keys %export : sort keys %export;
1200 foreach my $symbol (@symbols) {
1201 if (PLATFORM eq 'win32') {
1202 # Remembering the origin file of each symbol is an alternative to PL_ matching
1203 if (substr($symbol, 0, 3) eq 'PL_') {
1204 print "\t$symbol DATA\n";
1207 print "\t$symbol\n";
1210 elsif (PLATFORM eq 'os2') {
1211 printf qq( %-31s \@%s\n),
1212 qq("$symbol"), $ordinal{$symbol} || ++$sym_ord;
1213 printf qq( %-31s \@%s\n),
1214 qq("$exportperlmalloc{$symbol}" = "$symbol"),
1215 $ordinal{$exportperlmalloc{$symbol}} || ++$sym_ord
1216 if $exportperlmalloc and exists $exportperlmalloc{$symbol};
1222 # Then platform specific footers.
1224 if (PLATFORM eq 'os2') {
1229 Perl_OS2_handler_install
1231 ; LAST_ORDINAL=$sym_ord