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: PR ld/4504: Copy relocation doesn't preserve section alignment


On Tue, May 15, 2007 at 03:41:40PM +0930, Alan Modra wrote:
> On Mon, May 14, 2007 at 05:49:54PM -0700, H. J. Lu wrote:
> 
> I like the way you have consolidated this code, but do we really want
> to waste space in .dynbss like this?  I'm thinking of cases where an
> executable might need many variable in .dynbss, most of which do not
> need large alignment.  Hmm, one way you could cut down on the wasted
> space is to look at low bits of the symbol address in the shared lib.
> 

This is the patch I checked in.


H.J.
----
2007-05-15  H.J. Lu  <hongjiu.lu@intel.com>
	    Alan Modra  <amodra@bigpond.net.au>

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

	* elf-m10300.c (_bfd_mn10300_elf_adjust_dynamic_symbol): Call
	_bfd_elf_adjust_dynamic_copy to adjust for the copy in 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-15 06:15:43.000000000 -0700
+++ bfd/elf-bfd.h	2007-05-15 06:15:43.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_copy
+  (struct elf_link_hash_entry *, asection *);
+
 extern bfd_boolean _bfd_elf_link_sec_merge_syms
   (struct elf_link_hash_entry *, void *);
 
--- bfd/elf-m10300.c.dynbss	2007-04-26 22:54:03.000000000 -0700
+++ bfd/elf-m10300.c	2007-05-15 06:15:43.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,28 +4235,7 @@ _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;
-    }
-
-  /* Define the symbol as being at this point in the section.  */
-  h->root.u.def.section = s;
-  h->root.u.def.value = s->size;
-
-  /* Increment the section size to make room for the symbol.  */
-  s->size += h->size;
-
-  return TRUE;
+  return _bfd_elf_adjust_dynamic_copy (h, s);
 }
 
 /* Set the sizes of the dynamic sections.  */
--- bfd/elf32-arm.c.dynbss	2007-05-15 06:12:22.000000000 -0700
+++ bfd/elf32-arm.c	2007-05-15 06:15:43.000000000 -0700
@@ -8377,7 +8377,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;
 
@@ -8490,28 +8489,7 @@ 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;
-    }
-
-  /* Define the symbol as being at this point in the section.  */
-  h->root.u.def.section = s;
-  h->root.u.def.value = s->size;
-
-  /* Increment the section size to make room for the symbol.  */
-  s->size += h->size;
-
-  return TRUE;
+  return _bfd_elf_adjust_dynamic_copy (h, s);
 }
 
 /* Allocate space in .plt, .got and associated reloc sections for
--- bfd/elf32-cris.c.dynbss	2007-04-26 22:54:04.000000000 -0700
+++ bfd/elf32-cris.c	2007-05-15 06:15:43.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,31 +2428,7 @@ 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;
-    }
-
-  /* Define the symbol as being at this point in the section.  */
-  h->root.u.def.section = s;
-  h->root.u.def.value = s->size;
-
-  /* Increment the section size to make room for the symbol.  */
-  s->size += h->size;
-
-  return TRUE;
+  return _bfd_elf_adjust_dynamic_copy (h, s);
 }
 
 /* Look through the relocs for a section during the first phase.  */
--- bfd/elf32-hppa.c.dynbss	2007-04-26 22:54:04.000000000 -0700
+++ bfd/elf32-hppa.c	2007-05-15 06:15: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,30 +1928,9 @@ 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;
-    }
-
-  /* Define the symbol as being at this point in the section.  */
-  eh->root.u.def.section = sec;
-  eh->root.u.def.value = sec->size;
 
-  /* Increment the section size to make room for the symbol.  */
-  sec->size += eh->size;
-
-  return TRUE;
+  return _bfd_elf_adjust_dynamic_copy (eh, sec);
 }
 
 /* Allocate space in the .plt for entries that won't have relocations.
--- bfd/elf32-i370.c.dynbss	2007-04-26 22:54:04.000000000 -0700
+++ bfd/elf32-i370.c	2007-05-15 06:15:43.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,28 +545,7 @@ 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;
-    }
-
-  /* Define the symbol as being at this point in the section.  */
-  h->root.u.def.section = s;
-  h->root.u.def.value = s->size;
-
-  /* Increment the section size to make room for the symbol.  */
-  s->size += h->size;
-
-  return TRUE;
+  return _bfd_elf_adjust_dynamic_copy (h, s);
 }
 
 /* Increment the index of a dynamic symbol by a given amount.  Called
--- bfd/elf32-i386.c.dynbss	2007-05-15 06:15:43.000000000 -0700
+++ bfd/elf32-i386.c	2007-05-15 06:15:43.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,28 +1559,7 @@ 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;
-    }
-
-  /* Define the symbol as being at this point in the section.  */
-  h->root.u.def.section = s;
-  h->root.u.def.value = s->size;
-
-  /* Increment the section size to make room for the symbol.  */
-  s->size += h->size;
-
-  return TRUE;
+  return _bfd_elf_adjust_dynamic_copy (h, s);
 }
 
 /* Allocate space in .plt, .got and associated reloc sections for
--- bfd/elf32-m32r.c.dynbss	2007-04-26 22:54:05.000000000 -0700
+++ bfd/elf32-m32r.c	2007-05-15 06:15:43.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,28 +1960,7 @@ 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;
-    }
-
-  /* Define the symbol as being at this point in the section.  */
-  h->root.u.def.section = s;
-  h->root.u.def.value = s->size;
-
-  /* Increment the section size to make room for the symbol.  */
-  s->size += h->size;
-
-  return TRUE;
+  return _bfd_elf_adjust_dynamic_copy (h, s);
 }
 
 /* Allocate space in .plt, .got and associated reloc sections for
--- bfd/elf32-m68k.c.dynbss	2007-04-26 22:54:05.000000000 -0700
+++ bfd/elf32-m68k.c	2007-05-15 06:15:43.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,28 +1359,7 @@ 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;
-    }
-
-  /* Define the symbol as being at this point in the section.  */
-  h->root.u.def.section = s;
-  h->root.u.def.value = s->size;
-
-  /* Increment the section size to make room for the symbol.  */
-  s->size += h->size;
-
-  return TRUE;
+  return _bfd_elf_adjust_dynamic_copy (h, s);
 }
 
 /* Set the sizes of the dynamic sections.  */
--- bfd/elf32-ppc.c.dynbss	2007-05-11 06:44:13.000000000 -0700
+++ bfd/elf32-ppc.c	2007-05-15 06:15:43.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,28 +4277,7 @@ 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;
-    }
-
-  /* Define the symbol as being at this point in the section.  */
-  h->root.u.def.section = s;
-  h->root.u.def.value = s->size;
-
-  /* Increment the section size to make room for the symbol.  */
-  s->size += h->size;
-
-  return TRUE;
+  return _bfd_elf_adjust_dynamic_copy (h, s);
 }
 
 /* Generate a symbol to mark plt call stubs.  For non-PIC code the sym is
--- bfd/elf32-s390.c.dynbss	2007-04-26 22:54:05.000000000 -0700
+++ bfd/elf32-s390.c	2007-05-15 06:15:43.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,29 +1702,9 @@ 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;
-    }
 
-  /* Define the symbol as being at this point in the section.  */
-  h->root.u.def.section = s;
-  h->root.u.def.value = s->size;
-
-  /* Increment the section size to make room for the symbol.  */
-  s->size += h->size;
-
-  return TRUE;
+  return _bfd_elf_adjust_dynamic_copy (h, s);
 }
 
 /* Allocate space in .plt, .got and associated reloc sections for
--- bfd/elf32-sh.c.dynbss	2007-04-26 22:54:06.000000000 -0700
+++ bfd/elf32-sh.c	2007-05-15 06:15:43.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,28 +2612,7 @@ 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;
-    }
-
-  /* Define the symbol as being at this point in the section.  */
-  h->root.u.def.section = s;
-  h->root.u.def.value = s->size;
-
-  /* Increment the section size to make room for the symbol.  */
-  s->size += h->size;
-
-  return TRUE;
+  return _bfd_elf_adjust_dynamic_copy (h, s);
 }
 
 /* Allocate space in .plt, .got and associated reloc sections for
--- bfd/elf32-vax.c.dynbss	2007-04-26 22:54:06.000000000 -0700
+++ bfd/elf32-vax.c	2007-05-15 06:15:43.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,28 +1078,7 @@ 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;
-    }
-
-  /* Define the symbol as being at this point in the section.  */
-  h->root.u.def.section = s;
-  h->root.u.def.value = s->size;
-
-  /* Increment the section size to make room for the symbol.  */
-  s->size += h->size;
-
-  return TRUE;
+  return _bfd_elf_adjust_dynamic_copy (h, s);
 }
 
 /* Set the sizes of the dynamic sections.  */
--- bfd/elf64-ppc.c.dynbss	2007-05-10 08:30:08.000000000 -0700
+++ bfd/elf64-ppc.c	2007-05-15 06:15:43.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,29 +5919,9 @@ 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;
-    }
 
-  /* Define the symbol as being at this point in the section.  */
-  h->root.u.def.section = s;
-  h->root.u.def.value = s->size;
-
-  /* Increment the section size to make room for the symbol.  */
-  s->size += h->size;
-
-  return TRUE;
+  return _bfd_elf_adjust_dynamic_copy (h, s);
 }
 
 /* If given a function descriptor symbol, hide both the function code
--- bfd/elf64-s390.c.dynbss	2007-04-26 22:54:07.000000000 -0700
+++ bfd/elf64-s390.c	2007-05-15 06:15:43.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,29 +1677,9 @@ 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;
-    }
 
-  /* Define the symbol as being at this point in the section.  */
-  h->root.u.def.section = s;
-  h->root.u.def.value = s->size;
-
-  /* Increment the section size to make room for the symbol.  */
-  s->size += h->size;
-
-  return TRUE;
+  return _bfd_elf_adjust_dynamic_copy (h, s);
 }
 
 /* Allocate space in .plt, .got and associated reloc sections for
--- bfd/elf64-sh64.c.dynbss	2007-04-26 22:54:07.000000000 -0700
+++ bfd/elf64-sh64.c	2007-05-15 06:15:43.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,28 +3463,7 @@ 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;
-    }
-
-  /* Define the symbol as being at this point in the section.  */
-  h->root.u.def.section = s;
-  h->root.u.def.value = s->size;
-
-  /* Increment the section size to make room for the symbol.  */
-  s->size += h->size;
-
-  return TRUE;
+  return _bfd_elf_adjust_dynamic_copy (h, s);
 }
 
 /* This function is called via sh_elf_link_hash_traverse if we are
--- bfd/elf64-x86-64.c.dynbss	2007-05-15 06:15:43.000000000 -0700
+++ bfd/elf64-x86-64.c	2007-05-15 06:15:43.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,31 +1425,7 @@ 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;
-    }
-
-  /* Define the symbol as being at this point in the section.  */
-  h->root.u.def.section = s;
-  h->root.u.def.value = s->size;
-
-  /* Increment the section size to make room for the symbol.  */
-  s->size += h->size;
-
-  return TRUE;
+  return _bfd_elf_adjust_dynamic_copy (h, s);
 }
 
 /* Allocate space in .plt, .got and associated reloc sections for
--- bfd/elflink.c.dynbss	2007-05-15 06:15:43.000000000 -0700
+++ bfd/elflink.c	2007-05-15 06:34:46.000000000 -0700
@@ -2649,6 +2649,52 @@ _bfd_elf_adjust_dynamic_symbol (struct e
   return TRUE;
 }
 
+/* Adjust the dynamic symbol, H, for copy in the dynamic bss section,
+   DYNBSS.  */
+
+bfd_boolean
+_bfd_elf_adjust_dynamic_copy (struct elf_link_hash_entry *h,
+			      asection *dynbss)
+{
+  unsigned int power_of_two, orig_power_of_two;
+  bfd_vma mask;
+  asection *sec = h->root.u.def.section;
+
+  /* The section aligment of definition is the maximum alignment
+     requirement of symbols defined in the section.  */
+  power_of_two = bfd_get_section_alignment (dynbss->owner, dynbss);
+  orig_power_of_two = bfd_get_section_alignment (sec->owner, sec);
+
+  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;
+    }
+
+  /* We make sure that the symbol will be aligned properly.  Since we
+     don't know its alignment requirement, we start with the maximum
+     alignment and check low bits of the symbol address for the
+     minimum alignment.  */
+  mask = ((bfd_vma) 1 << orig_power_of_two) - 1;
+  while ((h->root.u.def.value & mask) != 0)
+    {
+       mask >>= 1;
+       --orig_power_of_two;
+    }
+  dynbss->size = BFD_ALIGN (dynbss->size, mask + 1);
+
+  /* Define the symbol as being at this point in DYNBSS.  */
+  h->root.u.def.section = dynbss;
+  h->root.u.def.value = dynbss->size;
+
+  /* Increment the size of DYNBSS to make room for the symbol.  */
+  dynbss->size += h->size;
+
+  return TRUE;
+}
+
 /* Adjust all external symbols pointing into SEC_MERGE sections
    to reflect the object merging within the sections.  */
 
--- bfd/elfxx-mips.c.dynbss	2007-05-15 06:12:22.000000000 -0700
+++ bfd/elfxx-mips.c	2007-05-15 06:15:44.000000000 -0700
@@ -7018,7 +7018,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;
@@ -7141,26 +7140,7 @@ _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))
-    return FALSE;
-
-  /* Define the symbol as being at this point in the section.  */
-  h->root.u.def.section = htab->sdynbss;
-  h->root.u.def.value = htab->sdynbss->size;
-
-  /* Increment the section size to make room for the symbol.  */
-  htab->sdynbss->size += h->size;
-
-  return TRUE;
+  return _bfd_elf_adjust_dynamic_copy (h, htab->sdynbss);
 }
 
 /* Return the number of dynamic section symbols required by OUTPUT_BFD.
--- bfd/elfxx-sparc.c.dynbss	2007-04-26 22:54:08.000000000 -0700
+++ bfd/elfxx-sparc.c	2007-05-15 06:15:44.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,29 +1817,9 @@ _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;
-    }
 
-  /* Define the symbol as being at this point in the section.  */
-  h->root.u.def.section = s;
-  h->root.u.def.value = s->size;
-
-  /* Increment the section size to make room for the symbol.  */
-  s->size += h->size;
-
-  return TRUE;
+  return _bfd_elf_adjust_dynamic_copy (h, s);
 }
 
 /* Allocate space in .plt, .got and associated reloc sections for


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