Subject: bug#28882: [bug-gnu-emacs] emacs-26.0.90 build feedback

From: "Nelson H. F. Beebe" <[email-masked]>
Date: Wed, 18 Oct 2017 11:58:11 -0600

Andreas Schwab asks about my build attempts for emacs-26.0.90 on
HardenedBSD:

>> Does it help to add -no-pie to LDFLAGS?

For HardenedBSD 11.1-STABLE-HBSD (FreeBSD 11.1-STABLE-HBSD #0), that
worked:

	rm src/emacs src/temacs
	gmake LDFLAGS=-no-pie

I installed that version.

I then tried the same on HardenedBSD 12.0-CURRENT (FreeBSD
12.0-CURRENT #0).

It complained that the -no-pie option was unrecognized, so I retried
with --no-pie: that was accepted, but there was still a segmentation
fault at dump time.

Next, based on the advice for NetBSD in etc/PROBLEMS about kernel
parameters that control address-space layout randomization (ASLR), 
I looked to see what HardenedBSD had:

	# sysctl -a | grep -i aslr
	kern.features.hbsd_aslr: 1
	options PAX_ASLR
	hardening.pax.aslr.status: 2

With those defaults, I get failure like this in the emacs build:

	Dumping under the name emacs
	11323200 of 33554432 static heap bytes used
	gmake[1]: *** [Makefile:738: bootstrap-emacs] Segmentation fault

In another window, as root, I then ran

	# sysctl kern.features.hbsd_aslr:0
	sysctl: oid 'kern.features.hbsd_aslr' is read only

	# sysctl hardening.pax.aslr.status:0
	hardening.pax.aslr.status: 2 -> 0

Then, back in the emacs build window, I ran

	% \rm src/emacs src/temacs
	% gmake
	...
	./temacs --batch  --load loadup bootstrap
	Loading loadup.el (source)...
	Using load-path (/local/build/cc/emacs-26.0.90/lisp /local/build/cc/emacs-26.0.90/lisp/emacs-lisp
	/local/build/cc/emacs-26.0.90/lisp/language /local/build/cc/emacs-26.0.90/lisp/international
	/local/build/cc/emacs-26.0.90/lisp/textmodes /local/build/cc/emacs-26.0.90/lisp/vc)
	Loading emacs-lisp/byte-run...
	Loading emacs-lisp/backquote...
	...
	Finding pointers to doc strings...
	Finding pointers to doc strings...done
	Dumping under the name emacs
	11323200 of 33554432 static heap bytes used
	96055 pure bytes used
	mv -f emacs bootstrap-emacs
	gmake -C ../lisp compile-first EMACS="../src/bootstrap-emacs"
	gmake[2]: Entering directory '/local/build/cc/emacs-26.0.90/lisp'
	gmake[2]: Nothing to be done for 'compile-first'.
	gmake[2]: Leaving directory '/local/build/cc/emacs-26.0.90/lisp'
	gmake -C ../admin/unidata all EMACS="../../src/bootstrap-emacs"
	gmake[2]: Entering directory '/local/build/cc/emacs-26.0.90/admin/unidata'
	  ELC      uvs.elc
	elf_load_section: truncated ELF file
	gmake[2]: *** [Makefile:72: uvs.elc] Abort trap

If I try to run the dumped emacs, I get

	% src/bootstrap-emacs --version
	elf_load_section: truncated ELF file
	Abort

Thus, disabling the ASLR feature in HardenedBSD 12.0 DOES let temacs
run to completion, but the result dumped emacs does not run correctly.

As I final experiment, I ported over the 11.1 emacs installation
directories to 12.0, and after installing some missing packages, and
creating some symlinks to missing older library versions, I was able
to get a usable emacs-26.0.90 on 12.0.  However, that has to be viewed
as a temporary stopgap.

The number of dependent shared libraries is frighteningly large

	% ldd $B/nemacs |wc -l
	96

so the import from 11.1 to 12.0 is fragile, and likely to break with
future system updates on the 12.0 system.

-------------------------------------------------------------------------------
- Nelson H. F. Beebe                    Tel: +1 801 581 5254                  -
- University of Utah                    FAX: +1 801 581 4148                  -
- Department of Mathematics, 110 LCB    Internet e-mail: [email-masked]  -
- 155 S 1400 E RM 233                       [email-masked]  [email-masked] -
- Salt Lake City, UT 84112-0090, USA    URL: http://www.math.utah.edu/~beebe/ -
-------------------------------------------------------------------------------