public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Re: the question about PT_DYNAMIC's p_offset value in elf file for mips platform
@ 2004-10-26  9:10 eagle_zhou
  2004-10-26 10:33 ` Nick Clifton
  0 siblings, 1 reply; 5+ messages in thread
From: eagle_zhou @ 2004-10-26  9:10 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils



hi Nick,

I think that .dynamic section should be the first section of dynamic
segment.

I have studied source codes in glibc(dynamic loader part), it's flow is :
find program header firstly,
then find PT_DYNAMIC segment,
finally find other dynamic section by searching PT_DYNAMIC
segment(regarding it as a array of struct Elf32_Dyn).

If .dynamic section is not the first section in dynamic segment,
how can i get other dynamic section information?
and isn't glibc source perfect?

thanks.






Nick Clifton <nickc@redhat.com> on 2004-10-26 16:30:11

To:   Eagle Zhou/ALI_SHA/ACER@ACER
cc:   binutils@sources.redhat.com

Subject:  Re: the question about PT_DYNAMIC's p_offset value in elf file
      for mips platform



Hi Eagle,

 > I do not know why PT_DYNAMIC's p_offset is 0x0000ac. I think the
 > correct value should be 0x1008.

The PT_DYNAMIC segment includes more than just the .dynamic section.  It
also includes sections like .hash, .dynsym etc.  Hence the segment
starts at the lowest offset of all of these sections, which in this case
is the .hash section.

If you have a look at the section to segment mapping output from readelf:

>       Section to Segment mapping:
>        Segment Sections...
>         00     .hash .dynsym .dynstr .text .MIPS.stubs .rel.dyn
>         01     .data .dynamic .got .bss
>         02     .reginfo .hash .dynsym .dynstr .text .MIPS.stubs .data
> .dynamic .debug_aranges .debug_pubnames .debug_info .debug_abbrev
> .debug_line .debug_frame .debug_str .pdr .rel.dyn .compact_rel .shstrtab
> .symtab


You can see the relationship between segments and sections.

Cheers
   Nick




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

* Re: the question about PT_DYNAMIC's p_offset value in elf file for mips platform
  2004-10-26  9:10 the question about PT_DYNAMIC's p_offset value in elf file for mips platform eagle_zhou
@ 2004-10-26 10:33 ` Nick Clifton
  2004-10-26 13:18   ` Thiemo Seufer
  0 siblings, 1 reply; 5+ messages in thread
From: Nick Clifton @ 2004-10-26 10:33 UTC (permalink / raw)
  To: eagle_zhou; +Cc: binutils

Hi Eagle,

> I think that .dynamic section should be the first section of dynamic
> segment.

For most ports this is true.  But for the MIPS it is not.  I will let a 
MIPS expert explain why, as I do not actually know the reason.

> If .dynamic section is not the first section in dynamic segment,
> how can i get other dynamic section information?

If you have a section header then discovering this information is 
simple.  Otherwise there is no easy way.  I think that with MIPS ports 
which do not have the .dynamic section at the start of the PT_DYNAMIC 
segment there is a requirement to keep the section header in an 
executable.  (I expect someone will correct me on this).

> and isn't glibc source perfect?

he he.  Well if you ask Uli Drepper then yes it probably is. :-)

Cheers
   Nick

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

* Re: the question about PT_DYNAMIC's p_offset value in elf file for mips platform
  2004-10-26 10:33 ` Nick Clifton
@ 2004-10-26 13:18   ` Thiemo Seufer
  0 siblings, 0 replies; 5+ messages in thread
From: Thiemo Seufer @ 2004-10-26 13:18 UTC (permalink / raw)
  To: Nick Clifton; +Cc: eagle_zhou, binutils

Nick Clifton wrote:
> Hi Eagle,
> 
> >I think that .dynamic section should be the first section of dynamic
> >segment.
> 
> For most ports this is true.  But for the MIPS it is not.  I will let a 
> MIPS expert explain why, as I do not actually know the reason.

I guess it is for historic reasons and/or compatibility to other
(read IRIX) operating systems.

> >If .dynamic section is not the first section in dynamic segment,
> >how can i get other dynamic section information?
> 
> If you have a section header then discovering this information is 
> simple.  Otherwise there is no easy way.  I think that with MIPS ports 
> which do not have the .dynamic section at the start of the PT_DYNAMIC 
> segment there is a requirement to keep the section header in an 
> executable.  (I expect someone will correct me on this).

Glibc's ld.so finds the offset from the magic _DYNAMIC symbol.


Thiemo

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

* Re: the question about PT_DYNAMIC's p_offset value in elf file for mips platform
  2004-10-26  7:21 eagle_zhou
@ 2004-10-26  8:24 ` Nick Clifton
  0 siblings, 0 replies; 5+ messages in thread
From: Nick Clifton @ 2004-10-26  8:24 UTC (permalink / raw)
  To: eagle_zhou; +Cc: binutils

Hi Eagle,

 > I do not know why PT_DYNAMIC's p_offset is 0x0000ac. I think the
 > correct value should be 0x1008.

The PT_DYNAMIC segment includes more than just the .dynamic section.  It 
also includes sections like .hash, .dynsym etc.  Hence the segment 
starts at the lowest offset of all of these sections, which in this case 
is the .hash section.

If you have a look at the section to segment mapping output from readelf:

>       Section to Segment mapping:
>        Segment Sections...
>         00     .hash .dynsym .dynstr .text .MIPS.stubs .rel.dyn
>         01     .data .dynamic .got .bss
>         02     .reginfo .hash .dynsym .dynstr .text .MIPS.stubs .data
> .dynamic .debug_aranges .debug_pubnames .debug_info .debug_abbrev
> .debug_line .debug_frame .debug_str .pdr .rel.dyn .compact_rel .shstrtab
> .symtab


You can see the relationship between segments and sections.

Cheers
   Nick

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

* the question about PT_DYNAMIC's p_offset value in elf file for mips platform
@ 2004-10-26  7:21 eagle_zhou
  2004-10-26  8:24 ` Nick Clifton
  0 siblings, 1 reply; 5+ messages in thread
From: eagle_zhou @ 2004-10-26  7:21 UTC (permalink / raw)
  To: binutils


I am researching shared library on mips platform.
and i have built one cross compile tools based on mips-elf target.
(the software package i used are : binutils-2.15/newlib-1.12.0/gcc-3.4.0)
I created a demo.so file by sequences listed below:

$mips-elf-gcc -EL -g  -fPIC -mabicalls -c  demo.c
$mips-elf-ld -EL -shared -o demo.so demo.o
$readelf -a demo.so >demo.elf

the content of demo.elf is :

     ELF Header:
       Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
       Class:                             ELF32
       Data:                              2's complement, little endian
       Version:                           1 (current)
       OS/ABI:                            UNIX - System V
       ABI Version:                       0
       Type:                              DYN (Shared object file)
       Machine:                           MIPS R3000
       Version:                           0x1
       Entry point address:               0x5ffe05a8
       Start of program headers:          52 (bytes into file)
       Start of section headers:          5908 (bytes into file)
       Flags:                             0x7, noreorder, pic, cpic, mips1
       Size of this header:               52 (bytes)
       Size of program headers:           32 (bytes)
       Number of program headers:         3
       Size of section headers:           40 (bytes)
       Number of section headers:         26
       Section header string table index: 23

     Section Headers:
       [Nr] Name              Type            Addr     Off    Size   ES Flg
Lk Inf Al
       [ 0]                   NULL            00000000 000000 000000 00
0   0  0
       [ 1] .reginfo          MIPS_REGINFO    5ffe0094 001104 000018 18
0   0  4
       [ 2] .hash             HASH            5ffe00ac 0000ac 00014c 00   A
3   0  4
       [ 3] .dynsym           DYNSYM          5ffe01f8 0001f8 0002c0 10   A
4  23  4
       [ 4] .dynstr           STRTAB          5ffe04b8 0004b8 0000dd 00   A
0   0  4
       [ 5] .text             PROGBITS        5ffe05a8 0005a8 000130 00  AX
0   0  4
       [ 6] .MIPS.stubs       PROGBITS        5ffe06d8 0006d8 000040 00  AX
0   0  4
       [ 7] .data             PROGBITS        60021000 001000 000008 00  WA
0   0  4
       [ 8] .dynamic          DYNAMIC         60021008 001008 0000c0 00   A
4   0  4
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       [ 9] .got              PROGBITS        600210d0 0010d0 000034 04 WAp
0   0 16
       [10] .sbss             NOBITS          60021104 00111c 000000 00 WAp
0   0  1
       [11] .bss              NOBITS          60021104 001104 000800 00  WA
0   0  4
       [12] .debug_aranges    MIPS_DWARF      00000000 00111c 000020 00
0   0  1
       [13] .debug_pubnames   MIPS_DWARF      00000000 00113c 00004b 00
0   0  1
       [14] .debug_info       MIPS_DWARF      00000000 001187 0001b4 00
0   0  1
       [15] .debug_abbrev     MIPS_DWARF      00000000 00133b 0000a8 00
0   0  1
       [16] .debug_line       MIPS_DWARF      00000000 0013e3 00004b 00
0   0  1
       [17] .debug_frame      MIPS_DWARF      00000000 001430 000050 00
0   0  4
       [18] .debug_str        MIPS_DWARF      00000000 001480 00000d 00
0   0  1
       [19] .pdr              PROGBITS        00000000 001490 000040 00
0   0  4
       [20] .mdebug.abi32     PROGBITS        00000000 0014d0 000000 00
0   0  1
       [21] .rel.dyn          REL             5ffe0598 000598 000010 08   A
3   0  4
       [22] .compact_rel      PROGBITS        00000000 0014d0 000150 00
0   0  4
       [23] .shstrtab         STRTAB          00000000 001620 0000f1 00
0   0  1
       [24] .symtab           SYMTAB          00000000 001b24 000300 10
25  27  4
       [25] .strtab           STRTAB          00000000 001e24 0000e4 00
0   0  1
     Key to Flags:
       W (write), A (alloc), X (execute), M (merge), S (strings)
       I (info), L (link order), G (group), x (unknown)
       O (extra OS processing required) o (OS specific), p (processor
specific)

     Program Headers:
       Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg
Align
       LOAD           0x000000 0x5ffe0000 0x5ffe0000 0x00718 0x00718 R E
0x1000
       LOAD           0x001000 0x60021000 0x60021000 0x00104 0x00904 RW
0x1000
       DYNAMIC        0x0000ac 0x5ffe00ac 0x5ffe00ac 0x4101c 0x4101c RWE
0x4
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      Section to Segment mapping:
       Segment Sections...
        00     .hash .dynsym .dynstr .text .MIPS.stubs .rel.dyn
        01     .data .dynamic .got .bss
        02     .reginfo .hash .dynsym .dynstr .text .MIPS.stubs .data
.dynamic .debug_aranges .debug_pubnames .debug_info .debug_abbrev
.debug_line .debug_frame .debug_str .pdr .rel.dyn .compact_rel .shstrtab
.symtab

     Dynamic section at offset 0x1008 contains 19 entries:
       Tag        Type                         Name/Value
      0x00000004 (HASH)                       0x5ffe00ac
      0x00000005 (STRTAB)                     0x5ffe04b8
      0x00000006 (SYMTAB)                     0x5ffe01f8
      0x0000000a (STRSZ)                      221 (bytes)
      0x0000000b (SYMENT)                     16 (bytes)
      0x00000016 (TEXTREL)                    0x0
      0x00000003 (PLTGOT)                     0x600210d0
      0x00000011 (REL)                        0x5ffe0598
      0x00000012 (RELSZ)                      16 (bytes)
      0x00000013 (RELENT)                     8 (bytes)
      0x70000001 (MIPS_RLD_VERSION)           1
      0x70000005 (MIPS_FLAGS)                 NOTPOT
      0x70000006 (MIPS_BASE_ADDRESS)          0x5ffe0000
      0x7000000a (MIPS_LOCAL_GOTNO)           7
      0x70000011 (MIPS_SYMTABNO)              44
      0x70000012 (MIPS_UNREFEXTNO)            23
      0x70000013 (MIPS_GOTSYM)                0x26
      0x70000014 (MIPS_HIPAGENO)              5
      0x00000000 (NULL)                       0x0
     ......
     ......

Is this elf file is right?
I do not know why PT_DYNAMIC's p_offset is 0x0000ac. I think the correct
value should be 0x1008.

I do not know the reason.
Does anyone have an idea of what goes wrong?






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

end of thread, other threads:[~2004-10-26 13:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-26  9:10 the question about PT_DYNAMIC's p_offset value in elf file for mips platform eagle_zhou
2004-10-26 10:33 ` Nick Clifton
2004-10-26 13:18   ` Thiemo Seufer
  -- strict thread matches above, loose matches on Subject: below --
2004-10-26  7:21 eagle_zhou
2004-10-26  8:24 ` Nick Clifton

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).