This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] Make the compiler do the math 2.
Hans-Peter Nilsson escreveu:
On Mon, 25 Sep 2006, Andreas Schwab wrote:
../../bfd/elflink.c:10069:47: error: macro "memcpy" requires 3 arguments, but only 2 given
For elflink.c 1.230 it's line 9707:
memcpy (fn_name, STRING_COMMA_LEN (".text."));
perhaps most easily fixed by simply disabling use of any
memcpy-macro:
(memcpy) (fn_name, STRING_COMMA_LEN (".text."));
brgds, H-P
Or simply replace with:
-memcpy (fn_name, STRING_COMMA_LEN (".text."));
+CONST_STRNCPY (fn_name, ".text.")
Although all cases of CONST_STRNCPY would
be better replaced with something using memcpy,
since strncpy has to check if the null terminator arrives before the
specified len, and memcpy,
obviously doesn't. That is, if the compiler doesn't optimize this away.
Also the return of CONST_STRNCPY is nowhere used, so this should be safe.
How about the attached patch?
I named the new macro LITCPY, since I think it serves more the purpose
of the
macro.
Please (call me stubborn ;) , ) review, and commit.
Cheers,
Pedro Alves
---
bfd/ChangeLog
2006-09-25 Pedro Alves <pedro_alves@portugalmail.pt>
* bfd-in.h (CONST_STRNCPY) : Delete.
(LITCPY) : New.
* bfd-in2.h : Regenerate.
* elflink.c (bfd_elf_gc_sections) : Use LITCPY. Don't manually
calculate string lengths.
* nlmcode.h (nlm_swap_auxiliary_headers_in) : Use LITCPY.
binutils/ChangeLog
2006-09-25 Pedro Alves <pedro_alves@portugalmail.pt>
* nlmconv.c (main) : Use LITCPY.
* prdbg.c (tg_class_static_member) : Likewise.
Index: bfd/bfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in.h,v
retrieving revision 1.117
diff -u -p -r1.117 bfd-in.h
--- bfd/bfd-in.h 16 Sep 2006 18:12:13 -0000 1.117
+++ bfd/bfd-in.h 25 Sep 2006 22:01:24 -0000
@@ -59,7 +59,7 @@ 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)
+#define LITCPY(DEST,STR) memcpy ((DEST), (STR), sizeof (STR) - 1)
/* The word size used by BFD on the host. This may be 64 with a 32
Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.230
diff -u -p -r1.230 elflink.c
--- bfd/elflink.c 16 Sep 2006 18:12:14 -0000 1.230
+++ bfd/elflink.c 25 Sep 2006 22:01:50 -0000
@@ -9704,8 +9704,9 @@ bfd_elf_gc_sections (bfd *abfd, struct b
fn_name = bfd_malloc (len + 6);
if (fn_name == NULL)
return FALSE;
- memcpy (fn_name, STRING_COMMA_LEN (".text."));
- memcpy (fn_name + 6, o->name + 18, len);
+ LITCPY (fn_name, ".text.");
+ memcpy (fn_name + sizeof (".text.") - 1, o->name
+ + sizeof (".gcc_except_table.") - 1, len);
fn_text = bfd_get_section_by_name (sub, fn_name);
free (fn_name);
if (fn_text == NULL || !fn_text->gc_mark)
Index: bfd/nlmcode.h
===================================================================
RCS file: /cvs/src/src/bfd/nlmcode.h,v
retrieving revision 1.19
diff -u -p -r1.19 nlmcode.h
--- bfd/nlmcode.h 16 Sep 2006 18:12:14 -0000 1.19
+++ bfd/nlmcode.h 25 Sep 2006 22:01:55 -0000
@@ -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"));
+ LITCPY (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 *abf
{
Nlm_External_Version_Header thdr;
- memcpy (thdr.stamp, STRING_COMMA_LEN ("VeRsIoN#"));
+ LITCPY (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 *abf
{
Nlm_External_Copyright_Header thdr;
- memcpy (thdr.stamp, STRING_COMMA_LEN ("CoPyRiGhT="));
+ LITCPY (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 *abf
{
Nlm_External_Extended_Header thdr;
- memcpy (thdr.stamp, STRING_COMMA_LEN ("MeSsAgEs"));
+ LITCPY (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 *abf
ds = find_nonzero (nlm_custom_header (abfd)->dataStamp,
sizeof (nlm_custom_header (abfd)->dataStamp));
- memcpy (thdr.stamp, STRING_COMMA_LEN ("CuStHeAd"));
+ LITCPY (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 *abf
{
Nlm_External_Custom_Header thdr;
- memcpy (thdr.stamp, STRING_COMMA_LEN ("CuStHeAd"));
+ LITCPY (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"));
+ LITCPY (thdr.dataStamp, "CyGnUsEx");
amt = sizeof (thdr);
if (bfd_bwrite ((void *) &thdr, amt, abfd) != amt)
return FALSE;
Index: binutils/nlmconv.c
===================================================================
RCS file: /cvs/src/src/binutils/nlmconv.c,v
retrieving revision 1.28
diff -u -p -r1.28 nlmconv.c
--- binutils/nlmconv.c 16 Sep 2006 18:12:17 -0000 1.28
+++ binutils/nlmconv.c 25 Sep 2006 22:01:59 -0000
@@ -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");
+ LITCPY (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");
+ LITCPY (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");
+ LITCPY (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");
+ LITCPY (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");
+ LITCPY (nlm_extended_header (outbfd)->stamp, "MeSsAgEs");
- CONST_STRNCPY (nlm_cygnus_ext_header (outbfd)->stamp, "CyGnUsEx");
+ LITCPY (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#");
+ LITCPY (version_hdr->stamp, "VeRsIoN#");
}
#ifdef NLMCONV_POWERPC
Index: binutils/prdbg.c
===================================================================
RCS file: /cvs/src/src/binutils/prdbg.c,v
retrieving revision 1.14
diff -u -p -r1.14 prdbg.c
--- binutils/prdbg.c 16 Sep 2006 18:12:17 -0000 1.14
+++ binutils/prdbg.c 25 Sep 2006 22:02:04 -0000
@@ -2157,8 +2157,8 @@ tg_class_static_member (void *p, const c
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);
+ LITCPY (full_name + len_class, "::");
+ memcpy (full_name + len_class + sizeof ("::") - 1, name, len_var + 1);
if (! substitute_type (info, full_name))
return FALSE;