This is the mail archive of the
mailing list for the binutils project.
Re: glibc: loading of shared objects with holes wastes address space
- From: Roland McGrath <roland at hack dot frob dot com>
- To: Mathias Krause <minipli at googlemail dot com>
- Cc: libc-alpha at sourceware dot org, binutils at sourceware dot org
- Date: Tue, 18 Oct 2011 10:04:05 -0700 (PDT)
- Subject: Re: glibc: loading of shared objects with holes wastes address space
- References: <CA+rthh_AeeVmEAotXy3M+ezqK9SOtydw4HBdeVtrgH9OJEPLGg@mail.gmail.com> <20111014164237.4FB7D2C0D3@topped-with-meat.com> <CA+rthh-t9=16zPpR29Xc0=x_nxeozvZYonxchCS+EeprHrPNCA@mail.gmail.com>
> It does, but creating a mapping that covers the whole file and even
> more beyond EOF with the flags of the first segment is not nice. It
> makes parts of the shared object executable that should not be. For
> only a short amount of time, though. Nevertheless, nothing one would
> expect from happening.
I suppose that is a valid point. Nevertheless, for ET_DYN objects, a
single initial mapping that is of the whole size is necessary to reserve
the address space required. That mapping needs to be from the file because
some kernels like to choose memory regions to use differently for file
mappings than for anonymous ones.
In the case where there is a hole that needs to be PROT_NONE, it could
achieve the same end result with the same number of system calls in a
different way. That is, do the initial mapping with PROT_NONE and then use
mprotect to set the first segment to its final protections (i.e. usually
PROT_READ|PROT_EXEC). That would not have the window of extra
executability that you are concerned about.