Thread overview
[Issue 23837] importc fails to link on windows x86 but successes on x64
Apr 13, 2023
Walter Bright
Apr 13, 2023
Temtaime
Apr 24, 2023
Walter Bright
Apr 25, 2023
Dlang Bot
Apr 26, 2023
Dlang Bot
April 13, 2023
https://issues.dlang.org/show_bug.cgi?id=23837

Walter Bright <bugzilla@digitalmars.com> changed:

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

--- Comment #1 from Walter Bright <bugzilla@digitalmars.com> ---
What's the command you use to compile it?

--
April 13, 2023
https://issues.dlang.org/show_bug.cgi?id=23837

--- Comment #2 from Temtaime <temtaime@gmail.com> ---
dmd main.d -m32

--
April 24, 2023
https://issues.dlang.org/show_bug.cgi?id=23837

--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> ---
The `__init{struct name}` symbol is generated as the initializer for a struct by the dmd.tocsym.toInitializer() function. It is inserted into the object file generated for the source file with the struct definition in it. Hence,

    dmd -m32 main.d

will fail to link, because the object file for test.c is not linked in. To fix,

    dmd -m32 main.d test.c

So why does the former still work on other platforms? If the struct is zero initialized, a section in the BSS segment of all zeros is used instead. But the relocations for BSS do not work for MSCOFF-32.

Since C structs are always default initialized to zero, a better solution would be to initialize the instance with code rather than copying zero'd data to it.

--
April 25, 2023
https://issues.dlang.org/show_bug.cgi?id=23837

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

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

--- Comment #4 from Dlang Bot <dlang-bot@dlang.rocks> ---
@WalterBright created dlang/dmd pull request #15126 "fix Issue 23837 - importc fails to link on windows x86 but successes …" fixing this issue:

- fix Issue 23837 - importc fails to link on windows x86 but successes on x64

https://github.com/dlang/dmd/pull/15126

--
April 26, 2023
https://issues.dlang.org/show_bug.cgi?id=23837

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

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

--- Comment #5 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #15126 "fix Issue 23837 - importc fails to link on windows x86 but successes …" was merged into master:

- 0159114c5b907268c6edc1ab042bb2ac576f54c9 by Walter Bright:
  fix Issue 23837 - importc fails to link on windows x86 but successes on x64

https://github.com/dlang/dmd/pull/15126

--