Skip to content

Ensure full LTO'd bitcode goes through the normal LTO pipeline instead of the thinlto pipeline #159624

Description

@PiJoules

(Summarized from https://g-issues.fuchsia.dev/issues/517626589)

If we build an rlib compiled with -Clto=fat but use the bitcode in a link using -Clto=thin then we will hit this assertion in thinLTOInternalizeModule:

      if (GS == DefinedGlobals.end()) {
        // Also check the original non-promoted non-globalized name. In some
        // cases a preempted weak value is linked in as a local copy because
        // it is referenced by an alias (IRLinker::linkGlobalValueProto).
        // In that case, since it was originally not a local value, it was
        // recorded in the index using the original name.
        // FIXME: This may not be needed once PR27866 is fixed.
        GS = DefinedGlobals.find(
            GlobalValue::getGUIDAssumingExternalLinkage(OrigName));
        assert(GS != DefinedGlobals.end());
      }
    }
    return !GlobalValue::isLocalLinkage(GS->second->linkage());

It appears that when rust is driving the link that it will unconditionally pipe all bitcode through the thin lto pipeline. I believe this is incorrect for these reasons:

  1. The fat lto pipeline doesn't emit module summaries in the first place (to be addressed in rustc_llvm: Emit module summaries when using -Clto=fat #159029)
  2. Full'fat lto'd bitcode should go through the normal full lto pipeline

Normally this would work if lld drives the link since lld knows how to dispatch which bitcode module goes through which pipeline. We should ensure rust does the same.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-LTOArea: Link-time optimization (LTO)C-bugCategory: This is a bug.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions