loader: Simplify logic for finding create function

The loader library no longer tries EVMC create function names with removed prefixes.
This commit is contained in:
Paweł Bylica 2019-11-04 16:22:55 +01:00
parent 67908adbf7
commit 8234e723f0
No known key found for this signature in database
GPG Key ID: 7A0C037434FE77EF
3 changed files with 16 additions and 22 deletions

View File

@ -61,21 +61,16 @@ enum evmc_loader_error_code
* After the DLL is successfully loaded the function tries to find the EVM create function in the
* library. The `filename` is used to guess the EVM name and the name of the create function.
* The create function name is constructed by the following rules. Consider example path:
* "/ethereum/libexample-interpreter.so".
* "/ethereum/libexample-interpreter.so.1.0".
* - the filename is taken from the path:
* "libexample-interpreter.so",
* - the "lib" prefix and file extension are stripped from the name:
* "libexample-interpreter.so.1.0",
* - the "lib" prefix and all file extensions are stripped from the name:
* "example-interpreter"
* - all "-" are replaced with "_" to construct _base name_:
* "example_interpreter",
* - the function name "evmc_create_" + _base name_ is searched in the library:
* "evmc_create_example_interpreter",
* - if function not found, the _base name_ is shorten by skipping the first word separated by "_":
* "interpreter",
* - then, the function of the shorter name "evmc_create_" + _base name_ is searched in the library:
* "evmc_create_interpreter",
* - the name shortening continues until a function is found or the name cannot be shorten more,
* - lastly, when no function found, the function name "evmc_create" is searched in the library.
* - if the function is not found, the function name "evmc_create" is searched in the library.
*
* If the create function is found in the library, the pointer to the function is returned.
* Otherwise, the ::EVMC_LOADER_SYMBOL_NOT_FOUND error code is signaled and NULL is returned.

View File

@ -163,15 +163,7 @@ evmc_create_fn evmc_load(const char* filename, enum evmc_loader_error_code* erro
*dash_pos++ = '_';
// Search for the built function name.
while ((create_fn = DLL_GET_CREATE_FN(handle, prefixed_name)) == NULL)
{
// Shorten the base name by skipping the `word_` segment.
const char* shorter_name_pos = strchr(base_name, '_');
if (!shorter_name_pos)
break;
memmove(base_name, shorter_name_pos + 1, strlen(shorter_name_pos) + 1);
}
create_fn = DLL_GET_CREATE_FN(handle, prefixed_name);
if (!create_fn)
create_fn = DLL_GET_CREATE_FN(handle, "evmc_create");

View File

@ -188,14 +188,12 @@ TEST_F(loader, load_empty_path)
EXPECT_TRUE(evmc_last_error_msg() == nullptr);
}
TEST_F(loader, load_prefix_aaa)
TEST_F(loader, load_aaa)
{
auto paths = {
"./aaa.evm",
"aaa.evm",
"unittests/libaaa.so",
"unittests/double-prefix-aaa.evm",
"unittests/double_prefix_aaa.evm",
};
const auto expected_vm_ptr = reinterpret_cast<evmc_vm*>(0xaaa);
@ -285,7 +283,16 @@ TEST_F(loader, load_windows_path)
TEST_F(loader, load_symbol_not_found)
{
auto paths = {"libaaa1.so", "eee2.so", "libeee3.x", "eee4", "_", "lib_.so"};
auto paths = {
"libaaa1.so",
"eee2.so",
"libeee3.x",
"eee4",
"_",
"lib_.so",
"unittests/double-prefix-aaa.evm",
"unittests/double_prefix_aaa.evm",
};
for (auto& path : paths)
{