diff --git a/src/os/portable/os-impl-no-symtab.c b/src/os/portable/os-impl-no-symtab.c index 270fd598d..5a36ecee9 100644 --- a/src/os/portable/os-impl-no-symtab.c +++ b/src/os/portable/os-impl-no-symtab.c @@ -35,7 +35,7 @@ * * See prototype for argument/return detail *-----------------------------------------------------------------*/ -int32 OS_GlobalSymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName) +int32 OS_SymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName) { return OS_ERR_NOT_IMPLEMENTED; } diff --git a/src/os/portable/os-impl-posix-dl-symtab.c b/src/os/portable/os-impl-posix-dl-symtab.c index 629ba8d8e..81d578ad3 100644 --- a/src/os/portable/os-impl-posix-dl-symtab.c +++ b/src/os/portable/os-impl-posix-dl-symtab.c @@ -134,18 +134,37 @@ int32 OS_GenericSymbolLookup_Impl(void *dl_handle, cpuaddr *SymbolAddress, const /*---------------------------------------------------------------- * - * Function: OS_GlobalSymbolLookup_Impl + * Function: OS_SymbolLookup_Impl * * Purpose: Implemented per internal OSAL API * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_GlobalSymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName) +int32 OS_SymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName) { - int32 status; + int32 status; + int32 local_status = OS_ERROR; + OS_object_iter_t iter; + /* First search global table */ status = OS_GenericSymbolLookup_Impl(OSAL_DLSYM_DEFAULT_HANDLE, SymbolAddress, SymbolName); + /* If not found iterate through module local symbols and break if found */ + if (status != OS_SUCCESS) + { + OS_ObjectIdIterateActive(OS_OBJECT_TYPE_OS_MODULE, &iter); + while (OS_ObjectIdIteratorGetNext(&iter)) + { + local_status = OS_ModuleSymbolLookup_Impl(&iter.token, SymbolAddress, SymbolName); + if (local_status == OS_SUCCESS) + { + status = local_status; + break; + } + } + OS_ObjectIdIteratorDestroy(&iter); + } + return status; } /* end OS_SymbolLookup_Impl */ diff --git a/src/os/shared/inc/os-shared-module.h b/src/os/shared/inc/os-shared-module.h index 86811e8e7..b43ded2a5 100644 --- a/src/os/shared/inc/os-shared-module.h +++ b/src/os/shared/inc/os-shared-module.h @@ -95,14 +95,15 @@ int32 OS_ModuleUnload_Impl(const OS_object_token_t *token); int32 OS_ModuleGetInfo_Impl(const OS_object_token_t *token, OS_module_prop_t *module_prop); /*---------------------------------------------------------------- - Function: OS_GlobalSymbolLookup_Impl + Function: OS_SymbolLookup_Impl - Purpose: Find the Address of a Symbol in the global symbol table. + Purpose: Find the Address of a Symbol in the symbol table. If global and + local tables exist all are checked. The address of the symbol will be stored in the pointer that is passed in. Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ -int32 OS_GlobalSymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName); +int32 OS_SymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName); /*---------------------------------------------------------------- Function: OS_SymbolLookup_Impl diff --git a/src/os/shared/src/osapi-module.c b/src/os/shared/src/osapi-module.c index 720da42ed..236006c24 100644 --- a/src/os/shared/src/osapi-module.c +++ b/src/os/shared/src/osapi-module.c @@ -361,9 +361,9 @@ int32 OS_SymbolLookup(cpuaddr *SymbolAddress, const char *SymbolName) OS_CHECK_POINTER(SymbolName); /* - * attempt to find the symbol in the global symbol table. + * attempt to find the symbol in the symbol table */ - return_code = OS_GlobalSymbolLookup_Impl(SymbolAddress, SymbolName); + return_code = OS_SymbolLookup_Impl(SymbolAddress, SymbolName); /* * If the OS call did not find the symbol or the loader is diff --git a/src/os/vxworks/src/os-impl-symtab.c b/src/os/vxworks/src/os-impl-symtab.c index 3956f0541..35ed770d9 100644 --- a/src/os/vxworks/src/os-impl-symtab.c +++ b/src/os/vxworks/src/os-impl-symtab.c @@ -108,16 +108,16 @@ int32 OS_GenericSymbolLookup_Impl(SYMTAB_ID SymTab, cpuaddr *SymbolAddress, cons /*---------------------------------------------------------------- * - * Function: OS_GlobalSymbolLookup_Impl + * Function: OS_SymbolLookup_Impl * * Purpose: Implemented per internal OSAL API * See prototype for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_GlobalSymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName) +int32 OS_SymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName) { return OS_GenericSymbolLookup_Impl(sysSymTbl, SymbolAddress, SymbolName); -} /* end OS_GlobalSymbolLookup_Impl */ +} /* end OS_SymbolLookup_Impl */ /*---------------------------------------------------------------- * @@ -130,7 +130,7 @@ int32 OS_GlobalSymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName) int32 OS_ModuleSymbolLookup_Impl(const OS_object_token_t *token, cpuaddr *SymbolAddress, const char *SymbolName) { /* - * NOTE: this is currently exactly the same as OS_GlobalSymbolLookup_Impl(). + * NOTE: this is currently exactly the same as OS_SymbolLookup_Impl(). * * Ideally this should get a SYMTAB_ID from the MODULE_ID and search only * for the symbols provided by that module - but it is not clear if vxWorks diff --git a/src/unit-test-coverage/portable/src/coveragetest-no-symtab.c b/src/unit-test-coverage/portable/src/coveragetest-no-symtab.c index ad7009970..f08ff8c9b 100644 --- a/src/unit-test-coverage/portable/src/coveragetest-no-symtab.c +++ b/src/unit-test-coverage/portable/src/coveragetest-no-symtab.c @@ -28,7 +28,7 @@ void Test_No_Symtab(void) { - OSAPI_TEST_FUNCTION_RC(OS_GlobalSymbolLookup_Impl, (NULL, NULL), OS_ERR_NOT_IMPLEMENTED); + OSAPI_TEST_FUNCTION_RC(OS_SymbolLookup_Impl, (NULL, NULL), OS_ERR_NOT_IMPLEMENTED); OSAPI_TEST_FUNCTION_RC(OS_ModuleSymbolLookup_Impl, (NULL, NULL, NULL), OS_ERR_NOT_IMPLEMENTED); OSAPI_TEST_FUNCTION_RC(OS_SymbolTableDump_Impl, (NULL, 0), OS_ERR_NOT_IMPLEMENTED); } diff --git a/src/unit-test-coverage/shared/src/coveragetest-module.c b/src/unit-test-coverage/shared/src/coveragetest-module.c index 4eace72c0..63644fc7e 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-module.c +++ b/src/unit-test-coverage/shared/src/coveragetest-module.c @@ -136,8 +136,8 @@ void Test_OS_SymbolLookup(void) actual = OS_SymbolLookup(&symaddr, "uttestsym0"); UtAssert_True(actual == expected, "OS_SymbolLookup(name=%s) (%ld) == OS_SUCCESS", "uttestsym0", (long)actual); - UT_ResetState(UT_KEY(OS_GlobalSymbolLookup_Impl)); - UT_SetDefaultReturnValue(UT_KEY(OS_GlobalSymbolLookup_Impl), OS_ERROR); + UT_ResetState(UT_KEY(OS_SymbolLookup_Impl)); + UT_SetDefaultReturnValue(UT_KEY(OS_SymbolLookup_Impl), OS_ERROR); /* this lookup should always fail */ symaddr = 0; diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-module-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-module-impl-stubs.c index 6413b0b05..bc7bcf2aa 100644 --- a/src/unit-test-coverage/ut-stubs/src/os-shared-module-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-module-impl-stubs.c @@ -29,19 +29,19 @@ /* * ---------------------------------------------------- - * Generated stub function for OS_GlobalSymbolLookup_Impl() + * Generated stub function for OS_SymbolLookup_Impl() * ---------------------------------------------------- */ -int32 OS_GlobalSymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName) +int32 OS_SymbolLookup_Impl(cpuaddr *SymbolAddress, const char *SymbolName) { - UT_GenStub_SetupReturnBuffer(OS_GlobalSymbolLookup_Impl, int32); + UT_GenStub_SetupReturnBuffer(OS_SymbolLookup_Impl, int32); - UT_GenStub_AddParam(OS_GlobalSymbolLookup_Impl, cpuaddr *, SymbolAddress); - UT_GenStub_AddParam(OS_GlobalSymbolLookup_Impl, const char *, SymbolName); + UT_GenStub_AddParam(OS_SymbolLookup_Impl, cpuaddr *, SymbolAddress); + UT_GenStub_AddParam(OS_SymbolLookup_Impl, const char *, SymbolName); - UT_GenStub_Execute(OS_GlobalSymbolLookup_Impl, Basic, NULL); + UT_GenStub_Execute(OS_SymbolLookup_Impl, Basic, NULL); - return UT_GenStub_GetReturnValue(OS_GlobalSymbolLookup_Impl, int32); + return UT_GenStub_GetReturnValue(OS_SymbolLookup_Impl, int32); } /* diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-symtab.c b/src/unit-test-coverage/vxworks/src/coveragetest-symtab.c index 9d2e84397..ea5fca3cb 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-symtab.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-symtab.c @@ -33,18 +33,18 @@ #include "OCS_fcntl.h" #include "OCS_symLib.h" -void Test_OS_GlobalSymbolLookup_Impl(void) +void Test_OS_SymbolLookup_Impl(void) { /* Test Case For: - * int32 OS_GlobalSymbolLookup_Impl( cpuaddr *SymbolAddress, const char *SymbolName ) + * int32 OS_SymbolLookup_Impl( cpuaddr *SymbolAddress, const char *SymbolName ) */ cpuaddr SymAddr; - OSAPI_TEST_FUNCTION_RC(OS_GlobalSymbolLookup_Impl(&SymAddr, "symname"), OS_SUCCESS); - OSAPI_TEST_FUNCTION_RC(OS_GlobalSymbolLookup_Impl(NULL, "symname"), OS_INVALID_POINTER); - OSAPI_TEST_FUNCTION_RC(OS_GlobalSymbolLookup_Impl(&SymAddr, NULL), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_SymbolLookup_Impl(&SymAddr, "symname"), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_SymbolLookup_Impl(NULL, "symname"), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_SymbolLookup_Impl(&SymAddr, NULL), OS_INVALID_POINTER); UT_SetDefaultReturnValue(UT_KEY(OCS_symFind), OCS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_GlobalSymbolLookup_Impl(&SymAddr, "symname"), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_SymbolLookup_Impl(&SymAddr, "symname"), OS_ERROR); } void Test_OS_ModuleSymbolLookup_Impl(void) @@ -144,7 +144,7 @@ void Osapi_Test_Teardown(void) {} void UtTest_Setup(void) { ADD_TEST(OS_SymTableIterator_Impl); - ADD_TEST(OS_GlobalSymbolLookup_Impl); + ADD_TEST(OS_SymbolLookup_Impl); ADD_TEST(OS_ModuleSymbolLookup_Impl); ADD_TEST(OS_SymbolTableDump_Impl); } diff --git a/src/unit-tests/osloader-test/ut_osloader_symtable_test.c b/src/unit-tests/osloader-test/ut_osloader_symtable_test.c index d96d9fe1a..5cbe943f1 100644 --- a/src/unit-tests/osloader-test/ut_osloader_symtable_test.c +++ b/src/unit-tests/osloader-test/ut_osloader_symtable_test.c @@ -96,7 +96,7 @@ void UT_os_symbol_lookup_test() UT_RETVAL(OS_SymbolLookup(&symbol_addr, 0), OS_INVALID_POINTER); /*-----------------------------------------------------*/ - /* Setup for remainder of tests */ + /* Setup for global symbol test */ if (UT_SETUP(OS_ModuleLoad(&module_id, "Mod1", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_GLOBAL_SYMBOLS))) { /*-----------------------------------------------------*/ @@ -112,6 +112,19 @@ void UT_os_symbol_lookup_test() /* Reset test environment */ UT_TEARDOWN(OS_ModuleUnload(module_id)); } + + /*-----------------------------------------------------*/ + /* Setup for local symbol test */ + if (UT_SETUP(OS_ModuleLoad(&module_id, "Mod1", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS))) + { + /*-----------------------------------------------------*/ + /* #5 Nominal, Local Symbols */ + + UT_NOMINAL(OS_SymbolLookup(&symbol_addr, "module1")); + + /* Reset test environment */ + UT_TEARDOWN(OS_ModuleUnload(module_id)); + } } /*--------------------------------------------------------------------------------*