分类: LINUX
2009-02-04 23:25:39
In this example, we use nm to print the symbols within the shared library, but then only emit those with the tag " T " to stdout (those symbols that are part of the .text section, or code segments). We also use the -n option to sort the output numerically by address, rather than the default, which is alphabetically by symbol name. This gives us relative address information within the library; if we wanted to know the specific sizes of these .text sections, we could use the -S option, as:
$ nm -n -S /usr/local/lib/libmyrand.so | grep " T " 00000608 T _init 0000074c 00000036 T initRand 00000784 0000003a T getSRand 000007be 00000050 T getRand 00000844 T _fini $
From this example, we can see that the initRand is located at relative offset 0x74c in the library and its size is 0¥36 (decimal 54) bytes. Many other options are available; the nm mainpage provides more detail on this.
#includevoid *dlopen( const char *filename, int flag ); const char *dlerror( void ); void *dlsym( void *handle, char *symbol ); int dlclose( void *handle );