www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - large Windows mingw64 project in C99 --- need ABI compatible D

reply NonNull <non-null use.startmail.com> writes:
Hello,

I have a large project written in C99 handed to me that 32-bit 
builds in Windows with the mingw32 compiler that comes with 
msys2. I'm working on 64-bit Windows 10.

Need to solve some nasty problems and move the build to 64 bits 
using the mingw64 compiler that comes with msys2.

Want to use D to improve some parts of this monster. But am 
confused about ABI issues.

Which D compiler should be used to be ABI compatible with 
mingw32? And which to be ABI compatible with mingw64?

The most important is the D compiler that is ABI compatible with 
the 64-bit mingw compiler because that is where this project is 
going.

How can I use D in this situation, where I need it to work 
directly with C data? building DLLs is not going to work here for 
that reason.
May 20 2020
next sibling parent welkam <wwwelkam gmail.com> writes:
On Wednesday, 20 May 2020 at 18:53:01 UTC, NonNull wrote:
 Which D compiler should be used to be ABI compatible with 
 mingw32? And which to be ABI compatible with mingw64?
I am not expert here but doesnt all C compilers have the same ABI? If yes then compile your code in 32 bits for 32 bit C obj files. If you are on 64 bit OS then D compilers will produce 64 bit executables by default. To change that use https://dlang.org/dmd-linux.html#switch-m32
May 20 2020
prev sibling parent reply kinke <noone nowhere.com> writes:
On Wednesday, 20 May 2020 at 18:53:01 UTC, NonNull wrote:
 Which D compiler should be used to be ABI compatible with 
 mingw32? And which to be ABI compatible with mingw64?
The natural choice for coupling mingw[64]-gcc would be GDC. Especially wrt. ABI, gdc apparently doesn't have to do much by itself, in sharp contrast to LDC. No idea where gdc's MinGW[-w64] support is at though and whether you need more recent D features not available in gdc. Wrt. LDC, I think the C ABI for the `-mtriple=x86_64-windows-gnu` target should be okay. IIRC, MinGW mostly adheres to Microsoft's official Win64 ABI and mostly just diverges wrt. `real` (80-bit x87 C `long double` vs. 64-bit double precision for MSVC), and that's covered by LDC IIRC. The C++ ABI (Itanium mangling, not the MSVC one) should be okay-ish; there might be differences wrt. what's considered a POD between MinGW and MSVC. Exception handling almost certainly doesn't work; TLS may likely not work either. In general, druntime and Phobos don't fully support MinGW[-w64], but if you restrict yourself to -betterC code, that might not be a problem.
 How can I use D in this situation, where I need it to work 
 directly with C data? building DLLs is not going to work here 
 for that reason.
With -betterC, generating mixed DLLs shouldn't be any trouble at all.
May 20 2020
parent reply NonNull <non-null use.startmail.com> writes:
On Wednesday, 20 May 2020 at 19:25:27 UTC, kinke wrote:
 On Wednesday, 20 May 2020 at 18:53:01 UTC, NonNull wrote:
 Which D compiler should be used to be ABI compatible with 
 mingw32? And which to be ABI compatible with mingw64?
The natural choice for coupling mingw[64]-gcc would be GDC. Especially wrt. ABI, gdc apparently doesn't have to do much by itself, in sharp contrast to LDC. No idea where gdc's MinGW[-w64] support is at though and whether you need more recent D features not available in gdc. [...]
Thanks for the detailed information! I see your point about gdc's ABI, but it seems gdc is not distributed for Windows at this juncture and I am looking for a simple way forward, so I will likely go with ldc2 with the option you suggested and see how it goes. Thanks again!
May 20 2020
parent reply kinke <noone nowhere.com> writes:
On Wednesday, 20 May 2020 at 20:45:26 UTC, NonNull wrote:
 [...] so I will likely go with ldc2 with the option you 
 suggested and see how it goes.

 Thanks again!
You're welcome. If you do come across an ABI issue, make sure to file an LDC issue. While I have no interest in MinGW, I want at least a working ABI.
May 20 2020
parent reply IGotD- <nise nise.com> writes:
On Wednesday, 20 May 2020 at 21:37:23 UTC, kinke wrote:
 You're welcome. If you do come across an ABI issue, make sure 
 to file an LDC issue. While I have no interest in MinGW, I want 
 at least a working ABI.
When you mention the ABI, is there something particular you have in mind or just in general?
May 20 2020
next sibling parent reply IGotD- <nise nise.com> writes:
On Wednesday, 20 May 2020 at 23:08:53 UTC, IGotD- wrote:
 On Wednesday, 20 May 2020 at 21:37:23 UTC, kinke wrote:
 You're welcome. If you do come across an ABI issue, make sure 
 to file an LDC issue. While I have no interest in MinGW, I 
 want at least a working ABI.
When you mention the ABI, is there something particular you have in mind or just in general?
That's a question to TS, NonNull.
May 20 2020
parent NonNull <non-null use.startmail.com> writes:
On Wednesday, 20 May 2020 at 23:10:12 UTC, IGotD- wrote:
 On Wednesday, 20 May 2020 at 23:08:53 UTC, IGotD- wrote:
 On Wednesday, 20 May 2020 at 21:37:23 UTC, kinke wrote:
 You're welcome. If you do come across an ABI issue, make sure 
 to file an LDC issue. While I have no interest in MinGW, I 
 want at least a working ABI.
When you mention the ABI, is there something particular you have in mind or just in general?
That's a question to TS, NonNull.
General.
May 20 2020
prev sibling parent reply kinke <noone nowhere.com> writes:
On Wednesday, 20 May 2020 at 23:08:53 UTC, IGotD- wrote:
 When you mention the ABI, is there something particular you 
 have in mind or just in general?
The ABI for MinGW targets in general. - Judging by https://forum.dlang.org/post/anfwqjjsteeyelbdhdci forum.dlang.org, you apparently use a very different definition of 'ABI'. See http://uclibc.org/docs/psABI-x86_64.pdf or https://docs.microsoft.com/en-us/cpp/build/x64-software-conv ntions?view=vs-2019 for what an ABI is. I guess what you meant is the druntime API implicitly used by the compiler (mostly, the _d_* hooks like _d_assert, _d_newclass etc.). That's well-defined already, e.g., see https://github.com/ldc-developers/ldc/blob/master/gen/runtime.cpp.
May 20 2020
parent IGotD- <nise nise.com> writes:
On Wednesday, 20 May 2020 at 23:28:09 UTC, kinke wrote:
 The ABI for MinGW targets in general. - Judging by 
 https://forum.dlang.org/post/anfwqjjsteeyelbdhdci forum.dlang.org, you
apparently use a very different definition of 'ABI'. See
http://uclibc.org/docs/psABI-x86_64.pdf or
https://docs.microsoft.com/en-us/cpp/build/x64-software-conv
ntions?view=vs-2019 for what an ABI is.

 I guess what you meant is the druntime API implicitly used by 
 the compiler (mostly, the _d_* hooks like _d_assert, 
 _d_newclass etc.). That's well-defined already, e.g., see 
 https://github.com/ldc-developers/ldc/blob/master/gen/runtime.cpp.
That's what I was thinking about, the ABI of x86-64 which originates from the ones that designed the ISA. The word ABI is used or misused in other areas as well, for example libc++abi which is a compatibility layer for libc++, that's why the word ABI turns up in a discussion about the druntime abstract interface.
May 20 2020