PATCH RFA: Permit objcopy -add-section to work with /dev/null
Ian Lance Taylor
iant@google.com
Fri Jan 15 21:57:00 GMT 2010
Sometimes it's handy to build an object using objcopy -I -O. Those
objects naturally don't have a .note.GNU-stack section. Therefore,
when they are linked into an executable, they cause to be executable
to be marked as requiring an executable stack. One obvious way to
avoid that is to run
objcopy --add-section .note.GNU-stack=/dev/null
Unfortunately, that fails in two ways.
First, it fails because objcopy silently fails when --add-section is
used with a zero length file:
size = get_file_size (s + 1);
if (size < 1)
{
status = 1;
break;
}
That just seems like an obvious bug.
Secondly, it fails because objcopy uses get_file_size to get the size
of the file being added into the section. get_file_size fails on
/dev/null because /dev/null is not an ordinary file.
This patch fixes both problems, and adds a couple of test cases. To
make the test cases easier to write, I introduce a simple variable
substitution in the options in run_dump_test tests: they can use
$srcdir, and it will be replaced with the source directory in which
they are being run. I can do that in a different way if people don't
like it.
OK for mainline?
Ian
binutils/ChangeLog:
2010-01-15 Ian Lance Taylor <iant@google.com>
* objcopy.c (copy_main): Rewrite OPTION_ADD_SECTION code to work
with non-ordinary files like /dev/null.
binutils/testsuite/ChangeLog:
2010-01-15 Ian Lance Taylor <iant@google.com>
* lib/utils-lib.exp (run_dump_test): Permit option values to use
$srcdir to refer to the source directory.
* binutils-all/add-section.d: New test.
* binutils-all/add-empty-section.d: New test.
* binutils-all/empty-file: New test input file.
* binutils-all/objcopy.exp: Run new tests.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.patch
Type: text/x-diff
Size: 5230 bytes
Desc: add-section
URL: <https://sourceware.org/pipermail/binutils/attachments/20100115/259983b9/attachment.bin>
More information about the Binutils
mailing list