-
Notifications
You must be signed in to change notification settings - Fork 729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FFI/Jextract] Failure to load a complex archive file (.a) on AIX in the jextract generation #19930
Comments
@zl-wang, is there any way to reach out to the AIX team to understand the details as to how |
@ChengJin01 this has been always like that on AIX. when there are multiple members in an archive, dlopen needs to name the specific member you want to load. I am going to look up man-page of dlopen and attach here later. |
dlopen SubroutineLast Updated: 2023-03-24 PurposeDynamically loads a module into the calling process. Syntax
DescriptionThe dlopen subroutine loads the module specified by FilePath into the executing process's address space. Dependents of the module are automatically loaded as well. If the module is already loaded, it is not loaded again, but a new, unique value will be returned by the dlopen subroutine. The dlopen subroutine is a portable way of dynamically loading shared libraries. It performs C++ static initialization of the modules that it loads, like the loadAndInit subroutine does. The value returned by the dlopen might be used in subsequent calls to dlsym and dlclose. If an error occurs during the operation, dlopen returns NULL. If the main application was linked with the -brtl option, then the runtime linker is invoked by dlopen. If the module being loaded was linked with runtime linking enabled, both intra-module and inter-module references are overridden by any symbols available in the main application. If runtime linking was enabled, but the module was not built enabled, then all inter-module references will be overridden, but some intra-module references will not be overridden. If the module being opened with dlopen or any of its dependents is being loaded for the first time, initialization routines for these newly-loaded routines are called (after runtime linking, if applicable) before dlopen returns. Initialization routines are the functions specified with the -binitfini: linker option when the module was built. (See the ld command for more information about this option.) After calling the initialization functions for all newly-loaded modules, C++ static initialization is performed. If you call the dlopen subroutine from within an initialization function or a C++ static initialization function, modules loaded by the nested dlopen subroutine might be initialized before completely initializing the originally loaded modules. If a dlopen subroutine is called from within a binitfini function, the initialization of the current module is abandoned for other modules. Note: If the module being loaded has read-other permission, the module is loaded into the global shared library segment. Modules loaded into the global shared library segment are not unloaded even if they are no longer being used. Use the slibclean command to remove unused modules from the global shared library segment. To load the module in the process private region, unload the module completely using the slibclean command, and then unset its read-other permission. The LIBPATH or LD_LIBRARY_PATH environment variables can be used to specify a list of directories in which the dlopen subroutine searches for the named module. The running application also contains a set of library search paths that were specified when the application was linked. The dlopen subroutine searches the modules based on the mechanism that the load subroutine defines, because the dlopen subroutine internally calls the load subroutine with the L_LIBPATH_EXEC flag.
Item | Description
-- | --
FilePath | Specifies the name of a file containing the loadable module. This parameter can be contain an absolute path, a relative path, or no path component. If FilePath contains a slash character, FilePath is used directly, and no directories are searched.If the FilePath parameter is /unix, dlopen returns a value that can be used to look up symbols in the current kernel image, including those symbols found in any kernel extension that was available at the time the process began execution.If the value of FilePath is NULL, a value for the main application is returned. This allows dynamically loaded objects to look up symbols in the main executable, or for an application to examine symbols available within itself.
Return ValuesUpon successful completion, dlopen returns a value that can be used in calls to the dlsym and dlclose subroutines. The value is not valid for use with the loadbind and unload subroutines. If the dlopen call fails, NULL (a value of 0) is returned and the global variable errno is set. If errno contains the value ENOEXEC, further information is available via the dlerror function. Syntax void *dlopen (FilePath, Flags); Description The dlopen subroutine is a portable way of dynamically loading shared libraries. It performs C++ static initialization of the modules that it loads, like the loadAndInit subroutine does. The value returned by the dlopen might be used in subsequent calls to dlsym and dlclose. If an error occurs during the operation, dlopen returns NULL. If the main application was linked with the -brtl option, then the runtime linker is invoked by dlopen. If the module being loaded was linked with runtime linking enabled, both intra-module and inter-module references are overridden by any symbols available in the main application. If runtime linking was enabled, but the module was not built enabled, then all inter-module references will be overridden, but some intra-module references will not be overridden. If the module being opened with dlopen or any of its dependents is being loaded for the first time, initialization routines for these newly-loaded routines are called (after runtime linking, if applicable) before dlopen returns. Initialization routines are the functions specified with the -binitfini: linker option when the module was built. (See the ld command for more information about this option.) After calling the initialization functions for all newly-loaded modules, C++ static initialization is performed. If you call the dlopen subroutine from within an initialization function or a C++ static initialization function, modules loaded by the nested dlopen subroutine might be initialized before completely initializing the originally loaded modules. If a dlopen subroutine is called from within a binitfini function, the initialization of the current module is abandoned for other modules. Note: If the module being loaded has read-other permission, the module is loaded into the global shared library segment. Modules loaded into the global shared library segment are not unloaded even if they are no longer being used. Use the slibclean command to remove unused modules from the global shared library segment. To load the module in the process private region, unload the module completely using the slibclean command, and then unset its read-other permission. Item If the value of FilePath is NULL, a value for the main application is returned. This allows dynamically loaded objects to look up symbols in the main executable, or for an application to examine symbols available within itself. Flags Item Return Values If the dlopen call fails, NULL (a value of 0) is returned and the global variable errno is set. If errno contains the value ENOEXEC, further information is available via the dlerror function. |
buried deep in the above in |
The problem with
Does |
that means you might need another shared-lib to satisfy the request. i am wondering how the executable was linked first. why can it be linked successfully, if there were missing symbols. |
I tried the following code but it ended up with a null handle.
|
These libraries (including |
Not specific to jdk23, not a new problem, not a blocker for jdk23, move it forward. |
@JasonFengJ9 For 0.48, this issue will need to be resolved by the end of this week. What's the current state of this issue? Based on this issue's impact, do we need it to be fixed in 0.48 or can it be pushed to 0.49? |
i have successfully built and run jextract on AIX (and Linux) for customer (Finanz Informatik). on AIX, there is a clang bug though (allocating 2TB memory). for official build, you might need to change the gradle build script to copy/extract libclang.so from libclang.a. the bug still exists in latest/current version of clang. OpenXL team is investigating, tracked here: https://github.ibm.com/compiler/wyvern/issues/20642 |
This is not a new problem. As per #19930 (comment), the customer has a running Moving to 0.49. |
@zl-wang is there any OpenJ9 change involved? Do we still need this issue for further investigation? |
no, i don't need to change anything in OpenJ9. If this issue was opened for the purpose of building jextract on AIX, i think it is better to be in jextract repository (in order to change the gradle script). otherwise, it can be closed. |
Thanks @zl-wang this issue was opened for OpenJ9 support of AIX |
Issue Number: 19930 |
Chatted with @zl-wang, the shared library |
The issue was detected when generating the jextract tool for FFI after the issue with native library loading (
.a
) was resolved (which is entirely different from the original problem being addressed in #19344).As explained in https://github.com/openjdk/jextract, the generation of the jextract tool requires the LLVM libraries in place, part of which (e.g.
libclang.a
) must be loaded by JDK to exploit the native functions in building the tool where the loading failure occurs in callingdlopen
(see #19344 (comment) for details), which most likely happens to the code around there at https://github.com/eclipse-openj9/openj9-omr/blob/9083c8237ac215927ac55b5db256780132983136/port/aix/omrsl.c#L216).Technically, the existing code dealing with
dlopen
currently only works to load a simple shared object (extremely simple format) suffixed with.a
but fails to support a complex archive file combined with many shared objects (likelibc.a
orlibclang.a
in LLVM). To address the problem, we need to figure out howdlopen
works to load these archives at first, especially in the case oflibc.a
/libclang.a
.FYI: @TobiAjila, @pshipton, @JasonFengJ9, @zl-wang, @keithc-ca
The text was updated successfully, but these errors were encountered: