This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] 'add symbol' feature in objcopy
- From: Ronald Hoogenboom <hoogenboom30 at zonnet dot nl>
- To: fracting at gmail dot com, Ronald Hoogenboom <hoogenboom30 at zonnet dot nl>
- Cc: binutils at sourceware dot org
- Date: Tue, 3 Nov 2015 23:08:31 +0100
- Subject: Re: [PATCH] 'add symbol' feature in objcopy
- Authentication-results: sourceware.org; auth=none
- References: <561D4796 dot 2080400 at atom dot grundel> <CALd+sZQZtJWcgc_U7ofBn2ezq4SToOQ=F+016_--pgA0LbKnSg at mail dot gmail dot com>
On 11/03/2015 02:03 PM, Qian Hong wrote:
Hi Ronald,
Thanks a lot for your work, it is a nice feature.
I tried latest cross compile binutils using mingw-w64-i686-gcc, and
found these warnings (-Werror):
objcopy.c: In function âparse_symflagsâ:
objcopy.c:792:7: error: implicit declaration of function âstrndupâ
[-Werror=implicit-function-declaration]
PARSE_OTHER ("before=", *other);
^
objcopy.c:774:9: error: incompatible implicit declaration of built-in
function âstrndupâ [-Werror]
fval = strndup (s + sizeof fname - 1, len - sizeof fname + 1)
^
objcopy.c:792:7: note: in expansion of macro âPARSE_OTHERâ
PARSE_OTHER ("before=", *other);
^
objcopy.c: In function âcopy_mainâ:
objcopy.c:4085:23: error: incompatible implicit declaration of
built-in function âstrndupâ [-Werror]
newsym->symdef = strndup (optarg, s - optarg);
^
cc1: all warnings being treated as errors
Makefile:939: recipe for target 'objcopy.o' failed
make[4]: *** [objcopy.o] Error 1
Would you mind have a look? Thanks!
Apparently, the strndup function is not 'portable' enough for mingw-w64.
There seems to be a xstrndup function in libiberty that could be used
instead. I'm sorry I don't have all the possible compilers handy to
verify all possible targets, but this should do.
--- objcopy.cmyorig 2015-11-03 23:03:39.227621417 +0100
+++ objcopy.c 2015-11-03 23:04:14.388246216 +0100
@@ -751,7 +751,7 @@
#define PARSE_FLAG(fname,fval) \
else if (len == (int)sizeof fname-1 && strncasecmp (fname, s, len) == 0) ret |= fval
#define PARSE_OTHER(fname,fval) \
- else if (len >= (int)sizeof fname && strncasecmp (fname, s, sizeof fname-1) == 0) fval=strndup(s+sizeof fname-1, len-sizeof fname+1)
+ else if (len >= (int)sizeof fname && strncasecmp (fname, s, sizeof fname-1) == 0) fval=xstrndup(s+sizeof fname-1, len-sizeof fname+1)
PARSE_FLAG ("local", BSF_LOCAL);
PARSE_FLAG ("global", BSF_GLOBAL);
PARSE_FLAG ("export", BSF_EXPORT);
@@ -3791,10 +3791,10 @@
fatal (_("bad format for %s"), "--add-symbol");
t = strchr (s+1, ':');
- newsym->symdef = strndup (optarg,s-optarg);
+ newsym->symdef = xstrndup (optarg,s-optarg);
if (t)
{
- newsym->section = strndup (s+1, t-(s+1));
+ newsym->section = xstrndup (s+1, t-(s+1));
newsym->symval = strtol (t+1, NULL, 0);
}
else