|
1 | 1 | /*
|
2 | 2 | * Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
|
3 |
| - * Copyright (c) 2012, 2024 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
|
@@ -1068,21 +1068,24 @@ static void* dll_load_library(const char *filename, int *eno, char *ebuf, int eb
|
1068 | 1068 | // If filename matches <name>.so, and loading fails, repeat with <name>.a.
|
1069 | 1069 | void *os::dll_load(const char *filename, char *ebuf, int ebuflen) {
|
1070 | 1070 | void* result = nullptr;
|
1071 |
| - char* const file_path = strdup(filename); |
1072 |
| - char* const pointer_to_dot = strrchr(file_path, '.'); |
1073 | 1071 | const char old_extension[] = ".so";
|
1074 | 1072 | const char new_extension[] = ".a";
|
1075 |
| - STATIC_ASSERT(sizeof(old_extension) >= sizeof(new_extension)); |
1076 | 1073 | // First try to load the existing file.
|
1077 |
| - int eno=0; |
| 1074 | + int eno = 0; |
1078 | 1075 | result = dll_load_library(filename, &eno, ebuf, ebuflen);
|
1079 |
| - // If the load fails,we try to reload by changing the extension to .a for .so files only. |
| 1076 | + // If the load fails, we try to reload by changing the extension to .a for .so files only. |
1080 | 1077 | // Shared object in .so format dont have braces, hence they get removed for archives with members.
|
1081 |
| - if (result == nullptr && eno == ENOENT && pointer_to_dot != nullptr && strcmp(pointer_to_dot, old_extension) == 0) { |
1082 |
| - snprintf(pointer_to_dot, sizeof(old_extension), "%s", new_extension); |
1083 |
| - result = dll_load_library(file_path, &eno, ebuf, ebuflen); |
| 1078 | + if (result == nullptr && eno == ENOENT) { |
| 1079 | + const char* pointer_to_dot = strrchr(filename, '.'); |
| 1080 | + if (pointer_to_dot != nullptr && strcmp(pointer_to_dot, old_extension) == 0) { |
| 1081 | + STATIC_ASSERT(sizeof(old_extension) >= sizeof(new_extension)); |
| 1082 | + char* tmp_path = os::strdup(filename); |
| 1083 | + size_t prefix_size = pointer_delta(pointer_to_dot, filename, 1); |
| 1084 | + os::snprintf(tmp_path + prefix_size, sizeof(old_extension), "%s", new_extension); |
| 1085 | + result = dll_load_library(tmp_path, &eno, ebuf, ebuflen); |
| 1086 | + os::free(tmp_path); |
| 1087 | + } |
1084 | 1088 | }
|
1085 |
| - FREE_C_HEAP_ARRAY(char, file_path); |
1086 | 1089 | return result;
|
1087 | 1090 | }
|
1088 | 1091 |
|
|
0 commit comments