Skip to content

Commit db9711f

Browse files
committed
[GR-38179] Load JLI library on osx for AWT
PullRequest: graal/11735
2 parents e259190 + 41f22d9 commit db9711f

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

sdk/mx.sdk/mx_sdk_vm_impl.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2730,6 +2730,14 @@ def cflags(self):
27302730
'-DLIBJVM_RELPATH=' + _libjvm_path,
27312731
]
27322732

2733+
# path to libjli - only needed on osx for AWT
2734+
if mx.is_darwin():
2735+
_libjli_path = join(_dist.path_substitutions.substitute('<jre_base>'), 'lib', mx.add_lib_suffix("libjli"))
2736+
_libjli_path = relpath(_libjli_path, start=_exe_dir)
2737+
_dynamic_cflags += [
2738+
'-DLIBJLI_RELPATH=' + _libjli_path,
2739+
]
2740+
27332741
# path to native image language library - this is set even if the library is not built, as it may be built after the fact
27342742
if self.jvm_launcher:
27352743
# since this distribution has no native library, we can only assume the default path: language_home/lib<lang>vm.so

sdk/src/org.graalvm.launcher.native/src/launcher.cc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@
109109
#include <mach-o/dyld.h>
110110
#include <sys/syslimits.h>
111111
#include <sys/stat.h>
112+
113+
#ifndef LIBJLI_RELPATH
114+
#error path to jli library undefined
115+
#endif
116+
#define LIBJLI_RELPATH_STR STR(LIBJLI_RELPATH)
117+
112118
#elif defined (_WIN32)
113119
#include <windows.h>
114120
#include <libloaderapi.h>
@@ -189,6 +195,19 @@ std::string exe_directory() {
189195
return exeDir;
190196
}
191197

198+
#if defined (__APPLE__)
199+
/* Load libjli - this is needed on osx for libawt, which uses JLI_* methods.
200+
* If the GraalVM libjli is not loaded, the osx linker will look up the symbol
201+
* via the JavaRuntimeSupport.framework (JRS), which will fall back to the
202+
* system JRE and fail if none is installed
203+
*/
204+
void *load_jli_lib(std::string exeDir) {
205+
std::stringstream libjliPath;
206+
libjliPath << exeDir << DIR_SEP_STR << LIBJLI_RELPATH_STR;
207+
return dlopen(libjliPath.str().c_str(), RTLD_NOW);
208+
}
209+
#endif
210+
192211
/* load the language library (either native library or libjvm) and return a
193212
* pointer to the JNI_CreateJavaVM function */
194213
CreateJVM load_vm_lib(std::string liblangPath) {
@@ -362,6 +381,15 @@ int main(int argc, char *argv[]) {
362381
}
363382
}
364383

384+
#if defined (__APPLE__)
385+
if (jvmMode) {
386+
if (!load_jli_lib(exeDir)) {
387+
std::cerr << "Loading libjli failed." << std::endl;
388+
return -1;
389+
}
390+
}
391+
#endif
392+
365393
/* parse VM args */
366394
JavaVM *vm;
367395
JNIEnv *env;

0 commit comments

Comments
 (0)