This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ELF addresses


On Thu, Feb 05, 2004 at 05:55:45PM -0600, Brian Blietz wrote:
> I am trying to figure out how to determine the starting address for an 
> elf file,
> in accordance to the e_entry param in the header.
> The e_entry will have the VMA, right?

Mostly true.  On some architecture, eg. powerpc64 linux, e_entry is
the address of a function descriptor, which then points to the actual
code entry addres.

> I get something along the lines of 0x0804832c.
> 
> What is the base address of the ELF file? Is it 0x08040000 ?
> How do I track this down and make it portable?

You can normally find this sort of info at
http://www.caldera.com/developers/gabi/ but it seems the website is
down at the moment.  Here's the relevant extract:

"As ``Program Loading'' in this chapter of the processor supplement
describes, the virtual addresses in the program headers might not
represent the actual virtual addresses of the program's memory
image. Executable files typically contain absolute code. To let the
process execute correctly, the segments must reside at the virtual
addresses used to build the executable file. On the other hand, shared
object segments typically contain position-independent code. This lets a
segment's virtual address change from one process to another, without
invalidating execution behavior. On some platforms, while the system
chooses virtual addresses for individual processes, it maintains the
relative position of one segment to another within any one shared
object. Because position-independent code on those platforms uses
relative addressing between segments, the difference between virtual
addresses in memory must match the difference between virtual addresses
in the file. The differences between the virtual address of any segment
in memory and the corresponding virtual address in the file is thus a
single constant value for any one executable or shared object in a given
process. This difference is the base address. One use of the base
address is to relocate the memory image of the file during dynamic
linking.

An executable or shared object file's base address (on platforms that
support the concept) is calculated during execution from three values:
the virtual memory load address, the maximum page size, and the lowest
virtual address of a program's loadable segment. To compute the base
address, one determines the memory address associated with the lowest
p_vaddr value for a PT_LOAD segment. This address is truncated to the
nearest multiple of the maximum page size. The corresponding p_vaddr
value itself is also truncated to the nearest multiple of the maximum
page size. The base address is the difference between the truncated
memory address and the truncated p_vaddr value."

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]