From: Ian Lance Taylor Date: Mon, 3 Nov 1997 17:39:13 +0000 (+0000) Subject: * objcopy.c (parse_flags): Make flag check case insensitive. X-Git-Tag: gdb-4_18~4337 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ee1f0bd101d402e7a879ae6af128b2c5a30aea48;p=platform%2Fupstream%2Fbinutils.git * objcopy.c (parse_flags): Make flag check case insensitive. Check for `contents' flag. Give an error for unrecognized flags. (copy_section): If the contents flag was set for a section that had no contents, zero out the new contents. * binutils.texi (objcopy): Document contents section flag. PR 10601. --- diff --git a/binutils/ChangeLog b/binutils/ChangeLog index 1cd0253..0635d6e 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,11 @@ +Mon Nov 3 12:36:19 1997 Ian Lance Taylor + + * objcopy.c (parse_flags): Make flag check case insensitive. + Check for `contents' flag. Give an error for unrecognized flags. + (copy_section): If the contents flag was set for a section that + had no contents, zero out the new contents. + * binutils.texi (objcopy): Document contents section flag. + Sun Nov 2 14:49:56 1997 Ian Lance Taylor * objcopy.c: Move new struct and variable definitions to top of diff --git a/binutils/binutils.texi b/binutils/binutils.texi index d117dc2..cc6b506 100644 --- a/binutils/binutils.texi +++ b/binutils/binutils.texi @@ -1004,9 +1004,12 @@ the named section does not exist. @item --set-section-flags @var{section}=@var{flags} Set the flags for the named section. The @var{flags} argument is a comma separated string of flag names. The recognized names are -@samp{alloc}, @samp{load}, @samp{readonly}, @samp{code}, @samp{data}, -and @samp{rom}. Not all flags are meaningful for all object file -formats. +@samp{alloc}, @samp{contents}, @samp{load}, @samp{readonly}, +@samp{code}, @samp{data}, and @samp{rom}. You can set the +@samp{contents} flag for a section which does not have contents, but it +is not meaningful to clear the @samp{contents} flag of a section which +does have contents--just remove the section instead. Not all flags are +meaningful for all object file formats. @item --add-section @var{sectionname}=@var{filename} Add a new section named @var{sectionname} while copying the file. The diff --git a/binutils/objcopy.c b/binutils/objcopy.c index f477695..7e05c1b 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -354,14 +354,31 @@ parse_flags (s) ++snext; } -#define PARSE_FLAG(fname,fval) if (strncmp (fname, s, len) == 0) ret |= fval; + if (0) ; +#define PARSE_FLAG(fname,fval) \ + else if (strncasecmp (fname, s, len) == 0) ret |= fval PARSE_FLAG ("alloc", SEC_ALLOC); PARSE_FLAG ("load", SEC_LOAD); PARSE_FLAG ("readonly", SEC_READONLY); PARSE_FLAG ("code", SEC_CODE); PARSE_FLAG ("data", SEC_DATA); PARSE_FLAG ("rom", SEC_ROM); + PARSE_FLAG ("contents", SEC_HAS_CONTENTS); #undef PARSE_FLAG + else + { + char *copy; + + copy = xmalloc (len + 1); + strncpy (copy, s, len); + copy[len] = '\0'; + fprintf (stderr, "%s: unrecognized section flag `%s'\n", + program_name, copy); + fprintf (stderr, + "%s: supported flags: alloc, load, readonly, code, data, rom, contents\n", + program_name); + exit (1); + } s = snext; } @@ -1272,6 +1289,22 @@ copy_section (ibfd, isection, obfdarg) } free (memhunk); } + else if (p->set_flags && (p->flags & SEC_HAS_CONTENTS) != 0) + { + PTR memhunk = (PTR) xmalloc ((unsigned) size); + + /* We don't permit the user to turn off the SEC_HAS_CONTENTS + flag--they can just remove the section entirely and add it + back again. However, we do permit them to turn on the + SEC_HAS_CONTENTS flag, and take it to mean that the section + contents should be zeroed out. */ + + memset (memhunk, 0, size); + if (! bfd_set_section_contents (obfd, osection, memhunk, (file_ptr) 0, + size)) + nonfatal (bfd_get_filename (obfd)); + free (memhunk); + } } /* Get all the sections. This is used when --gap-fill or --pad-to is