Kenwood HP 9000 Personal Computer User Manual


 
Chapter 6 237
Shared Library Management Routines
The shl_load Shared Library Management Routines
*/
}
free(orig_symbols); /* free memory allocated by
malloc */
return num_symbols; /* return the number of symbols
*/
}
The following example shows the source for a program named
show_all.c that calls show_symbols to show all imported and
exported symbols for every loaded shared library. It uses shl_get to get
the library handles of all loaded libraries.
show_all — Use show_symbols to Show All Symbols
#include <dl.h>
#include <stdio.h>
/* prototype for show_syms */
int show_syms(shl_t hndl, short type, int flags);
main()
{
int idx, num_syms;
struct shl_descriptor * desc;
for (idx=0; shl_get(idx, &desc) != -1; idx++) /* step through
libs */
{
printf(“[%s]\n”, desc->filename); /* show imports & exports for
each */
printf(“ Imports:\n”);
num_syms = show_symbols(desc->handle, TYPE_UNDEFINED,
IMPORT_SYMBOLS);
printf(“ TOTAL SYMBOLS: %d\n”, num_syms);
printf(“ Exports:\n”);
num_syms = show_symbols(desc->handle, TYPE_UNDEFINED,
EXPORT_SYMBOLS);
printf(“ TOTAL SYMBOLS: %d\n”, num_syms);
}
}
The show_all program shown above was compiled with the command:
$ cc -Aa -o show_all show_all.c show_symbols.c -ldld
NOTE The following output for the example will differ in 64-bit mode. For
example, STORAGE is not supported.
The output produced by running this program is shown below:
[show_all]
Imports:
errno STORAGE
_start PROCEDURE
malloc PROCEDURE
free PROCEDURE
exit PROCEDURE