@@ -1127,10 +1127,9 @@ bool os::dll_address_to_library_name(address addr, char* buf,
11271127 return true ;
11281128}
11291129
1130- void * os::dll_load (const char *filename, char *ebuf, int ebuflen) {
1130+ static void * dll_load_library (const char *filename, char *ebuf, int ebuflen) {
11311131
11321132 log_info (os)(" attempting shared library load of %s" , filename);
1133-
11341133 if (ebuf && ebuflen > 0 ) {
11351134 ebuf[0 ] = ' \0 ' ;
11361135 ebuf[ebuflen - 1 ] = ' \0 ' ;
@@ -1178,6 +1177,26 @@ void *os::dll_load(const char *filename, char *ebuf, int ebuflen) {
11781177 }
11791178 return nullptr ;
11801179}
1180+ // Load library named <filename>
1181+ // If filename matches <name>.so, and loading fails, repeat with <name>.a.
1182+ void *os::dll_load (const char *filename, char *ebuf, int ebuflen) {
1183+ void * result = nullptr ;
1184+ char * const file_path = strdup (filename);
1185+ char * const pointer_to_dot = strrchr (file_path, ' .' );
1186+ const char old_extension[] = " .so" ;
1187+ const char new_extension[] = " .a" ;
1188+ STATIC_ASSERT (sizeof (old_extension) >= sizeof (new_extension));
1189+ // First try to load the existing file.
1190+ result = dll_load_library (filename, ebuf, ebuflen);
1191+ // If the load fails,we try to reload by changing the extension to .a for .so files only.
1192+ // Shared object in .so format dont have braces, hence they get removed for archives with members.
1193+ if (result == nullptr && pointer_to_dot != nullptr && strcmp (pointer_to_dot, old_extension) == 0 ) {
1194+ snprintf (pointer_to_dot, sizeof (old_extension), " %s" , new_extension);
1195+ result = dll_load_library (file_path, ebuf, ebuflen);
1196+ }
1197+ FREE_C_HEAP_ARRAY (char , file_path);
1198+ return result;
1199+ }
11811200
11821201void os::print_dll_info (outputStream *st) {
11831202 st->print_cr (" Dynamic libraries:" );
0 commit comments