|
|
Message-ID: <20260908151014.GW25906@brightrain.aerifal.cx> Date: Tue, 8 Sep 2026 11:10:14 -0400 From: Rich Felker <dalias@...c.org> To: Markus Wichmann <nullplan@....net> Cc: musl@...ts.openwall.com Subject: Re: Add relro protections for static linking On Tue, Sep 08, 2026 at 04:17:05PM +0200, Markus Wichmann wrote: > Am Mon, Sep 07, 2026 at 09:21:52PM -0400 schrieb Rich Felker: > > On Mon, Mar 30, 2026 at 07:24:03PM +0200, Markus Wichmann wrote: > > > On another note, while looking at that function: Is it maybe sensible to > > > add malloc memory donation to it as well? Or is the LOAD segment > > > overhang different in static linking somehow? > > > > I seem to recall a long time ago not doing the donation with static > > linking for some reason, but I don't remember the details. It might > > have been that old kernels had the brk start mid-page at the end of > > bss, and that we were using raw brk without page alignment for the > > bump allocator. Or it might have been a matter of complex weak > > reference logic to avoid pulling in malloc unnecessarily. > > Looking at it more, it seems that calling __malloc_donate() will always > pull in the big malloc, and thus preclude the bump allocator from > working. Which we could fix up with weak references (a donation function > that only does something when the big malloc is also linked in), but > yeah, it seems like that would be digging pretty deep for a pretty small > potatoe. Particularly since mallocng has its donation function in a > separate file, probably for good reason as well. FWIW the original motive for donating these gaps to malloc was the large memory overhead/waste of linking lots of shared libraries, and needing not only a whole page for what would often be just a few tens of bytes of relocations, but also the link map structures. After donations, the link map structures would often fit in the gaps, with room leftover to avoid mapping any new memory for low amounts of malloc use you might see in a program that's just doing getling() or getaddrinfo() or something. And this could basically make dynamic linking free. I'm not sure how well it's actually working with mallocng and the way it statically assigns size classes to the carved-up gaps. Rich
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.