Skip to content

Commit

Permalink
Fix #1204, Search global and local symbol tables
Browse files Browse the repository at this point in the history
- Refactors symbol table searching to include
  both local and global symbol tables for POSIX
- Renamed global search to generic since there
  isn't currently a use case for global only search
  • Loading branch information
skliper committed Jan 12, 2022
1 parent 4cc6dbb commit 296c16d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
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

0 comments on commit 296c16d

Please sign in to comment.