1 ;;;; Generate stubs for C-linkage library functions which we need to refer to
4 ;;;; (But note this is only the Linux version, as per the FIXME
5 ;;;; note in the BSD version in undefineds.h.)
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
15 ;;;; This software is part of the SBCL system. See the README file for
16 ;;;; more information.
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.
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
31 ;;; And an attempt to work around the Sun toolchain... --ns
33 (defun ldso-stubify (fct stream
)
34 (apply #'format stream
"
35 .globl ldso_stub__~A ; \\
36 FUNCDEF(ldso_stub__~A) ; \\
38 sethi %hi(~A),%g1 ; \\
39 jmpl %g1+%lo(~A),%g0 ; \\
40 nop /* delay slot*/ ; \\
42 .size ldso_stub__~A,.L~Ae1-ldso_stub__~A ;~%"
43 (make-list 9 :initial-element fct
)))
46 (defun ldso-stubify (fct stream
)
47 (let ((stub (format nil
"ldso_stub__~a" fct
)))
48 (apply #'format stream
(list
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
67 #define LDSO_STUBIFY(fct) \\
69 .global ldso_stub__ ## fct ; \\
70 .type ldso_stub__ ## fct, %function ; \\
71 ldso_stub__ ## fct: ; \\
74 .size ldso_stub__ ## fct, .-ldso_stub__ ## fct"
76 #define LDSO_STUBIFY(fct) \\
78 .global ldso_stub__ ## fct ; \\
79 .type ldso_stub__ ## fct, %function ; \\
80 ldso_stub__ ## fct: ; \\
83 .size ldso_stub__ ## fct, .-ldso_stub__ ## fct"
86 #ifdef LISP_FEATURE_SPARC
87 #include \"sparc-funcdef.h\"
91 #!+(and (or x86 x86-64
) (not darwin
)) "
92 #define LDSO_STUBIFY(fct) \\
94 .globl ldso_stub__ ## fct ; \\
95 .type ldso_stub__ ## fct,@function ; \\
96 ldso_stub__ ## fct: ; \\
99 .size ldso_stub__ ## fct,.L ## fct ## e1-ldso_stub__ ## fct ;"
101 ;;; osf1 has ancient cpp that doesn't do ##
102 #!+(and osf1 alpha
) "
103 #define LDSO_STUBIFY(fct) \\
104 .globl ldso_stub__/**/fct ; \\
105 ldso_stub__/**/fct: ; \\
109 ;;; but there's no reason we need to put up with that on modern (Linux) OSes
110 #!+(and linux alpha
) "
111 #define LDSO_STUBIFY(fct) \\
112 .globl ldso_stub__ ## fct ; \\
113 .type ldso_stub__ ## fct,@function ; \\
114 ldso_stub__ ## fct: ; \\
116 .L ## fct ## e1: ; \\
117 .size ldso_stub__ ## fct,.L ## fct ## e1-ldso_stub__ ## fct ;"
123 #!+(and (not darwin
) ppc
) "
124 #define LDSO_STUBIFY(fct) \\
125 .globl ldso_stub__ ## fct ; \\
126 .type ldso_stub__ ## fct,@function ; \\
127 ldso_stub__ ## fct: ; \\
129 .L ## fct ## e1: ; \\
130 .size ldso_stub__ ## fct,.L ## fct ## e1-ldso_stub__ ## fct ;"
132 #!+(and darwin ppc
) "
133 #define LDSO_STUBIFY(fct) @\\
135 .globl _ldso_stub__ ## fct @\\
136 _ldso_stub__ ## fct: @\\
137 b _ldso_stub__ ## fct ## stub @\\
138 .symbol_stub _ldso_stub__ ## fct ## stub: @\\
139 .indirect_symbol _ ## fct @\\
140 lis r11,ha16(_ldso_stub__ ## fct ## $lazy_ptr) @\\
141 lwz r12,lo16(_ldso_stub__ ## fct ## $lazy_ptr)(r11) @\\
143 addi r11,r11,lo16(_ldso_stub__ ## fct ## $lazy_ptr) @\\
145 .lazy_symbol_pointer @\\
146 _ldso_stub__ ## fct ## $lazy_ptr: @\\
147 .indirect_symbol _ ## fct @\\
148 .long dyld_stub_binding_helper"
150 ;;; darwin x86 assembler is weird and follows the ppc assembler syntax
151 #!+(and darwin x86
) "
152 #define LDSO_STUBIFY(fct) \\
155 .globl _ldso_stub__ ## fct ; \\
156 _ldso_stub__ ## fct: ; \\
157 jmp L ## fct ## $stub ; \\
158 .section __IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5 ; \\
159 L ## fct ## $stub: ; \\
160 .indirect_symbol _ ## fct ; \\
166 .subsections_via_symbols ; "
169 #!+(and darwin x86-64
) "
170 #define LDSO_STUBIFY(fct) \\
172 .globl _ldso_stub__ ## fct ; \\
173 _ldso_stub__ ## fct: ; \\
177 ;;; KLUDGE: set up the vital fifth argument, passed on the
178 ;;; stack. Do this unconditionally, even if the stub is for a
179 ;;; function with few arguments: it can't hurt. We only do this for
180 ;;; the fifth argument, as the first four are passed in registers
181 ;;; and we apparently don't ever need to pass six arguments to a
182 ;;; libc function. -- CSR, 2003-10-29
183 ;;; Expanded to 8 arguments regardless. -- ths, 2005-03-24
185 #define LDSO_STUBIFY(fct) \\
186 .globl ldso_stub__ ## fct ; \\
187 .type ldso_stub__ ## fct,@function ; \\
188 .ent ldso_stub__ ## fct ; \\
189 ldso_stub__ ## fct: ; \\
209 .end ldso_stub__ ## fct ; \\
210 .size ldso_stub__ ## fct,.-ldso_stub__ ## fct ;"))
212 (defvar *stubs
* (append
239 #!+inode64
"fstat$INODE64"
269 #!+inode64
"lstat$INODE64"
271 #!+(or x86 x86-64
) "memcmp"
295 #!+inode64
"stat$INODE64"
309 ;; These aren't needed on the X86 because they're microcoded into the
310 ;; FPU, so the Lisp VOPs can implement them directly without having to
313 ;; Note: There might be some other functions in this category as well.
314 ;; E.g. I notice tanh() and acos() in the list above.. -- WHN 2001-06-07
326 '("ieee_get_fp_control"
327 "ieee_set_fp_control")
328 ;; FIXME: After 1.0 this should be made
329 ;; #!-linkage-table, as we only need these stubs if
330 ;; we don't have linkage-table. Done this way now to
331 ;; cut down on the number of ports affected.
332 #!-
(or win32 darwin freebsd netbsd openbsd
)
336 #!+(or openbsd freebsd dragonfly
)
346 #!+os-provides-dladdr
362 (with-open-file (f "src/runtime/ldso-stubs.S" :direction
:output
:if-exists
:supersede
)
363 (assert (= (length *preludes
*) 2))
364 (dolist (pre *preludes
*)
366 (dolist (stub *stubs
*)
367 (check-type stub string
)
368 (ldso-stubify stub f
))
371 // Mark the object as not requiring an executable stack.
372 .section .note.GNU-stack,\"\",%progbits