This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: a patch to set ELF header flags for empty linker output files


Hi Jim,

: This fixes a problem that showed up with ia64 linux kernel builds.
: If you call the linker with only archives, like so
: 	ld -r -o foo.o bar.a
: then we end up with an empty foo.o file,

Is it reasonable to expect an output in this case ?  According to the
documentation (ld.texinfo):

    If _no_ binary input files at all are specified, the linker
    does not produce any output, and issues the message `No input
    files'.

So perhaps it is a bug that this error is not being generated.  Of
course archives are binary files, although it could be argued that
they are not *direct* input files, but rather *support* input files.
From what you say about the ia64 linux kernel builds, however, it
appears that treating them as input files is the expected behavior,
so I guess producing the output file is OK.

: While looking at this, I noticed that it was possible to put
: inconsistent object files in an archive.  I am hoping that is not
: recommended usage.

True - it certainly isn't recommended, but it can be done.

: If this is valid, then an alternative here is to call
: bfd_merge_private_bfd_data for every member of every archive.  That
: way the result is unambiguous.  I can rewrite the patch this way if
: people think this is better.

The problem with that is what happens if the object files contain
incompatible flags ?  You would end up with an executable with an
illegal set of flags, which would be just as bad.
 
: Another alternative is to change bfd_merge_private_bfd_data so that it
: ignores empty input files.  Thus we get no error when we link in the
: empty drm.o file even though it has the wrong machine dependent ELF
: header flag bits set.

I actually like this idea.  Since the file is empty it cannot
contribute anything to the final executable (in terms of code, data,
symbols, etc), so why should it be able to contribute ELF header flags ?

: I don't like this suggestion though, as it may hide real errors.
: You can also get an empty file if you assemble an empty assembly 
: file, and we should complain if the wrong assembler options are used
: for that. 

Hmm, maybe a warning would be more appropriate.  Something along the
lines of:

  "warning - empty and incompatible object file <foo> detected during
  link, ignored."

A fourth alternative would be to extend the linker script syntax to
specify the default flags for the output file, if none are specified
by the input files.  I don't really like this idea though, as getting
the syntax right would be very hard, especially if it needs to support 
formats other than ELF.


: If I don't get any comments, I will go ahead and check in this patch
: in a day or two.

I think that your patch is conceptually neater, since it produces a
binary file that is compatible with other binary files that would be
produced by the linker if there were non-archive input files.

I think that ignoring empty binary files upon input is also a good
thing too, but I am not hung up on the idea.

Cheers
	Nick

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]