linking EFI binary from ELF objects and archives

Jan Beulich jbeulich@suse.com
Wed Sep 9 10:58:05 GMT 2020


Nick,

in PR 22369 you said

"I do wonder if we should issue an error message when attempting to
 perform cross-format links like this.  Although in theory of course
 the library could contain both COFF format objects and ELF format
 objects.  Which makes things a little more complicated.  Hmm, maybe
 I need to think about this."

Am I correctly understanding that while linking EFI binaries (i.e.
PE32+) from ELF _objects_ works, trying to also have _archives_ of
ELF objects involved doesn't? coff_link_check_archive_element()
looks to also confirm this suspicion (and observation), but then
again I'm not sure I'm not missing something else (like a magic
command line option making this work).

If this doesn't currently work, making it work wouldn't really help
for my purpose (as it also needs to work with older binutils), so
I'd then be looking for alternatives. Is behavior of "ld -r" well
defined when it comes to including archives? I.e. would the output
object have all necessary (and just those) objects pulled in from
the archive in order to satisfy undefined symbols? And if the
answer was yes, would you know whether this holds for sufficiently
old binutils (say 2.16 / 2.17-ish)?

As an aside - while looking at coff_link_check_archive_element() I
got puzzled by

  /* If the archive element has already been loaded then one
     of the symbols defined by that element might have been
     made undefined due to being in a discarded section.  */
  if (((struct coff_link_hash_entry *) h)->indx == -3)
    return TRUE;

  /* PR 22369 - Skip non COFF objects in the archive.  */
  if (! bfd_family_coff (abfd))
    return TRUE;

Shouldn't these two checks be the other way around, for the cast in
the first if() to be valid at all? Or is h's layout controlled by
the output format?

Jan


More information about the Binutils mailing list