2

Let's say there are multiple shared libraries linked to an executable. Say libaaa.so makes a reference to a global variable aaa and libbbb.so makes a reference to a global variable bbb.

My understanding is that the code accesses these variables indirectly via the GOT using offsets. I am having trouble understanding how the offset for aaa in libaaa.so and offset for bbb in libbbb.so manage to avoid conflicting with each other.

How is the code for the shared libraries generated such that all references in all the libraries end up at different offsets in the GOT?

I am sure I am missing something silly.

Ziffusion
  • 8,779
  • 4
  • 29
  • 57
  • 1
    The GOT is per-module, not per-application. Each module gets a fixup. Also see Ulrich Drepper's [How To Write Shared Libraries](https://www.akkadia.org/drepper/dsohowto.pdf). The GOT and PLT are covered in section 1.5.5. – jww Sep 22 '19 at 22:59
  • I thought the GOT had to be in the process data segment. And some register points to it at all times. Still not getting how the linker manages to allocate the GOT(s) so that it's offset from all modules is what it needs to be for each module. Thanks for the link. I'll check it out. – Ziffusion Sep 22 '19 at 23:57

0 Answers0