To find out which dynamic libraries export which symbol, on a GNU system, you can try something like:
ldconfig -p |
sed -n 's/.* => //p' |
sort -u |
xargs -d '\n' nm --defined-only -oDg |
grep -w getpid
(in first approximation; that could be improved by removing duplicates at inode level).
Something similar can be done with static libraries or any ELF or other object supported by
nm, though you may need to adapt the flags, and how to gather the list of files you want to search in.
NLMSG_DATA being all uppercase is more likely to be a C preprocessor macro.
$ grep -r NLMSG_DATA /usr/include
/usr/include/linux/netlink.h:#define NLMSG_DATA(nlh) ((void*)(((char*)nlh) + NLMSG_LENGTH(0)))
To look for definitions in C headers, instead of
grep, you may want to use some code indexing tools like
gtags and index the whole of
You can also get the C pre-processor to expand it:
printf '%s\n' '#include <linux/netlink.h>' 'please_describe[NLMSG_DATA(nlh)]' |
gcc -P -E -x c - | sed '/please_describe/,$!d'
please_describe[((void*)(((char*)nlh) + ((0) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) )))))]
So it just returns a pointer some offset off the input pointer based on the size of
struct nlmsghdr (which you could determine using the C compiler or debugging symbols of some object that uses that
Note that headers being not needed to run software, only to build them, they won't be installed by default for all libraries, so you may need to install some
xxx-devel packages to bring them in.
When you do have the man page for the library function (does not really apply here as it's some kernel API), chances are you also have the header files. You can work your way from the man page to the package and then to the headers and library. For instance on Debian and derivatives for the
$ man -w attr_setf
$ dpkg -S /usr/share/man/man3/attr_set.3.gz
$ dpkg -L libattr1-dev | grep /include/
For the libraries, you can guess the package is
libattr1 or use the fact that the
-dev package will depend on the runtime one:
$ apt-cache show libattr1-dev | grep Depends
Depends: libc6-dev | libc-dev, libattr1 (= 1:2.4.47-2build1)
$ dpkg -L libattr1 | grep /lib/
$ nm -Dg /lib/x86_64-linux-gnu/libattr.so.1 | grep attr_setf
00000000000016e0 T attr_setf
If you do not have the man page, but know it exists, you can look-up which package it's available from:
$ apt-file search -x 'man.*/attr_set\.\d'