Bug 24123 – More importc definitions are needed for macOS
Status
RESOLVED
Resolution
FIXED
Severity
blocker
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
x86_64
OS
Mac OS X
Creation time
2023-08-30T22:34:11Z
Last change time
2023-09-12T10:22:00Z
Keywords
ImportC, pull
Assigned to
No Owner
Creator
Jeffrey H. Johnson
Comments
Comment #0 by trnsz — 2023-08-30T22:34:11Z
Using DMD ImportC on macOS, most non-trivial programs that use stdio won't function.
Using macOS Intel 13.5, Darwin 22.6.0, Xcde 14.3.1, DMD64 v2.105.0.
Problem is that https://github.com/dlang/dmd/blob/25d2741b86b1060ec43d80dbcc8dc190d5453322/druntime/src/importc.h#L98 is incomplete.
For my application to compile and link, I had to add the following additional lines here in the APPLE section. I'm sure others will likely be needed, but this was enough for me.
# define __builtin___snprintf_chk(s, c, flag, os, fmt, ...) snprintf(s, c, fmt, __VA_ARGS__)
# define __builtin___sprintf_chk(s, flag, os, fmt, ...) sprintf(s, fmt, __VA_ARGS__)
# define __builtin___vsnprintf_chk(s, c, flag, os, fmt, ...) vsnprintf(s, c, fmt, __VA_ARGS__)
# define __builtin___strlcat_chk(dest, src, x, n) strlcat(dest,src,x)
# define __builtin___strlcpy_chk(dest, src, x, n) strlcpy(dest,src,x)
# define __builtin_object_size
----
I hope this is helpful!
Perhaps this should be another issue, but, it seems one cannot use C11 atomics.
I don't know if this is something that can be worked around, but if you try to use them, you get the following error messages from DMD:
file.c(99): Error: undefined identifier `__c11_atomic_load`
file.c(126): Error: undefined identifier `__c11_atomic_store`
file.c(204): Error: undefined identifier `__c11_atomic_store`
file.c(220): Error: undefined identifier `__c11_atomic_load`
file.c(429): Error: undefined identifier `__c11_atomic_init`
I can work around this for my application, but, as ImportC is supposed to be C11 compliant, I'd hope that C11 atomics can be supported on macOS.
Comment #1 by dlang-bot — 2023-09-12T06:21:00Z
@WalterBright created dlang/dmd pull request #15601 "fix Issue 24123 - More importc definitions are needed for macOS" fixing this issue:
- fix Issue 24123 - More importc definitions are needed for macOS
https://github.com/dlang/dmd/pull/15601
Comment #2 by bugzilla — 2023-09-12T06:24:53Z
Thank you for submitting the bug report. I created a pull request based on your contribution.
Please submit only one issue per bugzilla issue. I took the liberty of splitting the atomics issue into a separate issue:
https://issues.dlang.org/show_bug.cgi?id=24141
Comment #3 by dlang-bot — 2023-09-12T10:22:00Z
dlang/dmd pull request #15601 "fix Issue 24123 - More importc definitions are needed for macOS" was merged into master:
- 34f894e8bf5d57cc8220aa50c2a5d92eff7abd4b by Walter Bright:
fix Issue 24123 - More importc definitions are needed for macOS
https://github.com/dlang/dmd/pull/15601