This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
small speedup recording dynamic syms
- From: Alan Modra <amodra at bigpond dot net dot au>
- To: binutils at sources dot redhat dot com
- Date: Fri, 31 Oct 2003 00:45:56 +1030
- Subject: small speedup recording dynamic syms
Saves a malloc/free.
* elflink.c (_bfd_elf_link_record_dynamic_symbol): Modify versioned
symbol string in place.
Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.47
diff -u -p -r1.47 elflink.c
--- bfd/elflink.c 22 Oct 2003 06:58:16 -0000 1.47
+++ bfd/elflink.c 30 Oct 2003 13:37:42 -0000
@@ -353,9 +353,8 @@ _bfd_elf_link_record_dynamic_symbol (str
if (h->dynindx == -1)
{
struct elf_strtab_hash *dynstr;
- char *p, *alc;
+ char *p;
const char *name;
- bfd_boolean copy;
bfd_size_type indx;
/* XXX: The ABI draft says the linker must turn hidden and
@@ -393,28 +392,18 @@ _bfd_elf_link_record_dynamic_symbol (str
table. */
name = h->root.root.string;
p = strchr (name, ELF_VER_CHR);
- if (p == NULL)
- {
- alc = NULL;
- copy = FALSE;
- }
- else
- {
- size_t len = p - name + 1;
-
- alc = bfd_malloc (len);
- if (alc == NULL)
- return FALSE;
- memcpy (alc, name, len - 1);
- alc[len - 1] = '\0';
- name = alc;
- copy = TRUE;
- }
+ if (p != NULL)
+ /* We know that the p points into writable memory. In fact,
+ there are only a few symbols that have read-only names, being
+ those like _GLOBAL_OFFSET_TABLE_ that are created specially
+ by the backends. Most symbols will have names pointing into
+ an ELF string table read from a file, or to objalloc memory. */
+ *p = 0;
- indx = _bfd_elf_strtab_add (dynstr, name, copy);
+ indx = _bfd_elf_strtab_add (dynstr, name, p != NULL);
- if (alc != NULL)
- free (alc);
+ if (p != NULL)
+ *p = ELF_VER_CHR;
if (indx == (bfd_size_type) -1)
return FALSE;
--
Alan Modra
IBM OzLabs - Linux Technology Centre