Skip to content

Commit

Permalink
Revert "Epoll compiled on GLIBC only supports GLIBC at runtime (#11722)…
Browse files Browse the repository at this point in the history
…" (#11738)

Motivation:

It appears we can't do this while also ensuring that working glibc use cases are not impacted.
In particular, there's a musl/glibc compatibility layer which solves the binary compatibility even though musl can still be in the library mappings.

Modifications:

Reverts #11722

Result:

native libs can be used again on alpine with glibc-compat
  • Loading branch information
chrisvest committed Oct 7, 2021
1 parent a93c1d0 commit ee648c3
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 48 deletions.
13 changes: 1 addition & 12 deletions transport-native-epoll/src/main/c/netty_epoll_native.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ static jint netty_epoll_native_epollCtlAdd0(JNIEnv* env, jclass clazz, jint efd,
}
return res;
}

static jint netty_epoll_native_epollCtlMod0(JNIEnv* env, jclass clazz, jint efd, jint fd, jint flags) {
int res = epollCtl(env, efd, EPOLL_CTL_MOD, fd, flags);
if (res < 0) {
Expand Down Expand Up @@ -541,15 +540,6 @@ static jstring netty_epoll_native_kernelVersion(JNIEnv* env, jclass clazz) {
return NULL;
}

static jint netty_epoll_native_gnulibc(JNIEnv* env, jclass clazz) {
#ifdef __GLIBC__
return 1;
#else
// We are using an alternative libc, possibly musl but could be anything.
return 0;
#endif // __GLIBC__
}

static jboolean netty_epoll_native_isSupportingSendmmsg(JNIEnv* env, jclass clazz) {
if (SYS_sendmmsg == -1) {
return JNI_FALSE;
Expand Down Expand Up @@ -668,8 +658,7 @@ static const JNINativeMethod statically_referenced_fixed_method_table[] = {
{ "isSupportingSendmmsg", "()Z", (void *) netty_epoll_native_isSupportingSendmmsg },
{ "isSupportingRecvmmsg", "()Z", (void *) netty_epoll_native_isSupportingRecvmmsg },
{ "tcpFastopenMode", "()I", (void *) netty_epoll_native_tcpFastopenMode },
{ "kernelVersion", "()Ljava/lang/String;", (void *) netty_epoll_native_kernelVersion },
{ "gnulibc", "()I", (void *) netty_epoll_native_gnulibc }
{ "kernelVersion", "()Ljava/lang/String;", (void *) netty_epoll_native_kernelVersion }
};
static const jint statically_referenced_fixed_method_table_size = sizeof(statically_referenced_fixed_method_table) / sizeof(statically_referenced_fixed_method_table[0]);
static const JNINativeMethod fixed_method_table[] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,11 @@
import io.netty.util.internal.ClassInitializerUtil;
import io.netty.util.internal.NativeLibraryLoader;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.SystemPropertyUtil;
import io.netty.util.internal.ThrowableUtil;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.channels.FileChannel;
import java.nio.channels.Selector;

Expand All @@ -40,7 +36,6 @@
import static io.netty.channel.epoll.NativeStaticallyReferencedJniMethods.epollin;
import static io.netty.channel.epoll.NativeStaticallyReferencedJniMethods.epollout;
import static io.netty.channel.epoll.NativeStaticallyReferencedJniMethods.epollrdhup;
import static io.netty.channel.epoll.NativeStaticallyReferencedJniMethods.gnulibc;
import static io.netty.channel.epoll.NativeStaticallyReferencedJniMethods.isSupportingRecvmmsg;
import static io.netty.channel.epoll.NativeStaticallyReferencedJniMethods.isSupportingSendmmsg;
import static io.netty.channel.epoll.NativeStaticallyReferencedJniMethods.kernelVersion;
Expand All @@ -55,7 +50,6 @@
* <p>Static members which call JNI methods must be defined in {@link NativeStaticallyReferencedJniMethods}.
*/
public final class Native {
private static final boolean checkMusl = SystemPropertyUtil.getBoolean("io.netty.native.musl.check", true);
private static final InternalLogger logger = InternalLoggerFactory.getInstance(Native.class);

static {
Expand Down Expand Up @@ -83,9 +77,9 @@ public final class Native {
);

try {
// First, try calling a side effect free JNI method to see if the library was already
// First, try calling a side-effect free JNI method to see if the library was already
// loaded by the application.
gnulibc();
offsetofEpollData();
} catch (UnsatisfiedLinkError ignore) {
// The library was not previously loaded, load it now.
loadNativeLibrary();
Expand All @@ -98,33 +92,6 @@ public final class Native {
// Just ignore
}
}
if (checkMusl && gnulibc() == 1) {
// Our binary is compiled for linking with GLIBC.
// Let's check that we don't have anything that looks like Musl libc in our runtime.
try {
FileInputStream fis = new FileInputStream("/proc/self/maps");
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
String line;
while ((line = reader.readLine()) != null) {
if (line.contains("-musl-")) {
throw new LinkageError("Native library was compiled for linking with GLIBC, but GLIBC " +
"was not found among library mappings. This likely means the OS/JVM uses an " +
"alternative libc, such as musl. To fix, either use NIO transport, or build a " +
"native transport for your platform.");
}
}
} finally {
try {
fis.close();
} catch (IOException e) {
logger.debug("Failed to close /proc/self/maps file.", e);
}
}
} catch (IOException e) {
logger.debug("Unable to check libc compatibility.", e);
}
}
Unix.registerInternal(new Runnable() {
@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,4 @@ private NativeStaticallyReferencedJniMethods() { }
static native boolean isSupportingRecvmmsg();
static native int tcpFastopenMode();
static native String kernelVersion();
static native int gnulibc();
}

0 comments on commit ee648c3

Please sign in to comment.