Skip to content

--emit obj with --crate-type staticlib doesn't work when -C lto=thin is set #134998

@ChrisDenton

Description

@ChrisDenton
Member

I tried this code:

// answer.rs
pub fn answer() -> u64 {
    42
}

And compiled it with:

rustc answer.rs --crate-type staticlib --emit obj -C lto=thin

I expected to see an object file created. Instead it appears to succeed but no object file is produced.

Meta

rustc --version --verbose:

rustc 1.82.0 (f6e511eec 2024-10-15)
binary: rustc
commit-hash: f6e511eec7342f59a25f7c0534f1dbea00d01b14
commit-date: 2024-10-15
host: x86_64-pc-windows-msvc
release: 1.82.0
LLVM version: 19.1.1

Activity

added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Jan 1, 2025
added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
A-LTOArea: Link-time optimization (LTO)
A-CLIArea: Command-line interface (CLI) to the compiler
and removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Jan 2, 2025
bjorn3

bjorn3 commented on Jan 2, 2025

@bjorn3
Member

--emit obj copies a single object file out of the codegen results to the output location, but thinLTO produces a single object file per input llvm bitcode file, so at least one file per crate and unless -Ccodegen-units is used, by default 16 object files per crate. --emit obj doesn't know which of these object files you want.

ChrisDenton

ChrisDenton commented on Jan 2, 2025

@ChrisDenton
MemberAuthor

If it's simply not possible to produce an object file, I'd suggest the combination of flags should be an error. Or more generally it should at least warn if no object file was produced, if not error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-CLIArea: Command-line interface (CLI) to the compilerA-LTOArea: Link-time optimization (LTO)C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ChrisDenton@bjorn3@jieyouxu@rustbot

        Issue actions

          `--emit obj` with `--crate-type staticlib` doesn't work when `-C lto=thin` is set · Issue #134998 · rust-lang/rust