Discussion:
objcopy fails silently with an empty input file
Shaun Jackman
2005-04-12 23:35:00 UTC
Permalink
objcopy silently fails when the input file is empty. I'd rather it
didn't fail -- this used to work in previous versions -- but it
definitely shouldn't fail silently.

Cheers,
Shaun

$ arm-elf-objcopy --version | head -1
GNU objcopy 2.15
$ echo > not-empty
$ arm-elf-objcopy -Ibinary -Oelf32-little not-empty not-empty.o; echo $?
0
$ echo -n > empty
$ arm-elf-objcopy -Ibinary -Oelf32-little empty empty.o; echo $?
1
Nick Clifton
2005-04-13 16:06:59 UTC
Permalink
Hi Shaun,
Post by Shaun Jackman
objcopy silently fails when the input file is empty. I'd rather it
didn't fail -- this used to work in previous versions -- but it
definitely shouldn't fail silently.
Please could you try the attached patch and let me know if you have any
problems with it ?

Cheers
Nick

binutils/ChangeLog
2005-04-13 Nick Clifton <***@redhat.com>

* objcopy.c (copy_file): Emit a message when skipping an empty
input file.

Index: binutils/objcopy.c
===================================================================
RCS file: /cvs/src/src/binutils/objcopy.c,v
retrieving revision 1.77
diff -c -3 -p -r1.77 objcopy.c
*** binutils/objcopy.c 15 Mar 2005 17:45:18 -0000 1.77
--- binutils/objcopy.c 13 Apr 2005 16:06:23 -0000
*************** copy_file (const char *input_filename, c
*** 1701,1706 ****
--- 1701,1707 ----

if (get_file_size (input_filename) < 1)
{
+ non_fatal (_("%s: empty input file"), input_filename);
status = 1;
return;
}
Shaun Jackman
2005-04-13 17:21:18 UTC
Permalink
Thanks, Nick. The patch works, although it doesn't allow for this use case:
$ echo -n > empty
$ arm-elf-objcopy -I binary -O elf32-little empty empty.o; echo $?
arm-elf-objcopy: empty: empty input file
0
$ nm empty.o
00000000 D _binary_empty_end
00000000 A _binary_empty_size
00000000 D _binary_empty_start

I'd prefer this patch:
*************** copy_file (const char *input_filename, c
*** 1701,1706 ****
--- 1701,1703 ----

if (get_file_size (input_filename) < 1)
- {
+ non_fatal (_("%s: empty input file"), input_filename);
- status = 1;
- return;
- }

Perhaps this behaviour only makes sense when the input target is
binary, and this behviour could be selected only in that special case.

Cheers,
Shaun
Post by Nick Clifton
Hi Shaun,
Post by Shaun Jackman
objcopy silently fails when the input file is empty. I'd rather it
didn't fail -- this used to work in previous versions -- but it
definitely shouldn't fail silently.
Please could you try the attached patch and let me know if you have any
problems with it ?
Cheers
Nick
binutils/ChangeLog
* objcopy.c (copy_file): Emit a message when skipping an empty
input file.
Index: binutils/objcopy.c
===================================================================
RCS file: /cvs/src/src/binutils/objcopy.c,v
retrieving revision 1.77
diff -c -3 -p -r1.77 objcopy.c
*** binutils/objcopy.c 15 Mar 2005 17:45:18 -0000 1.77
--- binutils/objcopy.c 13 Apr 2005 16:06:23 -0000
*************** copy_file (const char *input_filename, c
*** 1701,1706 ****
--- 1701,1707 ----
if (get_file_size (input_filename) < 1)
{
+ non_fatal (_("%s: empty input file"), input_filename);
status = 1;
return;
}
Nick Clifton
2005-04-14 09:52:35 UTC
Permalink
Hi Shaun,
Post by Shaun Jackman
$ echo -n > empty
$ arm-elf-objcopy -I binary -O elf32-little empty empty.o; echo $?
arm-elf-objcopy: empty: empty input file
0
$ nm empty.o
00000000 D _binary_empty_end [...]
Strange - I do not get that behaviour:

% echo -n > empty
% objcopy -I binary -O elf32-little empty empty.o ; echo $?
objcopy: empty: empty input file
1
% nm empty.o
nm: 'empty.o': No such file

Are you sure that you applied the patch I sent correctly ?

Cheers
Nick
Shaun Jackman
2005-04-14 15:25:48 UTC
Permalink
Post by Nick Clifton
Hi Shaun,
Post by Shaun Jackman
$ echo -n > empty
$ arm-elf-objcopy -I binary -O elf32-little empty empty.o; echo $?
arm-elf-objcopy: empty: empty input file
0
$ nm empty.o
00000000 D _binary_empty_end [...]
% echo -n > empty
% objcopy -I binary -O elf32-little empty empty.o ; echo $?
objcopy: empty: empty input file
1
% nm empty.o
nm: 'empty.o': No such file
Are you sure that you applied the patch I sent correctly ?
Cheers
Nick
Sorry, Nick . I wasn't clear. The use case I posted was the behaviour
that I desired, which I get with the patch I posted. With your patch,
I see the same behaviour as you do. To clear things up, I would like
"empty input file" to be a warning, not an error, particularly when
the input BFD is 'binary'.

Cheers,
Shaun
Nick Clifton
2005-04-15 09:11:19 UTC
Permalink
Hi Shaun,
Post by Shaun Jackman
Sorry, Nick . I wasn't clear. The use case I posted was the behaviour
that I desired, which I get with the patch I posted. With your patch,
I see the same behaviour as you do. To clear things up, I would like
"empty input file" to be a warning, not an error, particularly when
the input BFD is 'binary'.
Ah - unfortunately I do not think that this is a good idea. The input
file could be empty for a variety of reasons - it could be a device, a
pipe, or some other kind of system file, instead of just an ordinary,
zero-sized file.

Besides - what is the value in creating an output file from an empty
input file ? What possible use can this output file have ?

Cheers
Nick
Shaun Jackman
2005-04-15 16:00:53 UTC
Permalink
Post by Nick Clifton
Ah - unfortunately I do not think that this is a good idea. The input
file could be empty for a variety of reasons - it could be a device, a
pipe, or some other kind of system file, instead of just an ordinary,
zero-sized file.
Besides - what is the value in creating an output file from an empty
input file ? What possible use can this output file have ?
Fair enough. The empty file is of limited use. I have an application
that writes a payload binary to flash. To make sure the build
succeeds, if a payload binary wasn't provided make simply touched
'payload.bin'. This had the slight benefit that if this app was
mistakenly run it wouldn't bork the flash, since the payload is zero
bytes. I'll replace 'touch payload.bin' with 'echo empty >
payload.bin', but this inherent benefit is lost. Instead, the app will
just have to check for a signature byte.

Cheers,
Shaun
Nick Clifton
2005-04-15 16:25:56 UTC
Permalink
Hi Shaun,
Post by Shaun Jackman
Fair enough. The empty file is of limited use. I have an application
that writes a payload binary to flash. To make sure the build
succeeds, if a payload binary wasn't provided make simply touched
'payload.bin'.
If no payload was provided then shouldn't the build fail ? [Of course
it is your system so it can behave as you wish].
Post by Shaun Jackman
This had the slight benefit that if this app was
mistakenly run it wouldn't bork the flash, since the payload is zero
bytes. I'll replace 'touch payload.bin' with 'echo empty >
payload.bin', but this inherent benefit is lost. Instead, the app will
just have to check for a signature byte.
You could easily create an dummy empty.o (eg using the objcopy patched
in the way you suggested) and then just copy this file into place if the
build process failed to create a non-zero length output file.

Cheers
Nick

Loading...