c - How to read the relocation records of an object file -
i'm trying understand linking stage of c toolchain. wrote sample programme , dissected resulting object file. while helped me improve understanding of processes involved, there things remain unclear me.
here are:
my (blazingly simple) sample program relevant parts of object disassembly the objects symbol table the objects relocation table part 1: handling of initialized variables.is correct, theses relocation table entries...
relocation records [.text]: offset type value 0000002b dir32 .data 00000035 dir32 .data 0000003f dir32 .data
... telling linker, addresses stored @ offset 2b
, 35
, 3f
.text
not absolute adresses, relative adresses (= offsets) in relation .data
? understanding enables linker to
i don't understand why uninitalized variables handled differently initialized variables. why register adresses stored in opcode,
equal uninitialized variables (0x0, 0x0 , 0x0), while being different initialized variables (0x0, 0x4 , 0x8)?also value field of relocation table entries exclusively unclear me. have expected .bss
section referenced there.
relocation records [.text]: offset type value 0000000d dir32 _var1_zeroed-0x00000004 00000017 dir32 _var2_zeroed-0x00000004 00000021 dir32 _var3_zeroed-0x00000004
... telling linker, addresses stored @ offset ...
no, linker no longer involved this. relocation tables tell loader, part of operating scheme that's responsible loading executable image memory addresses.
the linker builds executable image based on assumption ideal , image can loaded @ intended address. if that's case hunky-dory, nil needs done. if there's conflict however, virtual address space in utilize else, image needs relocated @ different address.
that requires addresses patched, offset between ideal , actual load address needs added. if .data section ends @ address addresses .text+0x2b, .text+0x35, etcetera, must changed. no different uninitialized variables, linker picked address them when _var1_zeroed-0x00000004 ends @ address .text+0x0d, .text+0x17, etcetera, need changed.
c object linker relocation
No comments:
Post a Comment