This is the mail archive of the binutils@sourceware.org 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: PATCH: ld/2411: ELF linker fails to create executable with more than 64k sections


On Fri, Mar 03, 2006 at 09:15:53AM -0800, H. J. Lu wrote:
> On Fri, Mar 03, 2006 at 02:43:51PM +1030, Alan Modra wrote:
> > On Thu, Mar 02, 2006 at 03:21:25PM -0800, H. J. Lu wrote:
> > > The ELF gABI doesn't support more than 64k sections in DSO and
> > > executable when there are dynamic symbols. This patch checks that.
> > 
> > I think you should put this check in bfd_elf_final_link rather than in
> > map_sections_to_segments, before the first call to
> > elf_link_output_extsym.  That puts it close to the code that outputs
> > dynamic section syms.
> > 
> > > +	(_("%B: Too many sections: %d (< %d)"),
> > > +	 abfd, bfd_count_sections (abfd), SHN_LORESERVE);
> > 
> > Typo.
> > 
> 
> Here is the updated patch.
> 
> 

It is OK to have dynamic symbols with 64K sections, which is one of
the old testcases, as long as the dynamic symbols aren't in the
sections beyond 64K. This patch checks section index for each dynamic
symbol to make sure it is supported.


H.J.
----
2006-03-03  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/2411
	* elflink.c (check_dynsym): New.
	(elf_link_output_extsym): Use it.
	(bfd_elf_final_link): Likewise.

--- bfd/elflink.c.64k	2006-03-02 14:16:50.000000000 -0800
+++ bfd/elflink.c	2006-03-03 10:58:55.000000000 -0800
@@ -6199,6 +6199,24 @@ elf_link_output_sym (struct elf_final_li
   return TRUE;
 }
 
+/* Return TRUE if the dynamic symbol SYM in ABFD is supported.  */
+
+static bfd_boolean
+check_dynsym (bfd *abfd, Elf_Internal_Sym *sym)
+{
+  if (sym->st_shndx > SHN_HIRESERVE)
+    {
+      /* The gABI doesn't support dynamic symbols in output sections
+         beyond 64k.  */
+      (*_bfd_error_handler)
+	(_("%B: Too many sections: %d (>= %d)"),
+	 abfd, bfd_count_sections (abfd), SHN_LORESERVE);
+      bfd_set_error (bfd_error_nonrepresentable_section);
+      return FALSE;
+    }
+  return TRUE;
+}
+
 /* For DSOs loaded in via a DT_NEEDED entry, emulate ld.so in
    allowing an unsatisfied unversioned symbol in the DSO to match a
    versioned symbol that would normally require an explicit version.
@@ -6631,6 +6649,11 @@ elf_link_output_extsym (struct elf_link_
 
       sym.st_name = h->dynstr_index;
       esym = finfo->dynsym_sec->contents + h->dynindx * bed->s->sizeof_sym;
+      if (! check_dynsym (finfo->output_bfd, &sym))
+	{
+	  eoinfo->failed = TRUE;
+	  return FALSE;
+	}
       bed->s->swap_symbol_out (finfo->output_bfd, &sym, esym, 0);
 
       bucketcount = elf_hash_table (finfo->info)->bucketcount;
@@ -8313,6 +8336,8 @@ bfd_elf_final_link (bfd *abfd, struct bf
 		continue;
 	      indx = elf_section_data (s)->this_idx;
 	      BFD_ASSERT (indx > 0);
+	      if (! check_dynsym (abfd, &sym))
+		return FALSE;
 	      sym.st_shndx = indx;
 	      sym.st_value = s->vma;
 	      dest = dynsym + dynindx * bed->s->sizeof_sym;
@@ -8348,6 +8373,8 @@ bfd_elf_final_link (bfd *abfd, struct bf
 
 		  sym.st_shndx =
 		    elf_section_data (s->output_section)->this_idx;
+		  if (! check_dynsym (abfd, &sym))
+		    return FALSE;
 		  sym.st_value = (s->output_section->vma
 				  + s->output_offset
 				  + e->isym.st_value);


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