From 5725561e169fa38f5f151a90f8924ee4cb3c6052 Mon Sep 17 00:00:00 2001 From: Kai Luo Date: Thu, 23 Mar 2023 17:27:53 +0800 Subject: [PATCH 1/2] Support embedding bitcode on AIX --- compiler/rustc_codegen_llvm/src/back/write.rs | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index 53b4296802ef7..6cfb76293829d 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -875,14 +875,19 @@ unsafe fn embed_bitcode( // passed though then these sections will show up in the final output. // Additionally the flag that we need to set here is `SHF_EXCLUDE`. // + // * XCOFF - AIX linker ignores content in .ipa and .info if no auxiliary + // symbol associated with these sections. + // // Unfortunately, LLVM provides no way to set custom section flags. For ELF // and COFF we emit the sections using module level inline assembly for that // reason (see issue #90326 for historical background). + let is_aix = cgcx.opts.target_triple.triple().contains("-aix"); let is_apple = cgcx.opts.target_triple.triple().contains("-ios") || cgcx.opts.target_triple.triple().contains("-darwin") || cgcx.opts.target_triple.triple().contains("-tvos") || cgcx.opts.target_triple.triple().contains("-watchos"); if is_apple + || is_aix || cgcx.opts.target_triple.triple().starts_with("wasm") || cgcx.opts.target_triple.triple().starts_with("asmjs") { @@ -895,7 +900,13 @@ unsafe fn embed_bitcode( ); llvm::LLVMSetInitializer(llglobal, llconst); - let section = if is_apple { c"__LLVM,__bitcode" } else { c".llvmbc" }; + let section = if is_apple { + "__LLVM,__bitcode" + } else if is_aix { + ".ipa" + } else { + ".llvmbc" + }; llvm::LLVMSetSection(llglobal, section.as_ptr().cast()); llvm::LLVMRustSetLinkage(llglobal, llvm::Linkage::PrivateLinkage); llvm::LLVMSetGlobalConstant(llglobal, llvm::True); @@ -907,7 +918,13 @@ unsafe fn embed_bitcode( c"rustc.embedded.cmdline".as_ptr().cast(), ); llvm::LLVMSetInitializer(llglobal, llconst); - let section = if is_apple { c"__LLVM,__cmdline" } else { c".llvmcmd" }; + let section = if is_apple { + "__LLVM,__cmdline" + } else if is_aix { + ".info" + } else { + ".llvmcmd" + }; llvm::LLVMSetSection(llglobal, section.as_ptr().cast()); llvm::LLVMRustSetLinkage(llglobal, llvm::Linkage::PrivateLinkage); } else { From 7b79cb1759fce014f23267ce7884ba8d6ab402e7 Mon Sep 17 00:00:00 2001 From: Kai Luo Date: Thu, 8 Jun 2023 13:24:35 +0800 Subject: [PATCH 2/2] Use `c`-prefixed string --- compiler/rustc_codegen_llvm/src/back/write.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index 6cfb76293829d..b6de5ee40c740 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -901,11 +901,11 @@ unsafe fn embed_bitcode( llvm::LLVMSetInitializer(llglobal, llconst); let section = if is_apple { - "__LLVM,__bitcode" + c"__LLVM,__bitcode" } else if is_aix { - ".ipa" + c".ipa" } else { - ".llvmbc" + c".llvmbc" }; llvm::LLVMSetSection(llglobal, section.as_ptr().cast()); llvm::LLVMRustSetLinkage(llglobal, llvm::Linkage::PrivateLinkage); @@ -919,11 +919,11 @@ unsafe fn embed_bitcode( ); llvm::LLVMSetInitializer(llglobal, llconst); let section = if is_apple { - "__LLVM,__cmdline" + c"__LLVM,__cmdline" } else if is_aix { - ".info" + c".info" } else { - ".llvmcmd" + c".llvmcmd" }; llvm::LLVMSetSection(llglobal, section.as_ptr().cast()); llvm::LLVMRustSetLinkage(llglobal, llvm::Linkage::PrivateLinkage);