Plan 9 from Bell Labs’s /usr/web/sources/contrib/gabidiaz/root/sys/man/2perl/DynaLoader

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


.\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sh \" Subsection heading
.br
.if t .Sp
.ne 5
.PP
\fB\\$1\fR
.PP
..
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings.  \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote.  | will give a
.\" real vertical bar.  \*(C+ will give a nicer C++.  Capital omega is used to
.\" do unbreakable dashes and therefore won't be available.  \*(C` and \*(C'
.\" expand to `' in nroff, nothing in troff, for use with C<>.
.tr \(*W-|\(bv\*(Tr
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
.    ds -- \(*W-
.    ds PI pi
.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
.    ds L" ""
.    ds R" ""
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds -- \|\(em\|
.    ds PI \(*p
.    ds L" ``
.    ds R" ''
'br\}
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
.\" entries marked with X<> in POD.  Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.if \nF \{\
.    de IX
.    tm Index:\\$1\t\\n%\t"\\$2"
..
.    nr % 0
.    rr F
.\}
.\"
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.hy 0
.if n .na
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear.  Run.  Save yourself.  No user-serviceable parts.
.    \" fudge factors for nroff and troff
.if n \{\
.    ds #H 0
.    ds #V .8m
.    ds #F .3m
.    ds #[ \f1
.    ds #] \fP
.\}
.if t \{\
.    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
.    ds #V .6m
.    ds #F 0
.    ds #[ \&
.    ds #] \&
.\}
.    \" simple accents for nroff and troff
.if n \{\
.    ds ' \&
.    ds ` \&
.    ds ^ \&
.    ds , \&
.    ds ~ ~
.    ds /
.\}
.if t \{\
.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
.    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
.    \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
.    \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
.    \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
.    ds : e
.    ds 8 ss
.    ds o a
.    ds d- d\h'-1'\(ga
.    ds D- D\h'-1'\(hy
.    ds th \o'bp'
.    ds Th \o'LP'
.    ds ae ae
.    ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "DynaLoader 3"
.TH DynaLoader 3 "2002-11-24" "perl v5.8.0" "Perl Programmers Reference Guide"
.SH "NAME"
DynaLoader \- Dynamically load C libraries into Perl code
.PP
dl_error(), dl_findfile(), dl_expandspec(), dl_load_file(), dl_unload_file(), dl_find_symbol(), dl_find_symbol_anywhere(), dl_undef_symbols(), dl_install_xsub(), dl_load_flags(), bootstrap() \- routines used by DynaLoader modules
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 4
\&    package YourPackage;
\&    require DynaLoader;
\&    @ISA = qw(... DynaLoader ...);
\&    bootstrap YourPackage;
.Ve
.PP
.Vb 2
\&    # optional method for 'global' loading
\&    sub dl_load_flags { 0x01 }
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
This document defines a standard generic interface to the dynamic
linking mechanisms available on many platforms.  Its primary purpose is
to implement automatic dynamic loading of Perl modules.
.PP
This document serves as both a specification for anyone wishing to
implement the DynaLoader for a new platform and as a guide for
anyone wishing to use the DynaLoader directly in an application.
.PP
The DynaLoader is designed to be a very simple high-level
interface that is sufficiently general to cover the requirements
of SunOS, \s-1HP\-UX\s0, NeXT, Linux, \s-1VMS\s0 and other platforms.
.PP
It is also hoped that the interface will cover the needs of \s-1OS/2\s0, \s-1NT\s0
etc and also allow pseudo-dynamic linking (using \f(CW\*(C`ld \-A\*(C'\fR at runtime).
.PP
It must be stressed that the DynaLoader, by itself, is practically
useless for accessing non-Perl libraries because it provides almost no
Perl-to-C 'glue'.  There is, for example, no mechanism for calling a C
library function or supplying arguments.  A C::DynaLib module
is available from \s-1CPAN\s0 sites which performs that function for some
common system types.  And since the year 2000, there's also Inline::C,
a module that allows you to write Perl subroutines in C.  Also available
from your local \s-1CPAN\s0 site.
.PP
DynaLoader Interface Summary
.PP
.Vb 11
\&  @dl_library_path
\&  @dl_resolve_using
\&  @dl_require_symbols
\&  $dl_debug
\&  @dl_librefs
\&  @dl_modules
\&                                                  Implemented in:
\&  bootstrap($modulename)                               Perl
\&  @filepaths = dl_findfile(@names)                     Perl
\&  $flags = $modulename->dl_load_flags                  Perl
\&  $symref  = dl_find_symbol_anywhere($symbol)          Perl
.Ve
.PP
.Vb 6
\&  $libref  = dl_load_file($filename, $flags)           C
\&  $status  = dl_unload_file($libref)                   C
\&  $symref  = dl_find_symbol($libref, $symbol)          C
\&  @symbols = dl_undef_symbols()                        C
\&  dl_install_xsub($name, $symref [, $filename])        C
\&  $message = dl_error                                  C
.Ve
.IP "@dl_library_path" 4
.IX Item "@dl_library_path"
The standard/default list of directories in which \fIdl_findfile()\fR will
search for libraries etc.  Directories are searched in order:
\&\f(CW$dl_library_path\fR[0], [1], ... etc
.Sp
@dl_library_path is initialised to hold the list of 'normal' directories
(\fI/usr/lib\fR, etc) determined by \fBConfigure\fR (\f(CW$Config{'libpth'}\fR).  This should
ensure portability across a wide range of platforms.
.Sp
@dl_library_path should also be initialised with any other directories
that can be determined from the environment at runtime (such as
\&\s-1LD_LIBRARY_PATH\s0 for SunOS).
.Sp
After initialisation \f(CW@dl_library_path\fR can be manipulated by an
application using push and unshift before calling \fIdl_findfile()\fR.
Unshift can be used to add directories to the front of the search order
either to save search time or to override libraries with the same name
in the 'normal' directories.
.Sp
The load function that \fIdl_load_file()\fR calls may require an absolute
pathname.  The \fIdl_findfile()\fR function and \f(CW@dl_library_path\fR can be
used to search for and return the absolute pathname for the
library/object that you wish to load.
.IP "@dl_resolve_using" 4
.IX Item "@dl_resolve_using"
A list of additional libraries or other shared objects which can be
used to resolve any undefined symbols that might be generated by a
later call to \fIload_file()\fR.
.Sp
This is only required on some platforms which do not handle dependent
libraries automatically.  For example the Socket Perl extension
library (\fIauto/Socket/Socket.so\fR) contains references to many socket
functions which need to be resolved when it's loaded.  Most platforms
will automatically know where to find the 'dependent' library (e.g.,
\&\fI/usr/lib/libsocket.so\fR).  A few platforms need to be told the
location of the dependent library explicitly.  Use \f(CW@dl_resolve_using\fR
for this.
.Sp
Example usage:
.Sp
.Vb 1
\&    @dl_resolve_using = dl_findfile('-lsocket');
.Ve
.IP "@dl_require_symbols" 4
.IX Item "@dl_require_symbols"
A list of one or more symbol names that are in the library/object file
to be dynamically loaded.  This is only required on some platforms.
.IP "@dl_librefs" 4
.IX Item "@dl_librefs"
An array of the handles returned by successful calls to \fIdl_load_file()\fR,
made by bootstrap, in the order in which they were loaded.
Can be used with \fIdl_find_symbol()\fR to look for a symbol in any of
the loaded files.
.IP "@dl_modules" 4
.IX Item "@dl_modules"
An array of module (package) names that have been bootstrap'ed.
.IP "\fIdl_error()\fR" 4
.IX Item "dl_error()"
Syntax:
.Sp
.Vb 1
\&    $message = dl_error();
.Ve
.Sp
Error message text from the last failed DynaLoader function.  Note
that, similar to errno in unix, a successful function call does not
reset this message.
.Sp
Implementations should detect the error as soon as it occurs in any of
the other functions and save the corresponding message for later
retrieval.  This will avoid problems on some platforms (such as SunOS)
where the error message is very temporary (e.g., \fIdlerror()\fR).
.IP "$dl_debug" 4
.IX Item "$dl_debug"
Internal debugging messages are enabled when \f(CW$dl_debug\fR is set true.
Currently setting \f(CW$dl_debug\fR only affects the Perl side of the
DynaLoader.  These messages should help an application developer to
resolve any DynaLoader usage problems.
.Sp
$dl_debug is set to \f(CW$ENV{'PERL_DL_DEBUG'}\fR if defined.
.Sp
For the DynaLoader developer/porter there is a similar debugging
variable added to the C code (see dlutils.c) and enabled if Perl was
built with the \fB\-DDEBUGGING\fR flag.  This can also be set via the
\&\s-1PERL_DL_DEBUG\s0 environment variable.  Set to 1 for minimal information or
higher for more.
.IP "\fIdl_findfile()\fR" 4
.IX Item "dl_findfile()"
Syntax:
.Sp
.Vb 1
\&    @filepaths = dl_findfile(@names)
.Ve
.Sp
Determine the full paths (including file suffix) of one or more
loadable files given their generic names and optionally one or more
directories.  Searches directories in \f(CW@dl_library_path\fR by default and
returns an empty list if no files were found.
.Sp
Names can be specified in a variety of platform independent forms.  Any
names in the form \fB\-lname\fR are converted into \fIlibname.*\fR, where \fI.*\fR is
an appropriate suffix for the platform.
.Sp
If a name does not already have a suitable prefix and/or suffix then
the corresponding file will be searched for by trying combinations of
prefix and suffix appropriate to the platform: \*(L"$name.o\*(R", \*(L"lib$name.*\*(R"
and \*(L"$name\*(R".
.Sp
If any directories are included in \f(CW@names\fR they are searched before
\&\f(CW@dl_library_path\fR.  Directories may be specified as \fB\-Ldir\fR.  Any other
names are treated as filenames to be searched for.
.Sp
Using arguments of the form \f(CW\*(C`\-Ldir\*(C'\fR and \f(CW\*(C`\-lname\*(C'\fR is recommended.
.Sp
Example: 
.Sp
.Vb 1
\&    @dl_resolve_using = dl_findfile(qw(-L/usr/5lib -lposix));
.Ve
.IP "\fIdl_expandspec()\fR" 4
.IX Item "dl_expandspec()"
Syntax:
.Sp
.Vb 1
\&    $filepath = dl_expandspec($spec)
.Ve
.Sp
Some unusual systems, such as \s-1VMS\s0, require special filename handling in
order to deal with symbolic names for files (i.e., \s-1VMS\s0's Logical Names).
.Sp
To support these systems a \fIdl_expandspec()\fR function can be implemented
either in the \fIdl_*.xs\fR file or code can be added to the autoloadable
\&\fIdl_expandspec()\fR function in \fIDynaLoader.pm\fR.  See \fIDynaLoader.pm\fR for
more information.
.IP "\fIdl_load_file()\fR" 4
.IX Item "dl_load_file()"
Syntax:
.Sp
.Vb 1
\&    $libref = dl_load_file($filename, $flags)
.Ve
.Sp
Dynamically load \f(CW$filename\fR, which must be the path to a shared object
or library.  An opaque 'library reference' is returned as a handle for
the loaded object.  Returns undef on error.
.Sp
The \f(CW$flags\fR argument to alters dl_load_file behaviour.  
Assigned bits:
.Sp
.Vb 3
\& 0x01  make symbols available for linking later dl_load_file's.
\&       (only known to work on Solaris 2 using dlopen(RTLD_GLOBAL))
\&       (ignored under VMS; this is a normal part of image linking)
.Ve
.Sp
(On systems that provide a handle for the loaded object such as SunOS
and \s-1HPUX\s0, \f(CW$libref\fR will be that handle.  On other systems \f(CW$libref\fR will
typically be \f(CW$filename\fR or a pointer to a buffer containing \f(CW$filename\fR.
The application should not examine or alter \f(CW$libref\fR in any way.)
.Sp
This is the function that does the real work.  It should use the
current values of \f(CW@dl_require_symbols\fR and \f(CW@dl_resolve_using\fR if required.
.Sp
.Vb 5
\&    SunOS: dlopen($filename)
\&    HP-UX: shl_load($filename)
\&    Linux: dld_create_reference(@dl_require_symbols); dld_link($filename)
\&    NeXT:  rld_load($filename, @dl_resolve_using)
\&    VMS:   lib$find_image_symbol($filename,$dl_require_symbols[0])
.Ve
.Sp
(The \fIdlopen()\fR function is also used by Solaris and some versions of
Linux, and is a common choice when providing a \*(L"wrapper\*(R" on other
mechanisms as is done in the \s-1OS/2\s0 port.)
.IP "\fIdl_unload_file()\fR" 4
.IX Item "dl_unload_file()"
Syntax:
.Sp
.Vb 1
\&    $status = dl_unload_file($libref)
.Ve
.Sp
Dynamically unload \f(CW$libref\fR, which must be an opaque 'library reference' as
returned from dl_load_file.  Returns one on success and zero on failure.
.Sp
This function is optional and may not necessarily be provided on all platforms.
If it is defined, it is called automatically when the interpreter exits for
every shared object or library loaded by DynaLoader::bootstrap.  All such
library references are stored in \f(CW@dl_librefs\fR by DynaLoader::Bootstrap as it
loads the libraries.  The files are unloaded in last\-in, first-out order.
.Sp
This unloading is usually necessary when embedding a shared-object perl (e.g.
one configured with \-Duseshrplib) within a larger application, and the perl
interpreter is created and destroyed several times within the lifetime of the
application.  In this case it is possible that the system dynamic linker will
unload and then subsequently reload the shared libperl without relocating any
references to it from any files DynaLoaded by the previous incarnation of the
interpreter.  As a result, any shared objects opened by DynaLoader may point to
a now invalid 'ghost' of the libperl shared object, causing apparently random
memory corruption and crashes.  This behaviour is most commonly seen when using
Apache and mod_perl built with the \s-1APXS\s0 mechanism.
.Sp
.Vb 5
\&    SunOS: dlclose($libref)
\&    HP-UX: ???
\&    Linux: ???
\&    NeXT:  ???
\&    VMS:   ???
.Ve
.Sp
(The \fIdlclose()\fR function is also used by Solaris and some versions of
Linux, and is a common choice when providing a \*(L"wrapper\*(R" on other
mechanisms as is done in the \s-1OS/2\s0 port.)
.IP "\fIdl_loadflags()\fR" 4
.IX Item "dl_loadflags()"
Syntax:
.Sp
.Vb 1
\&    $flags = dl_loadflags $modulename;
.Ve
.Sp
Designed to be a method call, and to be overridden by a derived class
(i.e. a class which has DynaLoader in its \f(CW@ISA\fR).  The definition in
DynaLoader itself returns 0, which produces standard behavior from
\&\fIdl_load_file()\fR.
.IP "\fIdl_find_symbol()\fR" 4
.IX Item "dl_find_symbol()"
Syntax:
.Sp
.Vb 1
\&    $symref = dl_find_symbol($libref, $symbol)
.Ve
.Sp
Return the address of the symbol \f(CW$symbol\fR or \f(CW\*(C`undef\*(C'\fR if not found.  If the
target system has separate functions to search for symbols of different
types then \fIdl_find_symbol()\fR should search for function symbols first and
then other types.
.Sp
The exact manner in which the address is returned in \f(CW$symref\fR is not
currently defined.  The only initial requirement is that \f(CW$symref\fR can
be passed to, and understood by, \fIdl_install_xsub()\fR.
.Sp
.Vb 5
\&    SunOS: dlsym($libref, $symbol)
\&    HP-UX: shl_findsym($libref, $symbol)
\&    Linux: dld_get_func($symbol) and/or dld_get_symbol($symbol)
\&    NeXT:  rld_lookup("_$symbol")
\&    VMS:   lib$find_image_symbol($libref,$symbol)
.Ve
.IP "\fIdl_find_symbol_anywhere()\fR" 4
.IX Item "dl_find_symbol_anywhere()"
Syntax:
.Sp
.Vb 1
\&    $symref = dl_find_symbol_anywhere($symbol)
.Ve
.Sp
Applies \fIdl_find_symbol()\fR to the members of \f(CW@dl_librefs\fR and returns
the first match found.
.IP "\fIdl_undef_symbols()\fR" 4
.IX Item "dl_undef_symbols()"
Example
.Sp
.Vb 1
\&    @symbols = dl_undef_symbols()
.Ve
.Sp
Return a list of symbol names which remain undefined after \fIload_file()\fR.
Returns \f(CW\*(C`()\*(C'\fR if not known.  Don't worry if your platform does not provide
a mechanism for this.  Most do not need it and hence do not provide it,
they just return an empty list.
.IP "\fIdl_install_xsub()\fR" 4
.IX Item "dl_install_xsub()"
Syntax:
.Sp
.Vb 1
\&    dl_install_xsub($perl_name, $symref [, $filename])
.Ve
.Sp
Create a new Perl external subroutine named \f(CW$perl_name\fR using \f(CW$symref\fR as
a pointer to the function which implements the routine.  This is simply
a direct call to \fInewXSUB()\fR.  Returns a reference to the installed
function.
.Sp
The \f(CW$filename\fR parameter is used by Perl to identify the source file for
the function if required by \fIdie()\fR, \fIcaller()\fR or the debugger.  If
\&\f(CW$filename\fR is not defined then \*(L"DynaLoader\*(R" will be used.
.IP "\fIbootstrap()\fR" 4
.IX Item "bootstrap()"
Syntax:
.Sp
bootstrap($module)
.Sp
This is the normal entry point for automatic dynamic loading in Perl.
.Sp
It performs the following actions:
.RS 4
.IP "\(bu" 8
locates an auto/$module directory by searching \f(CW@INC\fR
.IP "\(bu" 8
uses \fIdl_findfile()\fR to determine the filename to load
.IP "\(bu" 8
sets \f(CW@dl_require_symbols\fR to \f(CW\*(C`("boot_$module")\*(C'\fR
.IP "\(bu" 8
executes an \fIauto/$module/$module.bs\fR file if it exists
(typically used to add to \f(CW@dl_resolve_using\fR any files which
are required to load the module on the current platform)
.IP "\(bu" 8
calls \fIdl_load_flags()\fR to determine how to load the file.
.IP "\(bu" 8
calls \fIdl_load_file()\fR to load the file
.IP "\(bu" 8
calls \fIdl_undef_symbols()\fR and warns if any symbols are undefined
.IP "\(bu" 8
calls \fIdl_find_symbol()\fR for \*(L"boot_$module\*(R"
.IP "\(bu" 8
calls \fIdl_install_xsub()\fR to install it as \*(L"${module}::bootstrap\*(R"
.IP "\(bu" 8
calls &{\*(L"${module}::bootstrap\*(R"} to bootstrap the module (actually
it uses the function reference returned by dl_install_xsub for speed)
.RE
.RS 4
.RE
.SH "AUTHOR"
.IX Header "AUTHOR"
Tim Bunce, 11 August 1994.
.PP
This interface is based on the work and comments of (in no particular
order): Larry Wall, Robert Sanders, Dean Roehrich, Jeff Okamoto, Anno
Siegel, Thomas Neumann, Paul Marquess, Charles Bailey, myself and others.
.PP
Larry Wall designed the elegant inherited bootstrap mechanism and
implemented the first Perl 5 dynamic loader using it.
.PP
Solaris global loading added by Nick Ing-Simmons with design/coding
assistance from Tim Bunce, January 1996.

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].