bfd elflink.h patch

Andrew Macleod amacleod@cygnus.com
Mon Feb 25 11:36:00 GMT 2002


This patch is causing me a little problem on sparc64-linux:

revision 1.134
date: 2001/12/17 00:52:34;  author: amodra;  state: Exp;  lines: +289 -86
        Support for more than 64k ELF sections.
...
	* elflink.h (elf_link_is_defined_archive_symbol): Read symbol shndx
        extension, and use with elf_swap_symbol_in.
        (elf_link_record_local_dynamic_symbol): Likewise.
        (elf_link_add_object_symbols): Likewise.  Also translate st_shndx
        for elf sections > SHN_HIRESERVE.
        (NAME(bfd_elf,size_dynamic_sections)): Adjust elf_swap_symbol_out
        call.
        (struct elf_final_link_info): Add locsym_shndx and symshndxbuf.
        (elf_bfd_final_link): Allocate the above, and tidy code allocating
        other buffers.  Use elf_numsections instead of e_shnum.  Adjust
        elf_swap_symbol_out calls.
        (elf_link_output_sym): Swap out symbol shndx extension too.
        (elf_link_flush_output_syms): And flush them to disk.
        (elf_link_output_extsym): Use SHN_BAD.  Adjust elf_swap_symbol_out
        calls.
        (elf_gc_mark): Read symbol shndx extension, and use with
        elf_swap_symbol_in.
        (elf_link_input_bfd): Likewise,  Translate st_shndx for elf sections
        > SHN_HIRESERVE too.  Use SHN_BAD.
        (elf_reloc_symbol_deleted_p): Use symbol shndx extensions with
        elf_swap_symbol_in.  Translate st_shndx > SHN_HIRESERVE too.
        (elf_bfd_discard_info): Read symbol shndx extension.  Don't attempt
        to continue after a bfd error.


*************** elf_bfd_final_link (abfd, info)
*** 5268,5274 ****
                   the original st_name with the dynstr_index.  */
                sym = e->isym;

!             if (e->isym.st_shndx > 0 && e->isym.st_shndx < SHN_LORESERVE)
                {
                  s = bfd_section_from_elf_index (e->input_bfd,
                                                  e->isym.st_shndx);
--- 5384,5391 ----
                   the original st_name with the dynstr_index.  */
                sym = e->isym;

!             if (e->isym.st_shndx < SHN_LORESERVE
!                 || e->isym.st_shndx > SHN_HIRESERVE)
                {
                  s = bfd_section_from_elf_index (e->input_bfd,
                                                  e->isym.st_shndx);

bfd_final_link() is segfaulting on virtually everything I try to link 
immediately after the line:

s = bfd_section_from_elf_index (e->input_bfd, e->isym.st_shndx);

because it tries to dereference s. Index 0 is the output object, so it
comes back with a NULL section from the input bfd.  Before this
patch, the code skipped index 0, but after the patch, it no longer
does this. If I change it back to checking for 0 as well, my problem
goes away. Was this an oversight, or is there something else wrong?

The following patch fixes it for me:

Andrew

	* elflink.h  (elf_bfd_final_link): Dont look for input from section 0.

Index: elflink.h
===================================================================
RCS file: /cvs/cvsfiles/devo/bfd/elflink.h,v
retrieving revision 1.186
diff -c -p -r1.186 elflink.h
*** elflink.h	2002/01/21 00:18:31	1.186
--- elflink.h	2002/02/12 18:30:01
*************** elf_bfd_final_link (abfd, info)
*** 5390,5397 ****
                   the original st_name with the dynstr_index.  */
                sym = e->isym;
  
! 	      if (e->isym.st_shndx < SHN_LORESERVE
! 		  || e->isym.st_shndx > SHN_HIRESERVE)
  		{
  		  s = bfd_section_from_elf_index (e->input_bfd,
  						  e->isym.st_shndx);
--- 5390,5397 ----
                   the original st_name with the dynstr_index.  */
                sym = e->isym;
  
! 	      if (e->isym.st_shndx > 0 && (e->isym.st_shndx < SHN_LORESERVE
! 					   || e->isym.st_shndx > SHN_HIRESERVE))
  		{
  		  s = bfd_section_from_elf_index (e->input_bfd,
  						  e->isym.st_shndx);



More information about the Binutils mailing list