Retrieves symbol name for common object file symbol table entry.
Object File Access Routine Library (libld.a)
The ldgetname subroutine returns a pointer to the name associated with Symbol as a string. The string is in a static buffer local to the ldgetname subroutine that is overwritten by each call to the ldgetname subroutine and must therefore be copied by the caller if the name is to be saved.
The common object file format handles arbitrary length symbol names with the addition of a string table. The ldgetname subroutine returns the symbol name associated with a symbol table entry for an XCOFF-format object file.
The calling routine to provide a pointer to a buffer large enough to contain a symbol table entry for the associated object file. Since the ldopen subroutine provides magic number information (via the HEADER(ldPointer).f_magic macro), the calling application can always determine whether the Symbol pointer should refer to a 32-bit SYMENT or 64-bit SYMENT_64 structure.
The maximum length of a symbol name is BUFSIZ, defined in the stdio.h file.
Item | Description |
---|---|
ldPointer | Points to an LDFILE structure that was returned as the result of a successful call to the ldopen or ldaopen subroutine. |
Symbol | Points to an initialized 32-bit or 64-bit SYMENT structure. |
The ldgetname subroutine returns a null value (defined in the stdio.h file) for a COFF-format object file if the name cannot be retrieved. This situation can occur if one of the following is true:
Typically, the ldgetname subroutine is called immediately after a successful call to the ldtbread subroutine to retrieve the name associated with the symbol table entry filled by the ldtbread subroutine.
The following is an example of code that determines the object file type before making a call to the ldtbread and ldgetname subroutines.
#define __XCOFF32__
#define __XCOFF64__
#include <ldfcn.h>
SYMENT Symbol32;
SYMENT_64 Symbol64;
void *Symbol;
if ( HEADER(ldPointer).f_magic == U802TOCMAGIC )
Symbol = &Symbol32;
else if ( HEADER(ldPointer).f_magic == U64_TOCMAGIC )
Symbol = &Symbol64;
else
Symbol = NULL;
if ( Symbol )
/* for each symbol in the symbol table */
for ( symnum = 0 ; symnum < HEADER(ldPointer).f_nsyms ; symnum++ )
{
if ( ldtbread(ldPointer,symnum,Symbol) == SUCCESS )
{
char *name = ldgetname(ldPointer,Symbol)
if ( name )
{
/* Got the name... */
.
.
}
/* Increment symnum by the number of auxiliary entries */
if ( HEADER(ldPointer).f_magic == U802TOCMAGIC )
symnum += Symbol32.n_numaux;
else if ( HEADER(ldPointer).f_magic == U64_TOCMAGIC )
symnum += Symbol64.n_numaux;
}
else
{
/* Should have been a symbol...indicate the error */
.
.
}
}