How to get additional fields in the link_map structure, for example, l_info, l_libname, l_phdr, etc.?

Viewed 21

I have used dl_info to get the link map of the current program. However, I only get the following information: {l_addr = 140737354113024, l_name = 0x7ffff7ffeb50 "linux-vdso.so.1", l_ld = 0x7ffff7ffa3a0, l_next = 0x7ffff7fd4000, l_prev = 0x7ffff7ffe110} I have seen in gdb that the structure is extended and has more fields during libc's initialization (specifically, in setup_vdso). It looks like the following:

$5 = {
  l_addr = 0x7ffff7ffd000,
  l_name = 0x10f5bd80,
  l_ld = 0x7ffff7ffd3a0,
  l_next = 0x0,
  l_prev = 0x10eb8400,
  l_real = 0x10f5b8d0,
  l_ns = 0x0,
  l_libname = 0x10f5bd58,
  l_info = {0x0, 0x0, 0x0, 0x0, 0x10ea5a20, 0x10ea5a30, 0x10ea5a40, 0x0, 0x0, 0x0, 
    0x7ffff7ffd400, 0x7ffff7ffd410, 0x0, 0x0, 0x7ffff7ffd3a0, 0x0, 0x7ffff7ffd440, 
    0x0 <repeats 13 times>, 0x7ffff7ffd440, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
    0x7ffff7ffd430, 0x7ffff7ffd420, 0x0 <repeats 11 times>, 0x10ea5a50, 
    0x0 <repeats 25 times>, 0x10ea5a60},
  l_phdr = 0x7ffff7ffd040,
  l_entry = 0x0,
  l_phnum = 0x4,
  l_ldnum = 0x12,
  l_searchlist = {
    r_list = 0x10f5b8f8,
    r_nlist = 0x1
  },
  l_symbolic_searchlist = {
    r_list = 0x10f5bd50,
    r_nlist = 0x0
  },
  l_loader = 0x0,
  l_versions = 0x0,
  l_nversions = 0x0,
  l_nbuckets = 0x3,
  l_gnu_bitmask_idxbits = 0x0,
  l_gnu_shift = 0x6,
  l_gnu_bitmask = 0x7ffff7ffd178,
  {
    l_gnu_buckets = 0x7ffff7ffd180,
    l_chain = 0x7ffff7ffd180
  },
  {
    l_gnu_chain_zero = 0x7ffff7ffd188,
    l_buckets = 0x7ffff7ffd188
  },
  l_direct_opencount = 0x0,
  l_type = 0x1,
  l_relocated = 0x1,
.... many other fields

I can see these values in the memory (by examining under gdb). However, I don't know how to get these additional fields of link_map programmatically. How do I get this extra information? Particularly, I am looking for the l_info field.

1 Answers

How do I get this extra information?

This information is private to GLIBC and is intentionally not exposed to the end user.

The layout of the structure also changes from one version of GLIBC to the next, so your program may work on one system but break on a different one (or even on the same system after GLIBC update).

Related