aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPip Cet2025-01-18 20:55:18 +0000
committerPip Cet2025-02-01 17:02:50 +0000
commit4eabfd68c91185909be307435e5db8b8f0fb4102 (patch)
tree2bea05f1d7796c887f54220b363f324b3462437e /src
parent20e3959dc37685334579394b320ab93f751243fb (diff)
downloademacs-4eabfd68c91185909be307435e5db8b8f0fb4102.tar.gz
emacs-4eabfd68c91185909be307435e5db8b8f0fb4102.zip
Use #$ for lambda fixups in native compilation data vectors
The "#$" syntax is recognized by Fread, which substitutes Vload_file_name in its place. If Vload_file_name is bound appropriately, no other value can produce an object EQ to the one produced by "#$". We use this to check the data vector for entries that we know should have been initialized: if the value is still equal to what we bound Vload_file_name to when it was read, it wasn't initialized, and we abort. * lisp/emacs-lisp/comp.el (comp--#$): New defvar. (comp--finalize-container): Use it. * src/comp.c (ABI_VERSION): Bump. (emit_static_object): Ensure 'comp--#$' prints as "#$". (load_static_obj): Ensure '#$' reads as Vcomp__hashdollar. (check_comp_unit_relocs): Adjust assertion. (syms_of_comp): Define 'comp--#$'. * src/pdumper.c (dump_do_dump_relocation): Adjust assertion.
Diffstat (limited to 'src')
-rw-r--r--src/comp.c26
-rw-r--r--src/pdumper.c2
2 files changed, 22 insertions, 6 deletions
diff --git a/src/comp.c b/src/comp.c
index 2b2ac073214..692b28e00cb 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -468,7 +468,7 @@ load_gccjit_if_necessary (bool mandatory)
468 468
469 469
470/* Increase this number to force a new Vcomp_abi_hash to be generated. */ 470/* Increase this number to force a new Vcomp_abi_hash to be generated. */
471#define ABI_VERSION "9" 471#define ABI_VERSION "10"
472 472
473/* Length of the hashes used for eln file naming. */ 473/* Length of the hashes used for eln file naming. */
474#define HASH_LENGTH 8 474#define HASH_LENGTH 8
@@ -2666,6 +2666,12 @@ emit_static_object (const char *name, Lisp_Object obj)
2666 specbind (intern_c_string ("print-quoted"), Qt); 2666 specbind (intern_c_string ("print-quoted"), Qt);
2667 specbind (intern_c_string ("print-gensym"), Qt); 2667 specbind (intern_c_string ("print-gensym"), Qt);
2668 specbind (intern_c_string ("print-circle"), Qt); 2668 specbind (intern_c_string ("print-circle"), Qt);
2669 /* Bind print-number-table and print-continuous-numbering so comp--#$
2670 prints as #$. */
2671 Lisp_Object print_number_table = CALLN (Fmake_hash_table, QCtest, Qeq);
2672 Fputhash (Vcomp__hashdollar, build_string ("#$") , print_number_table);
2673 specbind (intern_c_string ("print-number-table"), print_number_table);
2674 specbind (intern_c_string ("print-continuous-numbering"), Qt);
2669 Lisp_Object str = Fprin1_to_string (obj, Qnil, Qnil); 2675 Lisp_Object str = Fprin1_to_string (obj, Qnil, Qnil);
2670 unbind_to (count, Qnil); 2676 unbind_to (count, Qnil);
2671 2677
@@ -5129,18 +5135,25 @@ typedef char *(*comp_lit_str_func) (void);
5129static Lisp_Object 5135static Lisp_Object
5130load_static_obj (struct Lisp_Native_Comp_Unit *comp_u, const char *name) 5136load_static_obj (struct Lisp_Native_Comp_Unit *comp_u, const char *name)
5131{ 5137{
5138 specpdl_ref count = SPECPDL_INDEX ();
5132 static_obj_t *blob = 5139 static_obj_t *blob =
5133 dynlib_sym (comp_u->handle, format_string ("%s_blob", name)); 5140 dynlib_sym (comp_u->handle, format_string ("%s_blob", name));
5141 /* Special value so we can recognize #$, which is used for entries in
5142 the static vector that must be overwritten at load time. This is a
5143 specific string that contains "#$", which is not EQ to any
5144 legitimate object returned by Fread. */
5145 specbind (intern_c_string ("load-file-name"),
5146 Vcomp__hashdollar);
5134 if (blob) 5147 if (blob)
5135 /* New blob format. */ 5148 /* New blob format. */
5136 return Fread (make_string (blob->data, blob->len)); 5149 return unbind_to (count, Fread (make_string (blob->data, blob->len)));
5137 5150
5138 static_obj_t *(*f)(void) = dynlib_sym (comp_u->handle, name); 5151 static_obj_t *(*f)(void) = dynlib_sym (comp_u->handle, name);
5139 if (!f) 5152 if (!f)
5140 xsignal1 (Qnative_lisp_file_inconsistent, comp_u->file); 5153 xsignal1 (Qnative_lisp_file_inconsistent, comp_u->file);
5141 5154
5142 blob = f (); 5155 blob = f ();
5143 return Fread (make_string (blob->data, blob->len)); 5156 return unbind_to (count, Fread (make_string (blob->data, blob->len)));
5144 5157
5145} 5158}
5146 5159
@@ -5157,7 +5170,7 @@ check_comp_unit_relocs (struct Lisp_Native_Comp_Unit *comp_u)
5157 for (ptrdiff_t i = 0; i < d_vec_len; i++) 5170 for (ptrdiff_t i = 0; i < d_vec_len; i++)
5158 { 5171 {
5159 Lisp_Object x = data_relocs[i]; 5172 Lisp_Object x = data_relocs[i];
5160 if (EQ (x, Q__lambda_fixup)) 5173 if (EQ (x, Vcomp__hashdollar))
5161 return false; 5174 return false;
5162 else if (NATIVE_COMP_FUNCTIONP (x)) 5175 else if (NATIVE_COMP_FUNCTIONP (x))
5163 { 5176 {
@@ -5610,7 +5623,6 @@ natively-compiled one. */);
5610 DEFSYM (Qfixnum, "fixnum"); 5623 DEFSYM (Qfixnum, "fixnum");
5611 DEFSYM (Qscratch, "scratch"); 5624 DEFSYM (Qscratch, "scratch");
5612 DEFSYM (Qlate, "late"); 5625 DEFSYM (Qlate, "late");
5613 DEFSYM (Q__lambda_fixup, "--lambda-fixup");
5614 DEFSYM (Qgccjit, "gccjit"); 5626 DEFSYM (Qgccjit, "gccjit");
5615 DEFSYM (Qcomp_subr_trampoline_install, "comp-subr-trampoline-install"); 5627 DEFSYM (Qcomp_subr_trampoline_install, "comp-subr-trampoline-install");
5616 DEFSYM (Qnative_comp_warning_on_missing_source, 5628 DEFSYM (Qnative_comp_warning_on_missing_source,
@@ -5792,6 +5804,10 @@ This is intended to be used only for development and
5792verification of the native compiler. */); 5804verification of the native compiler. */);
5793 comp_sanitizer_active = false; 5805 comp_sanitizer_active = false;
5794 5806
5807 DEFVAR_LISP ("comp--#$", Vcomp__hashdollar,
5808 doc: /* Special value which will print as "#$". */);
5809 Vcomp__hashdollar = build_string ("#$");
5810
5795 Fprovide (intern_c_string ("native-compile"), Qnil); 5811 Fprovide (intern_c_string ("native-compile"), Qnil);
5796#endif /* #ifdef HAVE_NATIVE_COMP */ 5812#endif /* #ifdef HAVE_NATIVE_COMP */
5797 5813
diff --git a/src/pdumper.c b/src/pdumper.c
index b2ceea2f8bd..20f2c426c53 100644
--- a/src/pdumper.c
+++ b/src/pdumper.c
@@ -5513,7 +5513,7 @@ dump_do_dump_relocation (const uintptr_t dump_base,
5513 XSETSUBR (tem, subr); 5513 XSETSUBR (tem, subr);
5514 Lisp_Object *fixup = 5514 Lisp_Object *fixup =
5515 &(comp_u->data_relocs[XFIXNUM (lambda_data_idx)]); 5515 &(comp_u->data_relocs[XFIXNUM (lambda_data_idx)]);
5516 eassert (EQ (*fixup, Q__lambda_fixup)); 5516 eassert (EQ (*fixup, Vcomp__hashdollar));
5517 *fixup = tem; 5517 *fixup = tem;
5518 Fputhash (tem, Qt, comp_u->lambda_gc_guard_h); 5518 Fputhash (tem, Qt, comp_u->lambda_gc_guard_h);
5519 } 5519 }