May 02, 2023
https://issues.dlang.org/show_bug.cgi?id=23877

          Issue ID: 23877
           Summary: ImportC: Importing byteswap.h results in undefined
                    reference to core.bitop.byteswap with -betterC
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody@puremagic.com
          Reporter: naydef@abv.bg

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

--