This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
tidy plt entries on x86, ppc
- From: Alan Modra <amodra at bigpond dot net dot au>
- To: binutils at sources dot redhat dot com
- Date: Sat, 17 May 2003 16:13:30 +0930
- Subject: tidy plt entries on x86, ppc
Removes some useless .plt entries, and tidies code a little.
* elf32-i386.c (elf_i386_adjust_dynamic_symbol): Use SYMBOL_CALLS_LOCAL
to trim plt entries. Move undefweak non-default visibility test..
(allocate_dynrelocs): ..from here.
* elf32-ppc.c (ppc_elf_adjust_dynamic_symbol): Don't test
dynamic_sections_created here. Update comment. Move undefweak
non-default visibility test..
(allocate_dynrelocs): ..from here. Fix comment.
* elf64-ppc.c (ppc64_elf_adjust_dynamic_symbol): Use SYMBOL_CALLS_LOCAL
to trim plt entries. Move undefweak non-default visibility test..
(allocate_dynrelocs): ..from here. Fix comment.
* elflink.h (elf_link_output_extsym): Compare ELF_ST_VISIBILITY with
STV_DEFAULT rather than comparing with zero.
* elflink.c (_bfd_elf_merge_symbol): Likewise.
(_bfd_elf_fix_symbol_flags): Likewise. Format comment.
Index: bfd/elf32-i386.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-i386.c,v
retrieving revision 1.102
diff -u -p -r1.102 elf32-i386.c
--- bfd/elf32-i386.c 15 May 2003 06:35:43 -0000 1.102
+++ bfd/elf32-i386.c 17 May 2003 05:14:44 -0000
@@ -1390,11 +1390,9 @@ elf_i386_adjust_dynamic_symbol (info, h)
|| (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
{
if (h->plt.refcount <= 0
- || (! info->shared
- && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
- && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0
- && h->root.type != bfd_link_hash_undefweak
- && h->root.type != bfd_link_hash_undefined))
+ || SYMBOL_CALLS_LOCAL (info, h)
+ || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
+ && h->root.type == bfd_link_hash_undefweak))
{
/* This case can occur if we saw a PLT32 reloc in an input
file, but the symbol was never referred to by a dynamic
@@ -1558,9 +1556,7 @@ allocate_dynrelocs (h, inf)
htab = elf_i386_hash_table (info);
if (htab->elf.dynamic_sections_created
- && h->plt.refcount > 0
- && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
- || h->root.type != bfd_link_hash_undefweak))
+ && h->plt.refcount > 0)
{
/* Make sure this symbol is output as a dynamic symbol.
Undefined weak syms won't yet be marked as dynamic. */
Index: bfd/elf32-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-ppc.c,v
retrieving revision 1.80
diff -u -p -r1.80 elf32-ppc.c
--- bfd/elf32-ppc.c 15 May 2003 06:35:43 -0000 1.80
+++ bfd/elf32-ppc.c 17 May 2003 05:14:47 -0000
@@ -2495,19 +2495,21 @@ ppc_elf_adjust_dynamic_symbol (info, h)
{
/* Clear procedure linkage table information for any symbol that
won't need a .plt entry. */
- if (! htab->elf.dynamic_sections_created
+ if (h->plt.refcount <= 0
|| SYMBOL_CALLS_LOCAL (info, h)
- || h->plt.refcount <= 0)
+ || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
+ && h->root.type == bfd_link_hash_undefweak))
{
/* A PLT entry is not required/allowed when:
- 1. We are not using ld.so; because then the PLT entry
- can't be set up, so we can't use one.
+ 1. We are not using ld.so; because then the PLT entry
+ can't be set up, so we can't use one. In this case,
+ ppc_elf_adjust_dynamic_symbol won't even be called.
- 2. We know for certain that a call to this symbol
- will go to this object.
+ 2. GC has rendered the entry unused.
- 3. GC has rendered the entry unused. */
+ 3. We know for certain that a call to this symbol
+ will go to this object, or will remain undefined. */
h->plt.offset = (bfd_vma) -1;
h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
}
@@ -2673,9 +2675,7 @@ allocate_dynrelocs (h, inf)
htab = ppc_elf_hash_table (info);
if (htab->elf.dynamic_sections_created
- && h->plt.refcount > 0
- && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
- || h->root.type != bfd_link_hash_undefweak))
+ && h->plt.refcount > 0)
{
/* Make sure this symbol is output as a dynamic symbol. */
if (h->dynindx == -1
@@ -2799,12 +2799,12 @@ allocate_dynrelocs (h, inf)
if (info->shared)
{
- /* Relocs that use pc_count are those that appear on a call
- insn, or certain REL relocs (see MUST_BE_DYN_RELOC) that can
- generated via assembly. We want calls to protected symbols
- to resolve directly to the function rather than going via the
- plt. If people want function pointer comparisons to work as
- expected then they should avoid writing weird assembly. */
+ /* Relocs that use pc_count are those that appear on a call insn,
+ or certain REL relocs (see MUST_BE_DYN_RELOC) that can be
+ generated via assembly. We want calls to protected symbols to
+ resolve directly to the function rather than going via the plt.
+ If people want function pointer comparisons to work as expected
+ then they should avoid writing weird assembly. */
if (SYMBOL_CALLS_LOCAL (info, h))
{
struct ppc_elf_dyn_relocs **pp;
Index: bfd/elf64-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-ppc.c,v
retrieving revision 1.97
diff -u -p -r1.97 elf64-ppc.c
--- bfd/elf64-ppc.c 15 May 2003 06:35:43 -0000 1.97
+++ bfd/elf64-ppc.c 17 May 2003 05:14:51 -0000
@@ -4505,10 +4505,9 @@ ppc64_elf_adjust_dynamic_symbol (info, h
break;
if (!((struct ppc_link_hash_entry *) h)->is_func_descriptor
|| ent == NULL
- || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
- || (! info->shared
- && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
- && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0))
+ || SYMBOL_CALLS_LOCAL (info, h)
+ || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
+ && h->root.type == bfd_link_hash_undefweak))
{
h->plt.plist = NULL;
h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
@@ -5496,9 +5495,7 @@ allocate_dynrelocs (h, inf)
if (htab->elf.dynamic_sections_created
&& h->dynindx != -1
- && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info->shared, h)
- && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
- || h->root.type != bfd_link_hash_undefweak))
+ && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info->shared, h))
{
struct plt_entry *pent;
bfd_boolean doneone = FALSE;
@@ -5621,12 +5618,12 @@ allocate_dynrelocs (h, inf)
if (info->shared)
{
- /* Relocs that use pc_count are those that appear on a call
- insn, or certain REL relocs (see MUST_BE_DYN_RELOC) that can
- generated via assembly. We want calls to protected symbols
- to resolve directly to the function rather than going via the
- plt. If people want function pointer comparisons to work as
- expected then they should avoid writing weird assembly. */
+ /* Relocs that use pc_count are those that appear on a call insn,
+ or certain REL relocs (see MUST_BE_DYN_RELOC) that can be
+ generated via assembly. We want calls to protected symbols to
+ resolve directly to the function rather than going via the plt.
+ If people want function pointer comparisons to work as expected
+ then they should avoid writing weird assembly. */
if (SYMBOL_CALLS_LOCAL (info, h))
{
struct ppc_dyn_relocs **pp;
Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.32
diff -u -p -r1.32 elflink.c
--- bfd/elflink.c 15 May 2003 14:54:47 -0000 1.32
+++ bfd/elflink.c 17 May 2003 05:14:53 -0000
@@ -855,7 +855,7 @@ _bfd_elf_merge_symbol (abfd, info, name,
/* If the old symbol has non-default visibility, we ignore the new
definition from a dynamic object. */
if (newdyn
- && ELF_ST_VISIBILITY (h->other)
+ && ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
&& !bfd_is_und_section (sec))
{
*skip = TRUE;
@@ -871,7 +871,7 @@ _bfd_elf_merge_symbol (abfd, info, name,
return TRUE;
}
else if (!newdyn
- && ELF_ST_VISIBILITY (sym->st_other)
+ && ELF_ST_VISIBILITY (sym->st_other) != STV_DEFAULT
&& (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0)
{
/* If the new symbol with non-default visibility comes from a
@@ -2427,8 +2427,8 @@ _bfd_elf_fix_symbol_flags (h, eif)
/* If -Bsymbolic was used (which means to bind references to global
symbols to the definition within the shared object), and this
symbol was defined in a regular object, then it actually doesn't
- need a PLT entry. Likewise, if the symbol has non-default
- visibility. If the symbol has hidden or internal visibility, we
+ need a PLT entry. Likewise, if the symbol has non-default
+ visibility. If the symbol has hidden or internal visibility, we
will force it local. */
if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0
&& eif->info->shared
@@ -2449,7 +2449,7 @@ _bfd_elf_fix_symbol_flags (h, eif)
/* If a weak undefined symbol has non-default visibility, we also
hide it from the dynamic linker. */
- if (ELF_ST_VISIBILITY (h->other)
+ if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
&& h->root.type == bfd_link_hash_undefweak)
{
struct elf_backend_data *bed;
Index: bfd/elflink.h
===================================================================
RCS file: /cvs/src/src/bfd/elflink.h,v
retrieving revision 1.223
diff -u -p -r1.223 elflink.h
--- bfd/elflink.h 15 May 2003 13:48:53 -0000 1.223
+++ bfd/elflink.h 17 May 2003 05:14:57 -0000
@@ -4620,7 +4620,7 @@ elf_link_output_extsym (h, data)
/* If a non-weak symbol with non-default visibility is not defined
locally, it is a fatal error. */
if (! finfo->info->relocateable
- && ELF_ST_VISIBILITY (sym.st_other)
+ && ELF_ST_VISIBILITY (sym.st_other) != STV_DEFAULT
&& ELF_ST_BIND (sym.st_info) != STB_WEAK
&& h->root.type != bfd_link_hash_undefweak
&& (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
--
Alan Modra
IBM OzLabs - Linux Technology Centre