Since there's some confusion, here are the two steps to get the "module" data for the current function.
- Get the current function, either by the IP register or by calling a small function that just returns
__builtin_return_address(0)
. Yet another method is to just take&foo
insidefoo()
. - Call
dladdr
, passing the address of the current function.