From 249c99957d1eb42d180351d819c8a89469fc0dfb Mon Sep 17 00:00:00 2001 From: Augie Fackler Date: Mon, 19 Oct 2026 11:55:05 -0400 Subject: [PATCH] PassWrapper: set LibraryOptions in TargetMachine ln LLVM 24+ LLVM 24 is cleaning up how LLVM library command line options work, which caused `tests/codegen-llvm/pgo-counter-bias.rs` to start failing against LLVM HEAD. Previously we were only populating global options for this, and reading that got removed recently. --- .../rustc_llvm/llvm-wrapper/PassWrapper.cpp | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp index da40bddc6ba81..66057715061f9 100644 --- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp @@ -55,11 +55,18 @@ // Conditional includes prevent clang-format from fully sorting the list, // so if any are needed, keep them separate down here. +#if LLVM_VERSION_GE(24, 0) +#include "llvm/Support/LibraryOptionsContext.h" +#endif using namespace llvm; static codegen::RegisterCodeGenFlags CGF; +#if LLVM_VERSION_GE(24, 0) +static cl::LibraryOptionsContext LibraryOptions; +#endif + typedef struct LLVMOpaqueTargetMachine *LLVMTargetMachineRef; DEFINE_STDCXX_CONVERSION_FUNCTIONS(TargetMachine, LLVMTargetMachineRef) @@ -369,6 +376,9 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine( } TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags(Trip); +#if LLVM_VERSION_GE(24, 0) + Options.MCOptions.LibraryOptions = &LibraryOptions; +#endif #if LLVM_VERSION_LT(24, 0) Options.FloatABIType = FloatABIType; @@ -446,7 +456,11 @@ extern "C" void LLVMRustSetLLVMOptions(int Argc, char **Argv) { if (Initialized) return; Initialized = true; +#if LLVM_VERSION_GE(24, 0) + cl::parseCommandLineOptions(LibraryOptions, ArrayRef(Argv, Argc)); +#else cl::ParseCommandLineOptions(Argc, Argv); +#endif } enum class LLVMRustFileType { @@ -470,6 +484,9 @@ LLVMRustWriteOutputFile(LLVMTargetMachineRef Target, LLVMModuleRef M, const char *Path, const char *DwoPath, LLVMRustFileType RustFileType, bool VerifyIR, bool DisableSimplifyLibCalls) { +#if LLVM_VERSION_GE(24, 0) + unwrap(M)->getContext().getLibraryOptions().assign(LibraryOptions); +#endif std::unique_ptr PM = std::make_unique(); @@ -693,6 +710,9 @@ extern "C" LLVMRustResult LLVMRustOptimize( const char *ExtraPasses, size_t ExtraPassesLen, const char *LLVMPlugins, size_t LLVMPluginsLen) { Module *TheModule = unwrap(ModuleRef); +#if LLVM_VERSION_GE(24, 0) + TheModule->getContext().getLibraryOptions().assign(LibraryOptions); +#endif TargetMachine *TM = unwrap(TMRef); OptimizationLevel OptLevel = fromRust(OptLevelRust);