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 capi for syscalls that break under musl's handling of 64-bit time_t #225

Merged
merged 1 commit into from
Oct 10, 2022

Conversation

redneb
Copy link
Contributor

@redneb redneb commented Oct 2, 2022

I maintain a repo with builds of GHC for the musl C standard library and I encountered a subtle bug of this library that affects GHC under 32-bit architectures with musl.

In 32-bit architectures, there was a transition where the C type time_t was redefined to be 64-bit in order to address the Y2038 problem. The way this was handled by musl was by introducing new versions of all affected syscalls that work with 64-bit time_t (e.g. __clock_gettime64 is like clock_gettime but with 64-bit time_t). In addition, a redirect was introduced to create an alias of the new versions of these functions under the old name (e.g. here's the redirection for clock_gettime).

The problem is that this redirection is defined as a C macro in a C header file and as such, it does not get picked by GHC when the foreign function import is done via ccall, but works just fine when capi is used. So this PR changes all affected syscalls to be imported with capi, which should be a fairly uncontroversial change.

@AshleyYakeley
Copy link
Member

You'll have to fix the builds. (There's a recent fix in master for the Free BSD build, so that might work here.)

@redneb
Copy link
Contributor Author

redneb commented Oct 10, 2022

I fixed the CI builds: there was a wrong header used for gettimeofday. There correct header for it is sys/time.h but time.h was being used. With ccall this didn't cause failures but capi is less forgiving.

@AshleyYakeley
Copy link
Member

Looks good. Is there any easy way of testing this? Ideally it would be great to have a CI build for musl, to ensure that it didn't get broken in the future.

@redneb
Copy link
Contributor Author

redneb commented Oct 10, 2022

I am working to create some musl based docker images, but for now I am not sure if there is an easy way. BTW this breakage was for 32 bit architectures only.

@AshleyYakeley AshleyYakeley merged commit 08a389a into haskell:master Oct 10, 2022
@AshleyYakeley
Copy link
Member

OK, well if you come up with something feel free to make a PR for a CI build later on.

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