Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1204, Search global and local symbol tables #1206

Merged
merged 1 commit into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/os/portable/os-impl-no-symtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
25 changes: 22 additions & 3 deletions src/os/portable/os-impl-posix-dl-symtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
7 changes: 4 additions & 3 deletions src/os/shared/inc/os-shared-module.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/os/shared/src/osapi-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/os/vxworks/src/os-impl-symtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

/*----------------------------------------------------------------
*
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/unit-test-coverage/shared/src/coveragetest-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/*
Expand Down
14 changes: 7 additions & 7 deletions src/unit-test-coverage/vxworks/src/coveragetest-symtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
15 changes: 14 additions & 1 deletion src/unit-tests/osloader-test/ut_osloader_symtable_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
{
/*-----------------------------------------------------*/
Expand All @@ -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));
}
}

/*--------------------------------------------------------------------------------*
Expand Down