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..Done !!


Hi Ian,
    Finally I could get the relocs sorted !!. There have been no side affects from this and
relocs are just intact.

Here is the diff that I am attaching. Please have a look into this and make any necessary
suggestions

Thanks !!

koundinya




*** /tmp/elf32-mips.c	Wed Mar 15 16:45:39 2000
--- elf32-mips.c	Wed Mar 15 16:02:17 2000
*************** static void mips_elf_allocate_dynamic_re
*** 193,198 ****
--- 193,205 ----
  static boolean mips_elf_stub_section_p 
    PARAMS ((bfd *, asection *));
  
+ static int sort_dynamic_relocs 
+   PARAMS ((const void *, const void *));
+ 
+ /* This will be used when we sort the dynamic relocation records */
+ static bfd *temp_bfd;
+ 
  /* The level of IRIX compatibility we're striving for.  */
  
--- 5048,5087 ----
  	    return false;
  	}
      }
    return true;
  }
  
+ /* This function is called via qsort() to sort the dynamic relocation
+    entries by increasing r_symndx value */
+
+ static int
+ sort_dynamic_relocs (arg1,arg2)
+ 	const PTR arg1;
+ 	const PTR arg2;
+ {
+   const Elf32_External_Rel *ext_reloc1 = (const Elf32_External_Rel *) arg1;
+   const Elf32_External_Rel *ext_reloc2 = (const Elf32_External_Rel *) arg2;
+ 
+   Elf_Internal_Rel int_reloc1; 
+   Elf_Internal_Rel int_reloc2; 
+ 
+   unsigned long r_symndx1;
+   unsigned long r_symndx2;
+ 
+   bfd_elf32_swap_reloc_in(temp_bfd,ext_reloc1,&int_reloc1);
+   bfd_elf32_swap_reloc_in(temp_bfd,ext_reloc2,&int_reloc2);
+ 
+   r_symndx1 = ELF32_R_SYM(int_reloc1.r_info);
+   r_symndx2 = ELF32_R_SYM(int_reloc2.r_info);
+  
+   if (r_symndx1 < r_symndx2)
+ 	return -1;
+   else if (r_symndx1 > r_symndx2)
+         return 1;
+   else
+ 	return 0;	
+ }
+   
  /* Returns the GOT section for ABFD.  */
  
*************** _bfd_mips_elf_finish_dynamic_sections (o
*** 8558,8563 ****
--- 8733,8757 ----
          }
        }

+     /* We need to sort the entries of the dynamic relocation section */
+
+     if (!ABI_64_P (output_bfd))
+       {
+         if (info->shared)
+           {
+             asection *reldyn;
+
+             reldyn = bfd_get_section_by_name (dynobj,
+                                      MIPS_ELF_REL_DYN_SECTION_NAME (dynobj));
+             if (reldyn != NULL && reldyn->reloc_count > 1)
+               {
+                 temp_bfd = output_bfd;
+                 qsort (reldyn->contents, (size_t) reldyn->reloc_count,
+                        sizeof (Elf32_External_Rel), sort_dynamic_relocs);
+               }
+           }
+       }
+
      /* Clean up a first relocation in .rel.dyn.  */
      s = bfd_get_section_by_name (dynobj,
                                 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj));


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