Skip to content

Parse LLVM options into an explicit global LibraryOptionsContext - #164591

Open
zmodem wants to merge 4 commits into
rust-lang:mainfrom
zmodem:parseCommandLineOptions
Open

zmodem wants to merge 4 commits into
rust-lang:mainfrom
zmodem:parseCommandLineOptions

Conversation

@zmodem

@zmodem zmodem commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

LLVM has been refactoring how it stores its internal (-mllvm) options recently, with the goal of getting rid of the global cl::opt objects.

After https://github.com/llvm/llvm-project/pull/233044 LTO passes no longer uses the global options, which would cause codegen-llvm/pgo-counter-bias.rs to fail since it relies on the -runtime-counter-relocation option to get passed to LTO.

IIUC, ideally we should change LLVMRustSetLLVMOptions to take an LLVMContext as argument and parse the options into that. However, I think by the time we currently call it, no such context has been created yet.

Instead, this PR maintains the status quo by parsing the options into a global object, which is then assigned to new LLVMContexts as they are created.

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 19, 2026
@rustbot

rustbot commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

r? @cuviper

rustbot has assigned @cuviper.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @cuviper

@zmodem

zmodem commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot label llvm-main

@rustbot rustbot added the llvm-main Marks PRs that are making Rust work with LLVM main (this label is consumed by CI tooling) label Oct 19, 2026
@zmodem

zmodem commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

r? @nikic

@rustbot rustbot assigned nikic and unassigned cuviper Oct 19, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@nikic

nikic commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

@MaskRay I'm curious how LibraryOptions is supposed to be adopted incrementally. Ideally, we would be parsing the options per-context -- but while not all options are per-context, the ones which are not would get parsed globally multiple times. That's not (thread) safe, right?

So does that mean that until the global options are entirely gone, we should basically keep using a global LibraryOptions, rather than a per-context (and thus per-thread) one? (That is, do what this PR does?)

This branch has not been deployed

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

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. llvm-main Marks PRs that are making Rust work with LLVM main (this label is consumed by CI tooling) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants