public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: David Allsopp <David.Allsopp@cl.cam.ac.uk>
To: "cygwin@cygwin.com" <cygwin@cygwin.com>
Subject: RE: Regression for OCaml introduced by rebase 4.4.4
Date: Fri, 09 Feb 2018 11:30:00 -0000	[thread overview]
Message-ID: <E51C5B015DBD1348A1D85763337FB6D90189A8933F@Remus.metastack.local> (raw)
In-Reply-To: <20180208151549.GA32555@calimero.vinschen.de>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 3424 bytes --]

Corinna Vinschen wrote:
> On Feb  8 11:47, David Allsopp wrote:
> > TL;DR flexlink-compiled DLLs (i.e. ocaml libraries) are broken by the
> > 0x200000000 base address requirement added in rebase 4.4.4. Possible
> > fixes for this at the bottom.
> > [...]
> >   $ ocaml
> >           OCaml version 4.04.2
> >
> >   # #load "unix.cma";;
> >   Cannot load required shared library dllunix.
> >   Reason: /usr/lib/ocaml/stublibs/dllunix.so: flexdll error: cannot
> > relocate RELOC_REL32, target is too far: 0xfffffffc013d8b5f
> 0x13d8b5f.
> >
> > This is a known problem and fundamental limitation of flexdll (there
> > is no
> > RELOC_REL64 in COFF).
> 
> Apart from that, not only Cygwin DLLs but also the Windows system DLLs
> are all loaded and relocated to the area beyond 0x1:80000000, so
> relocation beyond the 32 bit address space is no generic problem in
> Windows.  Why isn't that possible in FlexDLL?  I don't understand this.
> To me this looks like a bug in FlexDLL, not a requirement to let certain
> DLLs slip through the cracks.

There's a more full explanation of what and why for flexdll here: https://github.com/alainfrisch/flexdll/blob/master/README.md. I believe it's not unrelated to some of the black magic going on in Cygwin's autoload.cc, but without (at least at the moment), quite as much self-modifying code.

FlexDLL is "solving" the problem of allowing a dynamically loaded library to refer to symbols in the main application (or in previously dynamically loaded libraries, without loading them a second time, as the Windows loader I believe does). FlexDLL does this by deferring COFF relocations to runtime and it achieves that by sitting in front of both the linker when the DLL is constructed and also an application's main (or dllmain). For normal linking, since PE limits code size to 2GB, there is no need for a RELOC_REL64 relocation type. However, because we're actually resolving the symbols dynamically, on 64-bit the DLL may have been loaded too far from the executable (or other DLL) image it's resolving to (for actual Windows resolution to DLL symbols, you'd be using the stub code generated either by the linker or by __declspec(dllimport), which would similarly be guaranteed to be within the range of RELOC_REL32 because the stub itself is static).

When this was originally encountered for 64-bit MSVC (this was all added before Cygwin64 existed), the solution at the time was to keep the preferred base addresses low, but in reality what's really required is that everything is within a 2GB window somewhere in the address space.

I guess one can argue over whether that's a bug or a limitation, but the problem we face is that we can engineer it so that our DLLs and executables are within a 2GB range (having looked again at this in even more detail, we could just as readily do this with addresses > 0x200000000), but we still run the risk of rebase messing up the DLLs.

However, we'll scratch our heads some more on possible alternative solutions, since having a flag for DLLs which says "keep us within a 2GB range somewhere" sounds even more less likely to get merged than my previous suggestion.


David
\0ТÒÐÐ¥\a&ö&ÆVÒ\a&W\x06÷'G3¢\x02\x02\x02\x02\x02\x02\x06‡GG\x03¢òö7–wv–âæ6öÒ÷\a&ö&ÆV×2æ‡FÖÀФd\x15\x13¢\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x06‡GG\x03¢òö7–wv–âæ6öÒöf\x17\x12ðФFö7VÖVçF\x17F–öã¢\x02\x02\x02\x02\x02\x02\x02\x02\x06‡GG\x03¢òö7–wv–âæ6öÒöFö72æ‡FÖÀÐ¥Vç7V'67&–&R\x06–æfó¢\x02\x02\x02\x02\x02\x06‡GG\x03¢òö7–wv–âæ6öÒöÖÂò7Vç7V'67&–&R×6–×\x06ÆPРÐ

  reply	other threads:[~2018-02-09 11:30 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-08 11:47 David Allsopp
2018-02-08 15:04 ` Corinna Vinschen
2018-02-09 11:30   ` David Allsopp
2018-02-08 15:15 ` Corinna Vinschen
2018-02-09 11:30   ` David Allsopp [this message]
2018-02-09 11:40     ` Corinna Vinschen
2018-02-09 13:11       ` Corinna Vinschen
2018-02-09 13:19         ` David Allsopp
2018-02-09 13:13       ` David Allsopp
2018-02-09 17:11         ` Corinna Vinschen
2018-02-15 11:44           ` David Allsopp
2018-02-15 12:02             ` Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E51C5B015DBD1348A1D85763337FB6D90189A8933F@Remus.metastack.local \
    --to=david.allsopp@cl.cam.ac.uk \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).