https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90392

--- Comment #4 from ohaiziejohwahkeezuoz at xff dot cz ---
Without -save-temps, generated name is random. So while there's some issue
there, too, because '-ldl.res' doesn't make much sense as an output for %u.res,
it is not the cause of the assertion failure in ldlang.c:6868:

void
ldlang_add_file (lang_input_statement_type *entry)
{
  lang_statement_append (&file_chain,
                         (lang_statement_union_type *) entry,
                         &entry->next);

  /* The BFD linker needs to have a list of all input BFDs involved in
     a link.  */
  ASSERT (entry->the_bfd->link.next == NULL);      <----- line 6868
  ASSERT (entry->the_bfd != link_info.output_bfd);


I've added this code prior to the asserts:

  info_msg ("A:%pI\n", entry);
  info_msg ("B:%pB\n", entry->the_bfd);
  if (entry->the_bfd->link.next)
    info_msg ("C:%pB\n", entry->the_bfd->link.next);

This results in this output (I also have -Wl,--trace enabled here):

.....snip....

A:/workspace/megous.com/apps-c/static-deps/toolchains/aarch64-linux-musl/lib/gcc/aarch64-linux-musl/9.0.1/crtend.o
B:/workspace/megous.com/apps-c/static-deps/toolchains/aarch64-linux-musl/lib/gcc/aarch64-linux-musl/9.0.1/crtend.o
attempt to open
/workspace/megous.com/apps-c/static-deps/toolchains/aarch64-linux-musl/lib/gcc/aarch64-linux-musl/9.0.1/../../../../aarch64-linux-musl/lib/crtn.o
succeeded
/workspace/megous.com/apps-c/static-deps/toolchains/aarch64-linux-musl/lib/gcc/aarch64-linux-musl/9.0.1/../../../../aarch64-linux-musl/lib/crtn.o
A:/workspace/megous.com/apps-c/static-deps/toolchains/aarch64-linux-musl/lib/gcc/aarch64-linux-musl/9.0.1/../../../../aarch64-linux-musl/lib/crtn.o
B:/workspace/megous.com/apps-c/static-deps/toolchains/aarch64-linux-musl/lib/gcc/aarch64-linux-musl/9.0.1/../../../../aarch64-linux-musl/lib/crtn.o
apps/libapps.a
./libssl.a
./libcrypto.a
A:armcap.o
B:armcap.o (symbol from plugin)
C:a_bitstr.o (symbol from plugin)
/workspace/megous.com/apps-c/static-deps/toolchains/aarch64-linux-musl/lib/gcc/aarch64-linux-musl/9.0.1/../../../../aarch64-linux-musl/bin/ld:
internal error
/workspace/megous.com/apps-c/static-deps/toolchains/sources/binutils-gdb/ld/ldlang.c
6873

That is, as soon as libcrypto.a starts being linked, ldlang_add_file() gets
called from here:

  /* We don't call ldlang_add_file for an archive.  Instead, the
     add_symbols entry point will call ldlang_add_file, via the
     add_archive_element callback, for each element of the archive
     which is used.  */
  switch (bfd_get_format (entry->the_bfd))
    {
    default:
      break;

    case bfd_object:
      if (!entry->flags.reload)
        ldlang_add_file (entry);
      break;

but it receives something it doesn't expect in entry->the_bfd->link.next.

Reply via email to