Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop passing --image-base on Cygwin64 #89

Merged
merged 3 commits into from
Sep 23, 2020
Merged

Stop passing --image-base on Cygwin64 #89

merged 3 commits into from
Sep 23, 2020

Conversation

dra27
Copy link
Member

@dra27 dra27 commented Sep 17, 2020

On Cygwin64, --image-base 0x10000 is always passed to the linker. This generates invalid DLLs for Cygwin64. This has never worked reliably, as DLLs need unique base addresses on Cygwin to survive fork. However, since version 4.4.4 Cygwin's rebase forces DLLs to the correct base address in 0x2:00000000-0x4:00000000. Since Cygwin64 executables load in 0x1:00000000-0x1:80000000, DLLs are always too far RELOC_REL32.

Rather than dynamically generating branch islands, the new approach on the OCaml-side is to return to using __declspec(dllimport) only, which will cause the linker to do that work for us, as it should.

Regardless of the solution, --image-base should cease being passed to the linker on Cygwin64.

Cygwin64 has a memory layout which the attempt to place DLLs at 0x10000
violates. flexlink must either generate jump islands or the symbols must
be declared in the consuming library with __declspec(dllimport) to
ensure that they don't generate RIP-relative offsets.
@dra27
Copy link
Member Author

dra27 commented Sep 23, 2020

@alainfrisch - what do you think about this one? It will completely break shared library compilation of OCaml < 4.12 for Cygwin64, but equally it is broken at the moment, just more subtly (fork doesn't work). Equally, we should not be compiling DLLs for Cygwin64 at all like this. Cygwin's rebaseall can "corrupt" them at any moment by changing their base address - I think it only works at the moment because Cygwin Setup's rebase operation looks only at new DLLs.

An alternative would be to add a new flag which disables this automatic passing of --image-base, but it feels odd to have an explicit flag in order to select correct behaviour over incorrect behaviour?!

@alainfrisch
Copy link
Collaborator

Yes, I agree with your plan. Breaking "more" OCaml < 4.12 for Cygwin64 is ok.

@dra27
Copy link
Member Author

dra27 commented Sep 23, 2020

Ta - I'll cut a release in the next couple of days and ping the Cygwin maintainer (although I think that may involve offering to become the Cygwin maintainer......)

@dra27 dra27 merged commit 1ba65c1 into ocaml:master Sep 23, 2020
@dra27 dra27 deleted the cygwin64 branch September 23, 2020 11:09
@xavierleroy
Copy link

With my CompCert hat on, I would like to use OCaml under Cygwin64. How could we make progress with the new release of FlexDLL and the updated Cygwin64 package?

@dra27
Copy link
Member Author

dra27 commented Nov 30, 2020

I'm just testing 0.39 on my fork - assuming that's fine, I'll do the release later today.

@dra27
Copy link
Member Author

dra27 commented Nov 30, 2020

It's released, and I've proposed adopting the Cygwin package to push the release downstream as well.

dra27 added a commit to dra27/flexdll that referenced this pull request Dec 29, 2024
Previously:
  - -base applied to MSVC64
  - Cygwin64 had -base 0x10000 hard-coded until ocaml#89
  - mingw64 didn't specify -base at all

Now:
  - The default is not to change the base address at all
  - All 3 64-bit ports support -base
  - For now, still ignored for 32-bit ports
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants