aboutsummaryrefslogtreecommitdiffstats
path: root/src/comp.c
diff options
context:
space:
mode:
authorPip Cet2025-01-18 20:55:18 +0000
committerPip Cet2025-01-18 20:55:18 +0000
commit2ecb34990a92d45ae2845244f4ccfc96ffe04829 (patch)
treeb924bc2fd058cbc93d5896821fb614e0c9294dfd /src/comp.c
parentaa07e94439c663f768c32a689d14506d25a7a5bc (diff)
downloademacs-scratch/no-purespace.tar.gz
emacs-scratch/no-purespace.zip
Use #$ for lambda fixups in native compilation data vectorsscratch/no-purespace
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/comp.c')
-rw-r--r--src/comp.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/comp.c b/src/comp.c
index 8b38adec252..ab27b17b410 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
@@ -2682,6 +2682,12 @@ emit_static_object (const char *name, Lisp_Object obj)
2682 specbind (intern_c_string ("print-quoted"), Qt); 2682 specbind (intern_c_string ("print-quoted"), Qt);
2683 specbind (intern_c_string ("print-gensym"), Qt); 2683 specbind (intern_c_string ("print-gensym"), Qt);
2684 specbind (intern_c_string ("print-circle"), Qt); 2684 specbind (intern_c_string ("print-circle"), Qt);
2685 /* Bind print-number-table and print-continuous-numbering so comp--#$
2686 prints as #$. */
2687 Lisp_Object print_number_table = CALLN (Fmake_hash_table, QCtest, Qeq);
2688 Fputhash (Vcomp__hashdollar, build_string ("#$") , print_number_table);
2689 specbind (intern_c_string ("print-number-table"), print_number_table);
2690 specbind (intern_c_string ("print-continuous-numbering"), Qt);
2685 Lisp_Object str = Fprin1_to_string (obj, Qnil, Qnil); 2691 Lisp_Object str = Fprin1_to_string (obj, Qnil, Qnil);
2686 unbind_to (count, Qnil); 2692 unbind_to (count, Qnil);
2687 2693
@@ -5145,18 +5151,25 @@ typedef char *(*comp_lit_str_func) (void);
5145static Lisp_Object 5151static Lisp_Object
5146load_static_obj (struct Lisp_Native_Comp_Unit *comp_u, const char *name) 5152load_static_obj (struct Lisp_Native_Comp_Unit *comp_u, const char *name)
5147{ 5153{
5154 specpdl_ref count = SPECPDL_INDEX ();
5148 static_obj_t *blob = 5155 static_obj_t *blob =
5149 dynlib_sym (comp_u->handle, format_string ("%s_blob", name)); 5156 dynlib_sym (comp_u->handle, format_string ("%s_blob", name));
5157 /* Special value so we can recognize #$, which is used for entries in
5158 the static vector that must be overwritten at load time. This is a
5159 specific string that contains "#$", which is not EQ to any
5160 legitimate object returned by Fread. */
5161 specbind (intern_c_string ("load-file-name"),
5162 Vcomp__hashdollar);
5150 if (blob) 5163 if (blob)
5151 /* New blob format. */ 5164 /* New blob format. */
5152 return Fread (make_string (blob->data, blob->len)); 5165 return unbind_to (count, Fread (make_string (blob->data, blob->len)));
5153 5166
5154 static_obj_t *(*f)(void) = dynlib_sym (comp_u->handle, name); 5167 static_obj_t *(*f)(void) = dynlib_sym (comp_u->handle, name);
5155 if (!f) 5168 if (!f)
5156 xsignal1 (Qnative_lisp_file_inconsistent, comp_u->file); 5169 xsignal1 (Qnative_lisp_file_inconsistent, comp_u->file);
5157 5170
5158 blob = f (); 5171 blob = f ();
5159 return Fread (make_string (blob->data, blob->len)); 5172 return unbind_to (count, Fread (make_string (blob->data, blob->len)));
5160 5173
5161} 5174}
5162 5175
@@ -5173,7 +5186,7 @@ check_comp_unit_relocs (struct Lisp_Native_Comp_Unit *comp_u)
5173 for (ptrdiff_t i = 0; i < d_vec_len; i++) 5186 for (ptrdiff_t i = 0; i < d_vec_len; i++)
5174 { 5187 {
5175 Lisp_Object x = data_relocs[i]; 5188 Lisp_Object x = data_relocs[i];
5176 if (EQ (x, Q__lambda_fixup)) 5189 if (EQ (x, Vcomp__hashdollar))
5177 return false; 5190 return false;
5178 else if (NATIVE_COMP_FUNCTIONP (x)) 5191 else if (NATIVE_COMP_FUNCTIONP (x))
5179 { 5192 {
@@ -5622,7 +5635,6 @@ natively-compiled one. */);
5622 DEFSYM (Qfixnum, "fixnum"); 5635 DEFSYM (Qfixnum, "fixnum");
5623 DEFSYM (Qscratch, "scratch"); 5636 DEFSYM (Qscratch, "scratch");
5624 DEFSYM (Qlate, "late"); 5637 DEFSYM (Qlate, "late");
5625 DEFSYM (Q__lambda_fixup, "--lambda-fixup");
5626 DEFSYM (Qgccjit, "gccjit"); 5638 DEFSYM (Qgccjit, "gccjit");
5627 DEFSYM (Qcomp_subr_trampoline_install, "comp-subr-trampoline-install"); 5639 DEFSYM (Qcomp_subr_trampoline_install, "comp-subr-trampoline-install");
5628 DEFSYM (Qnative_comp_warning_on_missing_source, 5640 DEFSYM (Qnative_comp_warning_on_missing_source,
@@ -5804,6 +5816,10 @@ This is intended to be used only for development and
5804verification of the native compiler. */); 5816verification of the native compiler. */);
5805 comp_sanitizer_active = false; 5817 comp_sanitizer_active = false;
5806 5818
5819 DEFVAR_LISP ("comp--#$", Vcomp__hashdollar,
5820 doc: /* Special value which will print as "#$". */);
5821 Vcomp__hashdollar = build_string ("#$");
5822
5807 Fprovide (intern_c_string ("native-compile"), Qnil); 5823 Fprovide (intern_c_string ("native-compile"), Qnil);
5808#endif /* #ifdef HAVE_NATIVE_COMP */ 5824#endif /* #ifdef HAVE_NATIVE_COMP */
5809 5825