runtime/arm-arch.h: Define alien stack growth direction.
[sbcl/nyef.git] / tools-for-build / ldso-stubs.lisp
blobf9d037bdab0338e14a3311100a369645b45b340a
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 stream)
26 (format stream "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 stream)
34 (apply #'format stream "
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 #!+hppa
46 (defun ldso-stubify (fct stream)
47 (let ((stub (format nil "ldso_stub__~a" fct)))
48 (apply #'format stream (list
49 " .export ~A
50 ~A:
51 .proc
52 .callinfo
53 b,n ~a
54 .procend
55 .import ~a,code~%" stub stub fct fct))))
57 (defvar *preludes* '("
58 /* This is an automatically generated file, please do not hand-edit it.
59 * See the program tools-for-build/ldso-stubs.lisp. */
61 #ifndef LANGUAGE_ASSEMBLY
62 #define LANGUAGE_ASSEMBLY
63 #endif
64 #include \"sbcl.h\""
66 #!+arm "
67 #define LDSO_STUBIFY(fct) \\
68 .align ; \\
69 .global ldso_stub__ ## fct ; \\
70 .type ldso_stub__ ## fct, %function ; \\
71 ldso_stub__ ## fct: ; \\
72 ldr r8, =fct ; \\
73 bx r8 ; \\
74 .size ldso_stub__ ## fct, .-ldso_stub__ ## fct"
76 #!+sparc "
77 #ifdef LISP_FEATURE_SPARC
78 #include \"sparc-funcdef.h\"
79 #endif
80 .text"
82 #!+(and (or x86 x86-64) (not darwin)) "
83 #define LDSO_STUBIFY(fct) \\
84 .align 16 ; \\
85 .globl ldso_stub__ ## fct ; \\
86 .type ldso_stub__ ## fct,@function ; \\
87 ldso_stub__ ## fct: ; \\
88 jmp fct ; \\
89 .L ## fct ## e1: ; \\
90 .size ldso_stub__ ## fct,.L ## fct ## e1-ldso_stub__ ## fct ;"
92 ;;; osf1 has ancient cpp that doesn't do ##
93 #!+(and osf1 alpha) "
94 #define LDSO_STUBIFY(fct) \\
95 .globl ldso_stub__/**/fct ; \\
96 ldso_stub__/**/fct: ; \\
97 jmp fct ; \\
98 .L/**/fct/**/e1: ;"
100 ;;; but there's no reason we need to put up with that on modern (Linux) OSes
101 #!+(and linux alpha) "
102 #define LDSO_STUBIFY(fct) \\
103 .globl ldso_stub__ ## fct ; \\
104 .type ldso_stub__ ## fct,@function ; \\
105 ldso_stub__ ## fct: ; \\
106 jmp fct ; \\
107 .L ## fct ## e1: ; \\
108 .size ldso_stub__ ## fct,.L ## fct ## e1-ldso_stub__ ## fct ;"
110 #!+hppa "
111 .level 2.0
112 .text"
114 #!+(and (not darwin) ppc) "
115 #define LDSO_STUBIFY(fct) \\
116 .globl ldso_stub__ ## fct ; \\
117 .type ldso_stub__ ## fct,@function ; \\
118 ldso_stub__ ## fct: ; \\
119 b fct ; \\
120 .L ## fct ## e1: ; \\
121 .size ldso_stub__ ## fct,.L ## fct ## e1-ldso_stub__ ## fct ;"
123 #!+(and darwin ppc) "
124 #define LDSO_STUBIFY(fct) @\\
125 .text @\\
126 .globl _ldso_stub__ ## fct @\\
127 _ldso_stub__ ## fct: @\\
128 b _ldso_stub__ ## fct ## stub @\\
129 .symbol_stub _ldso_stub__ ## fct ## stub: @\\
130 .indirect_symbol _ ## fct @\\
131 lis r11,ha16(_ldso_stub__ ## fct ## $lazy_ptr) @\\
132 lwz r12,lo16(_ldso_stub__ ## fct ## $lazy_ptr)(r11) @\\
133 mtctr r12 @\\
134 addi r11,r11,lo16(_ldso_stub__ ## fct ## $lazy_ptr) @\\
135 bctr @\\
136 .lazy_symbol_pointer @\\
137 _ldso_stub__ ## fct ## $lazy_ptr: @\\
138 .indirect_symbol _ ## fct @\\
139 .long dyld_stub_binding_helper"
141 ;;; darwin x86 assembler is weird and follows the ppc assembler syntax
142 #!+(and darwin x86) "
143 #define LDSO_STUBIFY(fct) \\
144 .text ; \\
145 .align 4 ; \\
146 .globl _ldso_stub__ ## fct ; \\
147 _ldso_stub__ ## fct: ; \\
148 jmp L ## fct ## $stub ; \\
149 .section __IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5 ; \\
150 L ## fct ## $stub: ; \\
151 .indirect_symbol _ ## fct ; \\
152 hlt ; \\
153 hlt ; \\
154 hlt ; \\
155 hlt ; \\
156 hlt ; \\
157 .subsections_via_symbols ; "
159 ;;; darwin x86-64
160 #!+(and darwin x86-64) "
161 #define LDSO_STUBIFY(fct) \\
162 .align 4 ; \\
163 .globl _ldso_stub__ ## fct ; \\
164 _ldso_stub__ ## fct: ; \\
165 jmp _ ## fct ; \\
166 .L ## fct ## e1: ; "
168 ;;; KLUDGE: set up the vital fifth argument, passed on the
169 ;;; stack. Do this unconditionally, even if the stub is for a
170 ;;; function with few arguments: it can't hurt. We only do this for
171 ;;; the fifth argument, as the first four are passed in registers
172 ;;; and we apparently don't ever need to pass six arguments to a
173 ;;; libc function. -- CSR, 2003-10-29
174 ;;; Expanded to 8 arguments regardless. -- ths, 2005-03-24
175 #!+mips "
176 #define LDSO_STUBIFY(fct) \\
177 .globl ldso_stub__ ## fct ; \\
178 .type ldso_stub__ ## fct,@function ; \\
179 .ent ldso_stub__ ## fct ; \\
180 ldso_stub__ ## fct: ; \\
181 .set noat ; \\
182 addiu $29,-48 ; \\
183 sw $28,40($29) ; \\
184 sw $31,44($29) ; \\
185 lw $25,64($29) ; \\
186 lw $1,68($29) ; \\
187 sw $25,16($29) ; \\
188 sw $1,20($29) ; \\
189 lw $25,72($29) ; \\
190 lw $1,76($29) ; \\
191 sw $25,24($29) ; \\
192 sw $1,28($29) ; \\
193 .set at ; \\
194 la $25, fct ; \\
195 jalr $25 ; \\
196 lw $31,44($29) ; \\
197 lw $28,40($29) ; \\
198 addiu $29,48 ; \\
199 jr $31 ; \\
200 .end ldso_stub__ ## fct ; \\
201 .size ldso_stub__ ## fct,.-ldso_stub__ ## fct ;"))
203 (defvar *stubs* (append
204 '("_exit"
205 "accept"
206 "access"
207 "acos"
208 "acosh"
209 "asin"
210 "asinh"
211 "atanh"
212 "bind"
213 "cfgetispeed"
214 "cfgetospeed"
215 "cfsetispeed"
216 "cfsetospeed"
217 "chmod"
218 "chown"
219 "close"
220 "closedir"
221 "connect"
222 "cosh"
223 "creat"
224 "dup"
225 "dup2"
226 "execve"
227 "exit"
228 "fchmod"
229 "fchown"
230 "fcntl"
231 "fork"
232 "free"
233 "fstat"
234 #!+inode64 "fstat$INODE64"
235 "fsync"
236 "ftruncate"
237 "getcwd"
238 "getdtablesize"
239 "getegid"
240 "getenv"
241 "getgid"
242 "gethostbyaddr"
243 "gethostbyname"
244 "gethostname"
245 "getitimer"
246 "getpagesize"
247 "getpeername"
248 "getpgrp"
249 "getpid"
250 "getppid"
251 "getrusage"
252 "getsockname"
253 "gettimeofday"
254 "getuid"
255 "hypot"
256 "ioctl"
257 "isatty"
258 "kill"
259 "killpg"
260 "link"
261 "listen"
262 "log1p"
263 "lseek"
264 "lstat"
265 #!+inode64 "lstat$INODE64"
266 "malloc"
267 "memmove"
268 "mkdir"
269 "nanosleep"
270 "nl_langinfo"
271 "open"
272 "opendir"
273 "pipe"
274 "poll"
275 "pow"
276 "read"
277 "readdir"
278 "readlink"
279 "realpath"
280 "recv"
281 "rename"
282 "rmdir"
283 "select"
284 "send"
285 "setitimer"
286 "setpgrp"
287 "setsid"
288 "sinh"
289 "socket"
290 "stat"
291 #!+inode64 "stat$INODE64"
292 "strerror"
293 "strlen"
294 "symlink"
295 "sync"
296 "tanh"
297 "tcdrain"
298 "tcflow"
299 "tcflush"
300 "tcgetattr"
301 "tcsendbreak"
302 "tcsetattr"
303 "truncate"
304 "ttyname"
305 #!-hpux "tzname"
306 "unlink"
307 "utimes"
308 "wait3"
309 "waitpid"
310 "write")
311 ;; These aren't needed on the X86 because they're microcoded into the
312 ;; FPU, so the Lisp VOPs can implement them directly without having to
313 ;; call C code.
315 ;; Note: There might be some other functions in this category as well.
316 ;; E.g. I notice tanh() and acos() in the list above.. -- WHN 2001-06-07
317 #!-x86
318 '("sin"
319 "cos"
320 "tan"
321 "atan"
322 "atan2"
323 "exp"
324 "log"
325 "log10"
326 "sqrt")
327 #!+alpha
328 '("ieee_get_fp_control"
329 "ieee_set_fp_control")
330 ;; FIXME: After 1.0 this should be made
331 ;; #!-linkage-table, as we only need these stubs if
332 ;; we don't have linkage-table. Done this way now to
333 ;; cut down on the number of ports affected.
334 #!-(or win32 darwin freebsd netbsd openbsd)
335 '("ptsname"
336 "grantpt"
337 "unlockpt")
338 #!+(or openbsd freebsd)
339 '("openpty")
340 '("dlclose"
341 "dlerror"
342 "dlopen"
343 "dlsym")
344 #!+bsd
345 '("sysctl")
346 #!+darwin
347 '("sysctlbyname")
348 #!+os-provides-dladdr
349 '("dladdr")
350 #!-sunos ;; !defined(SVR4)
351 '("sigsetmask")))
353 (with-open-file (f "src/runtime/ldso-stubs.S" :direction :output :if-exists :supersede)
354 (assert (= (length *preludes*) 2))
355 (dolist (pre *preludes*)
356 (write-line pre f))
357 (dolist (stub *stubs*)
358 (check-type stub string)
359 (ldso-stubify stub f)))