PATCH: PR ld/4504: Copy relocation doesn't preserve section alignment
H. J. Lu
hjl@lucon.org
Mon May 14 22:52:00 GMT 2007
On Mon, May 14, 2007 at 12:52:44PM -0700, H. J. Lu wrote:
> 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.
>
>
Here are an updated patch and a testcase patch.
There may be more than one shared libraries with different section
alignments. The alignment of .dynbss is the maximum alignment among
all section alignments. When we align the symbol in .dynbss, we only
need to apply the current section alignment, not the maximum alignment
of .dynbss.
H.J.
---
-------------- next part --------------
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 13:13:20.000000000 -0700
@@ -9376,6 +9376,32 @@ _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);
+
+ /* We make sure that the symbol will be aligned properly. */
+ dynbss->size = BFD_ALIGN (dynbss->size,
+ (bfd_size_type) (1 << orig_power_of_two));
+
+ /* Adjust the section alignment if needed. */
+ if (orig_power_of_two > power_of_two)
+ return bfd_set_section_alignment (dynbss->owner, dynbss,
+ orig_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;
-------------- next part --------------
2007-05-14 H.J. Lu <hongjiu.lu@intel.com>
PR ld/4504
* ld-elf/data1.c: New file.
* ld-elf/data1.h: Likewise.
* ld-elf/dynbss1.c: Likewise.
* ld-elf/pass.out: Likewise.
* ld-elf/shared.exp (build_tests): Add "Build libdata1.so".
(run_tests): Add "Run with libdata1.so".
--- ld/testsuite/ld-elf/data1.c.dynbss 2007-05-14 15:40:50.000000000 -0700
+++ ld/testsuite/ld-elf/data1.c 2007-05-14 15:34:49.000000000 -0700
@@ -0,0 +1,6 @@
+#include "data1.h"
+
+char a1[1] __attribute__ ((aligned (ALIGNMENT1))) = { 10 };
+char a2[2] __attribute__ ((aligned (ALIGNMENT2)));
+char a3[3] __attribute__ ((aligned (ALIGNMENT3)));
+char a4[4] __attribute__ ((aligned (ALIGNMENT4)));
--- ld/testsuite/ld-elf/data1.h.dynbss 2007-05-14 15:40:47.000000000 -0700
+++ ld/testsuite/ld-elf/data1.h 2007-05-14 15:31:21.000000000 -0700
@@ -0,0 +1,9 @@
+#define ALIGNMENT1 0x8000
+#define ALIGNMENT2 0x4000
+#define ALIGNMENT3 0x2000
+#define ALIGNMENT4 0x1000
+
+extern char a1[1];
+extern char a2[2];
+extern char a3[3];
+extern char a4[4];
--- ld/testsuite/ld-elf/dynbss1.c.dynbss 2007-05-14 15:40:59.000000000 -0700
+++ ld/testsuite/ld-elf/dynbss1.c 2007-05-14 15:38:56.000000000 -0700
@@ -0,0 +1,20 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "data1.h"
+
+int
+main (void)
+{
+ if ((((long) (&a1)) & (ALIGNMENT1 - 1)))
+ abort ();
+ if ((((long) (&a2)) & (ALIGNMENT2 - 1)))
+ abort ();
+ if ((((long) (&a2)) & (ALIGNMENT3 - 1)))
+ abort ();
+ if ((((long) (&a3)) & (ALIGNMENT4 - 1)))
+ abort ();
+
+ printf ("PASS\n");
+
+ return(0) ;
+}
--- ld/testsuite/ld-elf/pass.out.dynbss 2007-05-14 15:41:11.000000000 -0700
+++ ld/testsuite/ld-elf/pass.out 2007-05-14 15:39:29.000000000 -0700
@@ -0,0 +1 @@
+PASS
--- ld/testsuite/ld-elf/shared.exp.dynbss 2007-05-14 15:30:07.000000000 -0700
+++ ld/testsuite/ld-elf/shared.exp 2007-05-14 15:39:56.000000000 -0700
@@ -117,6 +117,9 @@ set build_tests {
{"Build libdl6d.so with --dynamic-list-data -Bsymbolic"
"-shared -Wl,--dynamic-list-data,-Bsymbolic" "-fPIC"
{dl6.c} {} "libdl6d.so"}
+ {"Build libdata1.so"
+ "-shared" "-fPIC"
+ {data1.c} {} "libdata1.so"}
}
set run_tests {
@@ -226,6 +229,9 @@ set run_tests {
{"Run dl6d1 with --dynamic-list-data and dlopen on libdl6d.so"
"--dynamic-list-data -ldl" ""
{dl6dmain.c} "dl6d1" "dl6b.out"}
+ {"Run with libdata1.so"
+ "tmpdir/libdata1.so" ""
+ {dynbss1.c} "dynbss1" "pass.out"}
}
run_cc_link_tests $build_tests
More information about the Binutils
mailing list