问题
I'm trying to understand the dynamic linking of shared libraries on Linux. Given the following dump of Relocation section '.rela.plt':
Offset Info Type Sym. Value Sym. Name + Addend
000000373f68 0f8300000007 R_X86_64_JUMP_SLO 0000000000000000 _ZN8CashFlowmIERK7Paym + 0
000000373f70 0f9800000007 R_X86_64_JUMP_SLO 0000000000000000 _Z8printCapPK3CapP8_IO + 0
000000373f78 0f9900000007 R_X86_64_JUMP_SLO 0000000000000000 _ZN13SharedBaggage16ge + 0
000000373f80 0f9c00000007 R_X86_64_JUMP_SLO 0000000000000000 _Z11usdCurrencyv + 0
I have the following questions:
As far as I know, the lowest 3 bytes of r_info are used as an unsigned index into to the .dynsym section to point to the symbol. So, how to explain the following Relocation section entries which all have 0000007 as index into .dynsym section?
Would anyone tell me what "Sym. Value" is? is it the real value (which means address) of the symbol? If so, how come they are all zeros?
回答1:
No. In Elf32 files, the high 3 bytes of
r_info
are the symbol index and the low byte is the relocation type. In Elf64 files,r_info
is split as two 32-bit parts. The values0f83
, etc. in the high parts are the symbol indices.The symbol values shown are not part of the relocation table but come from the dynamic symbol table referenced by the relocation. There will only be a symbol value if the symbol is actually defined in this module (shared library). If it's undefined and relying on a definition from another module, you'll just see zero.
If I understand what you're asking, how resolution is done is an implementation detail, and probably outside the scope of an SO question. You should probably re-ask with specific questions about parts you don't understand for a particular implementation.
来源:https://stackoverflow.com/questions/48942103/how-to-understand-fields-of-relocation-section-rela-plt