public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* objcopy fails silently with an empty input file
@ 2005-04-12 23:35 Shaun Jackman
  2005-04-13 16:08 ` Nick Clifton
  0 siblings, 1 reply; 8+ messages in thread
From: Shaun Jackman @ 2005-04-12 23:35 UTC (permalink / raw)
  To: binutils

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: objcopy fails silently with an empty input file
  2005-04-12 23:35 objcopy fails silently with an empty input file Shaun Jackman
@ 2005-04-13 16:08 ` Nick Clifton
  2005-04-13 17:21   ` Shaun Jackman
  0 siblings, 1 reply; 8+ messages in thread
From: Nick Clifton @ 2005-04-13 16:08 UTC (permalink / raw)
  To: Shaun Jackman; +Cc: binutils

Hi Shaun,

> 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  <nickc@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;
       }

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: objcopy fails silently with an empty input file
  2005-04-13 16:08 ` Nick Clifton
@ 2005-04-13 17:21   ` Shaun Jackman
  2005-04-14  9:54     ` Nick Clifton
  0 siblings, 1 reply; 8+ messages in thread
From: Shaun Jackman @ 2005-04-13 17:21 UTC (permalink / raw)
  To: binutils

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

On 4/13/05, Nick Clifton <nickc@redhat.com> wrote:
> Hi Shaun,
> 
> > 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  <nickc@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;
>        }
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: objcopy fails silently with an empty input file
  2005-04-13 17:21   ` Shaun Jackman
@ 2005-04-14  9:54     ` Nick Clifton
  2005-04-14 15:25       ` Shaun Jackman
  0 siblings, 1 reply; 8+ messages in thread
From: Nick Clifton @ 2005-04-14  9:54 UTC (permalink / raw)
  To: Shaun Jackman; +Cc: binutils

Hi Shaun,

> 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 [...]

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: objcopy fails silently with an empty input file
  2005-04-14  9:54     ` Nick Clifton
@ 2005-04-14 15:25       ` Shaun Jackman
  2005-04-15  9:13         ` Nick Clifton
  0 siblings, 1 reply; 8+ messages in thread
From: Shaun Jackman @ 2005-04-14 15:25 UTC (permalink / raw)
  To: binutils

On 4/14/05, Nick Clifton <nickc@redhat.com> wrote:
> Hi Shaun,
> 
> > 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 [...]
> 
> 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

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: objcopy fails silently with an empty input file
  2005-04-14 15:25       ` Shaun Jackman
@ 2005-04-15  9:13         ` Nick Clifton
  2005-04-15 16:01           ` Shaun Jackman
  0 siblings, 1 reply; 8+ messages in thread
From: Nick Clifton @ 2005-04-15  9:13 UTC (permalink / raw)
  To: Shaun Jackman; +Cc: binutils

Hi Shaun,

> 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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: objcopy fails silently with an empty input file
  2005-04-15  9:13         ` Nick Clifton
@ 2005-04-15 16:01           ` Shaun Jackman
  2005-04-15 16:27             ` Nick Clifton
  0 siblings, 1 reply; 8+ messages in thread
From: Shaun Jackman @ 2005-04-15 16:01 UTC (permalink / raw)
  To: binutils

On 4/15/05, Nick Clifton <nickc@redhat.com> wrote:
> 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: objcopy fails silently with an empty input file
  2005-04-15 16:01           ` Shaun Jackman
@ 2005-04-15 16:27             ` Nick Clifton
  0 siblings, 0 replies; 8+ messages in thread
From: Nick Clifton @ 2005-04-15 16:27 UTC (permalink / raw)
  To: Shaun Jackman; +Cc: binutils

Hi Shaun,

> 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].

> 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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2005-04-15 16:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-12 23:35 objcopy fails silently with an empty input file Shaun Jackman
2005-04-13 16:08 ` Nick Clifton
2005-04-13 17:21   ` Shaun Jackman
2005-04-14  9:54     ` Nick Clifton
2005-04-14 15:25       ` Shaun Jackman
2005-04-15  9:13         ` Nick Clifton
2005-04-15 16:01           ` Shaun Jackman
2005-04-15 16:27             ` Nick Clifton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).