glibc: loading of shared objects with holes wastes address space

Roland McGrath roland@hack.frob.com
Fri Oct 14 16:56:00 GMT 2011


Mapping past the end of a file is not a problem.
It has perfectly well-defined semantics.

The behavior of occupying holes with PROT_NONE regions is what's
intended.  It was done this way because the previous behavior led to
undesireable results.  When holes of a page or more were left, then
unrelated later mappings would go there.  This created situations where
memory-access bugs could have extremely strange results.  For example,
the gap would often be filled by an allocation done for malloc.  Then a
buggy program that wrote off the end of the allocation would clobber
some library's data segment, which is much harder to figure out in
debugging than if it just clobbered some other malloc region.

So we're not going to back to how it was.

A change that I think would be reasonable is to extend the PROT_NONE
blackout regions only as far as the segment size rounded to p_align.
With normal objects, there won't be any gap beyond that.  With your
objects that use an unusual layout, the PROT_NONE region will still
cover the space that the phdrs say the object expects to be covered, but
not the whole region up until the next segment.  A cleanly-written patch
to implement that behavior would be fine with me.


Thanks,
Roland



More information about the Libc-alpha mailing list