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

From: Paul Eggert <[email-masked]>
Date: Fri, 18 Nov 2016 14:22:07 -0800

Ed Maste wrote:
> arm64 support was first available in a release in FreeBSD 11.0, without sbrk, and sbrk never existed on the stable/11 branch.

Thanks, I didn't know that. So Emacs has never worked in this environment.

> 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.