This is the mail archive of the binutils@sourceware.cygnus.com 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]

Re: sorting dynamic relocation entries.


Hi Ian,
    Though things are happening as required in _bfd_mips_elf_final_link(), the final
shared lib generated still does not have the relocation records sorted. I am doing as per
the pointers you provided. I am just working on the test case that I described
y'day...where I have just 3 dynamic relocs. I am attaching the code and the output from
the debugging statements that I have introduced.

What is surprising to me is that, after swapping in , sorting ,  swapping out and then
even when I swap in again to read the relocs (for testing) , things appear to work just
O.k i,e the relocs are sorted.

I wonder if something is happening after returning from _bfd_mips_final_link() ?.

What could be the problem ?

Please suggest.

Thanks a lot !!

koundinya


boolean
_bfd_mips_elf_final_link (abfd, info)
     bfd *abfd;
     struct bfd_link_info *info;
{
...............................................
...............................................

  /* The entries in the dynamic relocation section must be ordered by 
     increasing r_symndx value */

    if (info->shared) 
      { 
        asection *reldyn;
        bfd *dynobj1;

        dynobj1 = elf_hash_table (info)->dynobj;

        fprintf(stderr,"Filename1=\t%s\n",bfd_get_filename(abfd));
        reldyn = bfd_get_section_by_name (dynobj1,
                                MIPS_ELF_REL_DYN_SECTION_NAME(dynobj1));
		
	if (reldyn !=NULL)
          {
		unsigned int dyn_reloc_cont;
                unsigned int j;
  		Elf_Internal_Rel outrel[4],temprel[4];

		dyn_reloc_cont = reldyn->reloc_count;

		fprintf(stderr,"\nAfter Swapping in........................\n");
                for(j=0; j<dyn_reloc_cont; j++)
		{
  		bfd_elf32_swap_reloc_in(abfd,
		   (((Elf32_External_Rel *) reldyn->contents)+j),&outrel[j]);
		fprintf(stderr,"OFF=\t0x%lx\t INF=\t0x%lx\n",outrel[j].r_offset,outrel[j].r_info);
		}

                fprintf(stderr,"Calling qsort().........................\n");
		qsort (&outrel,(size_t) dyn_reloc_cont,sizeof(Elf_Internal_Rel),
				new_sort_dynamic_relocs);
                fprintf(stderr,"Completed qsort().........................\n");

		fprintf(stderr,"\nAfter Sorting and before Swapping out........................\n");

		/* Has no impact. But I am just keeping it */
		memset(reldyn->contents,0,dyn_reloc_cont*MIPS_ELF_REL_SIZE (dynobj1));
		for(j=0; j<dyn_reloc_cont; j++)
                {
		fprintf(stderr,"OFF=\t0x%lx\t INF=\t0x%lx\n",outrel[j].r_offset,outrel[j].r_info);
                bfd_elf32_swap_reloc_out(abfd,&outrel[j],
			(((Elf32_External_Rel *) reldyn->contents)+j));
		}
		/* Swap in again and read */

		fprintf(stderr,"\n Swapping in Again.....................\n");
                for(j=0; j<dyn_reloc_cont; j++)
		{
  		bfd_elf32_swap_reloc_in(abfd,
		   (((Elf32_External_Rel *) reldyn->contents)+j),&temprel[j]);
		fprintf(stderr,"OFF=\t0x%lx\t INF=\t0x%lx\n",temprel[j].r_offset,temprel[j].r_info);
		}
	  }
      } 

  return true;
}

static int
new_sort_dynamic_relocs (arg1,arg2)
	const PTR arg1;
	const PTR arg2;
{
  const Elf_Internal_Rel *reloc1 = (const Elf_Internal_Rel *) arg1;
  const Elf_Internal_Rel *reloc2 = (const Elf_Internal_Rel *) arg2;

  fprintf(stderr,"RELOC1 OFF=\t%lx\t INF=\t%lx\n",reloc1->r_offset,reloc1->r_info);
  fprintf(stderr,"RELOC2 OFF=\t%lx\t INF=\t%lx\n",reloc2->r_offset,reloc2->r_info);

  if (ELF32_R_SYM(reloc1->r_info) <  ELF32_R_SYM(reloc2->r_info))
	return -1;
  else if (ELF32_R_SYM(reloc1->r_info) >  ELF32_R_SYM(reloc2->r_info))
        return 1;
  else
	return 0;	
}

-----------------------------------------------------------------------

Filename1=	libruf.so

After Swapping in........................
OFF=	0x0	 INF=	0x0
OFF=	0x40710	 INF=	0x2503
OFF=	0x40720	 INF=	0x2403

Calling qsort().........................
RELOC1 OFF=	0	 INF=	0
RELOC2 OFF=	40710	 INF=	2503
RELOC1 OFF=	0	 INF=	0
RELOC2 OFF=	40720	 INF=	2403
RELOC1 OFF=	0	 INF=	0
RELOC2 OFF=	40710	 INF=	2503
RELOC1 OFF=	40710	 INF=	2503
RELOC2 OFF=	40720	 INF=	2403
RELOC1 OFF=	0	 INF=	0
RELOC2 OFF=	40720	 INF=	2403
Completed qsort().........................

After Sorting and before Swapping out........................
OFF=	0x0	 INF=	0x0
OFF=	0x40720	 INF=	0x2403
OFF=	0x40710	 INF=	0x2503

 Swapping in Again.....................
OFF=	0x0	 INF=	0x0
OFF=	0x40720	 INF=	0x2403
OFF=	0x40710	 INF=	0x2503

___________________________________________________________________________

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