Enable ASLR for dynamic libraries on Cygwin

This seems to avoid the fork failures described in etc/PROBLEMS
("Fork failures in a build with native compilation").

* lisp/treesit.el (treesit--install-language-grammar-1):
* lisp/emacs-lisp/comp.el (native-comp-driver-options): Add the
linker flag "-Wl,-dynamicbase" on Cygwin.
This commit is contained in:
Ken Brown 2023-03-26 15:02:30 -04:00
parent eb166287f3
commit 66b4394461
2 changed files with 14 additions and 7 deletions

View file

@ -186,8 +186,9 @@ and above."
:type '(repeat string)
:version "28.1")
(defcustom native-comp-driver-options (when (eq system-type 'darwin)
'("-Wl,-w"))
(defcustom native-comp-driver-options
(cond ((eq system-type 'darwin) '("-Wl,-w"))
((eq system-type 'cygwin) '("-Wl,-dynamicbase")))
"Options passed verbatim to the native compiler's back-end driver.
Note that not all options are meaningful; typically only the options
affecting the assembler and linker are likely to be useful.

View file

@ -3056,11 +3056,17 @@ function signals an error."
(apply #'treesit--call-process-signal
(if (file-exists-p "scanner.cc") c++ cc)
nil t nil
`("-fPIC" "-shared"
,@(directory-files
default-directory nil
(rx bos (+ anychar) ".o" eos))
"-o" ,lib-name))
(if (eq system-type 'cygwin)
`("-shared" "-Wl,-dynamicbase"
,@(directory-files
default-directory nil
(rx bos (+ anychar) ".o" eos))
"-o" ,lib-name)
`("-fPIC" "-shared"
,@(directory-files
default-directory nil
(rx bos (+ anychar) ".o" eos))
"-o" ,lib-name)))
;; Copy out.
(unless (file-exists-p out-dir)
(make-directory out-dir t))