question regarding link_elf.c

PL kadupl at wp.pl
Wed Sep 29 14:13:03 UTC 2010


Dnia 29-09-2010 o godz. 10:58 Andriy Gapon napisał(a):
> on 29/09/2010 11:18 PL said the following:
> > Hi everyone,
> > I'm not quiet sure if it is proper place to ask the question I have. If
> > not, please
> > direct me to the correct place I should post questions like:
> > 
> > Im working on some modifications around link_elf.c. According to elf(5)
> > man pages,
> > Elf_Shdr structure contains field called 'sh_addr', containing the
> > address at
> > which first byte of a section shall reside in the memory image. I am
> > particularily
> > interested in '.text' and '.data' sections. After link_elf_load_file()
> > loads the
> > file into a memory, we have linker_file structure filled in, including
> > 'address'
> > field. Now, assuming 'lf' being linker_file_t, already filled in by the
> > loading
> > routine, 'text_sh' being 'Elf_Shdr' for text section, and 'data_sh'
> > being 'Elf_Shdr'
> > for data section:
> > - lf->address + text_sh.sh_addr really points to the beginning of a
> > '.text' section
> >   in memory, however..
> > 
> > - lf->address + data_sh.sh_addr does not point to the valid location of
> > '.data' section
> >   in memory.
> > 
> > Sorry if my question is stupid, but im wondering why it is so ? I guess
> > it has something
> > to do with virtual memory mapping (?).
> 
> Perhaps the reason is simpler, like a bug in your code :-)
> You can do 'readelf -a' on a module that you load and check attributes
> of .data
> section and then compare with data_sh that you get at run-time.
> 
> --
> Andriy Gapon
> _______________________________________________
> freebsd-hackers at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe at freebsd.org"

It seems like it is not a problem in my own code, since readelf -S on a 
elf file
gives me the same results as my debug messages. I've created an empty 
module, to
simplify debugging. Both my code, and readelf says, that '.text' section 
address
is 0x3e0, and its size is 7 bytes. Adding 0x3e0 to lf->address points to 
a valid location.

'.data' is supposed to be at 0x1424 (again, both my code and readelf 
returns the same thing),
but the actual data starts at lf->address + 0x3e7. How do I know ? I've 
added global
initialized string variable in empty test module, and Im looking at the 
memory to determine
it's location. I'm not sure what is wrong then.




More information about the freebsd-hackers mailing list