Skip to content

C shim for static context to address Windows MinGW64 runtime failure #10

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

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

Conversation

prolic
Copy link

@prolic prolic commented May 19, 2025

This change attempts to address a Windows MinGW64 runtime failure that occurs during testing, where we see a "32 bit pseudo relocation out of range" error. The error suggests an issue with how GHC handles pointers in Windows executables.

  1. Adds a C shim (hs_secp256k1_shim.c) to handle the static context
  2. Updates the Haskell FFI bindings to use the shim instead of direct access
  3. Bumps version to 0.3.1 to reflect the FFI interface change

… failure

This change attempts to address a Windows MinGW64 runtime failure that occurs during
testing, where we see a "32 bit pseudo relocation out of range" error. The error
suggests an issue with how GHC handles pointers in Windows executables.

1. Adds a C shim (hs_secp256k1_shim.c) to handle the static context
2. Updates the Haskell FFI bindings to use the shim instead of direct access
3. Bumps version to 0.3.1 to reflect the FFI interface change
@prolic
Copy link
Author

prolic commented May 19, 2025

resolves #6

@prolic
Copy link
Author

prolic commented May 19, 2025

ping @ProofOfKeags

@prolic
Copy link
Author

prolic commented May 19, 2025

I don't know what's wrong the CI builds

@VnUgE
Copy link

VnUgE commented May 20, 2025

So I assume your limitation in haskell is that you can't reference global variables, so you needed to make a getter function to return the pointer to the global structure? The structure should be stored and mapped in the BSS segment of the process when the library is loaded, and externally referenced (via the pointer variable you're using). That means it's accessable to the linker (or dlsym()) assuming your compiler supports that?

@prolic
Copy link
Author

prolic commented May 20, 2025

On Linux, Haskell FFI sometimes works with global C variables indirectly because the ELF linker and GHC's runtime can resolve symbols like dlsym, even for globals — though Haskell itself doesn't support foreign import variable. If everything is statically linked, it just works.

On Windows (MinGW), global variables in DLLs are not exported by default unless marked with __declspec(dllexport), and Haskell can't import global variables directly anyway. Its FFI only supports importing functions. So you must use a getter function that returns a pointer to the global.

At least that's my understanding of it, please correct me if I'm wrong.

@VnUgE
Copy link

VnUgE commented May 20, 2025

Yep, you are correct. I just re-read the secp256k1.h header and see that when building the static library the global pointer variable won't be decorated with __declspec(dllexport) on Windows, so yeah you won't be able to get an address to it.

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.

2 participants