This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
PATCH: PR 757: Linker fails to set correct alignment for common symbol
- From: "H. J. Lu" <hjl at lucon dot org>
- To: binutils at sources dot redhat dot com
- Date: Tue, 22 Feb 2005 15:18:45 -0800
- Subject: PATCH: PR 757: Linker fails to set correct alignment for common symbol
We ignored alignment requirement of common symbolsif they are in DSO.
This patch tries to fix it.
H.J.
----
2005-02-22 H.J. Lu <hongjiu.lu@intel.com>
PR 757
* elf-bfd.h (_bfd_elf_merge_symbol): Add a pointer to unsigned
int.
* elf32-sh-symbian.c (sh_symbian_relocate_section): Pass NULL
to _bfd_elf_merge_symbol.
* elflink.c (_bfd_elf_merge_symbol): Use the pointer to
unsigned int to return the alignment of the old common symbol
in the dynamic object.
(_bfd_elf_add_default_symbol): Pass NULL to
_bfd_elf_merge_symbol.
(elf_link_add_object_symbols): Pass &old_alignment to
_bfd_elf_merge_symbol. Get the alignment of the new common
symbol in the dynamic object.
--- bfd/elf-bfd.h.comm 2005-02-21 11:07:13.000000000 -0800
+++ bfd/elf-bfd.h 2005-02-22 14:53:50.911295647 -0800
@@ -1554,7 +1554,8 @@ extern bfd_boolean _bfd_elf_maybe_strip_
extern bfd_boolean _bfd_elf_merge_symbol
(bfd *, struct bfd_link_info *, const char *, Elf_Internal_Sym *,
- asection **, bfd_vma *, struct elf_link_hash_entry **, bfd_boolean *,
+ asection **, bfd_vma *, unsigned int *,
+ struct elf_link_hash_entry **, bfd_boolean *,
bfd_boolean *, bfd_boolean *, bfd_boolean *);
extern bfd_boolean _bfd_elf_add_default_symbol
--- bfd/elf32-sh-symbian.c.comm 2005-02-21 11:07:31.000000000 -0800
+++ bfd/elf32-sh-symbian.c 2005-02-22 15:01:12.949180556 -0800
@@ -492,8 +492,11 @@ sh_symbian_relocate_section (bfd *
new_sym.st_other = ELF_ST_VISIBILITY (STV_DEFAULT);
new_sym.st_shndx = SHN_UNDEF;
- if (! _bfd_elf_merge_symbol (input_bfd, info, ptr->new_name, & new_sym, & psec,
- & new_value, & new_hash, & skip, & override, & type_change_ok,
+ if (! _bfd_elf_merge_symbol (input_bfd, info,
+ ptr->new_name, & new_sym,
+ & psec, & new_value, NULL,
+ & new_hash, & skip,
+ & override, & type_change_ok,
& size_change_ok))
{
_bfd_error_handler (_("%B: Failed to add renamed symbol %s"),
--- bfd/elflink.c.comm 2005-02-11 13:18:13.000000000 -0800
+++ bfd/elflink.c 2005-02-22 15:02:29.422299573 -0800
@@ -756,7 +756,8 @@ _bfd_elf_link_renumber_dynsyms (bfd *out
TYPE_CHANGE_OK if it is OK for the type to change. We set
SIZE_CHANGE_OK if it is OK for the size to change. By OK to
change, we mean that we shouldn't warn if the type or size does
- change. */
+ change. We set POLD_ALIGNMENT if an old common symbol in a dynamic
+ object is overridden by a regular object. */
bfd_boolean
_bfd_elf_merge_symbol (bfd *abfd,
@@ -765,6 +766,7 @@ _bfd_elf_merge_symbol (bfd *abfd,
Elf_Internal_Sym *sym,
asection **psec,
bfd_vma *pvalue,
+ unsigned int *pold_alignment,
struct elf_link_hash_entry **sym_hash,
bfd_boolean *skip,
bfd_boolean *override,
@@ -1269,9 +1271,10 @@ _bfd_elf_merge_symbol (bfd *abfd,
if (h->size > *pvalue)
*pvalue = h->size;
- /* FIXME: We no longer know the alignment required by the symbol
- in the dynamic object, so we just wind up using the one from
- the regular object. */
+ /* We need to remember the alignment required by the symbol
+ in the dynamic object. */
+ BFD_ASSERT (pold_alignment);
+ *pold_alignment = h->root.u.def.section->alignment_power;
olddef = FALSE;
olddyncommon = FALSE;
@@ -1383,8 +1386,8 @@ _bfd_elf_add_default_symbol (bfd *abfd,
size_change_ok = FALSE;
sec = *psec;
if (!_bfd_elf_merge_symbol (abfd, info, shortname, sym, &sec, value,
- &hi, &skip, &override, &type_change_ok,
- &size_change_ok))
+ NULL, &hi, &skip, &override,
+ &type_change_ok, &size_change_ok))
return FALSE;
if (skip)
@@ -1487,8 +1490,8 @@ nondefault:
size_change_ok = FALSE;
sec = *psec;
if (!_bfd_elf_merge_symbol (abfd, info, shortname, sym, &sec, value,
- &hi, &skip, &override, &type_change_ok,
- &size_change_ok))
+ NULL, &hi, &skip, &override,
+ &type_change_ok, &size_change_ok))
return FALSE;
if (skip)
@@ -3525,7 +3528,7 @@ elf_link_add_object_symbols (bfd *abfd,
{
int bind;
bfd_vma value;
- asection *sec;
+ asection *sec, *new_sec;
flagword flags;
const char *name;
struct elf_link_hash_entry *h;
@@ -3647,6 +3650,7 @@ elf_link_add_object_symbols (bfd *abfd,
type_change_ok = get_elf_backend_data (abfd)->type_change_ok;
old_alignment = 0;
old_bfd = NULL;
+ new_sec = sec;
if (is_elf_hash_table (hash_table))
{
@@ -3759,7 +3763,8 @@ elf_link_add_object_symbols (bfd *abfd,
name = newname;
}
- if (!_bfd_elf_merge_symbol (abfd, info, name, isym, &sec, &value,
+ if (!_bfd_elf_merge_symbol (abfd, info, name, isym, &sec,
+ &value, &old_alignment,
sym_hash, &skip, &override,
&type_change_ok, &size_change_ok))
goto error_free_vers;
@@ -3841,12 +3846,20 @@ elf_link_add_object_symbols (bfd *abfd,
}
/* Set the alignment of a common symbol. */
- if (isym->st_shndx == SHN_COMMON
+ if ((isym->st_shndx == SHN_COMMON
+ || bfd_is_com_section (sec))
&& h->root.type == bfd_link_hash_common)
{
unsigned int align;
- align = bfd_log2 (isym->st_value);
+ if (isym->st_shndx == SHN_COMMON)
+ align = bfd_log2 (isym->st_value);
+ else
+ {
+ /* The new symbol is a common symbol in a shared object.
+ We need to get the alignment from the section. */
+ align = new_sec->alignment_power;
+ }
if (align > old_alignment
/* Permit an alignment power of zero if an alignment of one
is specified and no other alignments have been specified. */