Skip to content

Commit cc83b6a

Browse files
authored
Merge pull request #21085 from mpirvu/jitserver_ssl_fix
Explicitly load libcrypto for JITServer
2 parents f3e9891 + c58d7df commit cc83b6a

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

runtime/compiler/net/LoadSSLLibs.cpp

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,37 @@ namespace JITServer
234234
{
235235
void *loadLibssl()
236236
{
237-
void *result = NULL;
237+
// We want to load libssl.so and get access to the functions inside.
238+
// When libssl3 (or higher) is bundled with the JDK, we want to load that version
239+
// in preference over the one present on the system. `dlopen` will do that because
240+
// the RUNPATH for the JIT dll (from which `dlopen` is invoked) includes the
241+
// "JDK/lib" path where libssl is bundled. However, as part of loading libssl3,
242+
// `dlopen` will also attempt to load libcrypto3 (because it is a dependency).
243+
// This is searched in the RPATH of the jitserver executable for a server,
244+
// or in the RPATH of the java executable for a client. Currently, the jitserver
245+
// executable does not include an RPATH, so libcrypto3 is searched on the system
246+
// and this may fail on systems that do not have version 3 installed. This problem
247+
// can be circumvented by performing an explicit `dlopen` for the crypto library,
248+
// in which case the RUNPATH for the JIT is going to be used as search path.
249+
250+
// Library names for CryptoSSL 3, 1.1.1, 1.1.0, 1.0.2 and symbolic links
251+
static const char * const cryptoLibNames[] =
252+
{
253+
"libcrypto.so.3", // 3.x library name
254+
"libcrypto.so.1.1", // 1.1.x library name
255+
"libcrypto.so.1.0.0", // 1.0.x library name
256+
"libcrypto.so.10", // 1.0.x library name on RHEL
257+
"libcrypto.so" // general symlink library name
258+
};
259+
260+
int numOfLibraries = sizeof(cryptoLibNames) / sizeof(cryptoLibNames[0]);
261+
262+
for (int i = 0; i < numOfLibraries; ++i)
263+
{
264+
if (dlopen(cryptoLibNames[i], RTLD_NOW))
265+
break; // Break out of the loop as soon as the library is loaded
266+
}
267+
238268

239269
// Library names for OpenSSL 3, 1.1.1, 1.1.0, 1.0.2 and symbolic links
240270
static const char * const libNames[] =
@@ -246,16 +276,13 @@ void *loadLibssl()
246276
"libssl.so" // general symlink library name
247277
};
248278

249-
int numOfLibraries = sizeof(libNames) / sizeof(libNames[0]);
250-
279+
numOfLibraries = sizeof(libNames) / sizeof(libNames[0]);
280+
void *result = NULL;
251281
for (int i = 0; i < numOfLibraries; ++i)
252282
{
253283
result = dlopen(libNames[i], RTLD_NOW);
254-
255284
if (result)
256-
{
257-
return result;
258-
}
285+
break;
259286
}
260287
return result;
261288
}

0 commit comments

Comments
 (0)