Define JNIEXPORT as visibility default with GCC?

Martin Buchholz martinrb at google.com
Thu Feb 14 01:32:40 UTC 2013


So, here's an obvious patch.   Any reason not to do this?  (although we can
do even better, as always)

http://cr.openjdk.java.net/~martin/webrevs/openjdk8/JNIEXPORT/
# HG changeset patch
# User martin
# Date 1360805180 28800
# Node ID 0d31e5e0a2c8e4a40c669a6c1c59530aa5f705bb
# Parent  397424fe9fb52dd622af409ed2e3f1fc3463ee8d
6666666: JNIEXPORT should use gcc visibility "default"
Summary: Define JNIEXPORT

diff --git a/src/solaris/javavm/export/jni_md.h
b/src/solaris/javavm/export/jni_md.h
--- a/src/solaris/javavm/export/jni_md.h
+++ b/src/solaris/javavm/export/jni_md.h
@@ -26,8 +26,14 @@
 #ifndef _JAVASOFT_JNI_MD_H_
 #define _JAVASOFT_JNI_MD_H_

-#define JNIEXPORT
-#define JNIIMPORT
+#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
+
 #define JNICALL

 typedef int jint;
On Wed, Feb 13, 2013 at 5:14 PM, Martin Buchholz <martinrb at google.com>wrote:

> 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
>>
>
>



More information about the core-libs-dev mailing list