objcopy: Add --update-section option.

New option for objcopy --update-section allows the contents of a section
to be updated while maintaining the section flags, and, for ELF files,
the section to segment mapping.

New test uses --dump-section and --update-section to check that a
section can be made larger and smaller with an update.

binutils/ChangeLog:

	* objcopy.c (update_sections): New list.
	(command_line_switch): Add OPTION_UPDATE_SECTION.
	(copy_options): Add update-section.
	(copy_usage): Document new option.
	(is_update_section): New function.
	(is_strip_section_1): Add check for attempt to update and remove
	the same section.
	(copy_object): Update size and content of requested sections.
	(skip_section): Don't copy for updated sections.
	(copy_main): Handle --update-section.
	* doc/binutils.texi (objcopy): Add description of --update-section
	option.
	* NEWS: Mention --update-section option.

binutils/testsuite/ChangeLog:

	* binutils-all/update-1.s: New file.
	* binutils-all/update-2.s: New file.
	* binutils-all/update-3.s: New file.
	* binutils-all/update-4.s: New file.
	* binutils-all/update-section.exp: New file.
This commit is contained in:
Andrew Burgess
2015-02-13 17:04:42 +00:00
parent b7236fbee4
commit acf1419f9c
10 changed files with 249 additions and 0 deletions

View File

@@ -1091,6 +1091,7 @@ objcopy [@option{-F} @var{bfdname}|@option{--target=}@var{bfdname}]
[@option{--set-section-flags} @var{sectionpattern}=@var{flags}]
[@option{--add-section} @var{sectionname}=@var{filename}]
[@option{--dump-section} @var{sectionname}=@var{filename}]
[@option{--update-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}]
@@ -1489,6 +1490,21 @@ 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 --update-section @var{sectionname}=@var{filename}
Replace the existing contents of a section named @var{sectionname}
with the contents of file @var{filename}. The size of the section
will be adjusted to the size of the file. The section flags for
@var{sectionname} will be unchanged. For ELF format files the section
to segment mapping will also remain unchanged, something which is not
possible using @option{--remove-section} followed by
@option{--add-section}. The option can be specified more than once.
Note - it is possible to use @option{--rename-section} and
@option{--update-section} to both update and rename a section from one
command line. In this case, pass the original section name to
@option{--update-section}, and the original and new section names to
@option{--rename-section}.
@item --rename-section @var{oldname}=@var{newname}[,@var{flags}]
Rename a section from @var{oldname} to @var{newname}, optionally
changing the section's flags to @var{flags} in the process. This has