title: How to get a pointer to a specific section of a dynamic library (Linux ELF)?
body: <p>As can be seen in the <a href="https://stackoverflow.com/questions/12159595/how-to-get-a-pointer-to-an-specific-section-of-a-program-from-within-itself-ma">second answer for this question</a> , it's quite simple to get a pointer to an specific section of a program from within itself, using the section's name. With <code>libelf</code>, just open the program's own file, loop over all sections (which are represented by <code>Elf64_Shdr</code> structs) in it, stop when the section name matches the one you want and use the pointer stored in the <code>sh_addr</code> element of the <code>Elf64_Shdr</code> struct. In this case, it's very simple to get the wanted pointer because it is defined in the ELF executable file.</p>
  
  <p>But, imagine you have a program that uses a dynamic library and you need to get a pointer to a section of that dynamic library. Since the addresses of its sections are defined in runtime, how is it possible to get pointers to sections of a dynamic library?</p>
  
  <p>By the way, both the dynamic library and the main program itself have, each one, a section with the same name (which is the one I need to get a pointer to). So, in this case, is it possible that these two sections with the same name are stored adjacently in memory, so that I just need to get a pointer to the main file's section (as I explained in the first paragraph) and add an offset to reach the dynamic library section?</p>