@@ -234,7 +234,37 @@ namespace JITServer
234
234
{
235
235
void *loadLibssl ()
236
236
{
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
+
238
268
239
269
// Library names for OpenSSL 3, 1.1.1, 1.1.0, 1.0.2 and symbolic links
240
270
static const char * const libNames[] =
@@ -246,16 +276,13 @@ void *loadLibssl()
246
276
" libssl.so" // general symlink library name
247
277
};
248
278
249
- int numOfLibraries = sizeof (libNames) / sizeof (libNames[0 ]);
250
-
279
+ numOfLibraries = sizeof (libNames) / sizeof (libNames[0 ]);
280
+ void *result = NULL ;
251
281
for (int i = 0 ; i < numOfLibraries; ++i)
252
282
{
253
283
result = dlopen (libNames[i], RTLD_NOW);
254
-
255
284
if (result)
256
- {
257
- return result;
258
- }
285
+ break ;
259
286
}
260
287
return result;
261
288
}
0 commit comments