From 8234e723f0006d1e310f42ba235451e2d53a13ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 4 Nov 2019 16:22:55 +0100 Subject: [PATCH] loader: Simplify logic for finding create function The loader library no longer tries EVMC create function names with removed prefixes. --- include/evmc/loader.h | 13 ++++--------- lib/loader/loader.c | 10 +--------- test/unittests/test_loader.cpp | 15 +++++++++++---- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/include/evmc/loader.h b/include/evmc/loader.h index 7a019a5..523139e 100644 --- a/include/evmc/loader.h +++ b/include/evmc/loader.h @@ -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. diff --git a/lib/loader/loader.c b/lib/loader/loader.c index 245a174..d820054 100644 --- a/lib/loader/loader.c +++ b/lib/loader/loader.c @@ -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"); diff --git a/test/unittests/test_loader.cpp b/test/unittests/test_loader.cpp index e0cc510..e2cd3f7 100644 --- a/test/unittests/test_loader.cpp +++ b/test/unittests/test_loader.cpp @@ -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(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) {