|
1 | 1 | /* |
2 | | - * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * Copyright 2012, 2014 SAP AG. All rights reserved. |
4 | 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5 | 5 | * |
@@ -1452,7 +1452,7 @@ bool os::dll_address_to_library_name(address addr, char* buf, |
1452 | 1452 |
|
1453 | 1453 | // Loads .dll/.so and in case of error it checks if .dll/.so was built |
1454 | 1454 | // for the same architecture as Hotspot is running on. |
1455 | | -void *os::dll_load(const char *filename, char *ebuf, int ebuflen) { |
| 1455 | +static void* dll_load_library(const char *filename, char *ebuf, int ebuflen) { |
1456 | 1456 |
|
1457 | 1457 | if (ebuf && ebuflen > 0) { |
1458 | 1458 | ebuf[0] = '\0'; |
@@ -1480,6 +1480,26 @@ void *os::dll_load(const char *filename, char *ebuf, int ebuflen) { |
1480 | 1480 | } |
1481 | 1481 | return NULL; |
1482 | 1482 | } |
| 1483 | +// Load library named <filename> |
| 1484 | +// If filename matches <name>.so, and loading fails, repeat with <name>.a. |
| 1485 | +void *os::dll_load(const char *filename, char *ebuf, int ebuflen) { |
| 1486 | + void* result = nullptr; |
| 1487 | + char* const file_path = strdup(filename); |
| 1488 | + char* const pointer_to_dot = strrchr(file_path, '.'); |
| 1489 | + const char old_extension[] = ".so"; |
| 1490 | + const char new_extension[] = ".a"; |
| 1491 | + STATIC_ASSERT(sizeof(old_extension) >= sizeof(new_extension)); |
| 1492 | + // First try to load the existing file. |
| 1493 | + result = dll_load_library(filename, ebuf, ebuflen); |
| 1494 | + // If the load fails,we try to reload by changing the extension to .a for .so files only. |
| 1495 | + // Shared object in .so format dont have braces, hence they get removed for archives with members. |
| 1496 | + if (result == nullptr && pointer_to_dot != nullptr && strcmp(pointer_to_dot, old_extension) == 0) { |
| 1497 | + snprintf(pointer_to_dot, sizeof(old_extension), "%s", new_extension); |
| 1498 | + result = dll_load_library(file_path, ebuf, ebuflen); |
| 1499 | + } |
| 1500 | + FREE_C_HEAP_ARRAY(char, file_path); |
| 1501 | + return result; |
| 1502 | +} |
1483 | 1503 |
|
1484 | 1504 | // Glibc-2.0 libdl is not MT safe. If you are building with any glibc, |
1485 | 1505 | // chances are you might want to run the generated bits against glibc-2.0 |
|
0 commit comments