/* List of sections to add to the output BFD. */
static struct section_add *add_sections;
+/* List of sections to update in the output BFD. */
+static struct section_add *update_sections;
+
/* List of sections to dump from the output BFD. */
static struct section_add *dump_sections;
enum command_line_switch
{
OPTION_ADD_SECTION=150,
+ OPTION_UPDATE_SECTION,
OPTION_DUMP_SECTION,
OPTION_CHANGE_ADDRESSES,
OPTION_CHANGE_LEADING_CHAR,
{
{"add-gnu-debuglink", required_argument, 0, OPTION_ADD_GNU_DEBUGLINK},
{"add-section", required_argument, 0, OPTION_ADD_SECTION},
+ {"update-section", required_argument, 0, OPTION_UPDATE_SECTION},
{"adjust-start", required_argument, 0, OPTION_CHANGE_START},
{"adjust-vma", required_argument, 0, OPTION_CHANGE_ADDRESSES},
{"adjust-section-vma", required_argument, 0, OPTION_CHANGE_SECTION_ADDRESS},
--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\
+ --update-section <name>=<file>\n\
+ Update contents of section <name> with\n\
+ contents found in <file>\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\
return strncmp (name + len - 4, ".dwo", 4) == 0;
}
+/* Return TRUE if section SEC is in the update list. */
+
+static bfd_boolean
+is_update_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
+{
+ if (update_sections != NULL)
+ {
+ struct section_add *pupdate;
+
+ for (pupdate = update_sections;
+ pupdate != NULL;
+ pupdate = pupdate->next)
+ {
+ if (strcmp (sec->name, pupdate->name) == 0)
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
/* See if a non-group section is being removed. */
static bfd_boolean
if (p && q)
fatal (_("error: section %s matches both remove and copy options"),
bfd_get_section_name (abfd, sec));
+ if (p && is_update_section (abfd, sec))
+ fatal (_("error: section %s matches both update and remove options"),
+ bfd_get_section_name (abfd, sec));
if (p != NULL)
return TRUE;
}
}
+ if (update_sections != NULL)
+ {
+ struct section_add *pupdate;
+
+ for (pupdate = update_sections;
+ pupdate != NULL;
+ pupdate = pupdate->next)
+ {
+ asection *osec;
+
+ pupdate->section = bfd_get_section_by_name (ibfd, pupdate->name);
+ if (pupdate->section == NULL)
+ fatal (_("error: %s not found, can't be updated"), pupdate->name);
+
+ osec = pupdate->section->output_section;
+ if (! bfd_set_section_size (obfd, osec, pupdate->size))
+ {
+ bfd_nonfatal_message (NULL, obfd, osec, NULL);
+ return FALSE;
+ }
+ }
+ }
+
if (dump_sections != NULL)
{
struct section_add * pdump;
}
}
+ if (update_sections != NULL)
+ {
+ struct section_add *pupdate;
+
+ for (pupdate = update_sections;
+ pupdate != NULL;
+ pupdate = pupdate->next)
+ {
+ asection *osec;
+
+ osec = pupdate->section->output_section;
+ if (! bfd_set_section_contents (obfd, osec, pupdate->contents,
+ 0, pupdate->size))
+ {
+ bfd_nonfatal_message (NULL, obfd, osec, NULL);
+ return FALSE;
+ }
+ }
+ }
+
if (gnu_debuglink_filename != NULL)
{
if (! bfd_fill_in_gnu_debuglink_section
if (is_strip_section (ibfd, isection))
return TRUE;
+ if (is_update_section (ibfd, isection))
+ return TRUE;
+
flags = bfd_get_section_flags (ibfd, isection);
if ((flags & SEC_GROUP) != 0)
return TRUE;
section_add_load_file (add_sections);
break;
+ case OPTION_UPDATE_SECTION:
+ update_sections = init_section_add (optarg, update_sections,
+ "--update-section");
+ section_add_load_file (update_sections);
+ break;
+
case OPTION_DUMP_SECTION:
dump_sections = init_section_add (optarg, dump_sections,
"--dump-section");