add native compilation unit pdumper support
authorAndrea Corallo <akrl@sdf.org>
Tue, 24 Dec 2019 13:51:18 +0000 (14:51 +0100)
committerAndrea Corallo <akrl@sdf.org>
Wed, 1 Jan 2020 10:38:16 +0000 (11:38 +0100)
src/comp.c
src/comp.h
src/pdumper.c

index 003d3d7ca4431785948cf9c8786d744aa07445f9..43b22a86805197dc463591fa536ab3cc5e798960 100644 (file)
@@ -3217,7 +3217,7 @@ load_static_obj (dynlib_handle_ptr handle, const char *name)
 }
 
 void
-load_comp_unit (struct Lisp_Native_Comp_Unit *comp_u)
+load_comp_unit (struct Lisp_Native_Comp_Unit *comp_u, bool loading_dump)
 {
   dynlib_handle_ptr handle = comp_u->handle;
   struct thread_state ***current_thread_reloc =
@@ -3237,22 +3237,26 @@ load_comp_unit (struct Lisp_Native_Comp_Unit *comp_u)
   *current_thread_reloc = &current_thread;
   *pure_reloc = (EMACS_INT **)&pure;
 
-  /* Imported data.  */
-  Lisp_Object d_vec = load_static_obj (handle, TEXT_DATA_RELOC_SYM);
-  EMACS_INT d_vec_len = XFIXNUM (Flength (d_vec));
-
-  for (EMACS_INT i = 0; i < d_vec_len; i++)
-      data_relocs[i] = AREF (d_vec, i);
-
-  comp_u->data_vec = d_vec;
   /* Imported functions.  */
   *freloc_link_table = freloc.link_table;
 
-  Lisp_Object comp_u_obj;
-  XSETNATIVE_COMP_UNIT (comp_u_obj, comp_u);
+  /* Imported data.  */
+  if (!loading_dump)
+    comp_u->data_vec = load_static_obj (handle, TEXT_DATA_RELOC_SYM);
+
+  EMACS_INT d_vec_len = XFIXNUM (Flength (comp_u->data_vec));
+
+  for (EMACS_INT i = 0; i < d_vec_len; i++)
+    data_relocs[i] = AREF (comp_u->data_vec, i);
 
-  /* Executing this will perform all the expected environment modification.  */
-  top_level_run (comp_u_obj);
+  if (!loading_dump)
+    {
+      Lisp_Object comp_u_obj;
+      XSETNATIVE_COMP_UNIT (comp_u_obj, comp_u);
+      /* Executing this will perform all the expected environment
+        modification.  */
+      top_level_run (comp_u_obj);
+    }
 
   return;
 }
@@ -3308,7 +3312,8 @@ DEFUN ("native-elisp-load", Fnative_elisp_load, Snative_elisp_load, 1, 1, 0,
   if (!comp_u->handle)
     xsignal2 (Qnative_lisp_load_failed, file, build_string (dynlib_error ()));
   comp_u->file = file;
-  load_comp_unit (comp_u);
+  comp_u->data_vec = Qnil;
+  load_comp_unit (comp_u, false);
 
   return Qt;
 }
index c4849ba13d1076256a147ebc12a9c309e7f5780f..90b4f40426b4d1ab8db3cae8d1f04ff3af9814e4 100644 (file)
@@ -47,7 +47,8 @@ XNATIVE_COMP_UNIT (Lisp_Object a)
 }
 
 /* Defined in comp.c.  */
-extern void load_comp_unit (struct Lisp_Native_Comp_Unit *);
+extern void load_comp_unit (struct Lisp_Native_Comp_Unit *comp_u,
+                           bool loading_dump);
 extern void syms_of_comp (void);
 /* Fill the freloc structure. Must be called before any eln is loaded.  */
 extern void fill_freloc (void);
index 4e770f79af5275703b264a8d33ef27c50021b3c4..2dbe6c73fb4b89b65394e5a7908745b39233fd0e 100644 (file)
@@ -197,6 +197,7 @@ enum dump_reloc_type
     /* dump_ptr = dump_ptr + dump_base  */
     RELOC_DUMP_TO_DUMP_PTR_RAW,
     /* dump_mpz = [rebuild bignum]  */
+    RELOC_NATIVE_COMP_UNIT,
     RELOC_BIGNUM,
     /* dump_lv = make_lisp_ptr (dump_lv + dump_base,
                                type - RELOC_DUMP_TO_DUMP_LV)
@@ -2991,6 +2992,11 @@ dump_native_comp_unit (struct dump_context *ctx,
   out->handle = NULL;
 
   dump_off comp_u_off = finish_dump_pvec (ctx, &out->header);
+  if (ctx->flags.dump_object_contents)
+    /* We'll do the real elf load during the LATE_RELOCS_1 relocation time. */
+    dump_push (&ctx->dump_relocs[LATE_RELOCS_1],
+              list2 (make_fixnum (RELOC_NATIVE_COMP_UNIT),
+                     dump_off_to_lisp (comp_u_off)));
   return comp_u_off;
 }
 #endif
@@ -5290,6 +5296,16 @@ dump_do_dump_relocation (const uintptr_t dump_base,
         dump_write_word_to_dump (dump_base, reloc_offset, value);
         break;
       }
+    case RELOC_NATIVE_COMP_UNIT:
+      {
+       struct Lisp_Native_Comp_Unit *comp_u =
+         dump_ptr (dump_base, reloc_offset);
+       comp_u->handle = dynlib_open (SSDATA (comp_u->file));
+       if (!comp_u->handle)
+         error ("%s", dynlib_error ());
+       load_comp_unit (comp_u, true);
+      }
+      break;
     case RELOC_BIGNUM:
       {
         struct Lisp_Bignum *bignum = dump_ptr (dump_base, reloc_offset);