16

How can I get a list of the functions defined in a shared object library, or find out if a particular function is defined in one?

2 Answers2

17

There are different executable file formats on a *nix system. a.out was a common format some years ago and today its ELF on nearby all major systems.

ELF consists of a headers describing each of the files data sections.

The part you are looking for is the symbol table, where each symbol (function, variable) is mapped to its address.

Shared libraries keep their global symbols in a section called .dynsym

What you are looking for are symbols of the type function and a global binding in this section.

readelf --syms ./libfoo.so will give you a output of the symbols.

On Solaris and FreeBSD theres also elfdump available.

objdump displays also a lot of information about your object file and you can specify a section by using the -j switch.

echox
  • 18,103
14

Use nm with the -D (dynamic) switch:

$ nm -D /usr/lib/libpng.so
00000000 A PNG12_0
     w _Jv_RegisterClasses
     w __cxa_finalize
     U __fprintf_chk
     w __gmon_start__
     U __longjmp_chk
     U __memcpy_chk
     U __snprintf_chk
     U __stack_chk_fail
     U _setjmp
     U abort
     U crc32
     U deflate
     U deflateEnd
     U deflateInit2_
     U deflateReset
     U fflush
     U fread
     U free
     U fwrite
     U gmtime
     U inflate
     U inflateEnd
     U inflateInit_
     U inflateReset
     U malloc
     U memcmp
     U memcpy
     U memset
00003fd0 T png_access_version_number
00016ef0 T png_build_grayscale_palette
00004810 T png_check_sig
0001d2d0 T png_chunk_error
0001d070 T png_chunk_warning
00013390 T png_convert_from_struct_tm
00014a90 T png_convert_from_time_t
000048d0 T png_convert_to_rfc1123
000051b0 T png_create_info_struct
00013040 T png_create_read_struct
00012c20 T png_create_read_struct_2
00014a40 T png_create_write_struct
00014710 T png_create_write_struct_2
00004230 T png_data_freer
00005140 T png_destroy_info_struct
00010eb0 T png_destroy_read_struct
00013da0 T png_destroy_write_struct
0001d0f0 T png_error
0001ca10 T png_free
00004a50 T png_free_data
0001c9d0 T png_free_default
...
fschmitt
  • 8,790