Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing target-abi to cross-lang llvm lto bitcode #123400

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,16 @@ pub unsafe fn create_module<'ll>(
llvm::LLVMMDNodeInContext(llcx, &name_metadata, 1),
);

if sess.opts.cg.linker_plugin_lto.enabled() {
llvm::LLVMRustAddModuleStringFlag(
llmod,
llvm::LLVMModFlagBehavior::Override,
c"target-abi".as_ptr(),
sess.target.llvm_abiname.as_ptr().cast(),
sess.target.llvm_abiname.len(),
)
}

// Add module flags specified via -Z llvm_module_flag
for (key, value, behavior) in &sess.opts.unstable_opts.llvm_module_flag {
let key = format!("{key}\0");
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1807,6 +1807,15 @@ extern "C" {
name: *const c_char,
value: u32,
);

pub fn LLVMRustAddModuleStringFlag(
M: &Module,
merge_behavior: LLVMModFlagBehavior,
name: *const c_char,
value: *const c_char,
valueLen: size_t,
);

pub fn LLVMRustHasModuleFlag(M: &Module, name: *const c_char, len: size_t) -> bool;

pub fn LLVMRustDIBuilderCreate(M: &Module) -> &mut DIBuilder<'_>;
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,16 @@ extern "C" void LLVMRustAddModuleFlag(
unwrap(M)->addModuleFlag(MergeBehavior, Name, Value);
}

extern "C" void LLVMRustAddModuleStringFlag(
LLVMModuleRef M,
Module::ModFlagBehavior MergeBehavior,
const char *Name,
const char *Value,
size_t ValueLen) {
unwrap(M)->addModuleFlag(MergeBehavior, Name,
MDString::get(unwrap(M)->getContext(), StringRef(Value, ValueLen)));
}

extern "C" bool LLVMRustHasModuleFlag(LLVMModuleRef M, const char *Name,
size_t Len) {
return unwrap(M)->getModuleFlag(StringRef(Name, Len)) != nullptr;
Expand Down
Loading