public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* entries in PT_DYNAMIC section refer to the correct address at runtime?
@ 2017-09-14  4:09 Yubin Ruan
  2017-09-14 10:25 ` Alan Modra
  0 siblings, 1 reply; 4+ messages in thread
From: Yubin Ruan @ 2017-09-14  4:09 UTC (permalink / raw)
  To: binutils; +Cc: elfutils-devel

Hi,

I read the ELF spec and note that, a segment designated by a program
header of type PT_DYNAMIC have several entries, many of which contain
addresses of other things. For example, an entry of type DT_SYMTAB was
described (in the ELF) spec to "holds the address of the symbol
table". I wonder whether this address is true at runtime?

Normally a program header would have the following structure:

typedef struct {
    Elf32_Word  p_type;
    Elf32_Off   p_offset;
    Elf32_Addr  p_vaddr;
    Elf32_Addr  p_paddr;
    Elf32_Word  p_filesz;
    Elf32_Word  p_memsz;
    Elf32_Word  p_flags;
    Elf32_Word  p_align;
} Elf32_Phdr;

The `p_vaddr` hold the virtual address (runtime address) for a shared
object file and a executable file. But, as stated in the ELF spec,
`p_vaddr` might not be correct for a shared object (because it is
required to be PIC). So, if that `p_vaddr` is not correct, will those
entries in PT_DYNAMIC be correct?

Yubin

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: entries in PT_DYNAMIC section refer to the correct address at runtime?
  2017-09-14  4:09 entries in PT_DYNAMIC section refer to the correct address at runtime? Yubin Ruan
@ 2017-09-14 10:25 ` Alan Modra
  2017-09-15  6:57   ` Yubin Ruan
  0 siblings, 1 reply; 4+ messages in thread
From: Alan Modra @ 2017-09-14 10:25 UTC (permalink / raw)
  To: Yubin Ruan; +Cc: binutils, elfutils-devel

On Thu, Sep 14, 2017 at 12:09:51PM +0800, Yubin Ruan wrote:
> Hi,
> 
> I read the ELF spec and note that, a segment designated by a program
> header of type PT_DYNAMIC have several entries, many of which contain
> addresses of other things. For example, an entry of type DT_SYMTAB was
> described (in the ELF) spec to "holds the address of the symbol
> table". I wonder whether this address is true at runtime?
> 
> Normally a program header would have the following structure:
> 
> typedef struct {
>     Elf32_Word  p_type;
>     Elf32_Off   p_offset;
>     Elf32_Addr  p_vaddr;
>     Elf32_Addr  p_paddr;
>     Elf32_Word  p_filesz;
>     Elf32_Word  p_memsz;
>     Elf32_Word  p_flags;
>     Elf32_Word  p_align;
> } Elf32_Phdr;
> 
> The `p_vaddr` hold the virtual address (runtime address) for a shared
> object file and a executable file. But, as stated in the ELF spec,
> `p_vaddr` might not be correct for a shared object (because it is
> required to be PIC). So, if that `p_vaddr` is not correct, will those
> entries in PT_DYNAMIC be correct?

DT_ entries that specify addresses will need to be offset by the base
address.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: entries in PT_DYNAMIC section refer to the correct address at runtime?
  2017-09-14 10:25 ` Alan Modra
@ 2017-09-15  6:57   ` Yubin Ruan
  2017-09-15  7:26     ` Alan Modra
  0 siblings, 1 reply; 4+ messages in thread
From: Yubin Ruan @ 2017-09-15  6:57 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils, elfutils-devel

2017-09-14 18:25 GMT+08:00 Alan Modra <amodra@gmail.com>:
> On Thu, Sep 14, 2017 at 12:09:51PM +0800, Yubin Ruan wrote:
>> Hi,
>>
>> I read the ELF spec and note that, a segment designated by a program
>> header of type PT_DYNAMIC have several entries, many of which contain
>> addresses of other things. For example, an entry of type DT_SYMTAB was
>> described (in the ELF) spec to "holds the address of the symbol
>> table". I wonder whether this address is true at runtime?
>>
>> Normally a program header would have the following structure:
>>
>> typedef struct {
>>     Elf32_Word  p_type;
>>     Elf32_Off   p_offset;
>>     Elf32_Addr  p_vaddr;
>>     Elf32_Addr  p_paddr;
>>     Elf32_Word  p_filesz;
>>     Elf32_Word  p_memsz;
>>     Elf32_Word  p_flags;
>>     Elf32_Word  p_align;
>> } Elf32_Phdr;
>>
>> The `p_vaddr` hold the virtual address (runtime address) for a shared
>> object file and a executable file. But, as stated in the ELF spec,
>> `p_vaddr` might not be correct for a shared object (because it is
>> required to be PIC). So, if that `p_vaddr` is not correct, will those
>> entries in PT_DYNAMIC be correct?
>
> DT_ entries that specify addresses will need to be offset by the base
> address.

Will base address be automatically adjusted by the dynamic linker if
it tries to loaded it at a different base address than that specified
in the `p_vaddr'?

Thanks,
Yubin

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: entries in PT_DYNAMIC section refer to the correct address at runtime?
  2017-09-15  6:57   ` Yubin Ruan
@ 2017-09-15  7:26     ` Alan Modra
  0 siblings, 0 replies; 4+ messages in thread
From: Alan Modra @ 2017-09-15  7:26 UTC (permalink / raw)
  To: Yubin Ruan; +Cc: binutils, elfutils-devel

On Fri, Sep 15, 2017 at 02:57:36PM +0800, Yubin Ruan wrote:
> 2017-09-14 18:25 GMT+08:00 Alan Modra <amodra@gmail.com>:
> > DT_ entries that specify addresses will need to be offset by the base
> > address.
> 
> Will base address be automatically adjusted by the dynamic linker if
> it tries to loaded it at a different base address than that specified
> in the `p_vaddr'?

That might depend on the dynamic linker.  glibc ld.so doesn't as far
as I know.  Build yourself a testcase and inspect the .dynamic section
of a shared library or PIE under gdb.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-09-15  7:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-14  4:09 entries in PT_DYNAMIC section refer to the correct address at runtime? Yubin Ruan
2017-09-14 10:25 ` Alan Modra
2017-09-15  6:57   ` Yubin Ruan
2017-09-15  7:26     ` Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).