badnack
badnack

Reputation: 777

Dynamically Loaded (DL) Libraries and first instruction

Is it possible using the Dynamically Loaded (DL) Libraries in c, to retrieve the address of the first instruction of the library? In other words I'd want to know the address from where the library has been loaded.

Upvotes: 2

Views: 67

Answers (1)

Cosmin Ratiu
Cosmin Ratiu

Reputation: 36

There are a few ways to do it:

  1. Use the glibc extension dladdr to get information about any exported function from the shared object. You need to have the name of an exported symbol to do this, though. It returns a Dl_info structure containing, amongst other things, the base address at which the object has been loaded. See 'man dladdr' for more details.

  2. Read and parse /proc/self/maps, looking for your library and noting the starting address of the segment that has the executable bit set ('x' in permissions).

Upvotes: 1

Related Questions