Define JNIEXPORT as visibility default with GCC?

Martin Buchholz martinrb at google.com
Wed Feb 13 17:14:40 PST 2013


This seems like an obvious improvement.
There are already bunches of places in the jdk sources that do things like:

./hotspot/src/cpu/x86/vm/jni_x86.h
#if defined(SOLARIS) || defined(LINUX) || defined(_ALLBSD_SOURCE)

#if defined(__GNUC__) && (__GNUC__ > 4) || (__GNUC__ == 4) &&
(__GNUC_MINOR__ > 2)
  #define JNIEXPORT     __attribute__((visibility("default")))
  #define JNIIMPORT     __attribute__((visibility("default")))
#else
  #define JNIEXPORT
  #define JNIIMPORT
#endif

This is *crazy*.  The visibility feature has nothing to do with x86, or
SOLARIS, or LINUX, or BSD.
JNIEXPORT should be defined to  __attribute__((visibility("default")))
#if #and #only #if:
defined(__GNUC__) && (__GNUC__ > 4) || (__GNUC__ == 4) && (__GNUC_MINOR__ >
2)

and that change should simply be made to the public exported jdk jni headers

Martin

On Mon, Feb 11, 2013 at 10:26 AM, Jeremy Manson <jeremymanson at google.com>wrote:

> Hi folks,
>
> Pardon if this has come up before; a quick search didn't indicate
> anything, but the mailing list archives are kind of hard to search.
>
> I wonder if it makes sense to define JNIEXPORT as meaning __attribute__
> ((visibility ("default"))) when compiling with gcc.  Currently, anyone
> building JNI code with -fvisibility=hidden and a stock Oracle JDK is at a
> loss: their JNI exports will be hidden along with everything else.
>
> I notice that both IcedTea and OS X have made this change independently,
> and it has been added to Hotspot's JNIEXPORT definition (so HS can be built
> with -fvisibility=hidden), but the change isn't present in the latest JDK8
> bits:
>
>
> http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/933742f4bb4c/src/solaris/javavm/export/jni_md.h
>
> The workaround is pretty ugly: people who want to use -fvisibility=hidden
> have to redefine JNIEXPORT.  Upstream, it would be a pretty simple change
> to jni_md.h, along the lines of:
>
> #if defined(__GNUC__) && __GNUC__ >= 4
>     #define JNIEXPORT __attribute__ ((visibility ("default")))
> #else
>     #define JNIEXPORT
> #endif
>
> Any thoughts?
>
> Jeremy
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/hotspot-runtime-dev/attachments/20130213/29246a7c/attachment.html 


More information about the hotspot-runtime-dev mailing list