Backport inhibit-automatic-native-compilation from Emacs 29
authorSean Whitton <spwhitton@spwhitton.name>
Sun, 18 Dec 2022 21:43:54 +0000 (14:43 -0700)
committerSean Whitton <spwhitton@spwhitton.name>
Sun, 18 Dec 2022 21:43:59 +0000 (14:43 -0700)
We intend to use the EMACS_INHIBIT_AUTOMATIC_NATIVE_COMPILATION
environment variable to address bugs like #1021842.

1  2 
debian/.git-dpm
debian/patches/0017-Add-inhibit-native-compilation.patch
debian/patches/0018-Rename-to-inhibit-automatic-native-compilation.patch
debian/patches/series

diff --cc debian/.git-dpm
index 0ac17b4f9a62f57a0686619a75d840c347e518ca,0000000000000000000000000000000000000000..c5c13c74196d379377a8f75af7a20d3478d2d28f
mode 100644,000000..100644
--- /dev/null
@@@ -1,8 -1,0 +1,8 @@@
- e9f3f14ed42f9dd36d1ca40b9a85852ae5932adb
- e9f3f14ed42f9dd36d1ca40b9a85852ae5932adb
 +# see git-dpm(1) from git-dpm package
++2f28496d038eebe3715cbcfd1cb3981fd5a69739
++2f28496d038eebe3715cbcfd1cb3981fd5a69739
 +279b82e64e15b5e2df3cb522636c6db85a8ee659
 +279b82e64e15b5e2df3cb522636c6db85a8ee659
 +emacs_28.2+1.orig.tar.xz
 +d7f49858bdec2d47110c2ed7b1d0005f157e20c3
 +26988304
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..ed6ba27148028b9f923586025247291e329f9946
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,148 @@@
++From 654428b65ae1036deb4cc6f02461074c84671648 Mon Sep 17 00:00:00 2001
++From: Lars Ingebrigtsen <larsi@gnus.org>
++Date: Mon, 3 Oct 2022 15:26:04 +0200
++Subject: Add 'inhibit-native-compilation'
++
++The following upstream patch has been backported:
++
++  Add new variable 'inhibit-native-compilation'
++
++  * lisp/startup.el (normal-top-level): Set
++  inhibit-native-compilation from environment variable.
++
++  * lisp/emacs-lisp/comp.el (comp-trampoline-compile): Don't write
++  trampolines to disk.
++
++  * lisp/progmodes/elisp-mode.el
++  (emacs-lisp-native-compile-and-load): Adjust.
++
++  * src/comp.c (syms_of_comp): New variable
++  inhibit-native-compilation.
++  (maybe_defer_native_compilation): Use it.
++
++Origin: upstream, commit: 5fec9182dbeffa88cef6651d8c798ef9665d6681
++Forwarded: not-needed
++---
++ lisp/emacs-lisp/comp.el      | 35 +++++++++++++++++++----------------
++ lisp/progmodes/elisp-mode.el |  2 +-
++ lisp/startup.el              |  7 +++++--
++ src/comp.c                   |  8 ++++++++
++ 4 files changed, 33 insertions(+), 19 deletions(-)
++
++diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
++index 8a3429c9b67..37abd886b49 100644
++--- a/lisp/emacs-lisp/comp.el
+++++ b/lisp/emacs-lisp/comp.el
++@@ -3793,22 +3793,25 @@ comp-trampoline-compile
++          (lexical-binding t))
++     (comp--native-compile
++      form nil
++-     (cl-loop
++-      for dir in (if native-compile-target-directory
++-                     (list (expand-file-name comp-native-version-dir
++-                                             native-compile-target-directory))
++-                   (comp-eln-load-path-eff))
++-      for f = (expand-file-name
++-               (comp-trampoline-filename subr-name)
++-               dir)
++-      unless (file-exists-p dir)
++-        do (ignore-errors
++-             (make-directory dir t)
++-             (cl-return f))
++-      when (file-writable-p f)
++-        do (cl-return f)
++-      finally (error "Cannot find suitable directory for output in \
++-`native-comp-eln-load-path'")))))
+++     ;; If we've disabled nativecomp, don't write the trampolines to
+++     ;; the eln cache (but create them).
+++     (and (not inhibit-native-compilation)
+++          (cl-loop
+++           for dir in (if native-compile-target-directory
+++                          (list (expand-file-name comp-native-version-dir
+++                                                  native-compile-target-directory))
+++                        (comp-eln-load-path-eff))
+++           for f = (expand-file-name
+++                    (comp-trampoline-filename subr-name)
+++                    dir)
+++           unless (file-exists-p dir)
+++           do (ignore-errors
+++                (make-directory dir t)
+++                (cl-return f))
+++           when (file-writable-p f)
+++           do (cl-return f)
+++           finally (error "Cannot find suitable directory for output in \
+++`native-comp-eln-load-path'"))))))
++ 
++ \f
++ ;; Some entry point support code.
++diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
++index bdd7751fc0c..2af174ff752 100644
++--- a/lisp/progmodes/elisp-mode.el
+++++ b/lisp/progmodes/elisp-mode.el
++@@ -218,7 +218,7 @@ emacs-lisp-native-compile-and-load
++ Load the compiled code when finished.
++ 
++ Use `emacs-lisp-byte-compile-and-load' in combination with
++-`native-comp-deferred-compilation' set to t to achieve asynchronous
+++`inhibit-native-compilation' set to nil to achieve asynchronous
++ native compilation."
++   (interactive nil emacs-lisp-mode)
++   (emacs-lisp--before-compile-buffer)
++diff --git a/lisp/startup.el b/lisp/startup.el
++index 0f5de5affc3..9e09a051c53 100644
++--- a/lisp/startup.el
+++++ b/lisp/startup.el
++@@ -524,7 +524,7 @@ startup--xdg-or-homedot
++      (t emacs-d-dir))))
++ 
++ (defvar native-comp-eln-load-path)
++-(defvar native-comp-deferred-compilation)
+++(defvar inhibit-native-compilation)
++ (defvar comp-enable-subr-trampolines)
++ 
++ (defun normal-top-level ()
++@@ -532,6 +532,9 @@ normal-top-level
++ It sets `command-line-processed', processes the command-line,
++ reads the initialization files, etc.
++ It is the default value of the variable `top-level'."
+++  ;; Allow disabling automatic .elc->.eln processing.
+++  (setq inhibit-native-compilation (getenv "EMACS_INHIBIT_NATIVE_COMPILATION"))
+++
++   (if command-line-processed
++       (message internal--top-level-message)
++     (setq command-line-processed t)
++@@ -550,7 +553,7 @@ normal-top-level
++         ;; in this session.  This is necessary if libgccjit is not
++         ;; available on MS-Windows, but Emacs was built with
++         ;; native-compilation support.
++-        (setq native-comp-deferred-compilation nil
+++        (setq inhibit-native-compilation t
++               comp-enable-subr-trampolines nil))
++ 
++       ;; Form `native-comp-eln-load-path'.
++diff --git a/src/comp.c b/src/comp.c
++index dc0359acdae..5600339581a 100644
++--- a/src/comp.c
+++++ b/src/comp.c
++@@ -4826,6 +4826,7 @@ maybe_defer_native_compilation (Lisp_Object function_name,
++     return;
++ 
++   if (!native_comp_deferred_compilation
+++      || !NILP (Vinhibit_native_compilation)
++       || noninteractive
++       || !NILP (Vpurify_flag)
++       || !COMPILEDP (definition)
++@@ -5336,6 +5337,13 @@ syms_of_comp (void)
++ {
++ #ifdef HAVE_NATIVE_COMP
++   /* Compiler control customizes.  */
+++  DEFVAR_LISP ("inhibit-native-compilation", Vinhibit_native_compilation,
+++            doc: /* If non-nil, inhibit automatic native compilation of loaded .elc files.
+++
+++After compilation, each function definition is updated to the native
+++compiled one.  */);
+++  Vinhibit_native_compilation = Qnil;
+++
++   DEFVAR_BOOL ("native-comp-deferred-compilation",
++             native_comp_deferred_compilation,
++             doc: /* If non-nil compile loaded .elc files asynchronously.
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..8b898e932c6e9143a9dcec960a2b55912e78870b
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,115 @@@
++From 2f28496d038eebe3715cbcfd1cb3981fd5a69739 Mon Sep 17 00:00:00 2001
++From: Lars Ingebrigtsen <larsi@gnus.org>
++Date: Mon, 3 Oct 2022 19:49:53 +0200
++Subject: Rename to 'inhibit-automatic-native-compilation'
++
++The following upstream patch has been backported:
++
++  Rename to inhibit-automatic-native-compilation
++
++  * src/comp.c (maybe_defer_native_compilation):
++  (syms_of_comp):
++  * lisp/startup.el (inhibit-native-compilation):
++  (normal-top-level):
++  * lisp/progmodes/elisp-mode.el (emacs-lisp-native-compile-and-load):
++  * lisp/emacs-lisp/comp.el (comp-trampoline-compile): Rename
++  inhibit-native-compilation to inhibit-automatic-native-compilation.
++
++Origin: upstream, commit f97993ee667f9be7589825f3a4fbc095d6944ec6
++Forwarded: not-needed
++---
++ lisp/emacs-lisp/comp.el      | 2 +-
++ lisp/progmodes/elisp-mode.el | 4 ++--
++ lisp/startup.el              | 7 ++++---
++ src/comp.c                   | 7 ++++---
++ 4 files changed, 11 insertions(+), 9 deletions(-)
++
++diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
++index 37abd886b49..04b27c6e66a 100644
++--- a/lisp/emacs-lisp/comp.el
+++++ b/lisp/emacs-lisp/comp.el
++@@ -3795,7 +3795,7 @@ comp-trampoline-compile
++      form nil
++      ;; If we've disabled nativecomp, don't write the trampolines to
++      ;; the eln cache (but create them).
++-     (and (not inhibit-native-compilation)
+++     (and (not inhibit-automatic-native-compilation)
++           (cl-loop
++            for dir in (if native-compile-target-directory
++                           (list (expand-file-name comp-native-version-dir
++diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
++index 2af174ff752..9c5c4230212 100644
++--- a/lisp/progmodes/elisp-mode.el
+++++ b/lisp/progmodes/elisp-mode.el
++@@ -218,8 +218,8 @@ emacs-lisp-native-compile-and-load
++ Load the compiled code when finished.
++ 
++ Use `emacs-lisp-byte-compile-and-load' in combination with
++-`inhibit-native-compilation' set to nil to achieve asynchronous
++-native compilation."
+++`inhibit-automatic-native-compilation' set to nil to achieve
+++asynchronous native compilation."
++   (interactive nil emacs-lisp-mode)
++   (emacs-lisp--before-compile-buffer)
++   (load (native-compile buffer-file-name)))
++diff --git a/lisp/startup.el b/lisp/startup.el
++index 9e09a051c53..6a879c83094 100644
++--- a/lisp/startup.el
+++++ b/lisp/startup.el
++@@ -524,7 +524,7 @@ startup--xdg-or-homedot
++      (t emacs-d-dir))))
++ 
++ (defvar native-comp-eln-load-path)
++-(defvar inhibit-native-compilation)
+++(defvar inhibit-automatic-native-compilation)
++ (defvar comp-enable-subr-trampolines)
++ 
++ (defun normal-top-level ()
++@@ -533,7 +533,8 @@ normal-top-level
++ reads the initialization files, etc.
++ It is the default value of the variable `top-level'."
++   ;; Allow disabling automatic .elc->.eln processing.
++-  (setq inhibit-native-compilation (getenv "EMACS_INHIBIT_NATIVE_COMPILATION"))
+++  (setq inhibit-automatic-native-compilation
+++        (getenv "EMACS_INHIBIT_AUTOMATIC_NATIVE_COMPILATION"))
++ 
++   (if command-line-processed
++       (message internal--top-level-message)
++@@ -553,7 +554,7 @@ normal-top-level
++         ;; in this session.  This is necessary if libgccjit is not
++         ;; available on MS-Windows, but Emacs was built with
++         ;; native-compilation support.
++-        (setq inhibit-native-compilation t
+++        (setq inhibit-automatic-native-compilation t
++               comp-enable-subr-trampolines nil))
++ 
++       ;; Form `native-comp-eln-load-path'.
++diff --git a/src/comp.c b/src/comp.c
++index 5600339581a..9a99033dae0 100644
++--- a/src/comp.c
+++++ b/src/comp.c
++@@ -4826,7 +4826,7 @@ maybe_defer_native_compilation (Lisp_Object function_name,
++     return;
++ 
++   if (!native_comp_deferred_compilation
++-      || !NILP (Vinhibit_native_compilation)
+++      || !NILP (Vinhibit_automatic_native_compilation)
++       || noninteractive
++       || !NILP (Vpurify_flag)
++       || !COMPILEDP (definition)
++@@ -5337,12 +5337,13 @@ syms_of_comp (void)
++ {
++ #ifdef HAVE_NATIVE_COMP
++   /* Compiler control customizes.  */
++-  DEFVAR_LISP ("inhibit-native-compilation", Vinhibit_native_compilation,
+++  DEFVAR_LISP ("inhibit-automatic-native-compilation",
+++            Vinhibit_automatic_native_compilation,
++             doc: /* If non-nil, inhibit automatic native compilation of loaded .elc files.
++ 
++ After compilation, each function definition is updated to the native
++ compiled one.  */);
++-  Vinhibit_native_compilation = Qnil;
+++  Vinhibit_automatic_native_compilation = Qnil;
++ 
++   DEFVAR_BOOL ("native-comp-deferred-compilation",
++             native_comp_deferred_compilation,
index 5f0f03c6d78925543835af94971cdb1c4c1f5946,0000000000000000000000000000000000000000..ba0d9f6c66e17d03576681c01327e4f73949cda6
mode 100644,000000..100644
--- /dev/null
@@@ -1,16 -1,0 +1,18 @@@
 +0001-Prefer-usr-share-info-emacs.patch
 +0002-Run-debian-startup-and-set-debian-emacs-flavor.patch
 +0003-Remove-files-that-appear-to-be-incompatible-with-the.patch
 +0004-Adjust-documentation-references-for-Debian.patch
 +0005-Modify-the-output-of-version-to-indicate-Debian-modi.patch
 +0006-Don-t-try-to-build-src-macuvs.h-via-IVD_Sequences.tx.patch
 +0007-Kill-gpg-agent-in-package-test.el-to-avoid-a-race.patch
 +0008-Mark-vc-bzr-test-fauilt-bzr-autoloads-as-unstable-fo.patch
 +0009-pdumper-set-DUMP_RELOC_ALIGNMENT_BITS-1-for-m68k.patch
 +0010-Avoid-fork-bomb-caused-by-native-compilation.patch
 +0011-Avoid-fork-bomb-caused-by-native-compilation-trampol.patch
 +0012-Fix-eln-files-not-being-generated-when-native-comp-a.patch
 +0013-Fix-large-core-dumps-from-background-processes.patch
 +0014-Mark-test-undo-region-as-unstable.patch
 +0015-Mark-flaky-test-process-tests-multiple-threads-waiti.patch
 +0016-Fix-ctags-local-command-execution-vulnerability-CVE-.patch
++0017-Add-inhibit-native-compilation.patch
++0018-Rename-to-inhibit-automatic-native-compilation.patch