0.8.8.23:
[sbcl/lichteblau.git] / tools-for-build / ldso-stubs.lisp
blob00cc8de958e754dd0941c0f357e3d223f90bfd4b
1 ;;;; Generate stubs for C-linkage library functions which we need to refer to
2 ;;;; from Lisp.
3 ;;;;
4 ;;;; (But note this is only the Linux version, as per the FIXME
5 ;;;; note in the BSD version in undefineds.h.)
6 ;;;;
7 ;;;; These stubs exist for the benefit of Lisp code that needs to refer
8 ;;;; to foreign symbols when dlsym() is not available (i.e. when dumping
9 ;;;; cold-sbcl.core, when we may be running in a host that's not SBCL,
10 ;;;; or on platforms that don't have it at all). If the runtime is
11 ;;;; dynamically linked, library functions won't be linked into it, so
12 ;;;; the map file won't show them. So, we need a bunch of stubs that
13 ;;;; nm(1) _can_ see.
14 ;;;;
15 ;;;; This software is part of the SBCL system. See the README file for
16 ;;;; more information.
17 ;;;;
18 ;;;; This software is derived from the CMU CL system, which was
19 ;;;; written at Carnegie Mellon University and released into the
20 ;;;; public domain. The software is in the public domain and is
21 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
22 ;;;; files for more information.
24 #!-sparc
25 (defun ldso-stubify (fct str)
26 (format str "LDSO_STUBIFY(~A)~%" fct))
28 ;;; This is an attempt to follow DB's hint of sbcl-devel
29 ;;; 2001-09-18. -- CSR
30 ;;;
31 ;;; And an attempt to work around the Sun toolchain... --ns
32 #!+sparc
33 (defun ldso-stubify (fct str)
34 (apply #'format str "
35 .globl ldso_stub__~A ; \\
36 FUNCDEF(ldso_stub__~A) ; \\
37 ldso_stub__~A: ; \\
38 sethi %hi(~A),%g1 ; \\
39 jmpl %g1+%lo(~A),%g0 ; \\
40 nop /* delay slot*/ ; \\
41 .L~Ae1: ; \\
42 .size ldso_stub__~A,.L~Ae1-ldso_stub__~A ;~%"
43 (make-list 9 :initial-element fct)))
45 (defvar *preludes* '("
46 /* This is an automatically generated file, please do not hand-edit it.
47 * See the program tools-for-build/ldso-stubs.lisp. */
49 #define LANGUAGE_ASSEMBLY
50 #include \"sbcl.h\""
52 #!+sparc "
53 #ifdef LISP_FEATURE_SPARC
54 #include \"sparc-funcdef.h\"
55 #endif
56 .text"
58 #!+x86 "
59 #define LDSO_STUBIFY(fct) \\
60 .align 16 ; \\
61 .globl ldso_stub__ ## fct ; \\
62 .type ldso_stub__ ## fct,@function ; \\
63 ldso_stub__ ## fct: ; \\
64 jmp fct ; \\
65 .L ## fct ## e1: ; \\
66 .size ldso_stub__ ## fct,.L ## fct ## e1-ldso_stub__ ## fct ;"
68 ;;; osf1 has ancient cpp that doesn't do ##
69 #!+(and osf1 alpha) "
70 #define LDSO_STUBIFY(fct) \\
71 .globl ldso_stub__/**/fct ; \\
72 ldso_stub__/**/fct: ; \\
73 jmp fct ; \\
74 .L/**/fct/**/e1: ;"
76 ;;; but there's no reason we need to put up with that on modern (Linux) OSes
77 #!+(and linux alpha) "
78 #define LDSO_STUBIFY(fct) \\
79 .globl ldso_stub__ ## fct ; \\
80 .type ldso_stub__ ## fct,@function ; \\
81 ldso_stub__ ## fct: ; \\
82 jmp fct ; \\
83 .L ## fct ## e1: ; \\
84 .size ldso_stub__ ## fct,.L ## fct ## e1-ldso_stub__ ## fct ;"
86 #!+(and linux ppc) "
87 #define LDSO_STUBIFY(fct) \\
88 .globl ldso_stub__ ## fct ; \\
89 .type ldso_stub__ ## fct,@function ; \\
90 ldso_stub__ ## fct: ; \\
91 b fct ; \\
92 .L ## fct ## e1: ; \\
93 .size ldso_stub__ ## fct,.L ## fct ## e1-ldso_stub__ ## fct ;"
95 #!+(and darwin ppc) "
96 #define LDSO_STUBIFY(fct) @\\
97 .text @\\
98 .globl ldso_stub___ ## fct @\\
99 ldso_stub___ ## fct: @\\
100 b ldso_stub__ ## fct ## stub @\\
101 .symbol_stub ldso_stub__ ## fct ## stub: @\\
102 .indirect_symbol _ ## fct @\\
103 lis r11,ha16(ldso_stub__ ## fct ## $lazy_ptr) @\\
104 lwz r12,lo16(ldso_stub__ ## fct ## $lazy_ptr)(r11) @\\
105 mtctr r12 @\\
106 addi r11,r11,lo16(ldso_stub__ ## fct ## $lazy_ptr) @\\
107 bctr @\\
108 .lazy_symbol_pointer @\\
109 ldso_stub__ ## fct ## $lazy_ptr: @\\
110 .indirect_symbol _ ## fct @\\
111 .long dyld_stub_binding_helper"
113 ;;; KLUDGE: set up the vital fifth argument, passed on the
114 ;;; stack. Do this unconditionally, even if the stub is for a
115 ;;; function with few arguments: it can't hurt. We only do this for
116 ;;; the fifth argument, as the first four are passed in registers
117 ;;; and we apparently don't ever need to pass six arguments to a
118 ;;; libc function. -- CSR, 2003-10-29
119 #!+mips "
120 #define LDSO_STUBIFY(fct) \\
121 .globl ldso_stub__ ## fct ; \\
122 .type ldso_stub__ ## fct,@function ; \\
123 ldso_stub__ ## fct: ; \\
124 addiu $29,-48 ; \\
125 sw $28,40($29) ; \\
126 sw $31,44($29) ; \\
127 lw $25,64($29) ; \\
128 sw $25,16($29) ; \\
129 la $25, fct ; \\
130 jalr $25 ; \\
131 lw $31,44($29) ; \\
132 lw $28,40($29) ; \\
133 addiu $29,48 ; \\
134 jr $31 ; \\
135 .L ## fct ## e1: ; \\
136 .size ldso_stub__ ## fct,.L ## fct ## e1-ldso_stub__ ## fct ;"))
138 (defvar *stubs* (append
139 '("accept"
140 "access"
141 "acos"
142 "acosh"
143 "asin"
144 "asinh"
145 "atanh"
146 "bind"
147 "cfgetispeed"
148 "cfgetospeed"
149 "cfsetispeed"
150 "cfsetospeed"
151 "chmod"
152 "chown"
153 "close"
154 "closedir"
155 "connect"
156 "cosh"
157 "creat"
158 "dup"
159 "dup2"
160 "execve"
161 "exit"
162 "fchmod"
163 "fchown"
164 "fcntl"
165 "fork"
166 "free"
167 "fstat"
168 "fsync"
169 "ftruncate"
170 "getcwd"
171 "getdtablesize"
172 "getegid"
173 "getenv"
174 "getgid"
175 "gethostbyaddr"
176 "gethostbyname"
177 "gethostname"
178 "getitimer"
179 "getpagesize"
180 "getpeername"
181 "getpgrp"
182 "getpid"
183 "getppid"
184 "getrusage"
185 "getsockname"
186 "gettimeofday"
187 "getuid"
188 "hypot"
189 "ioctl"
190 "isatty"
191 "kill"
192 "killpg"
193 "link"
194 "listen"
195 "log1p"
196 "lseek"
197 "lstat"
198 "malloc"
199 "memmove"
200 "mkdir"
201 "open"
202 "opendir"
203 "pipe"
204 "pow"
205 "read"
206 "readdir"
207 "readlink"
208 "recv"
209 "rename"
210 "rmdir"
211 "select"
212 "send"
213 "setitimer"
214 "setpgrp"
215 "setsid"
216 "sinh"
217 "socket"
218 "stat"
219 "strerror"
220 "strlen"
221 "symlink"
222 "sync"
223 "tanh"
224 "tcdrain"
225 "tcflow"
226 "tcflush"
227 "tcgetattr"
228 "tcsendbreak"
229 "tcsetattr"
230 "truncate"
231 "ttyname"
232 "tzname"
233 "unlink"
234 "utimes"
235 "wait3"
236 "write")
237 ;; These aren't needed on the X86 because they're microcoded into the
238 ;; FPU, so the Lisp VOPs can implement them directly without having to
239 ;; call C code.
241 ;; Note: There might be some other functions in this category as well.
242 ;; E.g. I notice tanh() and acos() in the list above.. -- WHN 2001-06-07
243 #!-x86
244 '("sin"
245 "cos"
246 "tan"
247 "atan"
248 "atan2"
249 "exp"
250 "log"
251 "log10"
252 "sqrt")
253 #!+alpha
254 '("ieee_get_fp_control"
255 "ieee_set_fp_control")
256 #!-darwin
257 '("dlclose"
258 "dlerror"
259 "dlopen"
260 "dlsym")
261 #!-(and sparc sunos) ;; !defined(SVR4)
262 '("sigsetmask")))
264 (with-open-file (f "src/runtime/ldso-stubs.S" :direction :output :if-exists :supersede)
265 (assert (= (length *preludes*) 2))
266 (dolist (pre *preludes*)
267 (write-line pre f))
268 (dolist (stub *stubs*)
269 (check-type stub string)
270 (ldso-stubify stub f)))