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]

PATCH: PR ld/4504: Copy relocation doesn't preserve section alignment


This patch fixes the longstanding ELF linker bug by applying
the maximum alignment to all symbols needing copy relocation.  We
can get the maximum alignment from the section alignment where
they are defined.


H.J.
----
2007-05-14  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/4504
	* elf-bfd.h (_bfd_elf_adjust_dynamic_bss): New.
	* elf.c (_bfd_elf_adjust_dynamic_bss): New.

	* elf-m10300.c (_bfd_mn10300_elf_adjust_dynamic_symbol): Call
	_bfd_elf_adjust_dynamic_bss to adjust alignment and size of
	dynamic bss section.
	* elf32-arm.c (elf32_arm_adjust_dynamic_symbol): Likewise.
	* elf32-cris.c (elf_cris_adjust_dynamic_symbol): Likewise.
	* elf32-hppa.c (elf32_hppa_adjust_dynamic_symbol): Likewise.
	* elf32-i370.c (i370_elf_adjust_dynamic_symbol): Likewise.
	* elf32-i386.c (elf_i386_adjust_dynamic_symbol): Likewise.
	* elf32-m32r.c (m32r_elf_adjust_dynamic_symbol): Likewise.
	* elf32-m68k.c (elf_m68k_adjust_dynamic_symbol): Likewise.
	* elf32-ppc.c (ppc_elf_adjust_dynamic_symbol): Likewise.
	* elf32-s390.c (elf_s390_adjust_dynamic_symbol): Likewise.
	* elf32-sh.c (sh_elf_adjust_dynamic_symbol): Likewise.
	* elf32-vax.c (elf_vax_adjust_dynamic_symbol): Likewise.
	* elf64-ppc.c (ppc64_elf_adjust_dynamic_symbol): Likewise.
	* elf64-s390.c (elf_s390_adjust_dynamic_symbol): Likewise.
	* elf64-sh64.c (sh64_elf64_adjust_dynamic_symbol): Likewise.
	* elf64-x86-64.c (elf64_x86_64_adjust_dynamic_symbol): Likewise.
	* elfxx-mips.c (_bfd_mips_vxworks_adjust_dynamic_symbol): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_adjust_dynamic_symbol): Likewise.

--- bfd/elf-bfd.h.dynbss	2007-05-14 09:01:48.000000000 -0700
+++ bfd/elf-bfd.h	2007-05-14 11:31:32.000000000 -0700
@@ -1740,6 +1740,9 @@ extern bfd_boolean _bfd_elf_fix_symbol_f
 extern bfd_boolean _bfd_elf_adjust_dynamic_symbol
   (struct elf_link_hash_entry *, void *);
 
+extern bfd_boolean _bfd_elf_adjust_dynamic_bss
+  (asection *, asection *);
+
 extern bfd_boolean _bfd_elf_link_sec_merge_syms
   (struct elf_link_hash_entry *, void *);
 
--- bfd/elf-m10300.c.dynbss	2007-05-14 09:01:48.000000000 -0700
+++ bfd/elf-m10300.c	2007-05-14 11:42:35.000000000 -0700
@@ -4096,7 +4096,6 @@ _bfd_mn10300_elf_adjust_dynamic_symbol (
 {
   bfd * dynobj;
   asection * s;
-  unsigned int power_of_two;
 
   dynobj = elf_hash_table (info)->dynobj;
 
@@ -4236,19 +4235,8 @@ _bfd_mn10300_elf_adjust_dynamic_symbol (
       h->needs_copy = 1;
     }
 
-  /* We need to figure out the alignment required for this symbol.  I
-     have no idea how ELF linkers handle this.  */
-  power_of_two = bfd_log2 (h->size);
-  if (power_of_two > 3)
-    power_of_two = 3;
-
-  /* Apply the required alignment.  */
-  s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
-  if (power_of_two > bfd_get_section_alignment (dynobj, s))
-    {
-      if (! bfd_set_section_alignment (dynobj, s, power_of_two))
-	return FALSE;
-    }
+  if (! _bfd_elf_adjust_dynamic_bss (s, h->root.u.def.section))
+    return FALSE;
 
   /* Define the symbol as being at this point in the section.  */
   h->root.u.def.section = s;
--- bfd/elf.c.dynbss	2007-05-14 09:01:48.000000000 -0700
+++ bfd/elf.c	2007-05-14 12:50:29.000000000 -0700
@@ -9376,6 +9376,36 @@ _bfd_elf_set_osabi (bfd * abfd,
   i_ehdrp->e_ident[EI_OSABI] = get_elf_backend_data (abfd)->elf_osabi;
 }
 
+/* Adjust size and alignment of the dynamic bss section, DYNBSS,
+   based on the original section, S.  */
+
+bfd_boolean
+_bfd_elf_adjust_dynamic_bss (asection *dynbss, asection *s)
+{
+  unsigned int power_of_two, orig_power_of_two;
+
+  /* The original aligment of section S is the maximum alignment
+     requirement of symbols defined in the section.  Since we don't
+     know the alignment requirement of individual symbols, we apply
+     the maximum alignment to all symbols needing copy relocation.  */
+  power_of_two = bfd_get_section_alignment (dynbss->owner, dynbss);
+  orig_power_of_two = bfd_get_section_alignment (s->owner, s);
+
+  if (orig_power_of_two > power_of_two)
+    {
+      /* Adjust the section alignment if needed.  */
+      if (! bfd_set_section_alignment (dynbss->owner, dynbss,
+				       orig_power_of_two))
+	return FALSE;
+      power_of_two = orig_power_of_two;
+    }
+
+  /* We make sure that the symbol will be aligned properly.  */
+  dynbss->size = BFD_ALIGN (dynbss->size,
+			    (bfd_size_type) (1 << power_of_two));
+
+  return TRUE;
+}
 
 /* Return TRUE for ELF symbol types that represent functions.
    This is the default version of this function, which is sufficient for
--- bfd/elf32-arm.c.dynbss	2007-05-14 09:01:48.000000000 -0700
+++ bfd/elf32-arm.c	2007-05-14 11:35:18.000000000 -0700
@@ -8387,7 +8387,6 @@ elf32_arm_adjust_dynamic_symbol (struct 
 {
   bfd * dynobj;
   asection * s;
-  unsigned int power_of_two;
   struct elf32_arm_link_hash_entry * eh;
   struct elf32_arm_link_hash_table *globals;
 
@@ -8500,19 +8499,8 @@ elf32_arm_adjust_dynamic_symbol (struct 
       h->needs_copy = 1;
     }
 
-  /* We need to figure out the alignment required for this symbol.  I
-     have no idea how ELF linkers handle this.  */
-  power_of_two = bfd_log2 (h->size);
-  if (power_of_two > 3)
-    power_of_two = 3;
-
-  /* Apply the required alignment.  */
-  s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
-  if (power_of_two > bfd_get_section_alignment (dynobj, s))
-    {
-      if (! bfd_set_section_alignment (dynobj, s, power_of_two))
-	return FALSE;
-    }
+  if (! _bfd_elf_adjust_dynamic_bss (s, h->root.u.def.section))
+    return FALSE;
 
   /* Define the symbol as being at this point in the section.  */
   h->root.u.def.section = s;
--- bfd/elf32-cris.c.dynbss	2007-05-14 09:01:48.000000000 -0700
+++ bfd/elf32-cris.c	2007-05-14 11:36:28.000000000 -0700
@@ -2221,7 +2221,6 @@ elf_cris_adjust_dynamic_symbol (info, h)
 {
   bfd *dynobj;
   asection *s;
-  unsigned int power_of_two;
   bfd_size_type plt_entry_size;
 
   dynobj = elf_hash_table (info)->dynobj;
@@ -2429,22 +2428,8 @@ elf_cris_adjust_dynamic_symbol (info, h)
       h->needs_copy = 1;
     }
 
-  /* Historic precedent: m68k and i386 allow max 8-byte alignment for the
-     thing to copy; so do we.  */
-
-  /* We need to figure out the alignment required for this symbol.  I
-     have no idea how ELF linkers handle this.  */
-  power_of_two = bfd_log2 (h->size);
-  if (power_of_two > 3)
-    power_of_two = 3;
-
-  /* Apply the required alignment.  */
-  s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
-  if (power_of_two > bfd_get_section_alignment (dynobj, s))
-    {
-      if (!bfd_set_section_alignment (dynobj, s, power_of_two))
-	return FALSE;
-    }
+  if (! _bfd_elf_adjust_dynamic_bss (s, h->root.u.def.section))
+    return FALSE;
 
   /* Define the symbol as being at this point in the section.  */
   h->root.u.def.section = s;
--- bfd/elf32-hppa.c.dynbss	2007-05-14 09:01:48.000000000 -0700
+++ bfd/elf32-hppa.c	2007-05-14 11:54:43.000000000 -0700
@@ -1819,7 +1819,6 @@ elf32_hppa_adjust_dynamic_symbol (struct
 {
   struct elf32_hppa_link_hash_table *htab;
   asection *sec;
-  unsigned int power_of_two;
 
   /* If this is a function, put it in the procedure linkage table.  We
      will fill in the contents of the procedure linkage table later.  */
@@ -1929,21 +1928,10 @@ elf32_hppa_adjust_dynamic_symbol (struct
       eh->needs_copy = 1;
     }
 
-  /* We need to figure out the alignment required for this symbol.  I
-     have no idea how other ELF linkers handle this.  */
-
-  power_of_two = bfd_log2 (eh->size);
-  if (power_of_two > 3)
-    power_of_two = 3;
-
-  /* Apply the required alignment.  */
   sec = htab->sdynbss;
-  sec->size = BFD_ALIGN (sec->size, (bfd_size_type) (1 << power_of_two));
-  if (power_of_two > bfd_get_section_alignment (htab->etab.dynobj, sec))
-    {
-      if (! bfd_set_section_alignment (htab->etab.dynobj, sec, power_of_two))
-	return FALSE;
-    }
+
+  if (! _bfd_elf_adjust_dynamic_bss (sec, eh->root.u.def.section))
+    return FALSE;
 
   /* Define the symbol as being at this point in the section.  */
   eh->root.u.def.section = sec;
--- bfd/elf32-i370.c.dynbss	2007-04-26 08:57:30.000000000 -0700
+++ bfd/elf32-i370.c	2007-05-14 11:37:25.000000000 -0700
@@ -461,7 +461,6 @@ i370_elf_adjust_dynamic_symbol (struct b
 {
   bfd *dynobj = elf_hash_table (info)->dynobj;
   asection *s;
-  unsigned int power_of_two;
 
 #ifdef DEBUG
   fprintf (stderr, "i370_elf_adjust_dynamic_symbol called for %s\n",
@@ -546,19 +545,8 @@ i370_elf_adjust_dynamic_symbol (struct b
       h->needs_copy = 1;
     }
 
-  /* We need to figure out the alignment required for this symbol.  I
-     have no idea how ELF linkers handle this.  */
-  power_of_two = bfd_log2 (h->size);
-  if (power_of_two > 4)
-    power_of_two = 4;
-
-  /* Apply the required alignment.  */
-  s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
-  if (power_of_two > bfd_get_section_alignment (dynobj, s))
-    {
-      if (! bfd_set_section_alignment (dynobj, s, power_of_two))
-	return FALSE;
-    }
+  if (! _bfd_elf_adjust_dynamic_bss (s, h->root.u.def.section))
+    return FALSE;
 
   /* Define the symbol as being at this point in the section.  */
   h->root.u.def.section = s;
--- bfd/elf32-i386.c.dynbss	2007-05-14 09:01:48.000000000 -0700
+++ bfd/elf32-i386.c	2007-05-14 11:33:06.000000000 -0700
@@ -1432,7 +1432,6 @@ elf_i386_adjust_dynamic_symbol (struct b
 {
   struct elf_i386_link_hash_table *htab;
   asection *s;
-  unsigned int power_of_two;
 
   /* If this is a function, put it in the procedure linkage table.  We
      will fill in the contents of the procedure linkage table later,
@@ -1560,19 +1559,8 @@ elf_i386_adjust_dynamic_symbol (struct b
       h->needs_copy = 1;
     }
 
-  /* We need to figure out the alignment required for this symbol.  I
-     have no idea how ELF linkers handle this.  */
-  power_of_two = bfd_log2 (h->size);
-  if (power_of_two > 3)
-    power_of_two = 3;
-
-  /* Apply the required alignment.  */
-  s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
-  if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
-    {
-      if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
-	return FALSE;
-    }
+  if (! _bfd_elf_adjust_dynamic_bss (s, h->root.u.def.section))
+    return FALSE;
 
   /* Define the symbol as being at this point in the section.  */
   h->root.u.def.section = s;
--- bfd/elf32-m32r.c.dynbss	2007-04-26 08:57:30.000000000 -0700
+++ bfd/elf32-m32r.c	2007-05-14 11:37:58.000000000 -0700
@@ -1833,7 +1833,6 @@ m32r_elf_adjust_dynamic_symbol (struct b
   struct elf_m32r_dyn_relocs *p;
   bfd *dynobj;
   asection *s;
-  unsigned int power_of_two;
 
 #ifdef DEBUG_PIC
   printf ("m32r_elf_adjust_dynamic_symbol()\n");
@@ -1961,19 +1960,8 @@ m32r_elf_adjust_dynamic_symbol (struct b
       h->needs_copy = 1;
     }
 
-  /* We need to figure out the alignment required for this symbol.  I
-     have no idea how ELF linkers handle this.  */
-  power_of_two = bfd_log2 (h->size);
-  if (power_of_two > 3)
-    power_of_two = 3;
-
-  /* Apply the required alignment.  */
-  s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
-  if (power_of_two > bfd_get_section_alignment (dynobj, s))
-    {
-      if (! bfd_set_section_alignment (dynobj, s, power_of_two))
-        return FALSE;
-    }
+  if (! _bfd_elf_adjust_dynamic_bss (s, h->root.u.def.section))
+    return FALSE;
 
   /* Define the symbol as being at this point in the section.  */
   h->root.u.def.section = s;
--- bfd/elf32-m68k.c.dynbss	2007-05-14 09:01:48.000000000 -0700
+++ bfd/elf32-m68k.c	2007-05-14 11:38:26.000000000 -0700
@@ -1215,7 +1215,6 @@ elf_m68k_adjust_dynamic_symbol (info, h)
   struct elf_m68k_link_hash_table *htab;
   bfd *dynobj;
   asection *s;
-  unsigned int power_of_two;
 
   htab = elf_m68k_hash_table (info);
   dynobj = elf_hash_table (info)->dynobj;
@@ -1360,19 +1359,8 @@ elf_m68k_adjust_dynamic_symbol (info, h)
       h->needs_copy = 1;
     }
 
-  /* We need to figure out the alignment required for this symbol.  I
-     have no idea how ELF linkers handle this.  */
-  power_of_two = bfd_log2 (h->size);
-  if (power_of_two > 3)
-    power_of_two = 3;
-
-  /* Apply the required alignment.  */
-  s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
-  if (power_of_two > bfd_get_section_alignment (dynobj, s))
-    {
-      if (!bfd_set_section_alignment (dynobj, s, power_of_two))
-	return FALSE;
-    }
+  if (! _bfd_elf_adjust_dynamic_bss (s, h->root.u.def.section))
+    return FALSE;
 
   /* Define the symbol as being at this point in the section.  */
   h->root.u.def.section = s;
--- bfd/elf32-ppc.c.dynbss	2007-05-14 09:01:48.000000000 -0700
+++ bfd/elf32-ppc.c	2007-05-14 11:38:58.000000000 -0700
@@ -4136,7 +4136,6 @@ ppc_elf_adjust_dynamic_symbol (struct bf
 {
   struct ppc_elf_link_hash_table *htab;
   asection *s;
-  unsigned int power_of_two;
 
 #ifdef DEBUG
   fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called for %s\n",
@@ -4278,19 +4277,8 @@ ppc_elf_adjust_dynamic_symbol (struct bf
       h->needs_copy = 1;
     }
 
-  /* We need to figure out the alignment required for this symbol.  I
-     have no idea how ELF linkers handle this.  */
-  power_of_two = bfd_log2 (h->size);
-  if (power_of_two > 4)
-    power_of_two = 4;
-
-  /* Apply the required alignment.  */
-  s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
-  if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
-    {
-      if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
-	return FALSE;
-    }
+  if (! _bfd_elf_adjust_dynamic_bss (s, h->root.u.def.section))
+    return FALSE;
 
   /* Define the symbol as being at this point in the section.  */
   h->root.u.def.section = s;
--- bfd/elf32-s390.c.dynbss	2007-05-14 09:01:48.000000000 -0700
+++ bfd/elf32-s390.c	2007-05-14 11:47:51.000000000 -0700
@@ -1582,7 +1582,6 @@ elf_s390_adjust_dynamic_symbol (info, h)
 {
   struct elf_s390_link_hash_table *htab;
   asection *s;
-  unsigned int power_of_two;
 
   /* If this is a function, put it in the procedure linkage table.  We
      will fill in the contents of the procedure linkage table later
@@ -1703,20 +1702,10 @@ elf_s390_adjust_dynamic_symbol (info, h)
       h->needs_copy = 1;
     }
 
-  /* We need to figure out the alignment required for this symbol.  I
-     have no idea how ELF linkers handle this.  */
-  power_of_two = bfd_log2 (h->size);
-  if (power_of_two > 3)
-    power_of_two = 3;
-
-  /* Apply the required alignment.  */
   s = htab->sdynbss;
-  s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
-  if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
-    {
-      if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
-	return FALSE;
-    }
+
+  if (! _bfd_elf_adjust_dynamic_bss (s, h->root.u.def.section))
+    return FALSE;
 
   /* Define the symbol as being at this point in the section.  */
   h->root.u.def.section = s;
--- bfd/elf32-sh.c.dynbss	2007-04-26 08:57:31.000000000 -0700
+++ bfd/elf32-sh.c	2007-05-14 11:40:03.000000000 -0700
@@ -2489,7 +2489,6 @@ sh_elf_adjust_dynamic_symbol (struct bfd
   struct elf_sh_link_hash_entry *eh;
   struct elf_sh_dyn_relocs *p;
   asection *s;
-  unsigned int power_of_two;
 
   htab = sh_elf_hash_table (info);
 
@@ -2613,19 +2612,8 @@ sh_elf_adjust_dynamic_symbol (struct bfd
       h->needs_copy = 1;
     }
 
-  /* We need to figure out the alignment required for this symbol.  I
-     have no idea how ELF linkers handle this.  */
-  power_of_two = bfd_log2 (h->size);
-  if (power_of_two > 3)
-    power_of_two = 3;
-
-  /* Apply the required alignment.  */
-  s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
-  if (power_of_two > bfd_get_section_alignment (htab->root.dynobj, s))
-    {
-      if (! bfd_set_section_alignment (htab->root.dynobj, s, power_of_two))
-	return FALSE;
-    }
+  if (! _bfd_elf_adjust_dynamic_bss (s, h->root.u.def.section))
+    return FALSE;
 
   /* Define the symbol as being at this point in the section.  */
   h->root.u.def.section = s;
--- bfd/elf32-vax.c.dynbss	2007-05-14 09:01:48.000000000 -0700
+++ bfd/elf32-vax.c	2007-05-14 11:40:28.000000000 -0700
@@ -925,7 +925,6 @@ elf_vax_adjust_dynamic_symbol (info, h)
 {
   bfd *dynobj;
   asection *s;
-  unsigned int power_of_two;
 
   dynobj = elf_hash_table (info)->dynobj;
 
@@ -1079,19 +1078,8 @@ elf_vax_adjust_dynamic_symbol (info, h)
       h->needs_copy = 1;
     }
 
-  /* We need to figure out the alignment required for this symbol.  I
-     have no idea how ELF linkers handle this.  */
-  power_of_two = bfd_log2 (h->size);
-  if (power_of_two > 3)
-    power_of_two = 3;
-
-  /* Apply the required alignment.  */
-  s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
-  if (power_of_two > bfd_get_section_alignment (dynobj, s))
-    {
-      if (!bfd_set_section_alignment (dynobj, s, power_of_two))
-	return FALSE;
-    }
+  if (! _bfd_elf_adjust_dynamic_bss (s, h->root.u.def.section))
+    return FALSE;
 
   /* Define the symbol as being at this point in the section.  */
   h->root.u.def.section = s;
--- bfd/elf64-ppc.c.dynbss	2007-05-14 09:01:48.000000000 -0700
+++ bfd/elf64-ppc.c	2007-05-14 11:49:31.000000000 -0700
@@ -5799,7 +5799,6 @@ ppc64_elf_adjust_dynamic_symbol (struct 
 {
   struct ppc_link_hash_table *htab;
   asection *s;
-  unsigned int power_of_two;
 
   htab = ppc_hash_table (info);
 
@@ -5920,20 +5919,10 @@ ppc64_elf_adjust_dynamic_symbol (struct 
       h->needs_copy = 1;
     }
 
-  /* We need to figure out the alignment required for this symbol.  I
-     have no idea how ELF linkers handle this.  */
-  power_of_two = bfd_log2 (h->size);
-  if (power_of_two > 4)
-    power_of_two = 4;
-
-  /* Apply the required alignment.  */
   s = htab->dynbss;
-  s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
-  if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
-    {
-      if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
-	return FALSE;
-    }
+
+  if (! _bfd_elf_adjust_dynamic_bss (s, h->root.u.def.section))
+    return FALSE;
 
   /* Define the symbol as being at this point in the section.  */
   h->root.u.def.section = s;
--- bfd/elf64-s390.c.dynbss	2007-05-14 09:01:48.000000000 -0700
+++ bfd/elf64-s390.c	2007-05-14 11:49:55.000000000 -0700
@@ -1557,7 +1557,6 @@ elf_s390_adjust_dynamic_symbol (info, h)
 {
   struct elf_s390_link_hash_table *htab;
   asection *s;
-  unsigned int power_of_two;
 
   /* If this is a function, put it in the procedure linkage table.  We
      will fill in the contents of the procedure linkage table later
@@ -1678,20 +1677,10 @@ elf_s390_adjust_dynamic_symbol (info, h)
       h->needs_copy = 1;
     }
 
-  /* We need to figure out the alignment required for this symbol.  I
-     have no idea how ELF linkers handle this.  */
-  power_of_two = bfd_log2 (h->size);
-  if (power_of_two > 3)
-    power_of_two = 3;
-
-  /* Apply the required alignment.  */
   s = htab->sdynbss;
-  s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
-  if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
-    {
-      if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
-	return FALSE;
-    }
+
+  if (! _bfd_elf_adjust_dynamic_bss (s, h->root.u.def.section))
+    return FALSE;
 
   /* Define the symbol as being at this point in the section.  */
   h->root.u.def.section = s;
--- bfd/elf64-sh64.c.dynbss	2007-04-26 08:57:32.000000000 -0700
+++ bfd/elf64-sh64.c	2007-05-14 11:42:03.000000000 -0700
@@ -3324,7 +3324,6 @@ sh64_elf64_adjust_dynamic_symbol (struct
 {
   bfd *dynobj;
   asection *s;
-  unsigned int power_of_two;
 
   dynobj = elf_hash_table (info)->dynobj;
 
@@ -3464,19 +3463,8 @@ sh64_elf64_adjust_dynamic_symbol (struct
       h->needs_copy = 1;
     }
 
-  /* We need to figure out the alignment required for this symbol.  I
-     have no idea how ELF linkers handle this.  */
-  power_of_two = bfd_log2 (h->size);
-  if (power_of_two > 3)
-    power_of_two = 3;
-
-  /* Apply the required alignment.  */
-  s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
-  if (power_of_two > bfd_get_section_alignment (dynobj, s))
-    {
-      if (! bfd_set_section_alignment (dynobj, s, power_of_two))
-	return FALSE;
-    }
+  if (! _bfd_elf_adjust_dynamic_bss (s, h->root.u.def.section))
+    return FALSE;
 
   /* Define the symbol as being at this point in the section.  */
   h->root.u.def.section = s;
--- bfd/elf64-x86-64.c.dynbss	2007-05-14 09:01:48.000000000 -0700
+++ bfd/elf64-x86-64.c	2007-05-14 12:35:53.000000000 -0700
@@ -1300,7 +1300,6 @@ elf64_x86_64_adjust_dynamic_symbol (stru
 {
   struct elf64_x86_64_link_hash_table *htab;
   asection *s;
-  unsigned int power_of_two;
 
   /* If this is a function, put it in the procedure linkage table.  We
      will fill in the contents of the procedure linkage table later,
@@ -1426,22 +1425,8 @@ elf64_x86_64_adjust_dynamic_symbol (stru
       h->needs_copy = 1;
     }
 
-  /* We need to figure out the alignment required for this symbol.  I
-     have no idea how ELF linkers handle this.	16-bytes is the size
-     of the largest type that requires hard alignment -- long double.  */
-  /* FIXME: This is VERY ugly. Should be fixed for all architectures using
-     this construct.  */
-  power_of_two = bfd_log2 (h->size);
-  if (power_of_two > 4)
-    power_of_two = 4;
-
-  /* Apply the required alignment.  */
-  s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
-  if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
-    {
-      if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
-	return FALSE;
-    }
+  if (! _bfd_elf_adjust_dynamic_bss (s, h->root.u.def.section))
+    return FALSE;
 
   /* Define the symbol as being at this point in the section.  */
   h->root.u.def.section = s;
--- bfd/elfxx-mips.c.dynbss	2007-04-29 18:13:55.000000000 -0700
+++ bfd/elfxx-mips.c	2007-05-14 12:02:51.000000000 -0700
@@ -7045,7 +7045,6 @@ _bfd_mips_vxworks_adjust_dynamic_symbol 
   bfd *dynobj;
   struct mips_elf_link_hash_entry *hmips;
   struct mips_elf_link_hash_table *htab;
-  unsigned int power_of_two;
 
   htab = mips_elf_hash_table (info);
   dynobj = elf_hash_table (info)->dynobj;
@@ -7168,16 +7167,8 @@ _bfd_mips_vxworks_adjust_dynamic_symbol 
       h->needs_copy = 1;
     }
 
-  /* We need to figure out the alignment required for this symbol.  */
-  power_of_two = bfd_log2 (h->size);
-  if (power_of_two > 4)
-    power_of_two = 4;
-
-  /* Apply the required alignment.  */
-  htab->sdynbss->size = BFD_ALIGN (htab->sdynbss->size,
-				   (bfd_size_type) 1 << power_of_two);
-  if (power_of_two > bfd_get_section_alignment (dynobj, htab->sdynbss)
-      && !bfd_set_section_alignment (dynobj, htab->sdynbss, power_of_two))
+  if (! _bfd_elf_adjust_dynamic_bss (htab->sdynbss,
+				     h->root.u.def.section))
     return FALSE;
 
   /* Define the symbol as being at this point in the section.  */
--- bfd/elfxx-sparc.c.dynbss	2007-05-14 09:01:48.000000000 -0700
+++ bfd/elfxx-sparc.c	2007-05-14 11:44:20.000000000 -0700
@@ -1701,7 +1701,6 @@ _bfd_sparc_elf_adjust_dynamic_symbol (st
   struct _bfd_sparc_elf_link_hash_entry * eh;
   struct _bfd_sparc_elf_dyn_relocs *p;
   asection *s;
-  unsigned int power_of_two;
 
   htab = _bfd_sparc_elf_hash_table (info);
 
@@ -1818,20 +1817,10 @@ _bfd_sparc_elf_adjust_dynamic_symbol (st
       h->needs_copy = 1;
     }
 
-  /* We need to figure out the alignment required for this symbol.  I
-     have no idea how ELF linkers handle this.  */
-  power_of_two = bfd_log2 (h->size);
-  if (power_of_two > htab->align_power_max)
-    power_of_two = htab->align_power_max;
-
-  /* Apply the required alignment.  */
   s = htab->sdynbss;
-  s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
-  if (power_of_two > bfd_get_section_alignment (dynobj, s))
-    {
-      if (! bfd_set_section_alignment (dynobj, s, power_of_two))
-	return FALSE;
-    }
+
+  if (! _bfd_elf_adjust_dynamic_bss (s, h->root.u.def.section))
+    return FALSE;
 
   /* Define the symbol as being at this point in the section.  */
   h->root.u.def.section = s;


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