[@option{--change-warnings}] [@option{--no-change-warnings}]
[@option{--set-section-flags} @var{sectionpattern}=@var{flags}]
[@option{--add-section} @var{sectionname}=@var{filename}]
+ [@option{--dump-section} @var{sectionname}=@var{filename}]
[@option{--rename-section} @var{oldname}=@var{newname}[,@var{flags}]]
[@option{--long-section-names} @{enable,disable,keep@}]
[@option{--change-leading-char}] [@option{--remove-leading-char}]
contents of the new section are taken from the file @var{filename}. The
size of the section will be the size of the file. This option only
works on file formats which can support sections with arbitrary names.
+Note - it may be necessary to use the @option{--set-section-flags}
+option to set the attributes of the newly created section.
+
+@item --dump-section @var{sectionname}=@var{filename}
+Place the contents of section named @var{sectionname} into the file
+@var{filename}, overwriting any contents that may have been there
+previously. This option is the inverse of @option{--add-section}.
+This option is similar to the @option{--only-section} option except
+that it does not create a formatted file, it just dumps the contents
+as raw binary data, without applying any relocations. The option can
+be specified more than once.
@item --rename-section @var{oldname}=@var{newname}[,@var{flags}]
Rename a section from @var{oldname} to @var{newname}, optionally
/* List of sections to add to the output BFD. */
static struct section_add *add_sections;
+/* List of sections to dump from the output BFD. */
+static struct section_add *dump_sections;
+
/* If non-NULL the argument to --add-gnu-debuglink.
This should be the filename to store in the .gnu_debuglink section. */
static const char * gnu_debuglink_filename = NULL;
enum command_line_switch
{
OPTION_ADD_SECTION=150,
+ OPTION_DUMP_SECTION,
OPTION_CHANGE_ADDRESSES,
OPTION_CHANGE_LEADING_CHAR,
OPTION_CHANGE_START,
{"disable-deterministic-archives", no_argument, 0, 'U'},
{"discard-all", no_argument, 0, 'x'},
{"discard-locals", no_argument, 0, 'X'},
+ {"dump-section", required_argument, 0, OPTION_DUMP_SECTION},
{"enable-deterministic-archives", no_argument, 0, 'D'},
{"extract-dwo", no_argument, 0, OPTION_EXTRACT_DWO},
{"extract-symbol", no_argument, 0, OPTION_EXTRACT_SYMBOL},
--set-section-flags <name>=<flags>\n\
Set section <name>'s properties to <flags>\n\
--add-section <name>=<file> Add section <name> found in <file> to output\n\
+ --dump-section <name>=<file> Dump the contents of section <name> into <file>\n\
--rename-section <old>=<new>[,<flags>] Rename section <old> to <new>\n\
--long-section-names {enable|disable|keep}\n\
Handle long section names in Coff objects.\n\
}
}
+ if (dump_sections != NULL)
+ {
+ struct section_add * pdump;
+
+ for (pdump = dump_sections; pdump != NULL; pdump = pdump->next)
+ {
+ asection * sec;
+
+ sec = bfd_get_section_by_name (ibfd, pdump->name);
+ if (sec == NULL)
+ {
+ bfd_nonfatal_message (NULL, ibfd, NULL,
+ _("can't dump section '%s' - it does not exist"),
+ pdump->name);
+ continue;
+ }
+
+ if ((bfd_get_section_flags (ibfd, sec) & SEC_HAS_CONTENTS) == 0)
+ {
+ bfd_nonfatal_message (NULL, ibfd, sec,
+ _("can't dump section - it has no contents"));
+ continue;
+ }
+
+ bfd_size_type size = bfd_get_section_size (sec);
+ if (size == 0)
+ {
+ bfd_nonfatal_message (NULL, ibfd, sec,
+ _("can't dump section - it is empty"));
+ continue;
+ }
+
+ FILE * f;
+ f = fopen (pdump->filename, FOPEN_WB);
+ if (f == NULL)
+ {
+ bfd_nonfatal_message (pdump->filename, NULL, NULL,
+ _("could not open section dump file"));
+ continue;
+ }
+
+ bfd_byte * contents = xmalloc (size);
+ if (bfd_get_section_contents (ibfd, sec, contents, 0, size))
+ fwrite (contents, 1, size, f);
+ else
+ bfd_nonfatal_message (NULL, ibfd, sec,
+ _("could not retrieve section contents"));
+
+ fclose (f);
+ free (contents);
+ }
+ }
+
if (gnu_debuglink_filename != NULL)
{
/* PR 15125: Give a helpful warning message if
}
break;
+ case OPTION_DUMP_SECTION:
+ {
+ const char *s;
+ struct section_add *pa;
+
+ s = strchr (optarg, '=');
+
+ if (s == NULL)
+ fatal (_("bad format for %s"), "--dump-section");
+
+ pa = (struct section_add *) xmalloc (sizeof * pa);
+ pa->name = xstrndup (optarg, s - optarg);
+ pa->filename = s + 1;
+ pa->next = dump_sections;
+ pa->contents = NULL;
+ dump_sections = pa;
+ }
+ break;
+
case OPTION_CHANGE_START:
change_start = parse_vma (optarg, "--change-start");
break;