Subject: bug#24892: {s, }brk removed from FreeBSD 11.x and later, arm64 architecture

From: Eli Zaretskii <[email-masked]>
Date: Sat, 19 Nov 2016 08:57:44 +0200

> From: Paul Eggert <[email-masked]>
> Date: Fri, 18 Nov 2016 14:22:07 -0800
> Cc: [email-masked], Brooks Davis <[email-masked]>,
> 	[email-masked], Ashish SHUKLA <[email-masked]>
> 
> > it seems there's an implementation that allocates memory out of a large array in .bss used for some platforms - could we make use of that here?
> 
> Quite possibly. Unfortunately the code that uses that array (in gmalloc.c) also 
> uses sbrk to move the break past the end of the large array. The large array is 
> intended for use only during the build process; during ordinary execution, sbrk 
> is used.
> 
> Perhaps Emacs could work around the problem by supplying a user-space sbrk 
> emulator, which uses mmap to support the old-fashioned model where the heap is 
> contiguous. Is that something that could be done easily? That is, is there some 
> way to reserve the address space for a potentially-large Emacs heap right after 
> .bss, such that library calls to malloc and mmap won't use this address space? 
> That might do the trick.
> 
> Brooks Davis wrote:
> > What does emacs actually need from sbrk()?  Could it get by with something with the same interface allocating from .bss or does it need its allocations to be at the end of .bss?
> 
> I think more the latter. The problem with a fixed-size .bss is that whatever 
> size we pick during the build is likely to be wrong for users. Also, Emacs saves 
> the entire build-time .bss into an executable, so an enormous .bss will be 
> counterproductive.

I agree with everything Paul wrote.

There's one other factor you should be aware of: Emacs 25.2 will most
probably start its pretest in a week or so.  If this problem can be
solved for FreeBSD on arm64 by providing a drop-in replacement for
sbrk, we could include that in 25.2, which is a strictly bug-fix
release that can only accept safe bug fixes.  If not, the solution
will have to wait for Emacs 26.1, currently being developed on the
master branch, which is unlikely to be released before mid-2017 or
even the end of 2017.  Not a catastrophe, given that Emacs never
worked on this host, but something to consider.

(It is, of course, possible to provide a simple and safe solution for
25.2 and a more elaborate one for 26.1.)

Thanks.