aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrea Corallo2020-08-17 11:54:55 +0200
committerAndrea Corallo2020-08-17 18:04:37 +0200
commit76faab27cf4055f6ac37b9b05c98bc03939afb7e (patch)
tree00f47222a242aed5f2fda5f982e3dafdc7fab0af /src
parent114b1d8f905edfeb7bd81b6a69c707336c01cde0 (diff)
downloademacs-76faab27cf4055f6ac37b9b05c98bc03939afb7e.tar.gz
emacs-76faab27cf4055f6ac37b9b05c98bc03939afb7e.zip
* Improve eln filename hashing
Make eln filename hashing logic insensitive to the installation process. * src/comp.c (epaths.h): New include to have PATH_DUMPLOADSEARCH, PATH_LOADSEARCH definitions. (loadsearch_re_list): New static var. (Fcomp_el_to_eln_filename): Update logic to have the eln hashing insensitive to the installation process. (syms_of_comp): GC protect 'loadsearch_re_list'.
Diffstat (limited to 'src')
-rw-r--r--src/comp.c62
1 files changed, 52 insertions, 10 deletions
diff --git a/src/comp.c b/src/comp.c
index f4111e2a291..ff73245b8de 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -29,6 +29,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
29#include <stdio.h> 29#include <stdio.h>
30#include <signal.h> 30#include <signal.h>
31#include <libgccjit.h> 31#include <libgccjit.h>
32#include <epaths.h>
32 33
33#include "puresize.h" 34#include "puresize.h"
34#include "window.h" 35#include "window.h"
@@ -3860,29 +3861,68 @@ compile_function (Lisp_Object func)
3860/* Entry points exposed to lisp. */ 3861/* Entry points exposed to lisp. */
3861/**********************************/ 3862/**********************************/
3862 3863
3864/* In use by Fcomp_el_to_eln_filename. */
3865static Lisp_Object loadsearch_re_list;
3866
3863DEFUN ("comp-el-to-eln-filename", Fcomp_el_to_eln_filename, 3867DEFUN ("comp-el-to-eln-filename", Fcomp_el_to_eln_filename,
3864 Scomp_el_to_eln_filename, 1, 2, 0, 3868 Scomp_el_to_eln_filename, 1, 2, 0,
3865 doc: /* Given a source file return the corresponding .eln true filename. 3869 doc: /* Given a source file return the corresponding .eln true filename.
3866If BASE-DIR is nil use the first entry in `comp-eln-load-path'. */) 3870If BASE-DIR is nil use the first entry in `comp-eln-load-path'. */)
3867 (Lisp_Object file_name, Lisp_Object base_dir) 3871 (Lisp_Object filename, Lisp_Object base_dir)
3868{ 3872{
3869 CHECK_STRING (file_name); 3873 CHECK_STRING (filename);
3870 if (suffix_p (file_name, ".gz")) 3874
3871 file_name = Fsubstring (file_name, Qnil, make_fixnum (-3)); 3875 if (suffix_p (filename, ".gz"))
3872 file_name = Fexpand_file_name (file_name, Qnil); 3876 filename = Fsubstring (filename, Qnil, make_fixnum (-3));
3873 Lisp_Object hashed = Fsubstring (comp_hash_string (file_name), Qnil, 3877 filename = Fexpand_file_name (filename, Qnil);
3874 make_fixnum (ELN_FILENAME_HASH_LEN)); 3878
3875 file_name = concat2 (Ffile_name_nondirectory (Fsubstring (file_name, Qnil, 3879 /* We create eln filenames with an hash in order to look-up these
3880 starting from the source filename, IOW have a relation
3881 /absolute/path/filename.el -> eln-cache/filename-hash.eln.
3882
3883 As installing .eln files compiled during the build changes their
3884 absolute path we need an hashing mechanism that is not sensitive
3885 to that. For this we replace if match PATH_DUMPLOADSEARCH or
3886 PATH_LOADSEARCH with '//' before generating the hash.
3887
3888 Another approach would be to hash using the source file content
3889 but this may have a measurable performance impact. */
3890
3891 if (NILP (loadsearch_re_list))
3892 {
3893 Lisp_Object loadsearch_list =
3894 Fcons (build_string (PATH_DUMPLOADSEARCH),
3895 Fcons (build_string (PATH_LOADSEARCH), Qnil));
3896 FOR_EACH_TAIL (loadsearch_list)
3897 loadsearch_re_list =
3898 Fcons (Fregexp_quote (XCAR (loadsearch_list)), loadsearch_re_list);
3899 }
3900 Lisp_Object loadsearch_res = loadsearch_re_list;
3901 FOR_EACH_TAIL (loadsearch_res)
3902 {
3903 Lisp_Object match_idx =
3904 Fstring_match (XCAR (loadsearch_res), filename, Qnil);
3905 if (EQ (match_idx, make_fixnum (0)))
3906 {
3907 filename =
3908 Freplace_match (build_string ("//"), Qt, Qt, filename, Qnil);
3909 break;
3910 }
3911 }
3912
3913 Lisp_Object hash = Fsubstring (comp_hash_string (filename), Qnil,
3914 make_fixnum (ELN_FILENAME_HASH_LEN));
3915 filename = concat2 (Ffile_name_nondirectory (Fsubstring (filename, Qnil,
3876 make_fixnum (-3))), 3916 make_fixnum (-3))),
3877 build_string ("-")); 3917 build_string ("-"));
3878 file_name = concat3 (file_name, hashed, build_string (NATIVE_ELISP_SUFFIX)); 3918 filename = concat3 (filename, hash, build_string (NATIVE_ELISP_SUFFIX));
3879 if (NILP (base_dir)) 3919 if (NILP (base_dir))
3880 base_dir = XCAR (Vcomp_eln_load_path); 3920 base_dir = XCAR (Vcomp_eln_load_path);
3881 3921
3882 if (!file_name_absolute_p (SSDATA (base_dir))) 3922 if (!file_name_absolute_p (SSDATA (base_dir)))
3883 base_dir = Fexpand_file_name (base_dir, Vinvocation_directory); 3923 base_dir = Fexpand_file_name (base_dir, Vinvocation_directory);
3884 3924
3885 return Fexpand_file_name (file_name, 3925 return Fexpand_file_name (filename,
3886 concat2 (base_dir, Vcomp_native_path_postfix)); 3926 concat2 (base_dir, Vcomp_native_path_postfix));
3887} 3927}
3888 3928
@@ -5055,6 +5095,8 @@ native compiled one. */);
5055 comp.emitter_dispatcher = Qnil; 5095 comp.emitter_dispatcher = Qnil;
5056 staticpro (&delayed_sources); 5096 staticpro (&delayed_sources);
5057 delayed_sources = Qnil; 5097 delayed_sources = Qnil;
5098 staticpro (&loadsearch_re_list);
5099 loadsearch_re_list = Qnil;
5058 5100
5059#ifdef WINDOWSNT 5101#ifdef WINDOWSNT
5060 staticpro (&all_loaded_comp_units_h); 5102 staticpro (&all_loaded_comp_units_h);