dmd icon indicating copy to clipboard operation
dmd copied to clipboard

ImportC: _InterlockedExchangeAdd and a ton of other VC intrinsics are not recognized

Open dlangBugzillaToGithub opened this issue 2 years ago • 10 comments

Max Samukha (@maxsamukha) reported this on 2023-05-05T19:58:20Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=23894

CC List

  • Walter Bright (@WalterBright)
  • Carl Sturtivant

Description

"Windows.h" intrinsics:

main.obj : error LNK2019: unresolved external symbol _InterlockedExchangeAdd referenced in function _InlineInterlockedAdd
main.obj : error LNK2019: unresolved external symbol _InterlockedExchangeAdd64 referenced in function _InlineInterlockedAdd64
main.obj : error LNK2019: unresolved external symbol _mul128 referenced in function MultiplyExtract128
main.obj : error LNK2019: unresolved external symbol __shiftright128 referenced in function MultiplyExtract128
main.obj : error LNK2019: unresolved external symbol _umul128 referenced in function UnsignedMultiplyExtract128
main.obj : error LNK2019: unresolved external symbol _ReadWriteBarrier referenced in function BarrierAfterRead
main.obj : error LNK2019: unresolved external symbol __stosb referenced in function RtlSecureZeroMemory
main.obj : error LNK2019: unresolved external symbol __readgsqword referenced in function NtCurrentTeb

Fun!

!!!There are attachements in the bugzilla issue that have not been copied over!!!

dlangBugzillaToGithub avatar May 05 '23 19:05 dlangBugzillaToGithub

bugzilla (@WalterBright) commented on 2023-05-11T06:01:59Z

ImportC doesn't support gcc's inline assembler, either. Is the use of these intrinsics blockable with some macro?

dlangBugzillaToGithub avatar May 11 '23 06:05 dlangBugzillaToGithub

maxsamukha commented on 2023-05-11T17:12:13Z

(In reply to Walter Bright from comment #1)
> Is the use of these intrinsics blockable with some macro?

I don't think so. They are not conditioned on a macro that could be simply (un)defined (if that's what you meant).

dlangBugzillaToGithub avatar May 11 '23 17:05 dlangBugzillaToGithub

bugzilla (@WalterBright) commented on 2023-05-29T07:10:30Z

Could you please post the section of code in the windows.h you have?

dlangBugzillaToGithub avatar May 29 '23 07:05 dlangBugzillaToGithub

maxsamukha commented on 2023-06-03T06:53:11Z

Created attachment 1878
VC intrinsics referenced by windows.h

dlangBugzillaToGithub avatar Jun 03 '23 06:06 dlangBugzillaToGithub

maxsamukha commented on 2023-06-03T06:53:58Z

(In reply to Walter Bright from comment #3)
> Could you please post the section of code in the windows.h you have?

Please see an isolated test case in the attachment.

dlangBugzillaToGithub avatar Jun 03 '23 06:06 dlangBugzillaToGithub

dfj1esp02 commented on 2023-12-01T10:26:40Z

Another problem is 

#define GENERIC_READ (0x80000000L)

these are interpreted as helper macros due to parentheses and skipped.

dlangBugzillaToGithub avatar Dec 01 '23 10:12 dlangBugzillaToGithub

bugzilla (@WalterBright) commented on 2023-12-02T02:27:35Z

(In reply to anonymous4 from comment #6)
> Another problem is 
> 
> #define GENERIC_READ (0x80000000L)
> 
> these are interpreted as helper macros due to parentheses and skipped.

This PR should resolve that problem.

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

dlangBugzillaToGithub avatar Dec 02 '23 02:12 dlangBugzillaToGithub

sturtivant commented on 2024-03-11T05:49:19Z

Here's a workaround.
https://forum.dlang.org/post/[email protected]
There's a list of all x64 MSVC intrinsics at the included link with prototypes with named parameters.

dlangBugzillaToGithub avatar Mar 11 '24 05:03 dlangBugzillaToGithub

I think I have a solution for the linker errors. The link error happens in functions marked __forceinline. We shouldn’t even be generating code for them unless they are used and so we shouldn’t be failing to link. ImportC is interpreting them as regular old functions with extern visibility.

drpriver avatar Apr 18 '25 22:04 drpriver

I'll make a new issue for the __forceinline

drpriver avatar Apr 18 '25 22:04 drpriver