|
1 | 1 | /* |
2 | 2 | * Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved. |
3 | | - * Copyright (c) 2012, 2023 SAP SE. All rights reserved. |
| 3 | + * Copyright (c) 2012, 2025 SAP SE. All rights reserved. |
4 | 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5 | 5 | * |
6 | 6 | * This code is free software; you can redistribute it and/or modify it |
@@ -1160,21 +1160,24 @@ static void* dll_load_library(const char *filename, int *eno, char *ebuf, int eb |
1160 | 1160 | // If filename matches <name>.so, and loading fails, repeat with <name>.a. |
1161 | 1161 | void *os::dll_load(const char *filename, char *ebuf, int ebuflen) { |
1162 | 1162 | void* result = nullptr; |
1163 | | - char* const file_path = strdup(filename); |
1164 | | - char* const pointer_to_dot = strrchr(file_path, '.'); |
1165 | 1163 | const char old_extension[] = ".so"; |
1166 | 1164 | const char new_extension[] = ".a"; |
1167 | | - STATIC_ASSERT(sizeof(old_extension) >= sizeof(new_extension)); |
1168 | 1165 | // First try to load the existing file. |
1169 | | - int eno=0; |
| 1166 | + int eno = 0; |
1170 | 1167 | result = dll_load_library(filename, &eno, ebuf, ebuflen); |
1171 | | - // If the load fails,we try to reload by changing the extension to .a for .so files only. |
| 1168 | + // If the load fails, we try to reload by changing the extension to .a for .so files only. |
1172 | 1169 | // Shared object in .so format dont have braces, hence they get removed for archives with members. |
1173 | | - if (result == nullptr && eno == ENOENT && pointer_to_dot != nullptr && strcmp(pointer_to_dot, old_extension) == 0) { |
1174 | | - snprintf(pointer_to_dot, sizeof(old_extension), "%s", new_extension); |
1175 | | - result = dll_load_library(file_path, &eno, ebuf, ebuflen); |
| 1170 | + if (result == nullptr && eno == ENOENT) { |
| 1171 | + const char* pointer_to_dot = strrchr(filename, '.'); |
| 1172 | + if (pointer_to_dot != nullptr && strcmp(pointer_to_dot, old_extension) == 0) { |
| 1173 | + STATIC_ASSERT(sizeof(old_extension) >= sizeof(new_extension)); |
| 1174 | + char* tmp_path = os::strdup(filename); |
| 1175 | + size_t prefix_size = pointer_delta(pointer_to_dot, filename, 1); |
| 1176 | + os::snprintf(tmp_path + prefix_size, sizeof(old_extension), "%s", new_extension); |
| 1177 | + result = dll_load_library(tmp_path, &eno, ebuf, ebuflen); |
| 1178 | + os::free(tmp_path); |
| 1179 | + } |
1176 | 1180 | } |
1177 | | - FREE_C_HEAP_ARRAY(char, file_path); |
1178 | 1181 | return result; |
1179 | 1182 | } |
1180 | 1183 |
|
|
0 commit comments