[Cbe-oss-dev] [PATCH] libspe2: revert my last patch

Alan Modra amodra at bigpond.net.au
Mon May 26 17:03:38 EST 2008


This patch reverts most of my last change to apply_relocations.  Daft
of me, but I somehow overlooked the fact that overlays are loaded by
the overlay manager from the image rather than libspe's ld_buffer.
Thus any relocations in overlays must be applied to the image.  We
could apply some relocs to ld_buffer but it is simpler to just apply
them all to the image.

Signed-off-by: Alan Modra <amodra at bigpond.net.au>

diff -urp libspe2-2.2.80.old/spebase/elf_loader.c libspe2-2.2.80/spebase/elf_loader.c
--- libspe2-2.2.80.old/spebase/elf_loader.c	2008-05-26 11:29:25.000000000 +0930
+++ libspe2-2.2.80/spebase/elf_loader.c	2008-05-26 11:29:49.000000000 +0930
@@ -201,26 +201,17 @@ copy_to_ld_buffer(spe_program_handle_t *
    without a symbol, which are to locations within ._ea.  */
 
 static void
-apply_relocations (spe_program_handle_t *handle,
-		   void *buf,
-		   Elf32_Shdr *rh,
-		   Elf32_Shdr *sh,
-		   Elf32_Shdr *eah)
+apply_relocations(spe_program_handle_t *handle, Elf32_Shdr *rh, Elf32_Shdr *sh)
 {
 #define R_SPU_PPU32 15
 #define R_SPU_PPU64 16
 	void *start = handle->elf_image;
 	Elf32_Rela *r, *r_end;
-	void *reloc_base = buf;
-
-	if (sh == eah)
-	{
-		/* Relocations in an executable specify r_offset as a
-		   virtual address, but if we are applying relocs for
-		   ._ea then the location we want is in the image.
-		   Adjust so as to poke relative to the image base.  */
-		reloc_base = start + sh->sh_offset - sh->sh_addr;
-	}
+	/* Relocations in an executable specify r_offset as a virtual
+	   address, but we are applying the reloc in the image before
+	   the section has been copied to its destination sh_addr.
+	   Adjust so as to poke relative to the image base.  */
+	void *reloc_base = start + sh->sh_offset - sh->sh_addr;
 
 	r = start + rh->sh_offset;
 	r_end = (void *)r + rh->sh_size;
@@ -255,7 +246,6 @@ _base_spe_load_spe_elf (spe_program_hand
 
 	Elf32_Shdr *shdr;
 	Elf32_Shdr *sh;
-	Elf32_Shdr *eah;
 
 	Elf32_Off  toe_addr = 0;
 	long	toe_size = 0;
@@ -284,18 +274,17 @@ _base_spe_load_spe_elf (spe_program_hand
 
 	/* traverse the sections to locate the toe segment */
 	/* by specification, the toe sections are grouped together in a segment */
-	eah = 0;
 	for (sh = shdr; sh < &shdr[ehdr->e_shnum]; ++sh)
 	{
 		DEBUG_PRINTF("section name: %s ( start: 0x%04x, size: 0x%04x)\n", str_table+sh->sh_name, sh->sh_offset, sh->sh_size );
+		if (sh->sh_type == SHT_RELA)
+			apply_relocations(handle, sh, &shdr[sh->sh_info]);
 		if (strcmp(".toe", str_table+sh->sh_name) == 0) {
 			DEBUG_PRINTF("section offset: %d\n", sh->sh_offset);
 			toe_size += sh->sh_size;
 			if ((toe_addr == 0) || (toe_addr > sh->sh_addr))
 				toe_addr = sh->sh_addr;
 		}
-		else if (strcmp("._ea", str_table+sh->sh_name) == 0)
-			eah = sh;
 		/* Disabled : Actually not needed, only good for testing
 		if (strcmp(".bss", str_table+sh->sh_name) == 0) {
 			DEBUG_PRINTF("zeroing .bss section:\n");
@@ -341,12 +330,6 @@ _base_spe_load_spe_elf (spe_program_hand
 		  return -errno;
 	  }
 
-	if (eah)
-		for (sh = shdr; sh < &shdr[ehdr->e_shnum]; ++sh)
-			if (sh->sh_type == SHT_RELA)
-				apply_relocations (handle, ld_buffer,
-						   sh, &shdr[sh->sh_info], eah);
-
 	/* Remember where the code wants to be started */
 	ld_info->entry = ehdr->e_entry;
 	DEBUG_PRINTF ("entry = 0x%x\n", ehdr->e_entry);

-- 
Alan Modra
Australia Development Lab, IBM



More information about the cbe-oss-dev mailing list