On Tuesday, 5 March 2024 at 00:20:36 UTC, Carl Sturtivant wrote:
On Monday, 4 March 2024 at 21:21:20 UTC, Carl Sturtivant wrote:
```
blah.obj: error LNK2019: unresolved external symbol _mul128
referenced in function MultiplyExtract128
blah.obj: error LNK2019: unresolved external symbol
__shiftright128 referenced in function MultiplyExtract128
blah.obj: error LNK2019: unresolved external symbol _umul128
referenced in function UnsignedMultiplyExtract128
blah.obj: error LNK2019: unresolved external symbol __stosb
referenced in function RtlSecureZeroMemory
blah.obj: error LNK2019: unresolved external symbol
__readgsqword referenced in function NtCurrentTeb
blah.obj: error LNK2019: unresolved external symbol
__imp_MapViewOfFileNuma2 referenced in function MapViewOfFile2
blah.obj: error LNK2019: unresolved external symbol
__imp_CharUpperW referenced in function ua_CharUpperW
```
I forced linkage of these unused symbols as follows, but it
would be nice to have a clean way to proceed.
```D
extern(C) {
int _InterlockedExchangeAdd(int* Addend, int Value) {
return 0; };
long _InterlockedExchangeAdd64(long* Addend, long Value) {
return 0; }
void _mul128() {};
void __shiftright128() {};
void _umul128() {};
void __stosb() {};
void __readgsqword() {};
void __imp_MapViewOfFileNuma2() {};
void __imp_CharUpperW() {};
}
```
I got the D signatures of the first two so as to generate the
correct linkage by using ImportC to translate the inclusion of
`Windows.h` into a .di file, and searching.
This looks like a combination of two issues:
1. Missing import libraries for Win32 API functions. Anything
starting with `__imp_` is a symbol that should be provided by a
DLL import library. MapViewOfFileNuma2 for example is provided
by onecore.lib in the Windows SDK, according to Microsoft
documentation.
2. C code referring to MSVC-specific compiler intrinsics. At
least InterlockedExchangeAdd, InterlockedExchangeAdd64 and _stosb
are such intrinsics. This is harder to resolve. There are two
ways forward here: either implement a shim function that
replicates the intrinsic's functionality if possible or add
support for these intrinsics to DMD.