aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bfd/ChangeLog10
-rw-r--r--bfd/bfd-in.h7
-rw-r--r--bfd/bfd-in2.h7
-rw-r--r--bfd/elflink.c15
-rw-r--r--bfd/nlmcode.h14
-rw-r--r--binutils/ChangeLog5
-rw-r--r--binutils/nlmconv.c18
-rw-r--r--binutils/prdbg.c10
8 files changed, 56 insertions, 30 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index a241894..562f857 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,13 @@
+2006-09-25 Pedro Alves <pedro_alves@portugalmail.pt>
+
+ * bfd-in.h (CONST_STRNCPY) : Delete.
+ (LITSTRCPY) : New.
+ (LITMEMCPY) : New.
+ * bfd-in2.h : Regenerate.
+ * elflink.c (bfd_elf_gc_sections) : Use LITMEMCPY. Don't manually
+ calculate string lengths.
+ * nlmcode.h (nlm_swap_auxiliary_headers_in) : Use LITMEMCPY.
+
2006-09-26 H.J. Lu <hongjiu.lu@intel.com>
PR ld/3223
diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h
index c11880e..8d86a23 100644
--- a/bfd/bfd-in.h
+++ b/bfd/bfd-in.h
@@ -59,7 +59,12 @@ extern "C" {
Note - these macros do NOT work if STR2 is not a constant string. */
#define CONST_STRNEQ(STR1,STR2) (strncmp ((STR1), (STR2), sizeof (STR2) - 1) == 0)
-#define CONST_STRNCPY(STR1,STR2) strncpy ((STR1), (STR2), sizeof (STR2) - 1)
+ /* strcpy() can have a similar problem, but since we know we are
+ copying a constant string, we can use memcpy which will be faster
+ since there is no need to check for a NUL byte inside STR. We
+ can also save time if we do not need to copy the terminating NUL. */
+#define LITMEMCPY(DEST,STR2) memcpy ((DEST), (STR2), sizeof (STR2) - 1)
+#define LITSTRCPY(DEST,STR2) memcpy ((DEST), (STR2), sizeof (STR2))
/* The word size used by BFD on the host. This may be 64 with a 32
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index a2c8ff8..0fc6232 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -66,7 +66,12 @@ extern "C" {
Note - these macros do NOT work if STR2 is not a constant string. */
#define CONST_STRNEQ(STR1,STR2) (strncmp ((STR1), (STR2), sizeof (STR2) - 1) == 0)
-#define CONST_STRNCPY(STR1,STR2) strncpy ((STR1), (STR2), sizeof (STR2) - 1)
+ /* strcpy() can have a similar problem, but since we know we are
+ copying a constant string, we can use memcpy which will be faster
+ since there is no need to check for a NUL byte inside STR. We
+ can also save time if we do not need to copy the terminating NUL. */
+#define LITMEMCPY(DEST,STR2) memcpy ((DEST), (STR2), sizeof (STR2) - 1)
+#define LITSTRCPY(DEST,STR2) memcpy ((DEST), (STR2), sizeof (STR2))
/* The word size used by BFD on the host. This may be 64 with a 32
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 9b45578..afff7aa 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -9691,21 +9691,24 @@ bfd_elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
easily due to needing special relocs to handle the
difference of two symbols in separate sections.
Don't keep code sections referenced by .eh_frame. */
+#define TEXT_PREFIX ".text."
+#define GCC_EXCEPT_TABLE_PREFIX ".gcc_except_table."
for (o = sub->sections; o != NULL; o = o->next)
if (!o->gc_mark && o->gc_mark_from_eh && (o->flags & SEC_CODE) == 0)
{
- if (CONST_STRNEQ (o->name, ".gcc_except_table."))
+ if (CONST_STRNEQ (o->name, GCC_EXCEPT_TABLE_PREFIX))
{
- unsigned long len;
char *fn_name;
+ const char *sec_name;
asection *fn_text;
+ unsigned o_name_prefix_len = strlen (GCC_EXCEPT_TABLE_PREFIX);
+ unsigned fn_name_prefix_len = strlen (TEXT_PREFIX);
- len = strlen (o->name + 18) + 1;
- fn_name = bfd_malloc (len + 6);
+ sec_name = o->name + o_name_prefix_len;
+ fn_name = bfd_malloc (strlen (sec_name) + fn_name_prefix_len + 1);
if (fn_name == NULL)
return FALSE;
- memcpy (fn_name, STRING_COMMA_LEN (".text."));
- memcpy (fn_name + 6, o->name + 18, len);
+ sprintf (fn_name, "%s%s", TEXT_PREFIX, sec_name);
fn_text = bfd_get_section_by_name (sub, fn_name);
free (fn_name);
if (fn_text == NULL || !fn_text->gc_mark)
diff --git a/bfd/nlmcode.h b/bfd/nlmcode.h
index 30e6f47..507d5d6 100644
--- a/bfd/nlmcode.h
+++ b/bfd/nlmcode.h
@@ -364,7 +364,7 @@ nlm_swap_auxiliary_headers_in (bfd *abfd)
if (bfd_seek (abfd, pos, SEEK_SET) != 0)
return FALSE;
- memcpy (nlm_cygnus_ext_header (abfd), STRING_COMMA_LEN ("CyGnUsEx"));
+ LITMEMCPY (nlm_cygnus_ext_header (abfd), "CyGnUsEx");
nlm_cygnus_ext_header (abfd)->offset = dataOffset;
nlm_cygnus_ext_header (abfd)->length = dataLength;
@@ -645,7 +645,7 @@ nlm_swap_auxiliary_headers_out (bfd *abfd)
{
Nlm_External_Version_Header thdr;
- memcpy (thdr.stamp, STRING_COMMA_LEN ("VeRsIoN#"));
+ LITMEMCPY (thdr.stamp, "VeRsIoN#");
put_word (abfd, (bfd_vma) nlm_version_header (abfd)->majorVersion,
(bfd_byte *) thdr.majorVersion);
put_word (abfd, (bfd_vma) nlm_version_header (abfd)->minorVersion,
@@ -672,7 +672,7 @@ nlm_swap_auxiliary_headers_out (bfd *abfd)
{
Nlm_External_Copyright_Header thdr;
- memcpy (thdr.stamp, STRING_COMMA_LEN ("CoPyRiGhT="));
+ LITMEMCPY (thdr.stamp, "CoPyRiGhT=");
amt = sizeof (thdr.stamp);
if (bfd_bwrite ((void *) thdr.stamp, amt, abfd) != amt)
return FALSE;
@@ -694,7 +694,7 @@ nlm_swap_auxiliary_headers_out (bfd *abfd)
{
Nlm_External_Extended_Header thdr;
- memcpy (thdr.stamp, STRING_COMMA_LEN ("MeSsAgEs"));
+ LITMEMCPY (thdr.stamp, "MeSsAgEs");
put_word (abfd,
(bfd_vma) nlm_extended_header (abfd)->languageID,
(bfd_byte *) thdr.languageID);
@@ -797,7 +797,7 @@ nlm_swap_auxiliary_headers_out (bfd *abfd)
ds = find_nonzero (nlm_custom_header (abfd)->dataStamp,
sizeof (nlm_custom_header (abfd)->dataStamp));
- memcpy (thdr.stamp, STRING_COMMA_LEN ("CuStHeAd"));
+ LITMEMCPY (thdr.stamp, "CuStHeAd");
hdrLength = (2 * NLM_TARGET_LONG_SIZE + (ds ? 8 : 0)
+ nlm_custom_header (abfd)->hdrLength);
put_word (abfd, hdrLength, thdr.length);
@@ -831,14 +831,14 @@ nlm_swap_auxiliary_headers_out (bfd *abfd)
{
Nlm_External_Custom_Header thdr;
- memcpy (thdr.stamp, STRING_COMMA_LEN ("CuStHeAd"));
+ LITMEMCPY (thdr.stamp, "CuStHeAd");
put_word (abfd, (bfd_vma) 2 * NLM_TARGET_LONG_SIZE + 8,
(bfd_byte *) thdr.length);
put_word (abfd, (bfd_vma) nlm_cygnus_ext_header (abfd)->offset,
(bfd_byte *) thdr.dataOffset);
put_word (abfd, (bfd_vma) nlm_cygnus_ext_header (abfd)->length,
(bfd_byte *) thdr.dataLength);
- memcpy (thdr.dataStamp, STRING_COMMA_LEN ("CyGnUsEx"));
+ LITMEMCPY (thdr.dataStamp, "CyGnUsEx");
amt = sizeof (thdr);
if (bfd_bwrite ((void *) &thdr, amt, abfd) != amt)
return FALSE;
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index f336b57..812afc2 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,8 @@
+2006-09-25 Pedro Alves <pedro_alves@portugalmail.pt>
+
+ * nlmconv.c (main) : Use LITMEMCPY.
+ * prdbg.c (tg_class_static_member) : Use LITSTRCPY.
+
2006-09-26 H.J. Lu <hongjiu.lu@intel.com>
PR binutils/3257
diff --git a/binutils/nlmconv.c b/binutils/nlmconv.c
index 6159dc9..6b8db6d 100644
--- a/binutils/nlmconv.c
+++ b/binutils/nlmconv.c
@@ -737,7 +737,7 @@ main (int argc, char **argv)
|| ! bfd_set_section_flags (outbfd, help_section,
SEC_HAS_CONTENTS))
bfd_fatal (_("help section"));
- CONST_STRNCPY (nlm_extended_header (outbfd)->stamp, "MeSsAgEs");
+ LITMEMCPY (nlm_extended_header (outbfd)->stamp, "MeSsAgEs");
}
}
if (message_file != NULL)
@@ -759,7 +759,7 @@ main (int argc, char **argv)
|| ! bfd_set_section_flags (outbfd, message_section,
SEC_HAS_CONTENTS))
bfd_fatal (_("message section"));
- CONST_STRNCPY (nlm_extended_header (outbfd)->stamp, "MeSsAgEs");
+ LITMEMCPY (nlm_extended_header (outbfd)->stamp, "MeSsAgEs");
}
}
if (modules != NULL)
@@ -795,7 +795,7 @@ main (int argc, char **argv)
|| ! bfd_set_section_flags (outbfd, rpc_section,
SEC_HAS_CONTENTS))
bfd_fatal (_("rpc section"));
- CONST_STRNCPY (nlm_extended_header (outbfd)->stamp, "MeSsAgEs");
+ LITMEMCPY (nlm_extended_header (outbfd)->stamp, "MeSsAgEs");
}
}
if (sharelib_file != NULL)
@@ -852,7 +852,7 @@ main (int argc, char **argv)
|| ! bfd_set_section_flags (outbfd, shared_section,
SEC_HAS_CONTENTS))
bfd_fatal (_("shared section"));
- CONST_STRNCPY (nlm_extended_header (outbfd)->stamp, "MeSsAgEs");
+ LITMEMCPY (nlm_extended_header (outbfd)->stamp, "MeSsAgEs");
}
}
}
@@ -863,9 +863,9 @@ main (int argc, char **argv)
/* At least for now, always create an extended header, because that
is what NLMLINK does. */
- CONST_STRNCPY (nlm_extended_header (outbfd)->stamp, "MeSsAgEs");
+ LITMEMCPY (nlm_extended_header (outbfd)->stamp, "MeSsAgEs");
- CONST_STRNCPY (nlm_cygnus_ext_header (outbfd)->stamp, "CyGnUsEx");
+ LITMEMCPY (nlm_cygnus_ext_header (outbfd)->stamp, "CyGnUsEx");
/* If the date was not given, force it in. */
if (nlm_version_header (outbfd)->month == 0
@@ -880,7 +880,7 @@ main (int argc, char **argv)
nlm_version_header (outbfd)->month = ptm->tm_mon + 1;
nlm_version_header (outbfd)->day = ptm->tm_mday;
nlm_version_header (outbfd)->year = ptm->tm_year + 1900;
- CONST_STRNCPY (version_hdr->stamp, "VeRsIoN#");
+ LITMEMCPY (version_hdr->stamp, "VeRsIoN#");
}
#ifdef NLMCONV_POWERPC
@@ -1747,9 +1747,9 @@ powerpc_build_stubs (bfd *inbfd, bfd *outbfd ATTRIBUTE_UNUSED,
/* Make a new undefined symbol with the same name but without
the leading `.'. */
- newsym = (asymbol *) xmalloc (sizeof (asymbol));
+ newsym = xmalloc (sizeof (asymbol));
*newsym = *sym;
- newname = (char *) xmalloc (strlen (bfd_asymbol_name (sym)));
+ newname = xmalloc (strlen (bfd_asymbol_name (sym)));
strcpy (newname, bfd_asymbol_name (sym) + 1);
newsym->name = newname;
diff --git a/binutils/prdbg.c b/binutils/prdbg.c
index 5b89595..7a0af83 100644
--- a/binutils/prdbg.c
+++ b/binutils/prdbg.c
@@ -724,8 +724,8 @@ pr_function_type (void *p, int argcount, bfd_boolean varargs)
/* Now the return type is on the top of the stack. */
- s = (char *) xmalloc (len);
- strcpy (s, "(|) (");
+ s = xmalloc (len);
+ LITSTRCPY (s, "(|) (");
if (argcount < 0)
strcat (s, "/* unknown */");
@@ -2153,12 +2153,10 @@ tg_class_static_member (void *p, const char *name,
len_var = strlen (name);
len_class = strlen (info->stack->next->type);
- full_name = (char *) xmalloc (len_var + len_class + 3);
+ full_name = xmalloc (len_var + len_class + 3);
if (! full_name)
return FALSE;
- memcpy (full_name, info->stack->next->type, len_class);
- memcpy (full_name + len_class, STRING_COMMA_LEN ("::"));
- memcpy (full_name + len_class + 2, name, len_var + 1);
+ sprintf (full_name, "%s::%s", info->stack->next->type, name);
if (! substitute_type (info, full_name))
return FALSE;