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

Use CAMLextern in caml_ forward declarations #157

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jonahbeckford
Copy link

@jonahbeckford jonahbeckford commented Nov 26, 2024

This PR changes the extern attribute in extern caml_... to be exactly what OCaml uses (CAMLextern):

https://github.com/ocaml/ocaml/blob/b0b5f92896002239491308d3f1651d6e548c109f/runtime/caml/misc.h#L123-L136

Fine Details

Without this change, on Windows 64-bit systems with OCaml bytecode you can get an obscure:

Fatal error: cannot load shared library dlldigestif_c_stubs
Reason: flexdll error: cannot relocate caml_leave_blocking_section RELOC_REL32, target is too far: FFFFFFFF2EDEC956  000000002EDEC956

because extern caml_leave_blocking_section generates the following pseudo-assembly:

CALL caml_leave_blocking_section ; this is a 32-bit relative address

which does not work safely across DLL boundaries with flexdll.

The indirection introduced by CAMLextern makes the pseudo-assembly instead:

CALL [caml_leave_blocking_section] ; this is a 64-bit indirect address

which works well with flexdll.

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.

1 participant