ELF, Program Header, convert virtual addresses to physical addresses
Ian Lance Taylor
Thu Aug 18 17:43:00 GMT 2005
Torsten Mohr <firstname.lastname@example.org> writes:
> i try to convert virtual addresses in an ELF file to
> physical addresses, all based on the program header
> entries with p_type == PT_LOAD.
What is the context? In other words, why do you want to do this?
> My first try to get the physical address P then was:
> P = X - p_vaddr + p_paddr
That is correct for the way that the GNU toolchain uses p_paddr. The
GNU toolchain uses p_paddr to represent the load address as set by the
AT modifier in a linker script.
> But that failed badly on an ELF file generated by a Greenhills
> toolchain for a NEC V850 and its program headers:
> readelf -l file.elf:
> Program Headers:
> Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
> LOAD 0x000240 0x00000000 0x00000000 0x00594 0x00594 R E 0
> LOAD 0x000840 0x00000600 0x00000000 0x00010 0x00010 R E 0
Evidently Green Hills doesn't use p_paddr at all. Presumably for them
p_paddr is always the same as p_vaddr.
More information about the Binutils