Commit | Line | Data |
---|---|---|
959f3c4c JH |
1 | ?RCS: $Id: d_dlsymun.U,v $ |
2 | ?RCS: | |
3 | ?RCS: Copyright (c) 1996-1998, Andy Dougherty | |
4 | ?RCS: | |
5 | ?RCS: You may distribute under the terms of either the GNU General Public | |
6 | ?RCS: License or the Artistic License, as specified in the README file. | |
7 | ?RCS: | |
8 | ?RCS: $Log: d_dlsymun.U,v $ | |
9 | ?RCS: | |
10 | ?RCS: | |
11 | ?MAKE:d_dlsymun: cat cc ccflags ldflags ld rm Setvar dlsrc i_dlfcn \ | |
12 | cccdlflags ccdlflags lddlflags libs dlext _o | |
13 | ?MAKE: -pick add $@ %< | |
14 | ?X: This is specific to perl5. | |
15 | ?S:d_dlsymun: | |
16 | ?S: This variable conditionally defines DLSYM_NEEDS_UNDERSCORE, which | |
17 | ?S: indicates that we need to prepend an underscore to the symbol | |
18 | ?S: name before calling dlsym(). | |
19 | ?S:. | |
20 | ?C:DLSYM_NEEDS_UNDERSCORE: | |
21 | ?C: This symbol, if defined, indicates that we need to prepend an | |
22 | ?C: underscore to the symbol name before calling dlsym(). This only | |
23 | ?C: makes sense if you *have* dlsym, which we will presume is the | |
24 | ?C: case if you're using dl_dlopen.xs. | |
25 | ?C:. | |
26 | ?H:#$d_dlsymun DLSYM_NEEDS_UNDERSCORE /**/ | |
27 | ?H:. | |
28 | ?F: !fred | |
29 | ?LINT:set d_dlsymun | |
30 | ?T: xxx | |
31 | : Check if dlsym need a leading underscore | |
32 | echo " " | |
33 | val="$undef" | |
34 | ||
35 | case "$dlsrc" in | |
36 | dl_dlopen.xs) | |
37 | echo "Checking whether your dlsym() needs a leading underscore ..." >&4 | |
38 | $cat >dyna.c <<'EOM' | |
39 | fred () { } | |
40 | EOM | |
41 | ||
42 | $cat >fred.c<<EOM | |
43 | ||
44 | #include <stdio.h> | |
45 | #$i_dlfcn I_DLFCN | |
46 | #ifdef I_DLFCN | |
47 | #include <dlfcn.h> /* the dynamic linker include file for Sunos/Solaris */ | |
48 | #else | |
49 | #include <sys/types.h> | |
50 | #include <nlist.h> | |
51 | #include <link.h> | |
52 | #endif | |
53 | ||
54 | extern int fred() ; | |
55 | ||
56 | int main() | |
57 | { | |
58 | void * handle ; | |
59 | void * symbol ; | |
60 | #ifndef RTLD_LAZY | |
61 | int mode = 1 ; | |
62 | #else | |
63 | int mode = RTLD_LAZY ; | |
64 | #endif | |
65 | handle = dlopen("./dyna.$dlext", mode) ; | |
66 | if (handle == NULL) { | |
67 | printf ("1\n") ; | |
68 | fflush (stdout) ; | |
69 | exit(0); | |
70 | } | |
71 | symbol = dlsym(handle, "fred") ; | |
72 | if (symbol == NULL) { | |
73 | /* try putting a leading underscore */ | |
74 | symbol = dlsym(handle, "_fred") ; | |
75 | if (symbol == NULL) { | |
76 | printf ("2\n") ; | |
77 | fflush (stdout) ; | |
78 | exit(0); | |
79 | } | |
80 | printf ("3\n") ; | |
81 | } | |
82 | else | |
83 | printf ("4\n") ; | |
84 | fflush (stdout) ; | |
85 | exit(0); | |
86 | } | |
87 | EOM | |
88 | : Call the object file tmp-dyna.o in case dlext=o. | |
89 | if $cc $ccflags $cccdlflags -c dyna.c > /dev/null 2>&1 && | |
90 | mv dyna${_o} tmp-dyna${_o} > /dev/null 2>&1 && | |
ff19f974 JH |
91 | $ld -o dyna.$dlext $lddlflags tmp-dyna${_o} > /dev/null 2>&1 && |
92 | $cc -o fred $ccflags $ldflags $cccdlflags $ccdlflags fred.c $libs > /dev/null 2>&1; then | |
959f3c4c JH |
93 | xxx=`./fred` |
94 | case $xxx in | |
95 | 1) echo "Test program failed using dlopen." >&4 | |
96 | echo "Perhaps you should not use dynamic loading." >&4;; | |
97 | 2) echo "Test program failed using dlsym." >&4 | |
98 | echo "Perhaps you should not use dynamic loading." >&4;; | |
99 | 3) echo "dlsym needs a leading underscore" >&4 | |
100 | val="$define" ;; | |
101 | 4) echo "dlsym doesn't need a leading underscore." >&4;; | |
102 | esac | |
103 | else | |
104 | echo "I can't compile and run the test program." >&4 | |
9a9edc35 | 105 | echo "I'm guessing that dlsym doesn't need a leading underscore." >&4 |
959f3c4c JH |
106 | fi |
107 | ;; | |
108 | esac | |
109 | ||
110 | $rm -f fred fred.? dyna.$dlext dyna.? tmp-dyna.? | |
111 | ||
112 | set d_dlsymun | |
113 | eval $setvar | |
114 |