RFR: 8305761: Resolve multiple definition of 'jvm' when statically linking with JDK native libraries

Jiangli Zhou jiangli at openjdk.org
Mon Apr 10 19:22:50 UTC 2023


On Mon, 10 Apr 2023 13:52:39 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>> Rename various 'jvm' variables to 'jvm_<lib_name>' to avoid duplicate symbol problems when statically linking the launcher executable with JDK native libraries.
>
> src/java.management/share/native/libmanagement/management.c line 36:
> 
>> 34: const JmmInterface* jmm_interface = NULL;
>> 35: JavaVM* jvm_management = NULL;
>> 36: jint jmm_version = 0;
> 
> Is there any reason why these field can't be static?

Thanks.

My understanding is that 'static' gives internal linkage. The static variable is limited to the scope of the translate unit that declares it. It seems to be okay to use 'static' for the 'jvm' variables in  [management.c](https://github.com/openjdk/jdk/pull/13397/files/0fa6a4b3984d91c124ee2adb9d6e1facdc63c156#diff-1717ac36c4bbefab688a4e75104417bec3687f78108096c2cca3af4ee552ab11) and [management_ext.c](https://github.com/openjdk/jdk/pull/13397/files#diff-0fa91a6686c9e5dc77bdef6981235785524108950075e58d2004853dc66e1977) to resolve the symbol issue. It's problematic for the usages in jdk.crypto.cryptoki code.

I'll change management.c and management_ext.c to define 'jvm' as 'static' as suggested.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/13397#discussion_r1162008444



More information about the security-dev mailing list