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: bfd_make_section


Hi,

Alan Modra <amodra@bigpond.net.au> wrote:
> On Fri, Jul 04, 2003 at 01:42:56PM +0930, Alan Modra wrote:
>> This fix will almost certainly expose errors in some ports, as I found
>> with ppc32 trying to create .rela.got twice.  If you see new ld
> 
> 	* elf32-sparc.c (elf32_sparc_check_relocs): Don't call
> 	create_got_section if we already have done so.
> 	* elf32-sh.c (sh_elf_create_dynamic_sections): Likewise.
> 	(sh_elf_check_relocs): Likewise.
> 	(sh_elf_adjust_dynamic_symbol): Delete "dynobj" var.  Use
> 	htab->root.dynobj instead.
> 	(sh_elf_check_relocs): Likewise.
> 	(sh_elf_finish_dynamic_sections): Likewise.

I've found that similar problems cause 2 new regressions on ld test and
glibc build failure on sh4-unknown-linux-gnu. With the attached patch,
these failures went away. I'd like to check it in soon.

Regards,
	kaz
--
2003-07-04  Kaz Kojima  <kkojima@rr.iij4u.or.jp>

	* elf32-sh.c (sh_elf_create_dynamic_sections): Don't call
	bfd_make_section for existing sections.

diff -u3prN ORIG/src/bfd/elf32-sh.c LOCAL/src/bfd/elf32-sh.c
--- ORIG/src/bfd/elf32-sh.c	Fri Jul  4 14:27:21 2003
+++ LOCAL/src/bfd/elf32-sh.c	Fri Jul  4 14:30:14 2003
@@ -3768,12 +3768,16 @@ sh_elf_create_dynamic_sections (abfd, in
   if (bed->plt_readonly)
     pltflags |= SEC_READONLY;
 
-  s = bfd_make_section (abfd, ".plt");
-  htab->splt = s;
-  if (s == NULL
-      || ! bfd_set_section_flags (abfd, s, pltflags)
-      || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
-    return FALSE;
+  s = htab->splt;
+  if (s == NULL)
+    {
+      s = bfd_make_section (abfd, ".plt");
+      htab->splt = s;
+      if (s == NULL
+	  || ! bfd_set_section_flags (abfd, s, pltflags)
+	  || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
+	return FALSE;
+    }
 
   if (bed->want_plt_sym)
     {
@@ -3797,13 +3801,17 @@ sh_elf_create_dynamic_sections (abfd, in
 	return FALSE;
     }
 
-  s = bfd_make_section (abfd,
-			bed->default_use_rela_p ? ".rela.plt" : ".rel.plt");
-  htab->srelplt = s;
-  if (s == NULL
-      || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
-      || ! bfd_set_section_alignment (abfd, s, ptralign))
-    return FALSE;
+  if (htab->srelplt == NULL)
+    {
+      s = bfd_make_section (abfd,
+			    (bed->default_use_rela_p ?
+			     ".rela.plt" : ".rel.plt"));
+      htab->srelplt = s;
+      if (s == NULL
+	  || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
+	  || ! bfd_set_section_alignment (abfd, s, ptralign))
+	return FALSE;
+    }
 
   if (htab->sgot == NULL
       && !create_got_section (abfd, info))
@@ -3825,6 +3833,8 @@ sh_elf_create_dynamic_sections (abfd, in
 	relname = (char *) bfd_malloc ((bfd_size_type) strlen (secname) + 6);
 	strcpy (relname, ".rela");
 	strcat (relname, secname);
+	if (bfd_get_section_by_name (abfd, secname))
+	  continue;
 	s = bfd_make_section (abfd, relname);
 	if (s == NULL
 	    || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
@@ -3841,11 +3851,14 @@ sh_elf_create_dynamic_sections (abfd, in
 	 image and use a R_*_COPY reloc to tell the dynamic linker to
 	 initialize them at run time.  The linker script puts the .dynbss
 	 section into the .bss section of the final image.  */
-      s = bfd_make_section (abfd, ".dynbss");
-      htab->sdynbss = s;
-      if (s == NULL
-	  || ! bfd_set_section_flags (abfd, s, SEC_ALLOC))
-	return FALSE;
+      if (htab->sdynbss == NULL)
+	{
+	  s = bfd_make_section (abfd, ".dynbss");
+	  htab->sdynbss = s;
+	  if (s == NULL
+	      || ! bfd_set_section_flags (abfd, s, SEC_ALLOC))
+	    return FALSE;
+	}
 
       /* The .rel[a].bss section holds copy relocs.  This section is not
 	 normally needed.  We need to create it here, though, so that the
@@ -3858,7 +3871,7 @@ sh_elf_create_dynamic_sections (abfd, in
 	 be needed, we can discard it later.  We will never need this
 	 section when generating a shared object, since they do not use
 	 copy relocs.  */
-      if (! info->shared)
+      if (! info->shared && htab->srelbss == NULL)
 	{
 	  s = bfd_make_section (abfd,
 				(bed->default_use_rela_p


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