|
| 1 | +Index: rustc-1.77.2-src/compiler/rustc_codegen_llvm/src/back/lto.rs |
| 2 | +=================================================================== |
| 3 | +--- rustc-1.77.2-src.orig/compiler/rustc_codegen_llvm/src/back/lto.rs |
| 4 | ++++ rustc-1.77.2-src/compiler/rustc_codegen_llvm/src/back/lto.rs |
| 5 | +@@ -607,7 +607,7 @@ pub(crate) fn run_pass_manager( |
| 6 | + "LTOPostLink".as_ptr().cast(), |
| 7 | + 11, |
| 8 | + ) { |
| 9 | +- llvm::LLVMRustAddModuleFlag( |
| 10 | ++ llvm::LLVMRustAddModuleFlagU32( |
| 11 | + module.module_llvm.llmod(), |
| 12 | + llvm::LLVMModFlagBehavior::Error, |
| 13 | + c"LTOPostLink".as_ptr().cast(), |
| 14 | +Index: rustc-1.77.2-src/compiler/rustc_codegen_llvm/src/context.rs |
| 15 | +=================================================================== |
| 16 | +--- rustc-1.77.2-src.orig/compiler/rustc_codegen_llvm/src/context.rs |
| 17 | ++++ rustc-1.77.2-src/compiler/rustc_codegen_llvm/src/context.rs |
| 18 | +@@ -203,13 +203,13 @@ pub unsafe fn create_module<'ll>( |
| 19 | + // to ensure intrinsic calls don't use it. |
| 20 | + if !sess.needs_plt() { |
| 21 | + let avoid_plt = c"RtLibUseGOT".as_ptr().cast(); |
| 22 | +- llvm::LLVMRustAddModuleFlag(llmod, llvm::LLVMModFlagBehavior::Warning, avoid_plt, 1); |
| 23 | ++ llvm::LLVMRustAddModuleFlagU32(llmod, llvm::LLVMModFlagBehavior::Warning, avoid_plt, 1); |
| 24 | + } |
| 25 | + |
| 26 | + // Enable canonical jump tables if CFI is enabled. (See https://reviews.llvm.org/D65629.) |
| 27 | + if sess.is_sanitizer_cfi_canonical_jump_tables_enabled() && sess.is_sanitizer_cfi_enabled() { |
| 28 | + let canonical_jump_tables = c"CFI Canonical Jump Tables".as_ptr().cast(); |
| 29 | +- llvm::LLVMRustAddModuleFlag( |
| 30 | ++ llvm::LLVMRustAddModuleFlagU32( |
| 31 | + llmod, |
| 32 | + llvm::LLVMModFlagBehavior::Override, |
| 33 | + canonical_jump_tables, |
| 34 | +@@ -220,7 +220,7 @@ pub unsafe fn create_module<'ll>( |
| 35 | + // Enable LTO unit splitting if specified or if CFI is enabled. (See https://reviews.llvm.org/D53891.) |
| 36 | + if sess.is_split_lto_unit_enabled() || sess.is_sanitizer_cfi_enabled() { |
| 37 | + let enable_split_lto_unit = c"EnableSplitLTOUnit".as_ptr().cast(); |
| 38 | +- llvm::LLVMRustAddModuleFlag( |
| 39 | ++ llvm::LLVMRustAddModuleFlagU32( |
| 40 | + llmod, |
| 41 | + llvm::LLVMModFlagBehavior::Override, |
| 42 | + enable_split_lto_unit, |
| 43 | +@@ -231,7 +231,7 @@ pub unsafe fn create_module<'ll>( |
| 44 | + // Add "kcfi" module flag if KCFI is enabled. (See https://reviews.llvm.org/D119296.) |
| 45 | + if sess.is_sanitizer_kcfi_enabled() { |
| 46 | + let kcfi = c"kcfi".as_ptr().cast(); |
| 47 | +- llvm::LLVMRustAddModuleFlag(llmod, llvm::LLVMModFlagBehavior::Override, kcfi, 1); |
| 48 | ++ llvm::LLVMRustAddModuleFlagU32(llmod, llvm::LLVMModFlagBehavior::Override, kcfi, 1); |
| 49 | + } |
| 50 | + |
| 51 | + // Control Flow Guard is currently only supported by the MSVC linker on Windows. |
| 52 | +@@ -240,7 +240,7 @@ pub unsafe fn create_module<'ll>( |
| 53 | + CFGuard::Disabled => {} |
| 54 | + CFGuard::NoChecks => { |
| 55 | + // Set `cfguard=1` module flag to emit metadata only. |
| 56 | +- llvm::LLVMRustAddModuleFlag( |
| 57 | ++ llvm::LLVMRustAddModuleFlagU32( |
| 58 | + llmod, |
| 59 | + llvm::LLVMModFlagBehavior::Warning, |
| 60 | + c"cfguard".as_ptr() as *const _, |
| 61 | +@@ -249,7 +249,7 @@ pub unsafe fn create_module<'ll>( |
| 62 | + } |
| 63 | + CFGuard::Checks => { |
| 64 | + // Set `cfguard=2` module flag to emit metadata and checks. |
| 65 | +- llvm::LLVMRustAddModuleFlag( |
| 66 | ++ llvm::LLVMRustAddModuleFlagU32( |
| 67 | + llmod, |
| 68 | + llvm::LLVMModFlagBehavior::Warning, |
| 69 | + c"cfguard".as_ptr() as *const _, |
| 70 | +@@ -267,26 +267,26 @@ pub unsafe fn create_module<'ll>( |
| 71 | + }; |
| 72 | + |
| 73 | + if sess.target.arch == "aarch64" { |
| 74 | +- llvm::LLVMRustAddModuleFlag( |
| 75 | ++ llvm::LLVMRustAddModuleFlagU32( |
| 76 | + llmod, |
| 77 | + behavior, |
| 78 | + c"branch-target-enforcement".as_ptr().cast(), |
| 79 | + bti.into(), |
| 80 | + ); |
| 81 | +- llvm::LLVMRustAddModuleFlag( |
| 82 | ++ llvm::LLVMRustAddModuleFlagU32( |
| 83 | + llmod, |
| 84 | + behavior, |
| 85 | + c"sign-return-address".as_ptr().cast(), |
| 86 | + pac_ret.is_some().into(), |
| 87 | + ); |
| 88 | + let pac_opts = pac_ret.unwrap_or(PacRet { leaf: false, key: PAuthKey::A }); |
| 89 | +- llvm::LLVMRustAddModuleFlag( |
| 90 | ++ llvm::LLVMRustAddModuleFlagU32( |
| 91 | + llmod, |
| 92 | + behavior, |
| 93 | + c"sign-return-address-all".as_ptr().cast(), |
| 94 | + pac_opts.leaf.into(), |
| 95 | + ); |
| 96 | +- llvm::LLVMRustAddModuleFlag( |
| 97 | ++ llvm::LLVMRustAddModuleFlagU32( |
| 98 | + llmod, |
| 99 | + behavior, |
| 100 | + c"sign-return-address-with-bkey".as_ptr().cast(), |
| 101 | +@@ -302,7 +302,7 @@ pub unsafe fn create_module<'ll>( |
| 102 | + |
| 103 | + // Pass on the control-flow protection flags to LLVM (equivalent to `-fcf-protection` in Clang). |
| 104 | + if let CFProtection::Branch | CFProtection::Full = sess.opts.unstable_opts.cf_protection { |
| 105 | +- llvm::LLVMRustAddModuleFlag( |
| 106 | ++ llvm::LLVMRustAddModuleFlagU32( |
| 107 | + llmod, |
| 108 | + llvm::LLVMModFlagBehavior::Override, |
| 109 | + c"cf-protection-branch".as_ptr().cast(), |
| 110 | +@@ -310,7 +310,7 @@ pub unsafe fn create_module<'ll>( |
| 111 | + ) |
| 112 | + } |
| 113 | + if let CFProtection::Return | CFProtection::Full = sess.opts.unstable_opts.cf_protection { |
| 114 | +- llvm::LLVMRustAddModuleFlag( |
| 115 | ++ llvm::LLVMRustAddModuleFlagU32( |
| 116 | + llmod, |
| 117 | + llvm::LLVMModFlagBehavior::Override, |
| 118 | + c"cf-protection-return".as_ptr().cast(), |
| 119 | +@@ -319,7 +319,7 @@ pub unsafe fn create_module<'ll>( |
| 120 | + } |
| 121 | + |
| 122 | + if sess.opts.unstable_opts.virtual_function_elimination { |
| 123 | +- llvm::LLVMRustAddModuleFlag( |
| 124 | ++ llvm::LLVMRustAddModuleFlagU32( |
| 125 | + llmod, |
| 126 | + llvm::LLVMModFlagBehavior::Error, |
| 127 | + c"Virtual Function Elim".as_ptr().cast(), |
| 128 | +@@ -329,7 +329,7 @@ pub unsafe fn create_module<'ll>( |
| 129 | + |
| 130 | + // Set module flag to enable Windows EHCont Guard (/guard:ehcont). |
| 131 | + if sess.opts.unstable_opts.ehcont_guard { |
| 132 | +- llvm::LLVMRustAddModuleFlag( |
| 133 | ++ llvm::LLVMRustAddModuleFlagU32( |
| 134 | + llmod, |
| 135 | + llvm::LLVMModFlagBehavior::Warning, |
| 136 | + c"ehcontguard".as_ptr() as *const _, |
| 137 | +@@ -354,6 +354,22 @@ pub unsafe fn create_module<'ll>( |
| 138 | + llvm::LLVMMDNodeInContext(llcx, &name_metadata, 1), |
| 139 | + ); |
| 140 | + |
| 141 | ++ // Emit RISC-V specific target-abi metadata |
| 142 | ++ // to workaround lld as the LTO plugin not |
| 143 | ++ // correctly setting target-abi for the LTO object |
| 144 | ++ // FIXME: https://github.com/llvm/llvm-project/issues/50591 |
| 145 | ++ // If llvm_abiname is empty, emit nothing. |
| 146 | ++ let llvm_abiname = &sess.target.options.llvm_abiname; |
| 147 | ++ if matches!(sess.target.arch.as_ref(), "riscv32" | "riscv64") && !llvm_abiname.is_empty() { |
| 148 | ++ llvm::LLVMRustAddModuleFlagString( |
| 149 | ++ llmod, |
| 150 | ++ llvm::LLVMModFlagBehavior::Error, |
| 151 | ++ c"target-abi".as_ptr(), |
| 152 | ++ llvm_abiname.as_ptr().cast(), |
| 153 | ++ llvm_abiname.len(), |
| 154 | ++ ); |
| 155 | ++ } |
| 156 | ++ |
| 157 | + // Add module flags specified via -Z llvm_module_flag |
| 158 | + for (key, value, behavior) in &sess.opts.unstable_opts.llvm_module_flag { |
| 159 | + let key = format!("{key}\0"); |
| 160 | +@@ -369,7 +385,7 @@ pub unsafe fn create_module<'ll>( |
| 161 | + // We already checked this during option parsing |
| 162 | + _ => unreachable!(), |
| 163 | + }; |
| 164 | +- llvm::LLVMRustAddModuleFlag(llmod, behavior, key.as_ptr().cast(), *value) |
| 165 | ++ llvm::LLVMRustAddModuleFlagU32(llmod, behavior, key.as_ptr().cast(), *value) |
| 166 | + } |
| 167 | + |
| 168 | + llmod |
| 169 | +Index: rustc-1.77.2-src/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs |
| 170 | +=================================================================== |
| 171 | +--- rustc-1.77.2-src.orig/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs |
| 172 | ++++ rustc-1.77.2-src/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs |
| 173 | +@@ -110,7 +110,7 @@ impl<'ll, 'tcx> CodegenUnitDebugContext< |
| 174 | + .unstable_opts |
| 175 | + .dwarf_version |
| 176 | + .unwrap_or(sess.target.default_dwarf_version); |
| 177 | +- llvm::LLVMRustAddModuleFlag( |
| 178 | ++ llvm::LLVMRustAddModuleFlagU32( |
| 179 | + self.llmod, |
| 180 | + llvm::LLVMModFlagBehavior::Warning, |
| 181 | + c"Dwarf Version".as_ptr().cast(), |
| 182 | +@@ -118,7 +118,7 @@ impl<'ll, 'tcx> CodegenUnitDebugContext< |
| 183 | + ); |
| 184 | + } else { |
| 185 | + // Indicate that we want CodeView debug information on MSVC |
| 186 | +- llvm::LLVMRustAddModuleFlag( |
| 187 | ++ llvm::LLVMRustAddModuleFlagU32( |
| 188 | + self.llmod, |
| 189 | + llvm::LLVMModFlagBehavior::Warning, |
| 190 | + c"CodeView".as_ptr().cast(), |
| 191 | +@@ -127,7 +127,7 @@ impl<'ll, 'tcx> CodegenUnitDebugContext< |
| 192 | + } |
| 193 | + |
| 194 | + // Prevent bitcode readers from deleting the debug info. |
| 195 | +- llvm::LLVMRustAddModuleFlag( |
| 196 | ++ llvm::LLVMRustAddModuleFlagU32( |
| 197 | + self.llmod, |
| 198 | + llvm::LLVMModFlagBehavior::Warning, |
| 199 | + c"Debug Info Version".as_ptr().cast(), |
| 200 | +Index: rustc-1.77.2-src/compiler/rustc_codegen_llvm/src/llvm/ffi.rs |
| 201 | +=================================================================== |
| 202 | +--- rustc-1.77.2-src.orig/compiler/rustc_codegen_llvm/src/llvm/ffi.rs |
| 203 | ++++ rustc-1.77.2-src/compiler/rustc_codegen_llvm/src/llvm/ffi.rs |
| 204 | +@@ -1792,12 +1792,21 @@ extern "C" { |
| 205 | + /// |
| 206 | + /// In order for Rust-C LTO to work, module flags must be compatible with Clang. What |
| 207 | + /// "compatible" means depends on the merge behaviors involved. |
| 208 | +- pub fn LLVMRustAddModuleFlag( |
| 209 | ++ pub fn LLVMRustAddModuleFlagU32( |
| 210 | + M: &Module, |
| 211 | + merge_behavior: LLVMModFlagBehavior, |
| 212 | + name: *const c_char, |
| 213 | + value: u32, |
| 214 | + ); |
| 215 | ++ |
| 216 | ++ pub fn LLVMRustAddModuleFlagString( |
| 217 | ++ M: &Module, |
| 218 | ++ merge_behavior: LLVMModFlagBehavior, |
| 219 | ++ name: *const c_char, |
| 220 | ++ value: *const c_char, |
| 221 | ++ value_len: size_t, |
| 222 | ++ ); |
| 223 | ++ |
| 224 | + pub fn LLVMRustHasModuleFlag(M: &Module, name: *const c_char, len: size_t) -> bool; |
| 225 | + |
| 226 | + pub fn LLVMRustDIBuilderCreate(M: &Module) -> &mut DIBuilder<'_>; |
| 227 | +Index: rustc-1.77.2-src/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp |
| 228 | +=================================================================== |
| 229 | +--- rustc-1.77.2-src.orig/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp |
| 230 | ++++ rustc-1.77.2-src/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp |
| 231 | +@@ -748,7 +748,7 @@ extern "C" uint32_t LLVMRustVersionMinor |
| 232 | + |
| 233 | + extern "C" uint32_t LLVMRustVersionMajor() { return LLVM_VERSION_MAJOR; } |
| 234 | + |
| 235 | +-extern "C" void LLVMRustAddModuleFlag( |
| 236 | ++extern "C" void LLVMRustAddModuleFlagU32( |
| 237 | + LLVMModuleRef M, |
| 238 | + Module::ModFlagBehavior MergeBehavior, |
| 239 | + const char *Name, |
| 240 | +@@ -756,6 +756,16 @@ extern "C" void LLVMRustAddModuleFlag( |
| 241 | + unwrap(M)->addModuleFlag(MergeBehavior, Name, Value); |
| 242 | + } |
| 243 | + |
| 244 | ++extern "C" void LLVMRustAddModuleFlagString( |
| 245 | ++ LLVMModuleRef M, |
| 246 | ++ Module::ModFlagBehavior MergeBehavior, |
| 247 | ++ const char *Name, |
| 248 | ++ const char *Value, |
| 249 | ++ size_t ValueLen) { |
| 250 | ++ unwrap(M)->addModuleFlag(MergeBehavior, Name, |
| 251 | ++ MDString::get(unwrap(M)->getContext(), StringRef(Value, ValueLen))); |
| 252 | ++} |
| 253 | ++ |
| 254 | + extern "C" bool LLVMRustHasModuleFlag(LLVMModuleRef M, const char *Name, |
| 255 | + size_t Len) { |
| 256 | + return unwrap(M)->getModuleFlag(StringRef(Name, Len)) != nullptr; |
| 257 | +Index: rustc-1.77.2-src/tests/codegen/riscv-target-abi.rs |
| 258 | +=================================================================== |
| 259 | +--- /dev/null |
| 260 | ++++ rustc-1.77.2-src/tests/codegen/riscv-target-abi.rs |
| 261 | +@@ -0,0 +1,20 @@ |
| 262 | ++//@ revisions:riscv64gc riscv32gc riscv32imac |
| 263 | ++ |
| 264 | ++//@[riscv64gc] compile-flags: --target=riscv64gc-unknown-linux-gnu |
| 265 | ++//@[riscv64gc] needs-llvm-components: riscv |
| 266 | ++// riscv64gc: !{i32 1, !"target-abi", !"lp64d"} |
| 267 | ++ |
| 268 | ++//@[riscv32gc] compile-flags: --target=riscv32gc-unknown-linux-musl |
| 269 | ++//@[riscv32gc] needs-llvm-components: riscv |
| 270 | ++// riscv32gc: !{i32 1, !"target-abi", !"ilp32d"} |
| 271 | ++ |
| 272 | ++//@[riscv32imac] compile-flags: --target=riscv32imac-unknown-none-elf |
| 273 | ++//@[riscv32imac] needs-llvm-components: riscv |
| 274 | ++// riscv32imac-NOT: !"target-abi" |
| 275 | ++ |
| 276 | ++#![feature(no_core, lang_items)] |
| 277 | ++#![crate_type = "lib"] |
| 278 | ++#![no_core] |
| 279 | ++ |
| 280 | ++#[lang = "sized"] |
| 281 | ++trait Sized {} |
0 commit comments