On Fri, 24 Nov 2023 14:04:07 GMT, Thomas Stuefe <stu...@openjdk.org> wrote:

> > > i would have to repeat the line 1132 and 1139 in os_aix.cpp again , if 
> > > the condition fails for .so files, because i have to reload it again and 
> > > check if the .a exists. In the shared code i had repeat less number of 
> > > lines i believe. Do you suggest moving lines 1132 to 1139 to another 
> > > function then ?
> > 
> > 
> > @tstuefe Any suggestion on this ?
> 
> ```
> --- a/src/hotspot/os/aix/os_aix.cpp
> +++ b/src/hotspot/os/aix/os_aix.cpp
> @@ -1108,7 +1108,7 @@ bool os::dll_address_to_library_name(address addr, 
> char* buf,
>    return true;
>  }
>  
> -void *os::dll_load(const char *filename, char *ebuf, int ebuflen) {
> +static void* dll_load_inner(const char *filename, char *ebuf, int ebuflen) {
>  
>    log_info(os)("attempting shared library load of %s", filename);
>  
> @@ -1158,6 +1158,35 @@ void *os::dll_load(const char *filename, char *ebuf, 
> int ebuflen) {
>    return nullptr;
>  }
>  
> +void* os::dll_load(const char *filename, char *ebuf, int ebuflen) {
> +
> +  void* result = nullptr;
> +
> +  // First try using *.so suffix; failing that, retry with *.a suffix.
> +  const size_t len = strlen(filename);
> +  constexpr size_t safety = 3 + 1;
> +  constexpr size_t bufsize = len + safety;
> +  char* buf = NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
> +  strcpy(buf, filename);
> +  char* const dot = strrchr(buf, '.');
> +
> +  assert(dot != nullptr, "Attempting to load a shared object without 
> extension? %s", filename);
> +  assert(strcmp(dot, ".a") == 0 || strcmp(dot, ".so") == 0,
> +      "Attempting to load a shared object that is neither *.so nor *.a", 
> filename);
> +
> +  sprintf(dot, ".so");
> +  result = dll_load_inner(buf, ebuf, ebuflen);
> +
> +  if (result == nullptr) {
> +    sprintf(dot, ".a");
> +    result = dll_load_inner(buf, ebuf, ebuflen);
> +  }
> +
> +  FREE_C_HEAP_ARRAY(char, buf);
> +
> +  return result;
> +}
> +
> ```

Hi @tstuefe 
Thanks for sharing!.
i have worked on an alternate code taking insight from your code. 
There are a couple of issues being faced, but the most improtant one is the 
segmentation fault that is occuring. 
1. The dll_load function makes copy of filename and appends .a and then tries 
to load the library. 
However , in jvmTiAgent.cpp, we call save_library_signature method. 
Since the changes to filename are happening only inside dlll_load, it is not 
reflected in jvmTiAgent, due to which stat64 command is run on .old ".so" 
filename  and not the ".a" filename.
So stat64 function call happens with invalid library name and hence it causes 
segmentation fault.

To make the changes reflected, we might need to do strcpy of modified 
filename(buffer) to filename inside dll_load , but that is not possible as it 
is const char*. I dont think we can/should change the signature of dll_load 
here.
  
2. I tried moving save_library_signature from jvmTiAgent to os_aix but then it 
also needs the "agent" object to be passed as well, which  will lead to change 
in signature of dll_load.

What do you think could be a solution for this ?

-------------

PR Comment: https://git.openjdk.org/jdk/pull/16604#issuecomment-1827661214

Reply via email to