Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / man / man3 / DynaLoader.3
CommitLineData
86530b38
AT
1.\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13
2.\"
3.\" Standard preamble:
4.\" ========================================================================
5.de Sh \" Subsection heading
6.br
7.if t .Sp
8.ne 5
9.PP
10\fB\\$1\fR
11.PP
12..
13.de Sp \" Vertical space (when we can't use .PP)
14.if t .sp .5v
15.if n .sp
16..
17.de Vb \" Begin verbatim text
18.ft CW
19.nf
20.ne \\$1
21..
22.de Ve \" End verbatim text
23.ft R
24.fi
25..
26.\" Set up some character translations and predefined strings. \*(-- will
27.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28.\" double quote, and \*(R" will give a right double quote. | will give a
29.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
30.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
31.\" expand to `' in nroff, nothing in troff, for use with C<>.
32.tr \(*W-|\(bv\*(Tr
33.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34.ie n \{\
35. ds -- \(*W-
36. ds PI pi
37. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
39. ds L" ""
40. ds R" ""
41. ds C` ""
42. ds C' ""
43'br\}
44.el\{\
45. ds -- \|\(em\|
46. ds PI \(*p
47. ds L" ``
48. ds R" ''
49'br\}
50.\"
51.\" If the F register is turned on, we'll generate index entries on stderr for
52.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53.\" entries marked with X<> in POD. Of course, you'll have to process the
54.\" output yourself in some meaningful fashion.
55.if \nF \{\
56. de IX
57. tm Index:\\$1\t\\n%\t"\\$2"
58..
59. nr % 0
60. rr F
61.\}
62.\"
63.\" For nroff, turn off justification. Always turn off hyphenation; it makes
64.\" way too many mistakes in technical documents.
65.hy 0
66.if n .na
67.\"
68.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69.\" Fear. Run. Save yourself. No user-serviceable parts.
70. \" fudge factors for nroff and troff
71.if n \{\
72. ds #H 0
73. ds #V .8m
74. ds #F .3m
75. ds #[ \f1
76. ds #] \fP
77.\}
78.if t \{\
79. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80. ds #V .6m
81. ds #F 0
82. ds #[ \&
83. ds #] \&
84.\}
85. \" simple accents for nroff and troff
86.if n \{\
87. ds ' \&
88. ds ` \&
89. ds ^ \&
90. ds , \&
91. ds ~ ~
92. ds /
93.\}
94.if t \{\
95. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101.\}
102. \" troff and (daisy-wheel) nroff accents
103.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110.ds ae a\h'-(\w'a'u*4/10)'e
111.ds Ae A\h'-(\w'A'u*4/10)'E
112. \" corrections for vroff
113.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115. \" for low resolution devices (crt and lpr)
116.if \n(.H>23 .if \n(.V>19 \
117\{\
118. ds : e
119. ds 8 ss
120. ds o a
121. ds d- d\h'-1'\(ga
122. ds D- D\h'-1'\(hy
123. ds th \o'bp'
124. ds Th \o'LP'
125. ds ae ae
126. ds Ae AE
127.\}
128.rm #[ #] #H #V #F C
129.\" ========================================================================
130.\"
131.IX Title "DynaLoader 3"
132.TH DynaLoader 3 "2002-06-01" "perl v5.8.0" "Perl Programmers Reference Guide"
133.SH "NAME"
134DynaLoader \- Dynamically load C libraries into Perl code
135.PP
136dl_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
137.SH "SYNOPSIS"
138.IX Header "SYNOPSIS"
139.Vb 4
140\& package YourPackage;
141\& require DynaLoader;
142\& @ISA = qw(... DynaLoader ...);
143\& bootstrap YourPackage;
144.Ve
145.PP
146.Vb 2
147\& # optional method for 'global' loading
148\& sub dl_load_flags { 0x01 }
149.Ve
150.SH "DESCRIPTION"
151.IX Header "DESCRIPTION"
152This document defines a standard generic interface to the dynamic
153linking mechanisms available on many platforms. Its primary purpose is
154to implement automatic dynamic loading of Perl modules.
155.PP
156This document serves as both a specification for anyone wishing to
157implement the DynaLoader for a new platform and as a guide for
158anyone wishing to use the DynaLoader directly in an application.
159.PP
160The DynaLoader is designed to be a very simple high-level
161interface that is sufficiently general to cover the requirements
162of SunOS, \s-1HP\-UX\s0, NeXT, Linux, \s-1VMS\s0 and other platforms.
163.PP
164It is also hoped that the interface will cover the needs of \s-1OS/2\s0, \s-1NT\s0
165etc and also allow pseudo-dynamic linking (using \f(CW\*(C`ld \-A\*(C'\fR at runtime).
166.PP
167It must be stressed that the DynaLoader, by itself, is practically
168useless for accessing non-Perl libraries because it provides almost no
169Perl-to-C 'glue'. There is, for example, no mechanism for calling a C
170library function or supplying arguments. A C::DynaLib module
171is available from \s-1CPAN\s0 sites which performs that function for some
172common system types. And since the year 2000, there's also Inline::C,
173a module that allows you to write Perl subroutines in C. Also available
174from your local \s-1CPAN\s0 site.
175.PP
176DynaLoader Interface Summary
177.PP
178.Vb 11
179\& @dl_library_path
180\& @dl_resolve_using
181\& @dl_require_symbols
182\& $dl_debug
183\& @dl_librefs
184\& @dl_modules
185\& Implemented in:
186\& bootstrap($modulename) Perl
187\& @filepaths = dl_findfile(@names) Perl
188\& $flags = $modulename->dl_load_flags Perl
189\& $symref = dl_find_symbol_anywhere($symbol) Perl
190.Ve
191.PP
192.Vb 6
193\& $libref = dl_load_file($filename, $flags) C
194\& $status = dl_unload_file($libref) C
195\& $symref = dl_find_symbol($libref, $symbol) C
196\& @symbols = dl_undef_symbols() C
197\& dl_install_xsub($name, $symref [, $filename]) C
198\& $message = dl_error C
199.Ve
200.IP "@dl_library_path" 4
201.IX Item "@dl_library_path"
202The standard/default list of directories in which \fIdl_findfile()\fR will
203search for libraries etc. Directories are searched in order:
204\&\f(CW$dl_library_path\fR[0], [1], ... etc
205.Sp
206@dl_library_path is initialised to hold the list of 'normal' directories
207(\fI/usr/lib\fR, etc) determined by \fBConfigure\fR (\f(CW$Config{'libpth'}\fR). This should
208ensure portability across a wide range of platforms.
209.Sp
210@dl_library_path should also be initialised with any other directories
211that can be determined from the environment at runtime (such as
212\&\s-1LD_LIBRARY_PATH\s0 for SunOS).
213.Sp
214After initialisation \f(CW@dl_library_path\fR can be manipulated by an
215application using push and unshift before calling \fIdl_findfile()\fR.
216Unshift can be used to add directories to the front of the search order
217either to save search time or to override libraries with the same name
218in the 'normal' directories.
219.Sp
220The load function that \fIdl_load_file()\fR calls may require an absolute
221pathname. The \fIdl_findfile()\fR function and \f(CW@dl_library_path\fR can be
222used to search for and return the absolute pathname for the
223library/object that you wish to load.
224.IP "@dl_resolve_using" 4
225.IX Item "@dl_resolve_using"
226A list of additional libraries or other shared objects which can be
227used to resolve any undefined symbols that might be generated by a
228later call to \fIload_file()\fR.
229.Sp
230This is only required on some platforms which do not handle dependent
231libraries automatically. For example the Socket Perl extension
232library (\fIauto/Socket/Socket.so\fR) contains references to many socket
233functions which need to be resolved when it's loaded. Most platforms
234will automatically know where to find the 'dependent' library (e.g.,
235\&\fI/usr/lib/libsocket.so\fR). A few platforms need to be told the
236location of the dependent library explicitly. Use \f(CW@dl_resolve_using\fR
237for this.
238.Sp
239Example usage:
240.Sp
241.Vb 1
242\& @dl_resolve_using = dl_findfile('-lsocket');
243.Ve
244.IP "@dl_require_symbols" 4
245.IX Item "@dl_require_symbols"
246A list of one or more symbol names that are in the library/object file
247to be dynamically loaded. This is only required on some platforms.
248.IP "@dl_librefs" 4
249.IX Item "@dl_librefs"
250An array of the handles returned by successful calls to \fIdl_load_file()\fR,
251made by bootstrap, in the order in which they were loaded.
252Can be used with \fIdl_find_symbol()\fR to look for a symbol in any of
253the loaded files.
254.IP "@dl_modules" 4
255.IX Item "@dl_modules"
256An array of module (package) names that have been bootstrap'ed.
257.IP "\fIdl_error()\fR" 4
258.IX Item "dl_error()"
259Syntax:
260.Sp
261.Vb 1
262\& $message = dl_error();
263.Ve
264.Sp
265Error message text from the last failed DynaLoader function. Note
266that, similar to errno in unix, a successful function call does not
267reset this message.
268.Sp
269Implementations should detect the error as soon as it occurs in any of
270the other functions and save the corresponding message for later
271retrieval. This will avoid problems on some platforms (such as SunOS)
272where the error message is very temporary (e.g., \fIdlerror()\fR).
273.IP "$dl_debug" 4
274.IX Item "$dl_debug"
275Internal debugging messages are enabled when \f(CW$dl_debug\fR is set true.
276Currently setting \f(CW$dl_debug\fR only affects the Perl side of the
277DynaLoader. These messages should help an application developer to
278resolve any DynaLoader usage problems.
279.Sp
280$dl_debug is set to \f(CW$ENV{'PERL_DL_DEBUG'}\fR if defined.
281.Sp
282For the DynaLoader developer/porter there is a similar debugging
283variable added to the C code (see dlutils.c) and enabled if Perl was
284built with the \fB\-DDEBUGGING\fR flag. This can also be set via the
285\&\s-1PERL_DL_DEBUG\s0 environment variable. Set to 1 for minimal information or
286higher for more.
287.IP "\fIdl_findfile()\fR" 4
288.IX Item "dl_findfile()"
289Syntax:
290.Sp
291.Vb 1
292\& @filepaths = dl_findfile(@names)
293.Ve
294.Sp
295Determine the full paths (including file suffix) of one or more
296loadable files given their generic names and optionally one or more
297directories. Searches directories in \f(CW@dl_library_path\fR by default and
298returns an empty list if no files were found.
299.Sp
300Names can be specified in a variety of platform independent forms. Any
301names in the form \fB\-lname\fR are converted into \fIlibname.*\fR, where \fI.*\fR is
302an appropriate suffix for the platform.
303.Sp
304If a name does not already have a suitable prefix and/or suffix then
305the corresponding file will be searched for by trying combinations of
306prefix and suffix appropriate to the platform: \*(L"$name.o\*(R", \*(L"lib$name.*\*(R"
307and \*(L"$name\*(R".
308.Sp
309If any directories are included in \f(CW@names\fR they are searched before
310\&\f(CW@dl_library_path\fR. Directories may be specified as \fB\-Ldir\fR. Any other
311names are treated as filenames to be searched for.
312.Sp
313Using arguments of the form \f(CW\*(C`\-Ldir\*(C'\fR and \f(CW\*(C`\-lname\*(C'\fR is recommended.
314.Sp
315Example:
316.Sp
317.Vb 1
318\& @dl_resolve_using = dl_findfile(qw(-L/usr/5lib -lposix));
319.Ve
320.IP "\fIdl_expandspec()\fR" 4
321.IX Item "dl_expandspec()"
322Syntax:
323.Sp
324.Vb 1
325\& $filepath = dl_expandspec($spec)
326.Ve
327.Sp
328Some unusual systems, such as \s-1VMS\s0, require special filename handling in
329order to deal with symbolic names for files (i.e., \s-1VMS\s0's Logical Names).
330.Sp
331To support these systems a \fIdl_expandspec()\fR function can be implemented
332either in the \fIdl_*.xs\fR file or code can be added to the autoloadable
333\&\fIdl_expandspec()\fR function in \fIDynaLoader.pm\fR. See \fIDynaLoader.pm\fR for
334more information.
335.IP "\fIdl_load_file()\fR" 4
336.IX Item "dl_load_file()"
337Syntax:
338.Sp
339.Vb 1
340\& $libref = dl_load_file($filename, $flags)
341.Ve
342.Sp
343Dynamically load \f(CW$filename\fR, which must be the path to a shared object
344or library. An opaque 'library reference' is returned as a handle for
345the loaded object. Returns undef on error.
346.Sp
347The \f(CW$flags\fR argument to alters dl_load_file behaviour.
348Assigned bits:
349.Sp
350.Vb 3
351\& 0x01 make symbols available for linking later dl_load_file's.
352\& (only known to work on Solaris 2 using dlopen(RTLD_GLOBAL))
353\& (ignored under VMS; this is a normal part of image linking)
354.Ve
355.Sp
356(On systems that provide a handle for the loaded object such as SunOS
357and \s-1HPUX\s0, \f(CW$libref\fR will be that handle. On other systems \f(CW$libref\fR will
358typically be \f(CW$filename\fR or a pointer to a buffer containing \f(CW$filename\fR.
359The application should not examine or alter \f(CW$libref\fR in any way.)
360.Sp
361This is the function that does the real work. It should use the
362current values of \f(CW@dl_require_symbols\fR and \f(CW@dl_resolve_using\fR if required.
363.Sp
364.Vb 5
365\& SunOS: dlopen($filename)
366\& HP-UX: shl_load($filename)
367\& Linux: dld_create_reference(@dl_require_symbols); dld_link($filename)
368\& NeXT: rld_load($filename, @dl_resolve_using)
369\& VMS: lib$find_image_symbol($filename,$dl_require_symbols[0])
370.Ve
371.Sp
372(The \fIdlopen()\fR function is also used by Solaris and some versions of
373Linux, and is a common choice when providing a \*(L"wrapper\*(R" on other
374mechanisms as is done in the \s-1OS/2\s0 port.)
375.IP "\fIdl_unload_file()\fR" 4
376.IX Item "dl_unload_file()"
377Syntax:
378.Sp
379.Vb 1
380\& $status = dl_unload_file($libref)
381.Ve
382.Sp
383Dynamically unload \f(CW$libref\fR, which must be an opaque 'library reference' as
384returned from dl_load_file. Returns one on success and zero on failure.
385.Sp
386This function is optional and may not necessarily be provided on all platforms.
387If it is defined, it is called automatically when the interpreter exits for
388every shared object or library loaded by DynaLoader::bootstrap. All such
389library references are stored in \f(CW@dl_librefs\fR by DynaLoader::Bootstrap as it
390loads the libraries. The files are unloaded in last\-in, first-out order.
391.Sp
392This unloading is usually necessary when embedding a shared-object perl (e.g.
393one configured with \-Duseshrplib) within a larger application, and the perl
394interpreter is created and destroyed several times within the lifetime of the
395application. In this case it is possible that the system dynamic linker will
396unload and then subsequently reload the shared libperl without relocating any
397references to it from any files DynaLoaded by the previous incarnation of the
398interpreter. As a result, any shared objects opened by DynaLoader may point to
399a now invalid 'ghost' of the libperl shared object, causing apparently random
400memory corruption and crashes. This behaviour is most commonly seen when using
401Apache and mod_perl built with the \s-1APXS\s0 mechanism.
402.Sp
403.Vb 5
404\& SunOS: dlclose($libref)
405\& HP-UX: ???
406\& Linux: ???
407\& NeXT: ???
408\& VMS: ???
409.Ve
410.Sp
411(The \fIdlclose()\fR function is also used by Solaris and some versions of
412Linux, and is a common choice when providing a \*(L"wrapper\*(R" on other
413mechanisms as is done in the \s-1OS/2\s0 port.)
414.IP "\fIdl_loadflags()\fR" 4
415.IX Item "dl_loadflags()"
416Syntax:
417.Sp
418.Vb 1
419\& $flags = dl_loadflags $modulename;
420.Ve
421.Sp
422Designed to be a method call, and to be overridden by a derived class
423(i.e. a class which has DynaLoader in its \f(CW@ISA\fR). The definition in
424DynaLoader itself returns 0, which produces standard behavior from
425\&\fIdl_load_file()\fR.
426.IP "\fIdl_find_symbol()\fR" 4
427.IX Item "dl_find_symbol()"
428Syntax:
429.Sp
430.Vb 1
431\& $symref = dl_find_symbol($libref, $symbol)
432.Ve
433.Sp
434Return the address of the symbol \f(CW$symbol\fR or \f(CW\*(C`undef\*(C'\fR if not found. If the
435target system has separate functions to search for symbols of different
436types then \fIdl_find_symbol()\fR should search for function symbols first and
437then other types.
438.Sp
439The exact manner in which the address is returned in \f(CW$symref\fR is not
440currently defined. The only initial requirement is that \f(CW$symref\fR can
441be passed to, and understood by, \fIdl_install_xsub()\fR.
442.Sp
443.Vb 5
444\& SunOS: dlsym($libref, $symbol)
445\& HP-UX: shl_findsym($libref, $symbol)
446\& Linux: dld_get_func($symbol) and/or dld_get_symbol($symbol)
447\& NeXT: rld_lookup("_$symbol")
448\& VMS: lib$find_image_symbol($libref,$symbol)
449.Ve
450.IP "\fIdl_find_symbol_anywhere()\fR" 4
451.IX Item "dl_find_symbol_anywhere()"
452Syntax:
453.Sp
454.Vb 1
455\& $symref = dl_find_symbol_anywhere($symbol)
456.Ve
457.Sp
458Applies \fIdl_find_symbol()\fR to the members of \f(CW@dl_librefs\fR and returns
459the first match found.
460.IP "\fIdl_undef_symbols()\fR" 4
461.IX Item "dl_undef_symbols()"
462Example
463.Sp
464.Vb 1
465\& @symbols = dl_undef_symbols()
466.Ve
467.Sp
468Return a list of symbol names which remain undefined after \fIload_file()\fR.
469Returns \f(CW\*(C`()\*(C'\fR if not known. Don't worry if your platform does not provide
470a mechanism for this. Most do not need it and hence do not provide it,
471they just return an empty list.
472.IP "\fIdl_install_xsub()\fR" 4
473.IX Item "dl_install_xsub()"
474Syntax:
475.Sp
476.Vb 1
477\& dl_install_xsub($perl_name, $symref [, $filename])
478.Ve
479.Sp
480Create a new Perl external subroutine named \f(CW$perl_name\fR using \f(CW$symref\fR as
481a pointer to the function which implements the routine. This is simply
482a direct call to \fInewXSUB()\fR. Returns a reference to the installed
483function.
484.Sp
485The \f(CW$filename\fR parameter is used by Perl to identify the source file for
486the function if required by \fIdie()\fR, \fIcaller()\fR or the debugger. If
487\&\f(CW$filename\fR is not defined then \*(L"DynaLoader\*(R" will be used.
488.IP "\fIbootstrap()\fR" 4
489.IX Item "bootstrap()"
490Syntax:
491.Sp
492bootstrap($module)
493.Sp
494This is the normal entry point for automatic dynamic loading in Perl.
495.Sp
496It performs the following actions:
497.RS 4
498.IP "\(bu" 8
499locates an auto/$module directory by searching \f(CW@INC\fR
500.IP "\(bu" 8
501uses \fIdl_findfile()\fR to determine the filename to load
502.IP "\(bu" 8
503sets \f(CW@dl_require_symbols\fR to \f(CW\*(C`("boot_$module")\*(C'\fR
504.IP "\(bu" 8
505executes an \fIauto/$module/$module.bs\fR file if it exists
506(typically used to add to \f(CW@dl_resolve_using\fR any files which
507are required to load the module on the current platform)
508.IP "\(bu" 8
509calls \fIdl_load_flags()\fR to determine how to load the file.
510.IP "\(bu" 8
511calls \fIdl_load_file()\fR to load the file
512.IP "\(bu" 8
513calls \fIdl_undef_symbols()\fR and warns if any symbols are undefined
514.IP "\(bu" 8
515calls \fIdl_find_symbol()\fR for \*(L"boot_$module\*(R"
516.IP "\(bu" 8
517calls \fIdl_install_xsub()\fR to install it as \*(L"${module}::bootstrap\*(R"
518.IP "\(bu" 8
519calls &{\*(L"${module}::bootstrap\*(R"} to bootstrap the module (actually
520it uses the function reference returned by dl_install_xsub for speed)
521.RE
522.RS 4
523.RE
524.SH "AUTHOR"
525.IX Header "AUTHOR"
526Tim Bunce, 11 August 1994.
527.PP
528This interface is based on the work and comments of (in no particular
529order): Larry Wall, Robert Sanders, Dean Roehrich, Jeff Okamoto, Anno
530Siegel, Thomas Neumann, Paul Marquess, Charles Bailey, myself and others.
531.PP
532Larry Wall designed the elegant inherited bootstrap mechanism and
533implemented the first Perl 5 dynamic loader using it.
534.PP
535Solaris global loading added by Nick Ing-Simmons with design/coding
536assistance from Tim Bunce, January 1996.