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,
    I am doing this. What could possibly be wrong ??, when I expect it to work.

This is the call to qsort().

qsort((Elf32_External_Rel **)reldyn->contents,
                reldyn->reloc_count, sizeof(Elf32_External_Rel),
                        sort_dynamic_relocations);

and here is the comparison 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 Elf32_External_Rel **rel1 = (const Elf32_External_Rel**) arg1;
  const Elf32_External_Rel **rel2 = (const Elf32_External_Rel**) arg2;

  bfd_vma rel1_rinfo = (unsigned long) rel1[1];
  bfd_vma rel2_rinfo = (unsigned long) rel2[1];

  if (ELF32_R_SYM(rel1_rinfo) < ELF32_R_SYM(rel2_rinfo))
    return -1;
  else if (ELF32_R_SYM(rel1_rinfo) > ELF32_R_SYM(rel2_rinfo))
    return 1;
  else
    return 0;
}


I tested and found that right symbol indices were being returned in the
comparison function. But still the dynamic relocations are not sorted ?.  Where
could things be wrong ??. Is there is any generic elf code that is trying to
sort based on offset or something after _final_link() returns ?? Or is there
anything else that I am still failing to do ??

Please suggest.

Thanks a lot.

koundinya




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