This is the mail archive of the cygwin-patches mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH RFC] fork: reduce chances for "address space is already occupied" errors

On Apr 24 17:09, Michael Haubenwallner wrote:
> On 4/12/19 7:40 PM, Corinna Vinschen wrote:
> > Hi Michael,
> > Nick Clifton, one of the binutils maintainers, made the following
> > suggestion in PM:
> > 
> > Allow the ld flag --enable-auto-image-base to take a filename as
> > argument.> 
> > The idea: The file is used by ld to generate the start address
> > for the next built DLL.  Mechanism:
> > 
> > 1.1. If ld links a DLL and if the file given to --enable-auto-image-base
> >      doesn't exist, ld will give the DLL the start address of the
> >      auto image base range.
> > 
> > 1.2: Next time, if ld links a DLL and if the file given to
> >      --enable-auto-image-base exists, it will use the address in that
> >      file as the start address for th just built DLL.
> > 
> > 2. It will store that address, plus the size of the DLL, rounded up to
> >    64K, in that file.
> The rounding up is fine to get some alignment for the base address itself,
> but it feels irrelevant if it was for "finding the next base" only.

Well,DLLs always start at a 64K boundary, so it makes sesne to round

> > 3. If the auto image base range is at an end, ld will wrap back to
> >    the start address of the auto image base range.> 
> > TBD: A way to enable this feature without having to change all
> >      packages' build systems.
> As the --enable-auto-image-base flag does not name any method for finding
> the image base beyond "automatic", IMHO using some predefined control file
> under the hoods should be fine.

The current preliminary solution is to check if a file
~/.ld-pe-auto-image-base exists.  If it doesn't, ld uses the usual
hashing to compute the base address.  If the file exists and is empty,
the base address range start address is used (i.e. 0x4:00000000),
otherwise the address is taken from the file and the next free address
after that is written back to the file.

The problem is that auto-image-basing occurs *so* early in ld,
that the size of the built DLL isn't known when writing the file back.
To do this right there needs to be a bigger change to ld, the current
infrastructure around image basing doesn't allow to call saving the file
content deferred.

So ATM, ld just adds ~38 Megs to the current DLL address, which is
1 Meg more than the largest Cygwin DLL on my system.

There's already a bit more in terms of settings, but that's still
in the works.


Corinna Vinschen
Cygwin Maintainer

Attachment: signature.asc
Description: PGP signature

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]