Bug 23877 – ImportC: Importing byteswap.h results in undefined reference to core.bitop.byteswap
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2023-05-02T14:50:43Z
Last change time
2023-05-11T11:06:08Z
Keywords
ImportC, pull
Assigned to
No Owner
Creator
naydef
Comments
Comment #0 by naydef — 2023-05-02T14:50:43Z
Not sure if this is a valid issue.
xawd.c
-----------------
#include <byteswap.h>
-----------------
Compile with:
dmd xawd.c -betterC
Error:
-----------------
/usr/bin/ld: /usr/lib64/gcc/x86_64-solus-linux/12/../../../../lib64/Scrt1.o: in function `_start':
/home/build/YPKG/root/glibc/build/glibc-2.36/csu/../sysdeps/x86_64/start.S:103: undefined reference to `main'
/usr/bin/ld: xawd.o: in function `_D10__builtins__T17__builtin_bswap16ZQuFNaNbNiNftZt':
xawd.c:(.text._D10__builtins__T17__builtin_bswap16ZQuFNaNbNiNftZt[_D10__builtins__T17__builtin_bswap16ZQuFNaNbNiNftZt]+0x10): undefined reference to `_D4core5bitop8byteswapFNaNbNiNftZt'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1
-----------------
This specific byteswap.h file has:
-----------------
static __inline __uint16_t
__bswap_16 (__uint16_t __bsx)
{
#if __GNUC_PREREQ (4, 8)
return __builtin_bswap16 (__bsx);
#else
return __bswap_constant_16 (__bsx);
#endif
}
-----------------
DMD64 D Compiler v2.103.0 Linux
Comment #1 by bugzilla — 2023-05-11T07:50:06Z
The problem is that in druntime/src/__builtins.di, which is loaded on every compile of an ImportC program, defines:
ushort __builtin_bswap16()(ushort value)
{
import core.bitop;
return core.bitop.byteswap(value);
}
and core.bitop.byteswap is defined in the D runtime library, not the C one. Hence it shows up as an undefined symbol when a link is attempted.
Comment #2 by bugzilla — 2023-05-11T08:02:40Z
-betterC is irrelevant for ImportC.
Comment #3 by dlang-bot — 2023-05-11T08:04:04Z
@WalterBright created dlang/dmd pull request #15224 "fix Issue 23877 - ImportC: Importing byteswap.h results in undefined …" fixing this issue:
- fix Issue 23877 - ImportC: Importing byteswap.h results in undefined reference to core.bitop.byteswap
https://github.com/dlang/dmd/pull/15224
Comment #4 by dlang-bot — 2023-05-11T11:06:08Z
dlang/dmd pull request #15224 "fix Issue 23877 - ImportC: Importing byteswap.h results in undefined …" was merged into master:
- c9b63234d03cd95ca4da665c2765ec355525b398 by Walter Bright:
fix Issue 23877 - ImportC: Importing byteswap.h results in undefined reference to core.bitop.byteswap
https://github.com/dlang/dmd/pull/15224