Accessing String Table Indexes for .rodata

Mark Wielaard mark@klomp.org
Fri Aug 31 11:33:00 GMT 2018


On Fri, 2018-08-31 at 19:07 +0800, Henry C wrote:
> Thanks for replying.
> 
> I mean for example,
> void myprintf(const char* ptr) {
>         printf("%p\n", ptr);
> }
> 
> int main() {
>         myprintf("hello world");
> }
> 
> Let's say the output is 0x403DE.
> 
> Does it mean that Elf64_Shdr::sh_addr of the string table (of
> .rodata)
> + the offset of "hello word" within the string table is guaranteed to
> be the virtual address 0x403DE?  As I am not sure whether virtual
> memory addresses of all string literals are defined/calculated when
> ELF is created.

No, that is not guaranteed. How data in an ELF file is mapped into
memory is determined by the program headers (not the section headers).
See also the picture showing the different ELF file data views in https
://en.wikipedia.org/wiki/Executable_and_Linkable_Format

Cheers,

Mark



More information about the Elfutils-devel mailing list