This is the mail archive of the binutils@sourceware.org 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: Help about calculation of addend for ELF relocations for MIPS arch


I'm still confused at computing `S' if the symbol is local.
Let's continue the example above.

$mips-elf-readelf -r foo.out
 Offset     Info    Type            Sym.Value  Sym. Name
0000004c  00000505 R_MIPS_HI16       00000000   .bss
00000058  00000506 R_MIPS_LO16       00000000   .bss

$mips-elf-readelf -s foo.out
 Num:    Value  Size Type    Bind   Vis      Ndx Name
...
     5: 00000000     0 SECTION LOCAL  DEFAULT    5

$mips-elf-objdump -S foo.out
c000004c:	3c130000 	lui	s3,0x0
...
c0000058:	8e640000 	lw	a0,0(s3)

$mips-elf-objdump -h foo.out
Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00002190  c0000000  c0000000  00000034  2**2
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
  1 .data         0000105c  c0002190  c0002190  000021c4  2**2
                  CONTENTS, ALLOC, LOAD, RELOC, DATA
  2 .bss          00000034  c00031ec  c00031ec  00003220  2**2
                  ALLOC
  3 .reginfo      00000018  00000000  00000000  00003220  2**2
                  CONTENTS, READONLY, LINK_ONCE_SAME_SIZE
  4 .pdr          000005e0  00000000  00000000  00003238  2**2
                  CONTENTS, RELOC, READONLY
  5 .mdebug.abi32 00000000  00000000  00000000  00003818  2**0
                  CONTENTS, READONLY

$mips-elf-objdump -h foo.img
Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00002190  188e1000  188e1000  00001000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .data         0000105c  18909000  18909000  00004000  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss          00000034  18921000  18921000  00006000  2**2
                  ALLOC
  3 .reginfo      00000018  00000000  00000000  00006000  2**2
                  CONTENTS, READONLY, LINK_ONCE_SAME_SIZE
  4 .pdr          000005e0  00000000  00000000  00006018  2**2
                  CONTENTS, READONLY
  5 .mdebug.abi32 00000000  00000000  00000000  000065f8  2**0
                  CONTENTS, READONLY

$mips-elf-objdump -S foo.img
188e104c:	3c131892 	lui	s3,0x1892
...
188e1058:	8e641000 	lw	a0,4096(s3)

As the specification says
S   Represents the value of the symbol whose index resides in the relocation
    entry, unless the the symbol is STB_LOCAL and is of type
    STT_SECTION in which case S represents the original sh_addr minus
    the final sh_addr.

Since the symbol is local, the formulas
 ((AHL + S) - (short)(AHL + S)) >> 16
 AHL + S
are applied to compuation of the relocation entries hi16/lo16 respectively.
AHL is zero. So
 hi16 = (S - (short)S) >> 16 = S >> 16
 lo16 = (short)S
And for this example, hi16 is 0x1892 and ho16 is 0x1000. So `S' should be
0x18921000. On the other hand, the original sh_addr is 0xc00031ec,
and the final sh_addr is 0x18921000. According to the specification,
`S' is 0xc00031ec - 0x18921000 = 0xa76e21ec, which is far different from
the appropriate value 0x18921000.

What's wrong?

------------
Best Regards
PRC
Aug 13, 2008


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