Subject: Re: bug#23529: Request for fixing randomize_va_space build issues

From: Eli Zaretskii <[email-masked]>
Date: Wed, 07 Sep 2016 21:11:36 +0300

> Cc: [email-masked], [email-masked], [email-masked]
> From: Paul Eggert <[email-masked]>
> Date: Wed, 7 Sep 2016 10:40:14 -0700
> 
> Eli Zaretskii wrote:
> >> PIE can relocate data as well as code.
> > Since we will be reading data into existing variables, that would
> > happen automatically.
> 
> I'm afraid I'm not following. Any existing variables (i.e., existing in Emacs 
> when it starts up) are of fixed size, so they can't hold all the data of a 
> dumped Emacs. The newly starting-up Emacs must decide how much storage to 
> allocate to hold the dumped state that Emacs is about to read.  This storage's 
> addresses should be randomized, and the data that Emacs reads will contain 
> pointers-to-data that Emacs itself would need to relocate.

Data that has to be dumped and loaded are accessed through pointers
(since it's malloced in temacs).  When Emacs starts, it will allocate
memory off the heap and read the dumped data into that, using those
pointers to access it.  The pointers are of fixed size, so they will
already exist in the Emacs binary (and relocated if PIE wants that).
I assume that randomization affects the addresses of the buffers
allocated off the heap, so we don't need to do anything else to
randomize the data we load.

> All this is doable, of course. It's just that it should be easier and more 
> portable to use the existing compilers and linkers rather than reinvent the wheel.

I very much doubt that it would be easier, since linking nowadays is
also much more complicated.  We'd need to plug the compiled data into
data structures that support the Lisp interpreter, something which the
compiler and linker won't help us.