This is the mail archive of the binutils@sources.redhat.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]
Other format: [Raw text]

Re: Bug in >64k-section ELF handling when linking (with -r)


On Sat, Nov 02, 2002 at 06:55:13AM +0100, Hans-Peter Nilsson wrote:
> not hold valid data.  Note the sh_offset field.  With $ holding
> elf_tdata(finfo->output_bfd)->symtab_shndx_hdr for the code at
> 5994:
> 
> (gdb) p *$
> $103 = {sh_name = 1838678, sh_type = 0, sh_flags = 0, sh_addr = 0,
> sh_size = 0, sh_entsize = 0, sh_link = 69182, sh_info = 0, 
> sh_offset = -1, sh_addralign = 0, bfd_section = 0x0, contents = 0x0}

Oh dear.  elf_bfd_final_link sets up symtab_hdr but not
symtab_shndx_hdr.  I guess I never tested >64k section support with
ld -r.  Would you mind running your test case with the following
patch applied?  If it passes, please commit the patch for me.

	* elflink.h (elf_bfd_final_link): Initialize symtab_shndx_hdr.
	Don't bother zeroing symtab_hdr fields.

Index: bfd/elflink.h
===================================================================
RCS file: /cvs/src/src/bfd/elflink.h,v
retrieving revision 1.192
diff -u -p -r1.192 elflink.h
--- bfd/elflink.h	22 Oct 2002 21:00:10 -0000	1.192
+++ bfd/elflink.h	2 Nov 2002 12:34:31 -0000
@@ -4919,6 +4919,7 @@ elf_bfd_final_link (abfd, info)
   Elf_Internal_Sym elfsym;
   unsigned int i;
   Elf_Internal_Shdr *symtab_hdr;
+  Elf_Internal_Shdr *symtab_shndx_hdr;
   Elf_Internal_Shdr *symstrtab_hdr;
   struct elf_backend_data *bed = get_elf_backend_data (abfd);
   struct elf_outext_info eoinfo;
@@ -5192,9 +5193,7 @@ elf_bfd_final_link (abfd, info)
   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   /* sh_name is set in prep_headers.  */
   symtab_hdr->sh_type = SHT_SYMTAB;
-  symtab_hdr->sh_flags = 0;
-  symtab_hdr->sh_addr = 0;
-  symtab_hdr->sh_size = 0;
+  /* sh_flags, sh_addr and sh_size all start off zero.  */
   symtab_hdr->sh_entsize = sizeof (Elf_External_Sym);
   /* sh_link is set in assign_section_numbers.  */
   /* sh_info is set below.  */
@@ -5204,6 +5203,16 @@ elf_bfd_final_link (abfd, info)
   off = elf_tdata (abfd)->next_file_pos;
   off = _bfd_elf_assign_file_position_for_section (symtab_hdr, off, true);
 
+  symtab_shndx_hdr = &elf_tdata (abfd)->symtab_shndx_hdr;
+  if (symtab_shndx_hdr->sh_name != 0)
+    {
+      symtab_shndx_hdr->sh_type = SHT_SYMTAB_SHNDX;
+      symtab_shndx_hdr->sh_entsize = sizeof (Elf_External_Sym_Shndx);
+      symtab_shndx_hdr->sh_addralign = sizeof (Elf_External_Sym_Shndx);
+      off = _bfd_elf_assign_file_position_for_section (symtab_shndx_hdr,
+						       off, true);
+    }
+
   /* Note that at this point elf_tdata (abfd)->next_file_pos is
      incorrect.  We do not yet know the size of the .symtab section.
      We correct next_file_pos below, after we do know the size.  */

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


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