[PATCH,SPU] Add new relocation, R_SPU_ADD_PIC
Trevor_Smigiel@playstation.sony.com
Trevor_Smigiel@playstation.sony.com
Thu Jul 16 22:35:00 GMT 2009
Forgot the patch, here it is.
Trevor
* Trevor Smigiel <Trevor_Smigiel@playstation.sony.com> [2009-07-16 15:04]:
> Hi,
>
> When generating position independent code for Cell SPU, we generate the
> following instruction sequence to compute the address of "symbol":
>
> # Compute the base PIC offset
> ila $2,.+8
> brsl $3,.+4
> sf $126,$2,$3
>
> # Add base PIC offset to absolute symbol address
> ila $5,symbol
> a $5,$5,$126
>
> When "symbol" is weak and undefined, we want a final value of 0, but the
> above sequence would generate the base PIC offset.
>
> Also, if DLL's were supported on SPU, we could not simply patch
> relocations at run time and get the correct result. The DLL loader
> could try subtracting the base PIC offset from symbols when patching,
> but would sometimes end up with a negative number which can not be
> loaded by 1 instruction (that would replace the ila).
>
> To address both of these issues, we mark the "a" instruction with a
> relocation to indicate that it is adding the base PIC offset to "symbol.
>
> # Add base PIC offset to absolute symbol address
> ila $5,symbol
> .reloc .,SPU_ADD_PIC,symbol
> a $5,$5,$126
>
> When the linker see the SPU_ADD_PIC relocation, it checks if "symbol" is
> weak and undefined, or will be dynamically resolved. If yes, it will
> change the "a" instruction so it becomes a copy instruction. Thus, the
> value computed in the 'ila' instruction will be correct. For example,
> change the above "a" to:
>
> ai $5,$5,0 # Add immediate 0
>
> For this to work the ABI must also specify that it is the third register
> in the 'a' instruction that contains the base PIC offset.
>
> Currently, binutils does nothing to address these issues. It just
> generates incorrect values.
>
> I used an old patch from Alan Modra which had a similar relocation
> called SPU_PIC as a reference and modified his test cases to suit this
> new relocation.
>
> The attached patch has been tested on SPU and x86 with no new failures.
>
> Ok?
>
> Trevor
>
> 2009-07-10 Trevor Smigiel <Trevor_Smigiel@playstation.sony.com>
> Alan Modra <amodra@bigpond.net.au>
>
> include/elf/
> * spu.h (R_SPU_ADD_PIC): New.
> bfd/
> * reloc.c (BFD_RELOC_SPU_ADD_PIC): Define.
> * bfd-in2.h: Regenerate.
> * libbfd.h: Regenerate.
> * elf32-spu.c (elf_howto_table): Add entries SPU_ADD_PIC.
> (spu_elf_bfd_to_reloc_type): Handle SPU_ADD_PIC.
> (spu_elf_relocate_section): Patch instructions marked by SPU_ADD_PIC.
> gas/
> * config/tc-spu.c (md_apply_fix): Handle SPU_ADD_PIC.
> * config/tc-spu.h (tc_fix_adjustable): Don't adjust for SPU_ADD_PIC.
> (TC_FORCE_RELOCATION): Emit relocs for SPU_ADD_PIC.
> ld/testsuite/
> * ld-spu/pic.d: New.
> * ld-spu/pic.s: New.
> * ld-spu/picdef.s: New.
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SPU_ADD_PIC.patch
Type: text/x-diff
Size: 8861 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20090716/dc733a7a/attachment.bin>
More information about the Binutils
mailing list