-
Notifications
You must be signed in to change notification settings - Fork 92
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 #252
Conversation
@TerrorJack could you please advise on wasm32 job? I remember there were some changes wrt |
It appears that in wasm32-wasi there is no
which is what we currently use in this package. So I think the solution here is to add an I pushed a commit that does that and the CI tests are passing everywhere now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, modulo perhaps the making dlopen
be safe
???
System/Posix/DynamicLinker/Prim.hsc
Outdated
@@ -84,10 +85,17 @@ data RTLDFlags | |||
| RTLD_LOCAL | |||
deriving (Show, Read) | |||
|
|||
#if defined(HAVE_DLFCN_H) | |||
foreign import capi unsafe "dlfcn.h dlopen" c_dlopen :: CString -> CInt -> IO (Ptr ()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dlopen
call can be comparatively expensive. One can reasonably argue that this should be safe
without a significant performance penalty. Once the object is loaded, the other calls should be quick.
Of course the same would then apply to the ccall
version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that dlopen
should be safe
and I would be happy to push another commit to do that. But I think this is part of a wider problem with this package (see #34) and I don't think we should tackle the problem in a piecemeal fashion. So I would prefer to not do this as part of this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that
dlopen
should besafe
and I would be happy to push another commit to do that. But I think this is part of a wider problem with this package (see #34) and I don't think we should tackle the problem in a piecemeal fashion. So I would prefer to not do this as part of this PR.
I can accept that I guess, though I tend to take a more opportunistic approach. Big bang fixes can be difficult, but spot improvements while looking at adjacent code are sometimes a good way to make progress. I'll leave the judgement call to you and others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "this is bad elsewhere too" isn't a good argument against fixing.
Rather fix it locally here and open a new ticket to fix the rest as well, unless this is controversial.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vdukhovni @hasufell I pushed added an additional commit that switches the imports of dlopen
& dlclose
to safe
. The reason that dlopen
needs safe
is obvious; it interacts with the local file system. But dlclose
also has to be safe
because it might trigger the execution of destructors defined in the library.
How do we know this is the only issue with header redirection? This frequently happens on darwin system too. I'd be fine with making all foreign imports use |
My take is that whenever possible we should use |
Here's how I came up with the changes included in the PR: I found the commit in the musl repo where the redirect was introduced and examined all changes there. I also searched for the
Agreed, |
So then we can just remove the CPP ifdef and keep capi? |
Unfortunately not. As I explained in a previous post here, it's need for |
I'm wondering whether (and if so, why?) this fix is enough—I believe that the Can someone please check if my thinking is correct? Thanks! |
I asked the Debian folks as well and it appears that |
From the debian discussion
Can you submit a PR? |
Suppose I can try but right now I have absolutely no idea what platform to use which would be affected. Turns out Debian i386 isn't adopting 64-bit time_t, only armhf, armel and a few others. And even there, the code in question isn't being used (as we established earlier). Suppose I could just fix |
Yeah, but it'll take months/years before Debian's t64 stuff trickles down to Ubuntu, and even then |
Even in absence of a reproducer, I am assuming there is a theoretical fix. What is it? Can you provide a PR for it? |
One such platform is Debian unstable armhf, which is in the process of transitioning to 64-bit time_t: https://wiki.debian.org/ReleaseGoals/64bit-time On that platform (as well as any other glibc/musl platform), however, CTimeVal isn't used for anything at all because there are #ifdefs that prefer using `utimensat` which takes CTimeSpec instead. This fix is therefore quite theoretical, as it is unknown whether there are any platforms actually affected. Related: haskell#252
Yes: #318 |
One such platform is Debian unstable armhf, which is in the process of transitioning to 64-bit time_t: https://wiki.debian.org/ReleaseGoals/64bit-time On that platform (as well as any other glibc/musl platform), however, CTimeVal isn't used for anything at all because there are #ifdefs that prefer using `utimensat` which takes CTimeSpec instead. This fix is therefore quite theoretical, as it is unknown whether there are any platforms actually affected. Related: haskell#252
One such platform is Debian unstable armhf, which is in the process of transitioning to 64-bit time_t: https://wiki.debian.org/ReleaseGoals/64bit-time On that platform (as well as any other glibc/musl platform), however, CTimeVal isn't used for anything at all because there are #ifdefs that prefer using `utimensat` which takes CTimeSpec instead. This fix is therefore quite theoretical, as it is unknown whether there are any platforms actually affected. Related: #252
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-bittime_t
(e.g.utimensat_time64
is likeutimensat
but with 64-bittime_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 forutimensat
).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 whencapi
is used. So this PR changes all affected syscalls to be imported withcapi
, which should be a fairly uncontroversial change.