#ifdef __cplusplus
extern \"C\"
#endif
-ECL_DLLEXPORT
+
void ~A(cl_object cblock)
{
/*
}
")
+(defconstant +lisp-init-wrapper+ "
+ECL_DLLEXPORT
+void ~A(cl_object cblock)
+{
+ /* This function is a wrapper over the randomized init function
+ * name. */
+ ~A(cblock);
+}
+")
+
(defconstant +lisp-program-main+ "
extern int
main(int argc, char **argv)
(find-archive system))
(fallback)))))
-(defun builder (target output-name &key lisp-files ld-flags
- (init-name nil)
- (main-name nil)
- (prologue-code "")
- (epilogue-code (when (eq target :program) '(SI::TOP-LEVEL T)))
- #+:win32 (system :console)
+(defun builder (target output-name
+ &key
+ lisp-files ld-flags
+ (init-name nil)
+ (main-name nil)
+ (prologue-code "")
+ (epilogue-code (when (eq target :program) '(SI::TOP-LEVEL T)))
+ #+:win32 (system :console)
&aux
- (*suppress-compiler-messages* (or *suppress-compiler-messages*
- (not *compile-verbose*))))
+ (*suppress-compiler-messages* (or *suppress-compiler-messages*
+ (not *compile-verbose*)))
+ (output-name (if (or (symbolp output-name) (stringp output-name))
+ (compile-file-pathname output-name :type target)
+ output-name))
+ (init-name (or init-name (compute-init-name output-name
+ :kind target)))
+ (wrap-init-name (compute-init-name output-name
+ :kind target
+ :wrapper t))
+ (main-name (or main-name (compute-init-name output-name
+ :kind target
+ :prefix "main_"))))
;;
;; The epilogue-code can be either a string made of C code, or a
;; lisp form. In the latter case we add some additional C code to
submodules-data))
(setq c-file (open c-name :direction :output :external-format :default))
(format c-file +lisp-program-header+ submodules)
- (when (or (symbolp output-name) (stringp output-name))
- (setf output-name (compile-file-pathname output-name :type target)))
- (unless init-name
- (setf init-name (compute-init-name output-name :kind target)))
- (unless main-name
- (setf main-name (compute-init-name output-name
- :kind target
- :prefix "main_")))
+
(let ((init-tag (init-name-tag init-name :kind target)))
(ecase target
(:program
(compiler-cc c-name o-name)
(linker-cc output-name (list* (namestring o-name) ld-flags)))
((:library :static-library :lib)
- (format c-file +lisp-program-init+ init-name init-tag prologue-code
- submodules epilogue-code)
- (cmpnote "Library initialization function is ~A" main-name)
+ (format c-file +lisp-program-init+
+ init-name init-tag prologue-code submodules epilogue-code)
+ (format c-file +lisp-init-wrapper+ wrap-init-name init-name)
(format c-file +lisp-library-main+
main-name prologue-code init-name epilogue-code)
(close c-file)
(linker-ar output-name o-name ld-flags))
#+dlopen
((:shared-library :dll)
- (format c-file +lisp-program-init+ init-name init-tag prologue-code
- submodules epilogue-code)
- (cmpnote "Library initialization function is ~A" main-name)
+ (format c-file +lisp-program-init+
+ init-name init-tag prologue-code submodules epilogue-code)
+ (format c-file +lisp-init-wrapper+ wrap-init-name init-name)
(format c-file +lisp-library-main+
main-name prologue-code init-name epilogue-code)
(close c-file)
(subseq name (length prefix) nil)
name))
-(defun compute-init-name (pathname &key (kind (guess-kind pathname)) (prefix nil))
+(defun compute-init-name (pathname &key (kind (guess-kind pathname))
+ (prefix nil)
+ (wrapper nil))
"Computes initialization function name. Libraries, FASLS and
programs init function names can't be randomized to allow
initialization from the C code which wants to use it."
((:fasl :fas)
(init-function-name "CODE" :kind :fas :prefix prefix))
((:static-library :lib)
- (init-function-name (remove-prefix +static-library-prefix+ filename)
+ (init-function-name (if wrapper
+ (remove-prefix +static-library-prefix+ filename)
+ unique-name)
:kind :lib
:prefix prefix))
((:shared-library :dll)
- (init-function-name (remove-prefix +shared-library-prefix+ filename)
+ (init-function-name (if wrapper
+ (remove-prefix +shared-library-prefix+ filename)
+ unique-name)
:kind :dll
:prefix prefix))
((:program)