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]

how does ld interpret ELF R_PPC_REL32?


I am having trouble understanging the ELF relocation R_PPC_REL32 and how ld interprets this relocation.

The standard defines R_PPC_REL32 as S + A - P where S is the value of the symbol, A is the addend in the relocation, and P is the place (section offset or address) of the storage unit being relocated (computed using r_offset).

So when I compile a simple program containing a switch statement, it generates these relocations for the rodata section of the object module, which contains a jump table. Each entry in the jump table is relocated to refer to a case of the switch statement. The relocations look like this:

Relocation section '.rela.rodata' at offset 0x1904 contains 17 entries: Offset     Info    Type                                        Sym.Value  Sym.Name + Addend 
00000000  0000021a R_PPC_REL32       00000000   .text        + 58
00000004  0000021a R_PPC_REL32       00000000   .text        + 68

I take this to mean:

0 + 58 - 0 = 58  for the first entry and 0 + 68 - 4 = 64  for the second entry.

This seems ok so far in that t8 is the offset in the text section of the first case statement's code and 64 is the offset in text of the second case statement
s code. When I link this file, producing another reloctable object module I get this:

Offset     Info    Type                                Sym.Value  Sym.Name + Addend
>> 00001bf0  0000011a R_PPC_REL32       00000000   .text        + 1d7d4 
>> 00001bf4  0000011a R_PPC_REL32       00000000   .text        + 1d7e4 

Now the calculations might be like this:

0 + 1d7d4 - 1bf0 = 1BBE4
0 + 1d7e4 - 1bf4 = 1BBF0

Is this right so far? 

I can't understand how these results correlate with what the linker actually does, and they bear no relation that I can see to the actual code of the case statements. The code of the case statements is at 0xd7d4 and 0xd7e0 respectively.

The values in the jump table do not seem to correlate with the values I calculated above; the values in the table are negative numbers which when added to the jump table start address find the code associated with each case, and the values do not seem to relate to these values above.

What does ld actually do with R_PPC_REL32 to get the proper results? I am new ld and binutils, and I am having a hard time finding the answer in the source.

Can help me understand this?

thanks,
David Dunkle 

--
Sent from the Gnu - Binutils - Users forum at Nabble.com:
http://www.nabble.com/how-does-ld-interpret-ELF-R_PPC_REL32--t422151.html#a1157038


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