Define JNIEXPORT as visibility default with GCC?

Jeremy Manson jeremymanson at
Mon Feb 11 18:26:07 UTC 2013

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

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")))
    #define JNIEXPORT

Any thoughts?


More information about the core-libs-dev mailing list