RFR: 8289275: Remove incorrect __declspec(dllimport) attributes from pointers in jdk.crypto.cryptoki [v2]

Julian Waters jwaters at openjdk.org
Sun Jul 10 08:22:53 UTC 2022


On Sat, 9 Jul 2022 07:46:39 GMT, Julian Waters <jwaters at openjdk.org> wrote:

>> Several instances of function pointers in jdk.crypto.cryptoki are marked with the dllimport attribute, which should only be applied to symbol declarations, of which a typedef'd function pointer is not. This would only be useful if a function pointer defined in the linked dll is desired to be imported, not if the pointer itself is created locally and used to store a function address. In addition to being incorrect, at least on the versions of Visual C++ the JDK supports today, it is also redundant; Typically they are used to avoid an indirect stub that jumps to the proper entry in the import address table, but usage of these typedefs involves loading the address of a function and directly (Usually through GetProcAddress, even in other cases it would simply be set to the address of a function anyway) assigning it to the pointer before immediately dispatching when called, which bypasses this procedure entirely and makes the attribute pointless.
>
> Julian Waters has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains two additional commits since the last revision:
> 
>  - Merge branch 'master' into typedefs
>  - Remove __declspec(dllimport) from pointers

Tested with `Microsoft (R) C/C++ Optimizing Compiler Version 19.31.31104` while observing `FPTR_VersionCheck` used in the method `JNIEXPORT jboolean JNICALL Java_sun_security_pkcs11_Secmod_nssVersionCheck` (j2secmod.c, line 40 and line 54), no differences in the generated assembly snippets:

Without __declspec(dllimport):

   0:	48 83 ec 38          	sub    $0x38,%rsp
   4:	48 8d 0d 00 00 00 00 	lea    0x0(%rip),%rcx        # b <main+0xb>
   b:	ff 54 24 20          	call   *0x20(%rsp)
   f:	33 c0                	xor    %eax,%eax
  11:	48 83 c4 38          	add    $0x38,%rsp
  15:	c3                   	ret   
``` 

With __declspec(dllimport):

   0:	48 83 ec 38          	sub    $0x38,%rsp
   4:	48 8d 0d 00 00 00 00 	lea    0x0(%rip),%rcx        # b <main+0xb>
   b:	ff 54 24 20          	call   *0x20(%rsp)
   f:	33 c0                	xor    %eax,%eax
  11:	48 83 c4 38          	add    $0x38,%rsp
  15:	c3                   	ret

-------------

PR: https://git.openjdk.org/jdk/pull/9353



More information about the security-dev mailing list