diff options
| author | Pip Cet | 2025-01-18 20:55:18 +0000 |
|---|---|---|
| committer | Pip Cet | 2025-01-18 20:55:18 +0000 |
| commit | 2ecb34990a92d45ae2845244f4ccfc96ffe04829 (patch) | |
| tree | b924bc2fd058cbc93d5896821fb614e0c9294dfd | |
| parent | aa07e94439c663f768c32a689d14506d25a7a5bc (diff) | |
| download | emacs-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.
| -rw-r--r-- | lisp/emacs-lisp/comp.el | 8 | ||||
| -rw-r--r-- | src/comp.c | 26 | ||||
| -rw-r--r-- | src/pdumper.c | 2 |
3 files changed, 26 insertions, 10 deletions
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index ab6fd77f11a..a8698ef6454 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el | |||
| @@ -42,6 +42,7 @@ | |||
| 42 | (defvar comp-subr-arities-h) | 42 | (defvar comp-subr-arities-h) |
| 43 | (defvar native-comp-eln-load-path) | 43 | (defvar native-comp-eln-load-path) |
| 44 | (defvar native-comp-enable-subr-trampolines) | 44 | (defvar native-comp-enable-subr-trampolines) |
| 45 | (defvar comp--\#$) | ||
| 45 | 46 | ||
| 46 | (declare-function comp--compile-ctxt-to-file0 "comp.c") | 47 | (declare-function comp--compile-ctxt-to-file0 "comp.c") |
| 47 | (declare-function comp--init-ctxt "comp.c") | 48 | (declare-function comp--init-ctxt "comp.c") |
| @@ -3254,10 +3255,9 @@ Set it into the `type' slot." | |||
| 3254 | ;; from the corresponding m-var. | 3255 | ;; from the corresponding m-var. |
| 3255 | collect (if (gethash obj | 3256 | collect (if (gethash obj |
| 3256 | (comp-ctxt-byte-func-to-func-h comp-ctxt)) | 3257 | (comp-ctxt-byte-func-to-func-h comp-ctxt)) |
| 3257 | ;; Hack not to have `--lambda-fixup' in | 3258 | ;; This prints as #$, so we can assert this |
| 3258 | ;; data relocations as it would trigger the | 3259 | ;; value does not remain in the data vector |
| 3259 | ;; check in 'check_comp_unit_relocs'. | 3260 | comp--\#$ |
| 3260 | (intern (concat (make-string 1 ?-) "-lambda-fixup")) | ||
| 3261 | obj)))) | 3261 | obj)))) |
| 3262 | 3262 | ||
| 3263 | (defun comp--finalize-relocs () | 3263 | (defun comp--finalize-relocs () |
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); | |||
| 5145 | static Lisp_Object | 5151 | static Lisp_Object |
| 5146 | load_static_obj (struct Lisp_Native_Comp_Unit *comp_u, const char *name) | 5152 | load_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 | |||
| 5804 | verification of the native compiler. */); | 5816 | verification 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 | ||
diff --git a/src/pdumper.c b/src/pdumper.c index d45bbc84bba..a27df8d96d4 100644 --- a/src/pdumper.c +++ b/src/pdumper.c | |||
| @@ -5504,7 +5504,7 @@ dump_do_dump_relocation (const uintptr_t dump_base, | |||
| 5504 | XSETSUBR (tem, subr); | 5504 | XSETSUBR (tem, subr); |
| 5505 | Lisp_Object *fixup = | 5505 | Lisp_Object *fixup = |
| 5506 | &(comp_u->data_relocs[XFIXNUM (lambda_data_idx)]); | 5506 | &(comp_u->data_relocs[XFIXNUM (lambda_data_idx)]); |
| 5507 | eassert (EQ (*fixup, Q__lambda_fixup)); | 5507 | eassert (EQ (*fixup, Vcomp__hashdollar)); |
| 5508 | *fixup = tem; | 5508 | *fixup = tem; |
| 5509 | Fputhash (tem, Qt, comp_u->lambda_gc_guard_h); | 5509 | Fputhash (tem, Qt, comp_u->lambda_gc_guard_h); |
| 5510 | } | 5510 | } |