Thread overview
[Issue 23877] ImportC: Importing byteswap.h results in undefined reference to core.bitop.byteswap
[Issue 23877] ImportC: Importing byteswap.h results in undefined reference to core.bitop.byteswap with -betterC
May 11, 2023
Walter Bright
May 11, 2023
Walter Bright
May 11, 2023
Walter Bright
May 11, 2023
Walter Bright
May 11, 2023
Dlang Bot
May 11, 2023
Dlang Bot
May 11, 2023
https://issues.dlang.org/show_bug.cgi?id=23877

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com

--- Comment #1 from Walter Bright <bugzilla@digitalmars.com> ---
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.

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

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ImportC

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

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|ImportC: Importing          |ImportC: Importing
                   |byteswap.h results in       |byteswap.h results in
                   |undefined reference to      |undefined reference to
                   |core.bitop.byteswap with    |core.bitop.byteswap
                   |-betterC                    |

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

--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> ---
-betterC is irrelevant for ImportC.

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

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #3 from Dlang Bot <dlang-bot@dlang.rocks> ---
@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

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

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from Dlang Bot <dlang-bot@dlang.rocks> ---
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

--