]> git.eshelyaron.com Git - emacs.git/commitdiff
Hash eln ABI once and add it to the output compilation path
authorAndreaCorallo <akrl@sdf.org>
Tue, 3 Mar 2020 22:23:41 +0000 (22:23 +0000)
committerAndrea Corallo <akrl@sdf.org>
Tue, 3 Mar 2020 22:23:41 +0000 (22:23 +0000)
lisp/emacs-lisp/comp.el
src/comp.c
src/comp.h
src/emacs.c
src/lread.c

index a9db8c6ff07322753a8e891200497429def9fa0f..342faa2879e535a8af7dfb77294b301d392f0d50 100644 (file)
@@ -2125,7 +2125,7 @@ Return the compilation unit file name."
                          (file-name-as-directory
                           (concat
                            (file-name-directory exp-file)
-                           system-configuration))
+                           comp-native-path-postfix))
                          (file-name-sans-extension
                           (file-name-nondirectory exp-file))))))))
     (comp-log "\n\f\n" 1)
index 425784b981026d5c92469777fb207635d122bad5..4940ae52b3dd0e5b894fa5fc2caabe385f0549d4 100644 (file)
@@ -250,8 +250,8 @@ format_string (const char *format, ...)
 
 /* Produce a key hashing Vcomp_subr_list.  */
 
-static Lisp_Object
-hash_subr_list (void)
+void
+hash_native_abi (void)
 {
   Lisp_Object string = Fmapconcat (intern_c_string ("subr-name"),
                                   Vcomp_subr_list, build_string (" "));
@@ -260,7 +260,17 @@ hash_subr_list (void)
   sha512_buffer (SSDATA (string), SCHARS (string), SSDATA (digest));
   hexbuf_digest (SSDATA (digest), SDATA (digest), SHA512_DIGEST_SIZE);
 
-  return digest;
+  /* Check runs once.  */
+  eassert (Vcomp_abi_hash);
+  Vcomp_abi_hash = digest;
+  /* If 10 characters are usually sufficient for git I guess 16 are
+     fine for us here.  */
+  Vcomp_native_path_postfix =
+    concat3 (Vsystem_configuration,
+            make_string ("-", 1),
+            Fsubstring_no_properties (Vcomp_abi_hash,
+                                      make_fixnum (0),
+                                      make_fixnum (16)));
 }
 
 static void
@@ -1976,8 +1986,9 @@ emit_ctxt_code (void)
       fields[n_frelocs++] = xmint_pointer (XCDR (el));
     }
 
-  /* Compute and store function link table hash.  */
-  emit_static_object (LINK_TABLE_HASH_SYM, hash_subr_list ());
+  /* Sign the .eln for the exposed ABI it expects at load.  */
+  eassert (!NILP (Vcomp_abi_hash));
+  emit_static_object (LINK_TABLE_HASH_SYM, Vcomp_abi_hash);
 
   Lisp_Object subr_l = Vcomp_subr_list;
   FOR_EACH_TAIL (subr_l)
@@ -3430,7 +3441,7 @@ load_comp_unit (struct Lisp_Native_Comp_Unit *comp_u, bool loading_dump)
            && freloc_link_table
            && top_level_run)
          || NILP (Fstring_equal (load_static_obj (comp_u, LINK_TABLE_HASH_SYM),
-                                 hash_subr_list ())))
+                                 Vcomp_abi_hash)))
        xsignal1 (Qnative_lisp_file_inconsistent, comp_u->file);
 
       *current_thread_reloc = &current_thread;
@@ -3657,6 +3668,12 @@ syms_of_comp (void)
               doc: /* Hash table symbol-function -> function-c-name.  For
                       internal use during  */);
   Vcomp_sym_subr_c_name_h = CALLN (Fmake_hash_table);
+  DEFVAR_LISP ("comp-abi-hash", Vcomp_abi_hash,
+              doc: /* String signing the ABI exposed to .eln files.  */);
+  Vcomp_abi_hash = Qnil;
+  DEFVAR_LISP ("comp-native-path-postfix", Vcomp_native_path_postfix,
+              doc: /* Postifix to be added to the .eln compilation path.  */);
+  Vcomp_native_path_postfix = Qnil;
 }
 
 #endif /* HAVE_NATIVE_COMP */
index 3aff440ecb749147acf91ed68b47a9a95d78d42d..070ec4d5ca95c282bc7dab88f541be586090d0a4 100644 (file)
@@ -61,8 +61,12 @@ XNATIVE_COMP_UNIT (Lisp_Object a)
 }
 
 /* Defined in comp.c.  */
+
+extern void hash_native_abi (void);
+
 extern void load_comp_unit (struct Lisp_Native_Comp_Unit *comp_u,
                            bool loading_dump);
 extern void syms_of_comp (void);
+
 #endif
 #endif
index da08aeb902242850326d10eaf7efadc9b3a216bb..b16ffa4295e9f3165850654a51c3b7fecaa6c36d 100644 (file)
@@ -1949,6 +1949,11 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
       keys_of_keyboard ();
       keys_of_keymap ();
       keys_of_window ();
+
+#ifdef HAVE_NATIVE_COMP
+      /* Must be after the last defsubr has run.  */
+      hash_native_abi ();
+#endif
     }
   else
     {
index 6d33bd3e4968884d1c2664502cbd1237ee29164a..acd2fea68810e44bc29721c44d311b9314f3797a 100644 (file)
@@ -1068,7 +1068,7 @@ effective_load_path (void)
       Lisp_Object el = XCAR (lp);
       new_lp =
        Fcons (concat2 (Ffile_name_as_directory (el),
-                       Vsystem_configuration),
+                       Vcomp_native_path_postfix),
               new_lp);
       new_lp = Fcons (el, new_lp);
     }
@@ -4427,6 +4427,7 @@ defsubr (union Aligned_Lisp_Subr *aname)
   XSETSUBR (tem, sname);
   set_symbol_function (sym, tem);
 #ifdef HAVE_NATIVE_COMP
+  eassert (NILP (Vcomp_abi_hash));
   Vcomp_subr_list = Fpurecopy (Fcons (tem, Vcomp_subr_list));
 #endif
 }