Subject: bug#60996: 29.0.60; Native compile fails to remove temp file for trampoline

From: Andy Moreton <[email-masked]>
Date: Sat, 21 Jan 2023 22:12:10 +0000

Recently emacs 29 (and master) has started showing an error and
backtrace during startup:

Debugger entered--Lisp error: (permission-denied "Removing old name" 
"Permission denied" "c:/Users/ajm/AppData/Local/Temp/comp-lambda-MTAMbr...")
delete-file("c:/Users/ajm/AppData/Local/Temp/comp-lambda-MTAMbr...")
   #f(compiled-function () #<bytecode 0xb2aa5c0c9e24501>)()
   comp--native-compile((lambda (arg0 &optional arg1 arg2 arg3) (let ((f 
#'format-mode-line)) (funcall f arg0 arg1 arg2 arg3))) nil nil)
   comp-trampoline-compile(format-mode-line)
   comp-subr-trampoline-install(format-mode-line)
   advice--add-function(:around (#f(compiled-function () #<bytecode 
0x3c5d8019df7e91>) . #f(compiled-function (gv--val) #<bytecode 
0x8fdecbbba7cb3c2>)) delight--format-mode-line nil)
   advice-add(format-mode-line :around delight--format-mode-line)
   require(delight nil t)
   (not (require 'delight nil t))
   (if (not (require 'delight nil t)) (display-warning 'use-package 
(format "Cannot load %s" 'delight) :error))
   (prog1 (if (not (require 'delight nil t)) (display-warning 
'use-package (format "Cannot load %s" 'delight) :error)) (let ((elapsed 
(float-time (time-subtract (current-time) now)))) (if (> elapsed 0.1) 
(message "%s...done (%.3fs)" "Loading package delight" elapsed) (message 
"%s...done" "Loading package delight"))))
   (let ((now (current-time))) (message "%s..." "Loading package 
delight") (prog1 (if (not (require 'delight nil t)) (display-warning 
'use-package (format "Cannot load %s" 'delight) :error)) (let ((elapsed 
(float-time (time-subtract (current-time) now)))) (if (> elapsed 0.1) 
(message "%s...done (%.3fs)" "Loading package delight" elapsed) (message 
"%s...done" "Loading package delight")))))
   (condition-case err (let ((now (current-time))) (message "%s..." 
"Loading package delight") (prog1 (if (not (require 'delight nil t)) 
(display-warning 'use-package (format "Cannot load %s" 'delight) 
:error)) (let ((elapsed (float-time (time-subtract ... now)))) (if (> 
elapsed 0.1) (message "%s...done (%.3fs)" "Loading package delight" 
elapsed) (message "%s...done" "Loading package delight"))))) ((debug 
error) (funcall use-package--warning1 :catch err)))
   load-with-code-conversion("c:/home/ajm/.emacs.d/init.el" 
"c:/home/ajm/.emacs.d/init.el" t t)
   load("c:/home/ajm/.emacs.d/init" noerror nomessage)
   startup--load-user-init-file(#f(compiled-function () #<bytecode 
-0x1cd3443936cf717e>) #f(compiled-function () #<bytecode 
-0x1f3c61addc0c4f35>) t)
   command-line()
   normal-top-level()

Tracing execution of emacs with Process Explorer shows that the temp
file used to native compile trampolines is opened and closed repeatedly
by emacs, and at the point of the backtrace is still open by the same
emacs process.

Adding a workaround to .emacs.d/init.el mitigates this problem:
  (setq comp-enable-subr-trampolines nil)

Running "emacs -Q" does not show the problem, but is then less likely to
native compile trampolines during startup.

I am not sure excactly when this issue started, but I did not see it in
emacs-29 or master bootstrapped before this month.

     AndyM

In GNU Emacs 29.0.60 (build 8, x86_64-w64-mingw32) of 2023-01-21 built
  on QUIETUS
Repository revision: b875c9bf67ebf858648a00307c370d7a196aab56
Repository branch: emacs-29
Windowing system distributor 'Microsoft Corp.', version 10.0.19045
System Description: Microsoft Windows 10 Pro (v10.0.2009.19045.2486)

Configured using:
  'configure --prefix=c:/emacs/29.0.60/mingw64-x86_64-O2-native-aot
  --cache-file=/c/emacs/git/emacs/emacs-29/build/mingw64-x86_64-O2-native-aot/config.cache
  --without-compress-install --without-dbus --with-gif --with-gnutls
  --without-imagemagick --with-jpeg --with-json --with-lcms2
  --with-modules --with-native-compilation=aot --with-png --without-pop
  --with-rsvg --with-sqlite3 --with-tiff --with-tree-sitter --with-xml2
  --with-xpm --enable-checking 'CPPFLAGS= -DNO_SHLWAPI_ISOS=1' 'CFLAGS=
  -O2 -g3 -gdwarf-4 -fdiagnostics-color=never'
  PKG_CONFIG_PATH=/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig'

Configured features:
ACL GIF GMP GNUTLS HARFBUZZ JPEG JSON LCMS2 LIBXML2 MODULES NATIVE_COMP
NOTIFY W32NOTIFY PDUMPER PNG RSVG SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS TREE_SITTER WEBP XPM ZLIB

Important settings:
   value of $LANG: ENG
   locale-coding-system: cp1252

Major mode: ELisp/l

Minor modes in effect:
   hexl-follow-ascii: t
   which-function-mode: t
   global-so-long-mode: t
   display-fill-column-indicator-mode: t
   desktop-save-mode: t
   auto-image-file-mode: t
   minibuffer-electric-default-mode: t
   override-global-mode: t
   tooltip-mode: t
   global-eldoc-mode: t
   eldoc-mode: t
   show-paren-mode: t
   mouse-wheel-mode: t
   menu-bar-mode: t
   file-name-shadow-mode: t
   global-font-lock-mode: t
   font-lock-mode: t
   blink-cursor-mode: t
   column-number-mode: t
   line-number-mode: t
   transient-mark-mode: t
   auto-composition-mode: t
   auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message yank-media rfc822 mml mml-sec
epa derived gnus-util mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util mail-prsvr mail-utils add-log time mule-util jka-compr
bug-reference dired-aux xcscope autorevert dired-x dired dired-loaddefs
sh-script treesit executable time-date vc-svn rnc-mode rng-nxml
rng-valid rng-loc rng-uri rng-parse nxml-parse rng-match rng-dt rng-util
rng-pttrn nxml-ns nxml-mode nxml-outln nxml-rap sgml-mode facemenu dom
nxml-util nxml-enc xmltok lua-mode advice rust-utils rust-mode
rust-rustfmt rust-playpen rust-compile rust-cargo meson-mode smie eglot
external-completion array filenotify jsonrpc ert ewoc debug backtrace
find-func xref flymake-proc flymake thingatpt project hexl grep vc-git
diff-mode vc-dispatcher graphviz-dot-mode compile text-property-search
xr which-func imenu so-long display-fill-column-indicator desktop
frameset cygwin-mount ange-ftp comint ansi-osc ansi-color ring hl-line
pcase image-file image-converter edmacro kmacro use-package-bind-key
use-package-delight minibuf-eldef delight comp comp-cstr warnings rx
bind-key easy-mmode cl-extra help-mode use-package-ensure
use-package-core finder-inf yaml-mode-autoloads xr-autoloads
rust-mode-autoloads rnc-mode-autoloads powershell-autoloads
plantuml-mode-autoloads meson-mode-autoloads markdown-mode-autoloads
lua-mode-autoloads htmlize-autoloads haskell-mode-autoloads
graphviz-dot-mode-autoloads gnuplot-autoloads
gnu-elpa-keyring-update-autoloads epg rfc6068 epg-config
gnu-elpa-keyring-update delight-autoloads debbugs-autoloads info
dash-autoloads cus-edit pp cus-load icons wid-edit package browse-url
url url-proxy url-privacy url-expand url-methods url-history url-cookie
generate-lisp-file url-domsuf url-util mailcap url-handlers url-parse
auth-source cl-seq eieio eieio-core cl-macs password-cache json url-vars
nsm map byte-opt gv bytecomp byte-compile subr-x gnutls puny cl-loaddefs
cl-lib rmc iso-transl tooltip cconv eldoc paren electric uniquify
ediff-hook vc-hooks lisp-float-type elisp-mode mwheel dos-w32 ls-lisp
disp-table term/w32-win w32-win w32-vars term/common-win tool-bar dnd
fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow
isearch easymenu timer select scroll-bar mouse jit-lock font-lock syntax
font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads w32notify w32 lcms2 multi-tty
make-network-process native-compile emacs)

Memory information:
((conses 16 388657 216671)
  (symbols 48 25171 486)
  (strings 32 119123 37613)
  (string-bytes 1 3096676)
  (vectors 16 49749)
  (vector-slots 8 1397743 432730)
  (floats 8 85 750)
  (intervals 56 5657 2026)
  (buffers 984 25))