Bug 23837 – importc fails to link on windows x86 but successes on x64
Status
RESOLVED
Resolution
FIXED
Severity
blocker
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2023-04-12T23:10:35Z
Last change time
2023-04-26T08:40:04Z
Keywords
pull
Assigned to
No Owner
Creator
Temtaime
Comments
Comment #0 by temtaime — 2023-04-12T23:10:35Z
main.d:
import test;
struct TexturePacker
{
stbrp_context _context;
}
void main()
{
auto res = TexturePacker();
}
test.c:
struct stbrp_context
{
int width;
int height;
int align;
int init_mode;
int heuristic;
};
it works on x86_64, but on x86_mscoff it fails with:
error: undefined symbol: __C.stbrp_context.__inittest
Comment #1 by bugzilla — 2023-04-13T01:10:43Z
What's the command you use to compile it?
Comment #2 by temtaime — 2023-04-13T10:20:02Z
dmd main.d -m32
Comment #3 by bugzilla — 2023-04-24T22:52:24Z
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.
Comment #4 by dlang-bot — 2023-04-25T02:43:33Z
@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
Comment #5 by dlang-bot — 2023-04-26T08:40:04Z
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