Mail Archives: djgpp/1999/04/16/17:13:06
Okay, I'm writing a dynamic loader for COFF files, and up to this point
I'm fine. i understand what's going on and I have no problem.
But I need to understand exactly what it is I need to do to relocate a
RELOC_REL32 entry in the relocation table for a section. e.g. i understand
how to find the symbol it references, and i THINK that I understand what it
references:
the relocation is relative when the entry is external, that is, not part
of the object itself. for RELOC_ADDR32 i understand that i just do this:
*(long *)section+r->r_vaddr += section;
that gives me the absolute address, because now it starts at a
different offset than before.
however, what i don't understand is what i do to RELOC_REL32. the file
describing this relocation says:
a.. Get the address of the symbol referred to.
b.. Add the value currently stored in the location being adjusted.
c.. Subtract the address of the beginning of the section.
d.. Add the original (unrelocated) address of the beginning of this
section. Normally this is zero for DJGPP as only the _text section, which is
first (and thus at unrelocated address zero), has relative relocs.
Note: The preceeding two steps can be replaced with the single step of
"subtract the amount you moved this section".
e.. Store the value back into the location being adjusted.
okay, so that sounds as if i'm supposed to:
*(long *)section+r->r_vaddr += section;
*(long *)section+r->r_vaddr -= (section - section_header.s_paddr);
that doesn't sound reasonable at all.
sections
[ 1] 000000000000 000000000000 .text (executable code)
[ 2] 000000000004 000000000000 .data (initialized data)
[ 3] 000000000004 000000000004 .bss (uninitialized data)
[ 4] 000000000008 000000000008 .xptdata (exported data)
[ 5] 000000000080 000000000016 .xptfunc (exported functions)
[ 0] 0x00000018 000000000048 Abs 0x05c70000 -> 0x06512af0 in .xptdata
[ 1] 0x00000022 000000000048 Abs 0x05c70000 -> 0x06512af0 in .xptdata
[ 2] 0x0000002c 000000000044 Abs 0x00000009 -> 0x008a2ab9 in .data
[ 3] 0x00000036 000000000046 Abs 0x00000001 -> 0x008a2ad1 in .bss
[ 4] 0x00000041 000000000054 Rel 0xa8e850fc:(_malloc)
[ 5] 0x00000054 000000000055 Rel 0x00000038:(_memset)
this is the output my program gives me on a test file. one of the functions
that gets output to .xptfunc references both _malloc and _memset, but they
aren't statically linked into the object, so, what is it that I need to do
to get _malloc and _memset's real addresses correctly patched into the file?
-={C}=-
- Raw text -