Bug 23608 – [musl 32-bit] Time functions linked incorrectly on musl >=1.2.0 / 32-bit
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2023-01-08T19:35:39Z
Last change time
2023-02-22T02:42:24Z
Keywords
pull
Assigned to
No Owner
Creator
Vladimir Panteleev
Comments
Comment #0 by dlang-bugzilla — 2023-01-08T19:35:39Z
(copied from PR)
musl switched to 64-bit time_t across all architectures in version 1.2.0:
https://musl.libc.org/time64.html
This change was done in a way which attempted to preserve ABI compatibility. To achieve this, the 32-bit versions of functions were left at their original names in the compiled library, and new 64-bit versions of functions were introduced. The header files then redirected calls to the standard function names to use the new 64-bit versions using the `__asm__("name")` construct, which is similar to D's `pragma(mangle, "name")`.
Commit ca0b670b87284afa341f1bef57f5614d88aecb4b tried addressing this change in musl by changing time_t to 64-bit when targeting new musl versions (the default). However, that change was incomplete, as it did not implement the function redirection part of the change, which is required to actually call the implementations using 64-bit time_t. As a result, it caused programs to link but return incorrect results at runtime on 32-bit architectures when targeting new musl versions.
I'm guessing what was fixed by that change is not interop between D and the musl libc, but between D and other C libraries which use the definition of `time_t` from the libc. https://github.com/dlang/druntime/pull/3275 causes Druntime to divide by zero at startup (https://github.com/dlang/dmd/blob/3368127d1a59ac1a7c95cf46a1c93a0ea73d665a/druntime/src/core/time.d#L2852) - because we are calling `clock_getres` with the expectation that it populates a `timespec` with 64-bit `time_t`, but we are actually calling the 32-bit version, so `ts.tv_nsec` remains at the default-initialized 0 value.
Comment #1 by dlang-bot — 2023-01-08T19:36:33Z
@CyberShadow updated dlang/dmd pull request #14794 "Fix linking to 64-bit time_t versions of functions on musl" fixing this issue:
- Fix linking to 64-bit time_t versions of functions on musl
musl switched to 64-bit time_t across all architectures in version
1.2.0:
https://musl.libc.org/time64.html
This change was done in a way which attempted to preserve ABI
compatibility. To achieve this, the 32-bit versions of functions were
left at their original names in the compiled library, and new 64-bit
versions of functions were introduced. The header files then
redirected calls to the standard function names to use the new 64-bit
versions using the __asm__("name") construct, which is similar to D's
pragma(mangle, "name").
This change is a fix-up for commit
ca0b670b87284afa341f1bef57f5614d88aecb4b, which tried addressing this
change in musl by changing time_t to 64-bit when targeting new musl
versions (the default). However, that change was incomplete, as it did
not implement the function redirection part of the change, which is
required to actually call the implementations using 64-bit time_t. As
a result, it caused programs to link but return incorrect results at
runtime on 32-bit architectures when targeting new musl versions.
Fix this by adjusting the mangled name of the D declarations of
affected functions when targeting musl on 32-bit platforms. Affected
functions in musl can be found by grepping for _REDIR_TIME64 and uses
of the __REDIR macro.
Fixes issue 23608.
https://github.com/dlang/dmd/pull/14794
Comment #2 by dlang-bot — 2023-02-19T17:31:47Z
@CyberShadow created dlang/dmd pull request #14895 "Fix linking to 64-bit time_t versions of functions on musl" fixing this issue:
- Fix linking to 64-bit time_t versions of functions on musl
musl switched to 64-bit time_t across all architectures in version
1.2.0:
https://musl.libc.org/time64.html
This change was done in a way which attempted to preserve ABI
compatibility. To achieve this, the 32-bit versions of functions were
left at their original names in the compiled library, and new 64-bit
versions of functions were introduced. The header files then
redirected calls to the standard function names to use the new 64-bit
versions using the __asm__("name") construct, which is similar to D's
pragma(mangle, "name").
This change is a fix-up for commit
ca0b670b87284afa341f1bef57f5614d88aecb4b, which tried addressing this
change in musl by changing time_t to 64-bit when targeting new musl
versions (the default). However, that change was incomplete, as it did
not implement the function redirection part of the change, which is
required to actually call the implementations using 64-bit time_t. As
a result, it caused programs to link but return incorrect results at
runtime on 32-bit architectures when targeting new musl versions.
Fix this by adjusting the mangled name of the D declarations of
affected functions when targeting musl on 32-bit platforms. Affected
functions in musl can be found by grepping for _REDIR_TIME64 and uses
of the __REDIR macro.
Fixes issue 23608.
https://github.com/dlang/dmd/pull/14895
Comment #3 by dlang-bot — 2023-02-20T00:32:36Z
dlang/dmd pull request #14895 "Fix linking to 64-bit time_t versions of functions on musl" was merged into stable:
- c13f8b554688538f5d36bf6a295f87aedfeb93ed by Vladimir Panteleev:
Fix linking to 64-bit time_t versions of functions on musl
musl switched to 64-bit time_t across all architectures in version
1.2.0:
https://musl.libc.org/time64.html
This change was done in a way which attempted to preserve ABI
compatibility. To achieve this, the 32-bit versions of functions were
left at their original names in the compiled library, and new 64-bit
versions of functions were introduced. The header files then
redirected calls to the standard function names to use the new 64-bit
versions using the __asm__("name") construct, which is similar to D's
pragma(mangle, "name").
This change is a fix-up for commit
ca0b670b87284afa341f1bef57f5614d88aecb4b, which tried addressing this
change in musl by changing time_t to 64-bit when targeting new musl
versions (the default). However, that change was incomplete, as it did
not implement the function redirection part of the change, which is
required to actually call the implementations using 64-bit time_t. As
a result, it caused programs to link but return incorrect results at
runtime on 32-bit architectures when targeting new musl versions.
Fix this by adjusting the mangled name of the D declarations of
affected functions when targeting musl on 32-bit platforms. Affected
functions in musl can be found by grepping for _REDIR_TIME64 and uses
of the __REDIR macro.
Fixes issue 23608.
https://github.com/dlang/dmd/pull/14895
Comment #4 by dlang-bot — 2023-02-22T02:42:24Z
dlang/dmd pull request #14904 "merge stable" was merged into master:
- bacf62c25a9587650044acf65e0cf40557b25521 by Vladimir Panteleev:
Fix linking to 64-bit time_t versions of functions on musl (#14895)
musl switched to 64-bit time_t across all architectures in version
1.2.0:
https://musl.libc.org/time64.html
This change was done in a way which attempted to preserve ABI
compatibility. To achieve this, the 32-bit versions of functions were
left at their original names in the compiled library, and new 64-bit
versions of functions were introduced. The header files then
redirected calls to the standard function names to use the new 64-bit
versions using the __asm__("name") construct, which is similar to D's
pragma(mangle, "name").
This change is a fix-up for commit
ca0b670b87284afa341f1bef57f5614d88aecb4b, which tried addressing this
change in musl by changing time_t to 64-bit when targeting new musl
versions (the default). However, that change was incomplete, as it did
not implement the function redirection part of the change, which is
required to actually call the implementations using 64-bit time_t. As
a result, it caused programs to link but return incorrect results at
runtime on 32-bit architectures when targeting new musl versions.
Fix this by adjusting the mangled name of the D declarations of
affected functions when targeting musl on 32-bit platforms. Affected
functions in musl can be found by grepping for _REDIR_TIME64 and uses
of the __REDIR macro.
Fixes issue 23608.
https://github.com/dlang/dmd/pull/14904