Re: [Sbcl-commits] master: Extend save-lisp-and-die to write an ELF .o file

Douglas Katzman via Sbcl-devel <[email protected]>
Newsgroups gmane.lisp.steel-bank.devel
Message-ID <CAOrNasz5OKp21SSW53YOz5r_4y5ZiFTSWEhLf5hrSs8vWNvOwQ@mail.gmail.com>
Of course, non-ELF.  I don't currently have a non-ELF platform. Could you
see if this diff looks right including removal of the irrelevant piece of
docstring?

_______________________________________________
Sbcl-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sbcl-devel
trythis.diff (application/x-patch, 3.9 KB)
diff --git a/src/code/save.lisp b/src/code/save.lisp
index 8d7bc30eb..8db5f7e4a 100644
--- a/src/code/save.lisp
+++ b/src/code/save.lisp
@@ -103,6 +103,7 @@
                                          (compression nil)
                                          #+win32
                                          (application-type :console))
+  #.(format nil
   "Save a \"core image\", i.e. enough information to restart a Lisp
 process later in the same state, in the file of the specified name.
 Only global state is preserved: the stack is unwound in the process.
@@ -122,9 +123,7 @@ The following &KEY arguments are defined:
      If true, arrange to combine the SBCL runtime and the core image
      to create a standalone executable.  If false (the default), the
      core image will not be executable on its own. Executable images
-     always behave as if they were passed the --noinform runtime option.
-     If :EXECUTABLE is :ELF-OBJECT, then the resulting core will be
-     wrapped in a .o which requires further linking. (EXPERIMENTAL)
+     always behave as if they were passed the --noinform runtime option.~A
 
   :SAVE-RUNTIME-OPTIONS
      If true, values of runtime options --dynamic-space-size and
@@ -206,6 +205,10 @@ This implementation is not as polished and painless as you might like:
 This isn't because we like it this way, but just because there don't
 seem to be good quick fixes for either limitation and no one has been
 sufficiently motivated to do lengthy fixes."
+  #+elf "
+     If :EXECUTABLE is :ELF-OBJECT, then the resulting core will be
+     wrapped in a .o which requires further linking. (EXPERIMENTAL)"
+  #-elf "")
   (declare (ignore environment-name))
   (declare (ignorable root-structures))
   (when (and callable-exports toplevel-supplied)
@@ -258,7 +261,8 @@ sufficiently motivated to do lengthy fixes."
           ;; since the GC will invalidate the stack.
           (sb-kernel::unsafe-clear-roots sb-vm:+highest-normal-generation+)
           (gc-and-save name
-                       (if (eq executable :elf-object) 2 (foreign-bool executable))
+                       #+elf (if (eq executable :elf-object) 2 (foreign-bool executable))
+                       #-elf (foreign-bool executable)
                        (foreign-bool purify)
                        (case save-runtime-options
                          (:accept-runtime-options 2)
diff --git a/src/runtime/GNUmakefile b/src/runtime/GNUmakefile
index 0858f8c43..1df082d3c 100644
--- a/src/runtime/GNUmakefile
+++ b/src/runtime/GNUmakefile
@@ -162,7 +162,7 @@ semiwrap-sbcl: shrinkwrap-sbcl.s $(LIBSBCL)
 # simpler version of core embedding where the core is just a section of the ELF file.
 # tools-for-build/elftool could kinda do this but it didn't work as well as it
 # does using the ELF writer from C, because firstly the interface is less
-# polished and secondly it did remove the need for -Wl,--export-dynamic.
+# polished and secondly it did not remove the need for -Wl,--export-dynamic.
 # Note about $(LIBS) - we don't really need -ldl except os-common does reference it
 # so removing it would break that. Also certain platforms need -lm and -lpthread
 # to get in there so using the same link options as for the ordinary "sbcl"
diff --git a/src/runtime/save.c b/src/runtime/save.c
index f38712658..662947c3d 100644
--- a/src/runtime/save.c
+++ b/src/runtime/save.c
@@ -914,6 +914,7 @@ gc_and_save(char *filename, int core_format, bool purify,
     save_to_filehandle(file, filename, lisp_init_function,
                        prepend_runtime, save_runtime_options,
                        compressed ? compression_level : COMPRESSION_LEVEL_NONE);
+#ifdef LISP_FEATURE_ELF
     if (elf_object) {
         file = fopen(filename, "r"); // reopen it for reading
         unlink(filename);
@@ -922,5 +923,6 @@ gc_and_save(char *filename, int core_format, bool purify,
         generate_elfcore_obj(filename, file, elf_c_symbols, n_symbols);
         printf("[Converted to ELF]\n");
     }
+#endif
     exit(0);
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.