diff --git a/testsuite-shading/pom.xml b/testsuite-shading/pom.xml index 5b42b7d662..f2fdf5db29 100644 --- a/testsuite-shading/pom.xml +++ b/testsuite-shading/pom.xml @@ -34,6 +34,8 @@ ${project.build.directory}/classes-shaded ${classesShadedDir}/META-INF/native shaded + shaded2 + ${project.artifactId}-${project.version}.jar io.netty. @@ -104,6 +106,7 @@ maven-shade-plugin + shade package shade @@ -122,6 +125,26 @@ + + shade-1 + package + + shade + + + + + ${project.groupId} + + + + + ${shadedPackagePrefix} + ${shadingPrefix2}.${shadedPackagePrefix} + + + + @@ -141,8 +164,36 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -156,6 +207,7 @@ ${shadingPrefix} + ${shadingPrefix2} @@ -211,6 +263,7 @@ maven-shade-plugin + shade package shade @@ -229,6 +282,26 @@ + + shade-1 + package + + shade + + + + + ${project.groupId} + + + + + ${shadedPackagePrefix} + ${shadingPrefix2}.${shadedPackagePrefix} + + + + @@ -248,8 +321,14 @@ - - + + + + + + + + @@ -263,6 +342,7 @@ ${shadingPrefix} + ${shadingPrefix2} diff --git a/testsuite-shading/src/test/java/io/netty/testsuite/shading/ShadingIT.java b/testsuite-shading/src/test/java/io/netty/testsuite/shading/ShadingIT.java index 1606bfcc9c..0f45fddef8 100644 --- a/testsuite-shading/src/test/java/io/netty/testsuite/shading/ShadingIT.java +++ b/testsuite-shading/src/test/java/io/netty/testsuite/shading/ShadingIT.java @@ -23,19 +23,26 @@ import java.lang.reflect.Method; public class ShadingIT { + private static final String SHADING_PREFIX = System.getProperty("shadingPrefix2"); + private static final String SHADING_PREFIX2 = System.getProperty("shadingPrefix"); + @Test public void testShadingNativeTransport() throws Exception { - testShading0(PlatformDependent.isOsx() ? "io.netty.channel.kqueue.KQueue" : "io.netty.channel.epoll.Epoll"); + String className = PlatformDependent.isOsx() ? + "io.netty.channel.kqueue.KQueue" : "io.netty.channel.epoll.Epoll"; + testShading0(SHADING_PREFIX, className); + testShading0(SHADING_PREFIX2, className); } @Ignore("Figure out why this sometimes fail on the CI") @Test public void testShadingTcnative() throws Exception { - testShading0("io.netty.handler.ssl.OpenSsl"); + String className = "io.netty.handler.ssl.OpenSsl"; + testShading0(SHADING_PREFIX, className); + testShading0(SHADING_PREFIX2, className); } - private static void testShading0(String classname) throws Exception { - String shadingPrefix = System.getProperty("shadingPrefix"); + private static void testShading0(String shadingPrefix, String classname) throws Exception { final Class clazz = Class.forName(shadingPrefix + '.' + classname); Method method = clazz.getMethod("ensureAvailability"); method.invoke(null); diff --git a/transport-native-epoll/pom.xml b/transport-native-epoll/pom.xml index 3fedacdad3..a67ae5fc2a 100644 --- a/transport-native-epoll/pom.xml +++ b/transport-native-epoll/pom.xml @@ -265,7 +265,7 @@ ${linux.sendmmsg.support}${glibc.sendmmsg.support} .*IO_NETTY_SENDMSSG_NOT_FOUND.* - CFLAGS=-O3 -DIO_NETTY_SENDMMSG_NOT_FOUND -Werror -fno-omit-frame-pointer -Wunused-variable -I${unix.common.include.unpacked.dir} + CFLAGS=-O3 -DIO_NETTY_SENDMMSG_NOT_FOUND -Werror -fno-omit-frame-pointer -Wunused-variable -fvisibility=hidden -I${unix.common.include.unpacked.dir} false @@ -281,7 +281,7 @@ ${jni.compiler.args.cflags} ^((?!CFLAGS=).)*$ - CFLAGS=-O3 -Werror -fno-omit-frame-pointer -Wunused-variable -I${unix.common.include.unpacked.dir} + CFLAGS=-O3 -Werror -fno-omit-frame-pointer -Wunused-variable -fvisibility=hidden -I${unix.common.include.unpacked.dir} false diff --git a/transport-native-epoll/src/main/c/netty_epoll_native.c b/transport-native-epoll/src/main/c/netty_epoll_native.c index 0352844c7d..68ef0ed2c0 100644 --- a/transport-native-epoll/src/main/c/netty_epoll_native.c +++ b/transport-native-epoll/src/main/c/netty_epoll_native.c @@ -65,11 +65,11 @@ struct mmsghdr { #endif // Those are initialized in the init(...) method and cached for performance reasons -jfieldID packetAddrFieldId = NULL; -jfieldID packetScopeIdFieldId = NULL; -jfieldID packetPortFieldId = NULL; -jfieldID packetMemoryAddressFieldId = NULL; -jfieldID packetCountFieldId = NULL; +static jfieldID packetAddrFieldId = NULL; +static jfieldID packetScopeIdFieldId = NULL; +static jfieldID packetPortFieldId = NULL; +static jfieldID packetMemoryAddressFieldId = NULL; +static jfieldID packetCountFieldId = NULL; // util methods static int getSysctlValue(const char * property, int* returnValue) { @@ -505,7 +505,7 @@ static void netty_epoll_native_JNI_OnUnLoad(JNIEnv* env) { } // Invoked by the JVM when statically linked -jint JNI_OnLoad_netty_transport_native_epoll(JavaVM* vm, void* reserved) { +static jint JNI_OnLoad_netty_transport_native_epoll0(JavaVM* vm, void* reserved) { JNIEnv* env; if ((*vm)->GetEnv(vm, (void**) &env, NETTY_JNI_VERSION) != JNI_OK) { return JNI_ERR; @@ -536,14 +536,7 @@ jint JNI_OnLoad_netty_transport_native_epoll(JavaVM* vm, void* reserved) { return ret; } -#ifndef NETTY_BUILD_STATIC -JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { - return JNI_OnLoad_netty_transport_native_epoll(vm, reserved); -} -#endif /* NETTY_BUILD_STATIC */ - -// Invoked by the JVM when statically linked -void JNI_OnUnload_netty_transport_native_epoll(JavaVM* vm, void* reserved) { +static void JNI_OnUnload_netty_transport_native_epoll0(JavaVM* vm, void* reserved) { JNIEnv* env; if ((*vm)->GetEnv(vm, (void**) &env, NETTY_JNI_VERSION) != JNI_OK) { // Something is wrong but nothing we can do about this :( @@ -552,8 +545,25 @@ void JNI_OnUnload_netty_transport_native_epoll(JavaVM* vm, void* reserved) { netty_epoll_native_JNI_OnUnLoad(env); } +// We build with -fvisibility=hidden so ensure we mark everything that needs to be visible with JNIEXPORT +// http://mail.openjdk.java.net/pipermail/core-libs-dev/2013-February/014549.html + +// Invoked by the JVM when statically linked +JNIEXPORT jint JNI_OnLoad_netty_transport_native_epoll(JavaVM* vm, void* reserved) { + return JNI_OnLoad_netty_transport_native_epoll0(vm, reserved); +} + +// Invoked by the JVM when statically linked +JNIEXPORT void JNI_OnUnload_netty_transport_native_epoll(JavaVM* vm, void* reserved) { + JNI_OnUnload_netty_transport_native_epoll0(vm, reserved); +} + #ifndef NETTY_BUILD_STATIC +JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { + return JNI_OnLoad_netty_transport_native_epoll0(vm, reserved); +} + JNIEXPORT void JNI_OnUnload(JavaVM* vm, void* reserved) { - JNI_OnUnload_netty_transport_native_epoll(vm, reserved); + JNI_OnUnload_netty_transport_native_epoll0(vm, reserved); } #endif /* NETTY_BUILD_STATIC */ diff --git a/transport-native-kqueue/pom.xml b/transport-native-kqueue/pom.xml index 749a2036f8..e8e38f562b 100644 --- a/transport-native-kqueue/pom.xml +++ b/transport-native-kqueue/pom.xml @@ -361,7 +361,7 @@ ${project.build.directory}/unix-common-lib ${unix.common.lib.dir}/META-INF/native/lib ${unix.common.lib.dir}/META-INF/native/include - CFLAGS=-O3 -Werror -fno-omit-frame-pointer -Wunused-variable -I${unix.common.include.unpacked.dir} + CFLAGS=-O3 -Werror -fno-omit-frame-pointer -Wunused-variable -fvisibility=hidden -I${unix.common.include.unpacked.dir} LDFLAGS=-z now -L${unix.common.lib.unpacked.dir} -Wl,--whole-archive -l${unix.common.lib.name} -Wl,--no-whole-archive true diff --git a/transport-native-kqueue/src/main/c/netty_kqueue_eventarray.c b/transport-native-kqueue/src/main/c/netty_kqueue_eventarray.c index ad7a20d654..0fb0c4cffd 100644 --- a/transport-native-kqueue/src/main/c/netty_kqueue_eventarray.c +++ b/transport-native-kqueue/src/main/c/netty_kqueue_eventarray.c @@ -24,7 +24,7 @@ #include "netty_unix_jni.h" #include "netty_unix_util.h" -jfieldID kqueueJniPtrFieldId = NULL; +static jfieldID kqueueJniPtrFieldId = NULL; static void netty_kqueue_eventarray_evSet(JNIEnv* env, jclass clzz, jlong keventAddress, jobject channel, jint ident, jshort filter, jshort flags, jint fflags) { // Create a global pointer, cast it as a long, and retain it in java to re-use and free later. diff --git a/transport-native-kqueue/src/main/c/netty_kqueue_native.c b/transport-native-kqueue/src/main/c/netty_kqueue_native.c index 94899e037e..389569735e 100644 --- a/transport-native-kqueue/src/main/c/netty_kqueue_native.c +++ b/transport-native-kqueue/src/main/c/netty_kqueue_native.c @@ -65,7 +65,7 @@ #endif /* NOTE_DISCONNECTED */ #endif /* __APPLE__ */ -clockid_t waitClockId = 0; // initialized by netty_unix_util_initialize_wait_clock +static clockid_t waitClockId = 0; // initialized by netty_unix_util_initialize_wait_clock static jint netty_kqueue_native_kqueueCreate(JNIEnv* env, jclass clazz) { jint kq = kqueue(); @@ -318,8 +318,7 @@ static void netty_kqueue_native_JNI_OnUnLoad(JNIEnv* env) { netty_kqueue_eventarray_JNI_OnUnLoad(env); } -// Invoked by the JVM when statically linked -jint JNI_OnLoad_netty_transport_native_kqueue(JavaVM* vm, void* reserved) { +static jint JNI_OnLoad_netty_transport_native_kqueue0(JavaVM* vm, void* reserved) { JNIEnv* env; if ((*vm)->GetEnv(vm, (void**) &env, NETTY_JNI_VERSION) != JNI_OK) { return JNI_ERR; @@ -351,14 +350,7 @@ jint JNI_OnLoad_netty_transport_native_kqueue(JavaVM* vm, void* reserved) { return ret; } -#ifndef NETTY_BUILD_STATIC -JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { - return JNI_OnLoad_netty_transport_native_kqueue(vm, reserved); -} -#endif /* NETTY_BUILD_STATIC */ - -// Invoked by the JVM when statically linked -void JNI_OnUnload_netty_transport_native_kqueue(JavaVM* vm, void* reserved) { +static void JNI_OnUnload_netty_transport_native_kqueue0(JavaVM* vm, void* reserved) { JNIEnv* env; if ((*vm)->GetEnv(vm, (void**) &env, NETTY_JNI_VERSION) != JNI_OK) { // Something is wrong but nothing we can do about this :( @@ -367,8 +359,25 @@ void JNI_OnUnload_netty_transport_native_kqueue(JavaVM* vm, void* reserved) { netty_kqueue_native_JNI_OnUnLoad(env); } +// We build with -fvisibility=hidden so ensure we mark everything that needs to be visible with JNIEXPORT +// http://mail.openjdk.java.net/pipermail/core-libs-dev/2013-February/014549.html + +// Invoked by the JVM when statically linked +JNIEXPORT jint JNI_OnLoad_netty_transport_native_kqueue(JavaVM* vm, void* reserved) { + return JNI_OnLoad_netty_transport_native_kqueue0(vm, reserved); +} + +// Invoked by the JVM when statically linked +JNIEXPORT void JNI_OnUnload_netty_transport_native_kqueue(JavaVM* vm, void* reserved) { + JNI_OnUnload_netty_transport_native_kqueue0(vm, reserved); +} + #ifndef NETTY_BUILD_STATIC +JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { + return JNI_OnLoad_netty_transport_native_kqueue0(vm, reserved); +} + JNIEXPORT void JNI_OnUnload(JavaVM* vm, void* reserved) { - return JNI_OnUnload_netty_transport_native_kqueue(vm, reserved); + return JNI_OnUnload_netty_transport_native_kqueue0(vm, reserved); } #endif /* NETTY_BUILD_STATIC */ diff --git a/transport-native-unix-common/pom.xml b/transport-native-unix-common/pom.xml index d08cfad494..78d8c918d2 100644 --- a/transport-native-unix-common/pom.xml +++ b/transport-native-unix-common/pom.xml @@ -101,7 +101,7 @@ - +