From 43b6f05dfb46637a414520b27430fbe3b0f005fa Mon Sep 17 00:00:00 2001 From: AndreaCorallo Date: Tue, 3 Mar 2020 22:23:41 +0000 Subject: [PATCH] Hash eln ABI once and add it to the output compilation path --- lisp/emacs-lisp/comp.el | 2 +- src/comp.c | 29 +++++++++++++++++++++++------ src/comp.h | 4 ++++ src/emacs.c | 5 +++++ src/lread.c | 3 ++- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index a9db8c6ff07..342faa2879e 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el @@ -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 \n" 1) diff --git a/src/comp.c b/src/comp.c index 425784b9810..4940ae52b3d 100644 --- a/src/comp.c +++ b/src/comp.c @@ -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 = ¤t_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 */ diff --git a/src/comp.h b/src/comp.h index 3aff440ecb7..070ec4d5ca9 100644 --- a/src/comp.h +++ b/src/comp.h @@ -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 diff --git a/src/emacs.c b/src/emacs.c index da08aeb9022..b16ffa4295e 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -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 { diff --git a/src/lread.c b/src/lread.c index 6d33bd3e496..acd2fea6881 100644 --- a/src/lread.c +++ b/src/lread.c @@ -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 } -- 2.39.5