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,
    At last I could finally read the relocations and sort them. But still
have one problem and some doubts.

This is what I am doing in _bfd_mips_elf_final_link().

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

        dynobj1 = elf_hash_table (info)->dynobj;

        reldyn = bfd_get_section_by_name (dynobj1,
                                MIPS_ELF_REL_DYN_SECTION_NAME(dynobj1));

        if (reldyn !=NULL)
          {
            Elf_Internal_Rela **dynamic_relocs = NULL;
            unsigned int i;
            unsigned long my_symndx; /* Just for testing */

             /* Still need to make a check for return from bfd_malloc() */
            dynamic_relocs = (Elf_Internal_Rela**)
                        bfd_malloc (reldyn->reloc_count *
                                sizeof(Elf_Internal_Rela*));

            /* Read the relocs from the memory */
              for (i=0; i< reldyn->reloc_count; i++)
                {
                  dynamic_relocs[i]= (Elf_Internal_Rela *)
                        (reldyn->contents+(MIPS_ELF_REL_SIZE(dynobj1)*i));
                 }
                 dynamic_relocs[i] = NULL;

                /* Perform the sort */
                qsort(dynamic_relocs,(size_t) reldyn->reloc_count,
                        sizeof (dynamic_relocs[0]),sort_dynamic_relocations);

            }


Below is the sorting function.

/* Sort the dynamic relocations based on the symbol index. This is called
   via qsort() */

static int
sort_dynamic_relocations (arg1, arg2)
    const void *arg1;
    const void *arg2;
{
  const Elf_Internal_Rela **rela1 = (const Elf_Internal_Rela**) arg1;
  const Elf_Internal_Rela **rela2 = (const Elf_Internal_Rela**) arg2;

  if (ELF32_R_SYM((*rela1)->r_info) < ELF32_R_SYM((*rela2)->r_info))
     return -1;
  else if (ELF32_R_SYM((*rela1)->r_info) > ELF32_R_SYM((*rela2)->r_info))
     return 1;
  else
     return 0;

}


After this I checked that the sorting was happening without any problem (
I printed the table and checked the result ) .

Does the above code look O.K ?. In particular is the reading of the relocs
O.K ?

Now how do I reflect the change in the "contents" field of the .rel.dyn
section ??

  should I call the bfd_elf32_swap_reloc_out() ?. I tried a few other things
like memcpy() ing et all., which did not quite work ?. I am now stuck with
this problem.


Please suggest.

Thanks !

koundinya






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