[PATCH] Emit undefined weak symbols only when used
Jakub Jelinek
jakub@redhat.com
Sun Jan 20 02:30:00 GMT 2002
http://gcc.gnu.org/ml/gcc-patches/2001-10/msg01382.html:
On Fri, Oct 26, 2001 at 09:55:17AM -0700, Richard Henderson wrote:
> On Fri, Oct 26, 2001 at 11:01:03AM +0200, Jakub Jelinek wrote:
> > Every weak prototype, even if it is not used at all, adds an entry to
> > .dynsym and symbol name to .dynstr...
>
> Seems like this is something that ought to get fixed in
> the assembler. We shouldn't add the symbol to the table
> unless it is used elsewhere.
>
Here is a patch to implement that.
gas will not emit foo symbol for input like:
.weak foo
but will for either:
.weak foo
foo:
or
.weak foo
movl foo, %eax
, the first one will handle .protected/.hidden/.internal the same way.
Note that Sun assembler will always emit the weak symbols (current gas
behaviour), but during linking if the same symbol is weak undef in one file
and non-weak undef in another file, it will be non-weak, so the only
difference is if foo is actually not used anywhere for anything, in which
case it just pollutes .symtab/.dynsymtab and e.g. in case of
__register_frame_info_bases () __attribute__((weak)); which is never used
causes binaries/libraries to require GCC_3.0 symbol version from glibc which
isn't actually needed for anything.
Jakub
-------------- next part --------------
2002-01-20 Jakub Jelinek <jakub@redhat.com>
* config/obj-elf.c (elf_frob_file_before_adjust): Remove symbols
made because of .weak, if they are neither defined nor used in any
way.
--- gas/config/obj-elf.c.jj Sun Jan 13 18:19:37 2002
+++ gas/config/obj-elf.c Sat Jan 19 23:52:21 2002
@@ -2003,9 +2003,9 @@ elf_frob_file_before_adjust ()
symbolS *symp;
for (symp = symbol_rootP; symp; symp = symbol_next (symp))
- if (symbol_get_obj (symp)->versioned_name)
+ if (!S_IS_DEFINED (symp))
{
- if (!S_IS_DEFINED (symp))
+ if (symbol_get_obj (symp)->versioned_name)
{
char *p;
@@ -2025,6 +2025,14 @@ elf_frob_file_before_adjust ()
&& symbol_used_in_reloc_p (symp) == 0)
symbol_remove (symp, &symbol_rootP, &symbol_lastP);
}
+
+ /* If there was .weak foo, but foo was neither defined nor
+ used anywhere, remove it. */
+
+ else if (S_IS_WEAK (symp)
+ && symbol_used_p (symp) == 0
+ && symbol_used_in_reloc_p (symp) == 0)
+ symbol_remove (symp, &symbol_rootP, &symbol_lastP);
}
}
}
More information about the Binutils
mailing list