Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / man / man3 / DynaLoader.3
CommitLineData
920dae64
AT
1.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32
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 "2001-09-21" "perl v5.8.8" "Perl Programmers Reference Guide"
133.SH "NAME"
134DynaLoader \- Dynamically load C libraries into Perl code
135.SH "SYNOPSIS"
136.IX Header "SYNOPSIS"
137.Vb 4
138\& package YourPackage;
139\& require DynaLoader;
140\& @ISA = qw(... DynaLoader ...);
141\& bootstrap YourPackage;
142.Ve
143.PP
144.Vb 2
145\& # optional method for 'global' loading
146\& sub dl_load_flags { 0x01 }
147.Ve
148.SH "DESCRIPTION"
149.IX Header "DESCRIPTION"
150This document defines a standard generic interface to the dynamic
151linking mechanisms available on many platforms. Its primary purpose is
152to implement automatic dynamic loading of Perl modules.
153.PP
154This document serves as both a specification for anyone wishing to
155implement the DynaLoader for a new platform and as a guide for
156anyone wishing to use the DynaLoader directly in an application.
157.PP
158The DynaLoader is designed to be a very simple high-level
159interface that is sufficiently general to cover the requirements
160of SunOS, \s-1HP\-UX\s0, NeXT, Linux, \s-1VMS\s0 and other platforms.
161.PP
162It is also hoped that the interface will cover the needs of \s-1OS/2\s0, \s-1NT\s0
163etc and also allow pseudo-dynamic linking (using \f(CW\*(C`ld \-A\*(C'\fR at runtime).
164.PP
165It must be stressed that the DynaLoader, by itself, is practically
166useless for accessing non-Perl libraries because it provides almost no
167Perl-to-C 'glue'. There is, for example, no mechanism for calling a C
168library function or supplying arguments. A C::DynaLib module
169is available from \s-1CPAN\s0 sites which performs that function for some
170common system types. And since the year 2000, there's also Inline::C,
171a module that allows you to write Perl subroutines in C. Also available
172from your local \s-1CPAN\s0 site.
173.PP
174DynaLoader Interface Summary
175.PP
176.Vb 12
177\& @dl_library_path
178\& @dl_resolve_using
179\& @dl_require_symbols
180\& $dl_debug
181\& @dl_librefs
182\& @dl_modules
183\& @dl_shared_objects
184\& Implemented in:
185\& bootstrap($modulename) Perl
186\& @filepaths = dl_findfile(@names) Perl
187\& $flags = $modulename->dl_load_flags Perl
188\& $symref = dl_find_symbol_anywhere($symbol) Perl
189.Ve
190.PP
191.Vb 6
192\& $libref = dl_load_file($filename, $flags) C
193\& $status = dl_unload_file($libref) C
194\& $symref = dl_find_symbol($libref, $symbol) C
195\& @symbols = dl_undef_symbols() C
196\& dl_install_xsub($name, $symref [, $filename]) C
197\& $message = dl_error C
198.Ve
199.IP "@dl_library_path" 4
200.IX Item "@dl_library_path"
201The standard/default list of directories in which \fIdl_findfile()\fR will
202search for libraries etc. Directories are searched in order:
203\&\f(CW$dl_library_path\fR[0], [1], ... etc
204.Sp
205@dl_library_path is initialised to hold the list of 'normal' directories
206(\fI/usr/lib\fR, etc) determined by \fBConfigure\fR (\f(CW$Config{'libpth'}\fR). This should
207ensure portability across a wide range of platforms.
208.Sp
209@dl_library_path should also be initialised with any other directories
210that can be determined from the environment at runtime (such as
211\&\s-1LD_LIBRARY_PATH\s0 for SunOS).
212.Sp
213After initialisation \f(CW@dl_library_path\fR can be manipulated by an
214application using push and unshift before calling \fIdl_findfile()\fR.
215Unshift can be used to add directories to the front of the search order
216either to save search time or to override libraries with the same name
217in the 'normal' directories.
218.Sp
219The load function that \fIdl_load_file()\fR calls may require an absolute
220pathname. The \fIdl_findfile()\fR function and \f(CW@dl_library_path\fR can be
221used to search for and return the absolute pathname for the
222library/object that you wish to load.
223.IP "@dl_resolve_using" 4
224.IX Item "@dl_resolve_using"
225A list of additional libraries or other shared objects which can be
226used to resolve any undefined symbols that might be generated by a
227later call to \fIload_file()\fR.
228.Sp
229This is only required on some platforms which do not handle dependent
230libraries automatically. For example the Socket Perl extension
231library (\fIauto/Socket/Socket.so\fR) contains references to many socket
232functions which need to be resolved when it's loaded. Most platforms
233will automatically know where to find the 'dependent' library (e.g.,
234\&\fI/usr/lib/libsocket.so\fR). A few platforms need to be told the
235location of the dependent library explicitly. Use \f(CW@dl_resolve_using\fR
236for this.
237.Sp
238Example usage:
239.Sp
240.Vb 1
241\& @dl_resolve_using = dl_findfile('-lsocket');
242.Ve
243.IP "@dl_require_symbols" 4
244.IX Item "@dl_require_symbols"
245A list of one or more symbol names that are in the library/object file
246to be dynamically loaded. This is only required on some platforms.
247.IP "@dl_librefs" 4
248.IX Item "@dl_librefs"
249An array of the handles returned by successful calls to \fIdl_load_file()\fR,
250made by bootstrap, in the order in which they were loaded.
251Can be used with \fIdl_find_symbol()\fR to look for a symbol in any of
252the loaded files.
253.IP "@dl_modules" 4
254.IX Item "@dl_modules"
255An array of module (package) names that have been bootstrap'ed.
256.IP "@dl_shared_objects" 4
257.IX Item "@dl_shared_objects"
258An array of file names for the shared objects that were loaded.
259.IP "\fIdl_error()\fR" 4
260.IX Item "dl_error()"
261Syntax:
262.Sp
263.Vb 1
264\& $message = dl_error();
265.Ve
266.Sp
267Error message text from the last failed DynaLoader function. Note
268that, similar to errno in unix, a successful function call does not
269reset this message.
270.Sp
271Implementations should detect the error as soon as it occurs in any of
272the other functions and save the corresponding message for later
273retrieval. This will avoid problems on some platforms (such as SunOS)
274where the error message is very temporary (e.g., \fIdlerror()\fR).
275.IP "$dl_debug" 4
276.IX Item "$dl_debug"
277Internal debugging messages are enabled when \f(CW$dl_debug\fR is set true.
278Currently setting \f(CW$dl_debug\fR only affects the Perl side of the
279DynaLoader. These messages should help an application developer to
280resolve any DynaLoader usage problems.
281.Sp
282$dl_debug is set to \f(CW$ENV{'PERL_DL_DEBUG'}\fR if defined.
283.Sp
284For the DynaLoader developer/porter there is a similar debugging
285variable added to the C code (see dlutils.c) and enabled if Perl was
286built with the \fB\-DDEBUGGING\fR flag. This can also be set via the
287\&\s-1PERL_DL_DEBUG\s0 environment variable. Set to 1 for minimal information or
288higher for more.
289.IP "\fIdl_findfile()\fR" 4
290.IX Item "dl_findfile()"
291Syntax:
292.Sp
293.Vb 1
294\& @filepaths = dl_findfile(@names)
295.Ve
296.Sp
297Determine the full paths (including file suffix) of one or more
298loadable files given their generic names and optionally one or more
299directories. Searches directories in \f(CW@dl_library_path\fR by default and
300returns an empty list if no files were found.
301.Sp
302Names can be specified in a variety of platform independent forms. Any
303names in the form \fB\-lname\fR are converted into \fIlibname.*\fR, where \fI.*\fR is
304an appropriate suffix for the platform.
305.Sp
306If a name does not already have a suitable prefix and/or suffix then
307the corresponding file will be searched for by trying combinations of
308prefix and suffix appropriate to the platform: \*(L"$name.o\*(R", \*(L"lib$name.*\*(R"
309and \*(L"$name\*(R".
310.Sp
311If any directories are included in \f(CW@names\fR they are searched before
312\&\f(CW@dl_library_path\fR. Directories may be specified as \fB\-Ldir\fR. Any other
313names are treated as filenames to be searched for.
314.Sp
315Using arguments of the form \f(CW\*(C`\-Ldir\*(C'\fR and \f(CW\*(C`\-lname\*(C'\fR is recommended.
316.Sp
317Example:
318.Sp
319.Vb 1
320\& @dl_resolve_using = dl_findfile(qw(-L/usr/5lib -lposix));
321.Ve
322.IP "\fIdl_expandspec()\fR" 4
323.IX Item "dl_expandspec()"
324Syntax:
325.Sp
326.Vb 1
327\& $filepath = dl_expandspec($spec)
328.Ve
329.Sp
330Some unusual systems, such as \s-1VMS\s0, require special filename handling in
331order to deal with symbolic names for files (i.e., \s-1VMS\s0's Logical Names).
332.Sp
333To support these systems a \fIdl_expandspec()\fR function can be implemented
334either in the \fIdl_*.xs\fR file or code can be added to the autoloadable
335\&\fIdl_expandspec()\fR function in \fIDynaLoader.pm\fR. See \fIDynaLoader.pm\fR for
336more information.
337.IP "\fIdl_load_file()\fR" 4
338.IX Item "dl_load_file()"
339Syntax:
340.Sp
341.Vb 1
342\& $libref = dl_load_file($filename, $flags)
343.Ve
344.Sp
345Dynamically load \f(CW$filename\fR, which must be the path to a shared object
346or library. An opaque 'library reference' is returned as a handle for
347the loaded object. Returns undef on error.
348.Sp
349The \f(CW$flags\fR argument to alters dl_load_file behaviour.
350Assigned bits:
351.Sp
352.Vb 3
353\& 0x01 make symbols available for linking later dl_load_file's.
354\& (only known to work on Solaris 2 using dlopen(RTLD_GLOBAL))
355\& (ignored under VMS; this is a normal part of image linking)
356.Ve
357.Sp
358(On systems that provide a handle for the loaded object such as SunOS
359and \s-1HPUX\s0, \f(CW$libref\fR will be that handle. On other systems \f(CW$libref\fR will
360typically be \f(CW$filename\fR or a pointer to a buffer containing \f(CW$filename\fR.
361The application should not examine or alter \f(CW$libref\fR in any way.)
362.Sp
363This is the function that does the real work. It should use the
364current values of \f(CW@dl_require_symbols\fR and \f(CW@dl_resolve_using\fR if required.
365.Sp
366.Vb 5
367\& SunOS: dlopen($filename)
368\& HP-UX: shl_load($filename)
369\& Linux: dld_create_reference(@dl_require_symbols); dld_link($filename)
370\& NeXT: rld_load($filename, @dl_resolve_using)
371\& VMS: lib$find_image_symbol($filename,$dl_require_symbols[0])
372.Ve
373.Sp
374(The \fIdlopen()\fR function is also used by Solaris and some versions of
375Linux, and is a common choice when providing a \*(L"wrapper\*(R" on other
376mechanisms as is done in the \s-1OS/2\s0 port.)
377.IP "\fIdl_unload_file()\fR" 4
378.IX Item "dl_unload_file()"
379Syntax:
380.Sp
381.Vb 1
382\& $status = dl_unload_file($libref)
383.Ve
384.Sp
385Dynamically unload \f(CW$libref\fR, which must be an opaque 'library reference' as
386returned from dl_load_file. Returns one on success and zero on failure.
387.Sp
388This function is optional and may not necessarily be provided on all platforms.
389If it is defined, it is called automatically when the interpreter exits for
390every shared object or library loaded by DynaLoader::bootstrap. All such
391library references are stored in \f(CW@dl_librefs\fR by DynaLoader::Bootstrap as it
392loads the libraries. The files are unloaded in last\-in, first-out order.
393.Sp
394This unloading is usually necessary when embedding a shared-object perl (e.g.
395one configured with \-Duseshrplib) within a larger application, and the perl
396interpreter is created and destroyed several times within the lifetime of the
397application. In this case it is possible that the system dynamic linker will
398unload and then subsequently reload the shared libperl without relocating any
399references to it from any files DynaLoaded by the previous incarnation of the
400interpreter. As a result, any shared objects opened by DynaLoader may point to
401a now invalid 'ghost' of the libperl shared object, causing apparently random
402memory corruption and crashes. This behaviour is most commonly seen when using
403Apache and mod_perl built with the \s-1APXS\s0 mechanism.
404.Sp
405.Vb 5
406\& SunOS: dlclose($libref)
407\& HP-UX: ???
408\& Linux: ???
409\& NeXT: ???
410\& VMS: ???
411.Ve
412.Sp
413(The \fIdlclose()\fR function is also used by Solaris and some versions of
414Linux, and is a common choice when providing a \*(L"wrapper\*(R" on other
415mechanisms as is done in the \s-1OS/2\s0 port.)
416.IP "\fIdl_load_flags()\fR" 4
417.IX Item "dl_load_flags()"
418Syntax:
419.Sp
420.Vb 1
421\& $flags = dl_load_flags $modulename;
422.Ve
423.Sp
424Designed to be a method call, and to be overridden by a derived class
425(i.e. a class which has DynaLoader in its \f(CW@ISA\fR). The definition in
426DynaLoader itself returns 0, which produces standard behavior from
427\&\fIdl_load_file()\fR.
428.IP "\fIdl_find_symbol()\fR" 4
429.IX Item "dl_find_symbol()"
430Syntax:
431.Sp
432.Vb 1
433\& $symref = dl_find_symbol($libref, $symbol)
434.Ve
435.Sp
436Return the address of the symbol \f(CW$symbol\fR or \f(CW\*(C`undef\*(C'\fR if not found. If the
437target system has separate functions to search for symbols of different
438types then \fIdl_find_symbol()\fR should search for function symbols first and
439then other types.
440.Sp
441The exact manner in which the address is returned in \f(CW$symref\fR is not
442currently defined. The only initial requirement is that \f(CW$symref\fR can
443be passed to, and understood by, \fIdl_install_xsub()\fR.
444.Sp
445.Vb 5
446\& SunOS: dlsym($libref, $symbol)
447\& HP-UX: shl_findsym($libref, $symbol)
448\& Linux: dld_get_func($symbol) and/or dld_get_symbol($symbol)
449\& NeXT: rld_lookup("_$symbol")
450\& VMS: lib$find_image_symbol($libref,$symbol)
451.Ve
452.IP "\fIdl_find_symbol_anywhere()\fR" 4
453.IX Item "dl_find_symbol_anywhere()"
454Syntax:
455.Sp
456.Vb 1
457\& $symref = dl_find_symbol_anywhere($symbol)
458.Ve
459.Sp
460Applies \fIdl_find_symbol()\fR to the members of \f(CW@dl_librefs\fR and returns
461the first match found.
462.IP "\fIdl_undef_symbols()\fR" 4
463.IX Item "dl_undef_symbols()"
464Example
465.Sp
466.Vb 1
467\& @symbols = dl_undef_symbols()
468.Ve
469.Sp
470Return a list of symbol names which remain undefined after \fIload_file()\fR.
471Returns \f(CW\*(C`()\*(C'\fR if not known. Don't worry if your platform does not provide
472a mechanism for this. Most do not need it and hence do not provide it,
473they just return an empty list.
474.IP "\fIdl_install_xsub()\fR" 4
475.IX Item "dl_install_xsub()"
476Syntax:
477.Sp
478.Vb 1
479\& dl_install_xsub($perl_name, $symref [, $filename])
480.Ve
481.Sp
482Create a new Perl external subroutine named \f(CW$perl_name\fR using \f(CW$symref\fR as
483a pointer to the function which implements the routine. This is simply
484a direct call to \fInewXSUB()\fR. Returns a reference to the installed
485function.
486.Sp
487The \f(CW$filename\fR parameter is used by Perl to identify the source file for
488the function if required by \fIdie()\fR, \fIcaller()\fR or the debugger. If
489\&\f(CW$filename\fR is not defined then \*(L"DynaLoader\*(R" will be used.
490.IP "\fIbootstrap()\fR" 4
491.IX Item "bootstrap()"
492Syntax:
493.Sp
494bootstrap($module)
495.Sp
496This is the normal entry point for automatic dynamic loading in Perl.
497.Sp
498It performs the following actions:
499.RS 4
500.IP "*" 8
501locates an auto/$module directory by searching \f(CW@INC\fR
502.IP "*" 8
503uses \fIdl_findfile()\fR to determine the filename to load
504.IP "*" 8
505sets \f(CW@dl_require_symbols\fR to \f(CW\*(C`("boot_$module")\*(C'\fR
506.IP "*" 8
507executes an \fIauto/$module/$module.bs\fR file if it exists
508(typically used to add to \f(CW@dl_resolve_using\fR any files which
509are required to load the module on the current platform)
510.IP "*" 8
511calls \fIdl_load_flags()\fR to determine how to load the file.
512.IP "*" 8
513calls \fIdl_load_file()\fR to load the file
514.IP "*" 8
515calls \fIdl_undef_symbols()\fR and warns if any symbols are undefined
516.IP "*" 8
517calls \fIdl_find_symbol()\fR for \*(L"boot_$module\*(R"
518.IP "*" 8
519calls \fIdl_install_xsub()\fR to install it as \*(L"${module}::bootstrap\*(R"
520.IP "*" 8
521calls &{\*(L"${module}::bootstrap\*(R"} to bootstrap the module (actually
522it uses the function reference returned by dl_install_xsub for speed)
523.RE
524.RS 4
525.RE
526.SH "AUTHOR"
527.IX Header "AUTHOR"
528Tim Bunce, 11 August 1994.
529.PP
530This interface is based on the work and comments of (in no particular
531order): Larry Wall, Robert Sanders, Dean Roehrich, Jeff Okamoto, Anno
532Siegel, Thomas Neumann, Paul Marquess, Charles Bailey, myself and others.
533.PP
534Larry Wall designed the elegant inherited bootstrap mechanism and
535implemented the first Perl 5 dynamic loader using it.
536.PP
537Solaris global loading added by Nick Ing-Simmons with design/coding
538assistance from Tim Bunce, January 1996.