From ff9e40e9fefacfda9cce38d8884694b1c5207b1c Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Wed, 13 May 2020 22:43:48 +0100 Subject: [PATCH] * Add check_comp_unit_relocs * src/comp.c (check_comp_unit_relocs): Add function to verify relocation coherency. (load_comp_unit): Call it. --- src/comp.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/comp.c b/src/comp.c index d1f8fe23f0d..dab102cccd9 100644 --- a/src/comp.c +++ b/src/comp.c @@ -3572,6 +3572,37 @@ load_static_obj (struct Lisp_Native_Comp_Unit *comp_u, const char *name) return Fread (make_string (res->data, res->len)); } +/* Return false when something is wrong or true otherwise. */ + +static bool +check_comp_unit_relocs (struct Lisp_Native_Comp_Unit *comp_u) +{ + dynlib_handle_ptr handle = comp_u->handle; + Lisp_Object *data_relocs = dynlib_sym (handle, DATA_RELOC_SYM); + Lisp_Object *data_imp_relocs = dynlib_sym (handle, DATA_RELOC_IMPURE_SYM); + + EMACS_INT d_vec_len = XFIXNUM (Flength (comp_u->data_vec)); + for (EMACS_INT i = 0; i < d_vec_len; i++) + if (!EQ (data_relocs[i], AREF (comp_u->data_vec, i))) + return false; + + d_vec_len = XFIXNUM (Flength (comp_u->data_impure_vec)); + for (EMACS_INT i = 0; i < d_vec_len; i++) + { + Lisp_Object x = data_imp_relocs[i]; + if (EQ (x, Qlambda_fixup)) + return false; + else if (SUBR_NATIVE_COMPILEDP (x)) + { + if (NILP (Fgethash (x, comp_u->lambda_gc_guard, Qnil))) + return false; + } + else if (!EQ (data_imp_relocs[i], AREF (comp_u->data_impure_vec, i))) + return false; + } + return true; +} + void load_comp_unit (struct Lisp_Native_Comp_Unit *comp_u, bool loading_dump, bool late_load) @@ -3691,6 +3722,8 @@ load_comp_unit (struct Lisp_Native_Comp_Unit *comp_u, bool loading_dump, data_ephemeral_vec = data_ephemeral_vec; } + eassert (check_comp_unit_relocs (comp_u)); + return; } -- 2.39.5