aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2006-09-28 12:59:25 +0000
committerNick Clifton <nickc@redhat.com>2006-09-28 12:59:25 +0000
commitea9986ff0085095cd23ec95dc0e42177c062e117 (patch)
tree82db9fd23cc38c85fa029aaf30bbf5196b9ed5e1 /bfd
parent2642de2a6c63f6a5710395e0ab502d6929d2ffd6 (diff)
downloadgdb-ea9986ff0085095cd23ec95dc0e42177c062e117.zip
gdb-ea9986ff0085095cd23ec95dc0e42177c062e117.tar.gz
gdb-ea9986ff0085095cd23ec95dc0e42177c062e117.tar.bz2
* 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. * nlmconv.c (main) : Use LITMEMCPY. * prdbg.c (tg_class_static_member) : Use LITSTRCPY.
Diffstat (limited to 'bfd')
-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
5 files changed, 38 insertions, 15 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;