0

Trying to understand how the relocation happens in the situation below I have a shared library libbigshr.so which uses another shared library libfunlib.so. In the latter I have declared this global variable foo. To compile the former I had to do forward declaration as extern int foo.

.rel.dyn at libbigshr.so

Offset     Info    Type            Sym.Value  Sym. Name

000005a5  00000401 R_386_32          00000000   foo
000005ab  00000401 R_386_32          00000000   foo
000005c7  00000401 R_386_32          00000000   foo

.rel.dyn at libfunlib.so

000005a5  00000901 R_386_32          00002010   foo

In the libfunlib the translation offset is proper value (0x2010), therefore I don't have problem. But wanted to know the how the correct addresses were inserted in libbigshr. I can understand, that once a variable has been allocated the memory and its location is identified the same can be used everywhere else. But I am interested in the procedure of doing so.

Due to my ignorance my question may not have sufficient data to answer it - so please let me know and I will furnish more details.

ultimate cause
  • 2,264
  • 4
  • 27
  • 44

1 Answers1

1

The correct address is generated by relocation processing at run time, by the dynamic linker. For example, in glibc, R_386_32 is processed in the i386 version of the elf_machine_rel function in the file sysdeps/i386/dl-machine.h. The glibc wiki has an overview of process startup. For details, see the references in the Linux Standard Base, particular those concerning the System V Application Binary Interface. For machine-specific information, H.J. Lu maintains a set of x86 ABI documents.

Florian Weimer
  • 32,022
  • 3
  • 48
  • 92
  • Agree. I calculated and verified that in gdb for libfunlib.so. But wanted to understand the same for the other library. Thanks and +1 for pointers. Need more help to understand the rest. – ultimate cause Apr 01 '18 at 18:22