1use std::collections::VecDeque;
2use std::ffi::{CStr, CString};
3use std::fmt::Write;
4use std::path::Path;
5use std::sync::Once;
6use std::{ptr, slice, str};
7
8use libc::c_int;
9use rustc_codegen_ssa::base::wants_wasm_eh;
10use rustc_codegen_ssa::codegen_attrs::check_tied_features;
11use rustc_data_structures::fx::{FxHashMap, FxHashSet};
12use rustc_data_structures::small_c_str::SmallCStr;
13use rustc_data_structures::unord::UnordSet;
14use rustc_fs_util::path_to_c_string;
15use rustc_middle::bug;
16use rustc_session::Session;
17use rustc_session::config::{PrintKind, PrintRequest};
18use rustc_span::Symbol;
19use rustc_target::spec::{MergeFunctions, PanicStrategy, SmallDataThresholdSupport};
20use rustc_target::target_features::{RUSTC_SPECIAL_FEATURES, RUSTC_SPECIFIC_FEATURES};
21
22use crate::back::write::create_informational_target_machine;
23use crate::errors::{
24 FixedX18InvalidArch, ForbiddenCTargetFeature, PossibleFeature, UnknownCTargetFeature,
25 UnknownCTargetFeaturePrefix, UnstableCTargetFeature,
26};
27use crate::llvm;
28
29static INIT: Once = Once::new();
30
31pub(crate) fn init(sess: &Session) {
32 unsafe {
33 if llvm::LLVMIsMultithreaded() != 1 {
35 bug!("LLVM compiled without support for threads");
36 }
37 INIT.call_once(|| {
38 configure_llvm(sess);
39 });
40 }
41}
42
43fn require_inited() {
44 if !INIT.is_completed() {
45 bug!("LLVM is not initialized");
46 }
47}
48
49unsafe fn configure_llvm(sess: &Session) {
50 let n_args = sess.opts.cg.llvm_args.len() + sess.target.llvm_args.len();
51 let mut llvm_c_strs = Vec::with_capacity(n_args + 1);
52 let mut llvm_args = Vec::with_capacity(n_args + 1);
53
54 unsafe {
55 llvm::LLVMRustInstallErrorHandlers();
56 }
57 if std::env::var_os("CI").is_some() {
61 unsafe {
62 llvm::LLVMRustDisableSystemDialogsOnCrash();
63 }
64 }
65
66 fn llvm_arg_to_arg_name(full_arg: &str) -> &str {
67 full_arg.trim().split(|c: char| c == '=' || c.is_whitespace()).next().unwrap_or("")
68 }
69
70 let cg_opts = sess.opts.cg.llvm_args.iter().map(AsRef::as_ref);
71 let tg_opts = sess.target.llvm_args.iter().map(AsRef::as_ref);
72 let sess_args = cg_opts.chain(tg_opts);
73
74 let user_specified_args: FxHashSet<_> =
75 sess_args.clone().map(|s| llvm_arg_to_arg_name(s)).filter(|s| !s.is_empty()).collect();
76
77 {
78 let mut add = |arg: &str, force: bool| {
81 if force || !user_specified_args.contains(llvm_arg_to_arg_name(arg)) {
82 let s = CString::new(arg).unwrap();
83 llvm_args.push(s.as_ptr());
84 llvm_c_strs.push(s);
85 }
86 };
87 add("rustc -Cllvm-args=\"...\" with", true);
89 if sess.opts.unstable_opts.time_llvm_passes {
90 add("-time-passes", false);
91 }
92 if sess.opts.unstable_opts.print_llvm_passes {
93 add("-debug-pass=Structure", false);
94 }
95 if sess.target.generate_arange_section
96 && !sess.opts.unstable_opts.no_generate_arange_section
97 {
98 add("-generate-arange-section", false);
99 }
100
101 match sess.opts.unstable_opts.merge_functions.unwrap_or(sess.target.merge_functions) {
102 MergeFunctions::Disabled | MergeFunctions::Trampolines => {}
103 MergeFunctions::Aliases => {
104 add("-mergefunc-use-aliases", false);
105 }
106 }
107
108 if wants_wasm_eh(sess) {
109 add("-wasm-enable-eh", false);
110 }
111
112 if sess.target.os == "emscripten"
113 && !sess.opts.unstable_opts.emscripten_wasm_eh
114 && sess.panic_strategy() == PanicStrategy::Unwind
115 {
116 add("-enable-emscripten-cxx-exceptions", false);
117 }
118
119 add("-preserve-alignment-assumptions-during-inlining=false", false);
122
123 add("-import-cold-multiplier=0.1", false);
125
126 if sess.print_llvm_stats() {
127 add("-stats", false);
128 }
129
130 for arg in sess_args {
131 add(&(*arg), true);
132 }
133
134 match (
135 sess.opts.unstable_opts.small_data_threshold,
136 sess.target.small_data_threshold_support(),
137 ) {
138 (Some(threshold), SmallDataThresholdSupport::LlvmArg(arg)) => {
141 add(&format!("--{arg}={threshold}"), false)
142 }
143 _ => (),
144 };
145 }
146
147 if sess.opts.unstable_opts.llvm_time_trace {
148 unsafe { llvm::LLVMRustTimeTraceProfilerInitialize() };
149 }
150
151 rustc_llvm::initialize_available_targets();
152
153 unsafe { llvm::LLVMRustSetLLVMOptions(llvm_args.len() as c_int, llvm_args.as_ptr()) };
154}
155
156pub(crate) fn time_trace_profiler_finish(file_name: &Path) {
157 unsafe {
158 let file_name = path_to_c_string(file_name);
159 llvm::LLVMRustTimeTraceProfilerFinish(file_name.as_ptr());
160 }
161}
162
163enum TargetFeatureFoldStrength<'a> {
164 EnableOnly(&'a str),
167 Both(&'a str),
169}
170
171impl<'a> TargetFeatureFoldStrength<'a> {
172 fn as_str(&self) -> &'a str {
173 match self {
174 TargetFeatureFoldStrength::EnableOnly(feat) => feat,
175 TargetFeatureFoldStrength::Both(feat) => feat,
176 }
177 }
178}
179
180pub(crate) struct LLVMFeature<'a> {
181 llvm_feature_name: &'a str,
182 dependency: Option<TargetFeatureFoldStrength<'a>>,
183}
184
185impl<'a> LLVMFeature<'a> {
186 fn new(llvm_feature_name: &'a str) -> Self {
187 Self { llvm_feature_name, dependency: None }
188 }
189
190 fn with_dependency(
191 llvm_feature_name: &'a str,
192 dependency: TargetFeatureFoldStrength<'a>,
193 ) -> Self {
194 Self { llvm_feature_name, dependency: Some(dependency) }
195 }
196
197 fn contains(&self, feat: &str) -> bool {
198 self.iter().any(|dep| dep == feat)
199 }
200
201 fn iter(&'a self) -> impl Iterator<Item = &'a str> {
202 let dependencies = self.dependency.iter().map(|feat| feat.as_str());
203 std::iter::once(self.llvm_feature_name).chain(dependencies)
204 }
205}
206
207impl<'a> IntoIterator for LLVMFeature<'a> {
208 type Item = &'a str;
209 type IntoIter = impl Iterator<Item = &'a str>;
210
211 fn into_iter(self) -> Self::IntoIter {
212 let dependencies = self.dependency.into_iter().map(|feat| feat.as_str());
213 std::iter::once(self.llvm_feature_name).chain(dependencies)
214 }
215}
216
217pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFeature<'a>> {
230 let arch = if sess.target.arch == "x86_64" {
231 "x86"
232 } else if sess.target.arch == "arm64ec" {
233 "aarch64"
234 } else if sess.target.arch == "sparc64" {
235 "sparc"
236 } else if sess.target.arch == "powerpc64" {
237 "powerpc"
238 } else {
239 &*sess.target.arch
240 };
241 match (arch, s) {
242 ("x86", "sse4.2") => Some(LLVMFeature::with_dependency(
243 "sse4.2",
244 TargetFeatureFoldStrength::EnableOnly("crc32"),
245 )),
246 ("x86", "pclmulqdq") => Some(LLVMFeature::new("pclmul")),
247 ("x86", "rdrand") => Some(LLVMFeature::new("rdrnd")),
248 ("x86", "bmi1") => Some(LLVMFeature::new("bmi")),
249 ("x86", "cmpxchg16b") => Some(LLVMFeature::new("cx16")),
250 ("x86", "lahfsahf") => Some(LLVMFeature::new("sahf")),
251 ("aarch64", "rcpc2") => Some(LLVMFeature::new("rcpc-immo")),
252 ("aarch64", "dpb") => Some(LLVMFeature::new("ccpp")),
253 ("aarch64", "dpb2") => Some(LLVMFeature::new("ccdp")),
254 ("aarch64", "frintts") => Some(LLVMFeature::new("fptoint")),
255 ("aarch64", "fcma") => Some(LLVMFeature::new("complxnum")),
256 ("aarch64", "pmuv3") => Some(LLVMFeature::new("perfmon")),
257 ("aarch64", "paca") => Some(LLVMFeature::new("pauth")),
258 ("aarch64", "pacg") => Some(LLVMFeature::new("pauth")),
259 ("aarch64", "pauth-lr") if get_version().0 < 19 => None,
260 ("aarch64", "sve-b16b16") if get_version().0 < 20 => Some(LLVMFeature::new("b16b16")),
262 ("aarch64", "sme-b16b16") if get_version().0 < 20 => Some(LLVMFeature::new("b16b16")),
263 ("aarch64", "flagm2") => Some(LLVMFeature::new("altnzcv")),
264 ("aarch64", "neon") => {
266 Some(LLVMFeature::with_dependency("neon", TargetFeatureFoldStrength::Both("fp-armv8")))
267 }
268 ("aarch64", "fhm") => Some(LLVMFeature::new("fp16fml")),
271 ("aarch64", "fp16") => Some(LLVMFeature::new("fullfp16")),
272 ("aarch64", "fpmr") if get_version().0 != 18 => None,
274 ("arm", "fp16") => Some(LLVMFeature::new("fullfp16")),
275 ("riscv32" | "riscv64", "unaligned-scalar-mem") if get_version().0 == 18 => {
278 Some(LLVMFeature::new("fast-unaligned-access"))
279 }
280 ("riscv32" | "riscv64", "zaamo") if get_version().0 < 19 => None,
282 ("riscv32" | "riscv64", "zabha") if get_version().0 < 19 => None,
283 ("riscv32" | "riscv64", "zalrsc") if get_version().0 < 19 => None,
284 ("riscv32" | "riscv64", "zama16b") if get_version().0 < 19 => None,
285 ("riscv32" | "riscv64", "zacas") if get_version().0 < 20 => None,
286 ("x86", s) if s.starts_with("avx512") => {
288 Some(LLVMFeature::with_dependency(s, TargetFeatureFoldStrength::EnableOnly("evex512")))
289 }
290 ("wasm32" | "wasm64", "wide-arithmetic") if get_version() < (20, 0, 0) => None,
293 ("sparc", "leoncasa") => Some(LLVMFeature::new("hasleoncasa")),
294 ("sparc", "v8plus") if get_version().0 == 19 => Some(LLVMFeature::new("v9")),
299 ("sparc", "v8plus") if get_version().0 < 19 => None,
300 ("powerpc", "power8-crypto") => Some(LLVMFeature::new("crypto")),
301 (_, s) => Some(LLVMFeature::new(s)),
302 }
303}
304
305pub(crate) fn target_features_cfg(sess: &Session) -> (Vec<Symbol>, Vec<Symbol>) {
310 let target_machine = create_informational_target_machine(sess, true);
317 let mut features: FxHashSet<Symbol> = sess
320 .target
321 .rust_target_features()
322 .iter()
323 .filter(|(feature, _, _)| {
324 if RUSTC_SPECIAL_FEATURES.contains(feature) {
326 return true;
327 }
328 if let Some(feat) = to_llvm_features(sess, feature) {
329 for llvm_feature in feat {
330 let cstr = SmallCStr::new(llvm_feature);
331 if !unsafe { llvm::LLVMRustHasFeature(target_machine.raw(), cstr.as_ptr()) } {
335 return false;
336 }
337 }
338 true
339 } else {
340 false
341 }
342 })
343 .map(|(feature, _, _)| Symbol::intern(feature))
344 .collect();
345
346 for (enabled, feature) in
348 sess.opts.cg.target_feature.split(',').filter_map(|s| match s.chars().next() {
349 Some('+') => Some((true, Symbol::intern(&s[1..]))),
350 Some('-') => Some((false, Symbol::intern(&s[1..]))),
351 _ => None,
352 })
353 {
354 if enabled {
355 #[allow(rustc::potential_query_instability)]
360 features.extend(
361 sess.target
362 .implied_target_features(feature.as_str())
363 .iter()
364 .map(|s| Symbol::intern(s)),
365 );
366 } else {
367 #[allow(rustc::potential_query_instability)]
372 features.retain(|f| {
373 if sess.target.implied_target_features(f.as_str()).contains(&feature.as_str()) {
374 false
377 } else {
378 true
380 }
381 });
382 }
383 }
384
385 let f = |allow_unstable| {
387 sess.target
388 .rust_target_features()
389 .iter()
390 .filter_map(|(feature, gate, _)| {
391 if allow_unstable
395 || (gate.in_cfg()
396 && (sess.is_nightly_build() || gate.requires_nightly().is_none()))
397 {
398 Some(Symbol::intern(feature))
399 } else {
400 None
401 }
402 })
403 .filter(|feature| features.contains(&feature))
404 .collect()
405 };
406
407 let target_features = f(false);
408 let unstable_target_features = f(true);
409 (target_features, unstable_target_features)
410}
411
412pub(crate) fn print_version() {
413 let (major, minor, patch) = get_version();
414 println!("LLVM version: {major}.{minor}.{patch}");
415}
416
417pub(crate) fn get_version() -> (u32, u32, u32) {
418 unsafe {
420 (llvm::LLVMRustVersionMajor(), llvm::LLVMRustVersionMinor(), llvm::LLVMRustVersionPatch())
421 }
422}
423
424pub(crate) fn print_passes() {
425 unsafe {
427 llvm::LLVMRustPrintPasses();
428 }
429}
430
431fn llvm_target_features(tm: &llvm::TargetMachine) -> Vec<(&str, &str)> {
432 let len = unsafe { llvm::LLVMRustGetTargetFeaturesCount(tm) };
433 let mut ret = Vec::with_capacity(len);
434 for i in 0..len {
435 unsafe {
436 let mut feature = ptr::null();
437 let mut desc = ptr::null();
438 llvm::LLVMRustGetTargetFeature(tm, i, &mut feature, &mut desc);
439 if feature.is_null() || desc.is_null() {
440 bug!("LLVM returned a `null` target feature string");
441 }
442 let feature = CStr::from_ptr(feature).to_str().unwrap_or_else(|e| {
443 bug!("LLVM returned a non-utf8 feature string: {}", e);
444 });
445 let desc = CStr::from_ptr(desc).to_str().unwrap_or_else(|e| {
446 bug!("LLVM returned a non-utf8 feature string: {}", e);
447 });
448 ret.push((feature, desc));
449 }
450 }
451 ret
452}
453
454pub(crate) fn print(req: &PrintRequest, out: &mut String, sess: &Session) {
455 require_inited();
456 let tm = create_informational_target_machine(sess, false);
457 match req.kind {
458 PrintKind::TargetCPUs => print_target_cpus(sess, tm.raw(), out),
459 PrintKind::TargetFeatures => print_target_features(sess, tm.raw(), out),
460 _ => bug!("rustc_codegen_llvm can't handle print request: {:?}", req),
461 }
462}
463
464fn print_target_cpus(sess: &Session, tm: &llvm::TargetMachine, out: &mut String) {
465 let cpu_names = llvm::build_string(|s| unsafe {
466 llvm::LLVMRustPrintTargetCPUs(&tm, s);
467 })
468 .unwrap();
469
470 struct Cpu<'a> {
471 cpu_name: &'a str,
472 remark: String,
473 }
474 let target_cpu = handle_native(&sess.target.cpu);
476 let make_remark = |cpu_name| {
477 if cpu_name == target_cpu {
478 let target = &sess.target.llvm_target;
481 format!(
482 " - This is the default target CPU for the current build target (currently {target})."
483 )
484 } else {
485 "".to_owned()
486 }
487 };
488 let mut cpus = cpu_names
489 .lines()
490 .map(|cpu_name| Cpu { cpu_name, remark: make_remark(cpu_name) })
491 .collect::<VecDeque<_>>();
492
493 if sess.host.arch == sess.target.arch {
496 let host = get_host_cpu_name();
497 cpus.push_front(Cpu {
498 cpu_name: "native",
499 remark: format!(" - Select the CPU of the current host (currently {host})."),
500 });
501 }
502
503 let max_name_width = cpus.iter().map(|cpu| cpu.cpu_name.len()).max().unwrap_or(0);
504 writeln!(out, "Available CPUs for this target:").unwrap();
505 for Cpu { cpu_name, remark } in cpus {
506 let width = if remark.is_empty() { 0 } else { max_name_width };
508 writeln!(out, " {cpu_name:<width$}{remark}").unwrap();
509 }
510}
511
512fn print_target_features(sess: &Session, tm: &llvm::TargetMachine, out: &mut String) {
513 let mut llvm_target_features = llvm_target_features(tm);
514 let mut known_llvm_target_features = FxHashSet::<&'static str>::default();
515 let mut rustc_target_features = sess
516 .target
517 .rust_target_features()
518 .iter()
519 .filter_map(|(feature, gate, _implied)| {
520 if !gate.in_cfg() {
521 return None;
523 }
524 let llvm_feature = to_llvm_features(sess, *feature)?.llvm_feature_name;
527 let desc =
528 match llvm_target_features.binary_search_by_key(&llvm_feature, |(f, _d)| f).ok() {
529 Some(index) => {
530 known_llvm_target_features.insert(llvm_feature);
531 llvm_target_features[index].1
532 }
533 None => "",
534 };
535
536 Some((*feature, desc))
537 })
538 .collect::<Vec<_>>();
539
540 rustc_target_features.extend_from_slice(&[(
542 "crt-static",
543 "Enables C Run-time Libraries to be statically linked",
544 )]);
545 rustc_target_features.sort();
547
548 llvm_target_features.retain(|(f, _d)| !known_llvm_target_features.contains(f));
549
550 let max_feature_len = llvm_target_features
551 .iter()
552 .chain(rustc_target_features.iter())
553 .map(|(feature, _desc)| feature.len())
554 .max()
555 .unwrap_or(0);
556
557 writeln!(out, "Features supported by rustc for this target:").unwrap();
558 for (feature, desc) in &rustc_target_features {
559 writeln!(out, " {feature:max_feature_len$} - {desc}.").unwrap();
560 }
561 writeln!(out, "\nCode-generation features supported by LLVM for this target:").unwrap();
562 for (feature, desc) in &llvm_target_features {
563 writeln!(out, " {feature:max_feature_len$} - {desc}.").unwrap();
564 }
565 if llvm_target_features.is_empty() {
566 writeln!(out, " Target features listing is not supported by this LLVM version.")
567 .unwrap();
568 }
569 writeln!(out, "\nUse +feature to enable a feature, or -feature to disable it.").unwrap();
570 writeln!(out, "For example, rustc -C target-cpu=mycpu -C target-feature=+feature1,-feature2\n")
571 .unwrap();
572 writeln!(out, "Code-generation features cannot be used in cfg or #[target_feature],").unwrap();
573 writeln!(out, "and may be renamed or removed in a future version of LLVM or rustc.\n").unwrap();
574}
575
576fn get_host_cpu_name() -> &'static str {
578 let mut len = 0;
579 let slice: &'static [u8] = unsafe {
582 let ptr = llvm::LLVMRustGetHostCPUName(&mut len);
583 assert!(!ptr.is_null());
584 slice::from_raw_parts(ptr, len)
585 };
586 str::from_utf8(slice).expect("host CPU name should be UTF-8")
587}
588
589fn handle_native(cpu_name: &str) -> &str {
592 match cpu_name {
593 "native" => get_host_cpu_name(),
594 _ => cpu_name,
595 }
596}
597
598pub(crate) fn target_cpu(sess: &Session) -> &str {
599 let cpu_name = sess.opts.cg.target_cpu.as_deref().unwrap_or_else(|| &sess.target.cpu);
600 handle_native(cpu_name)
601}
602
603pub(crate) fn global_llvm_features(
606 sess: &Session,
607 diagnostics: bool,
608 only_base_features: bool,
609) -> Vec<String> {
610 let mut features = vec![];
629
630 match sess.opts.cg.target_cpu {
632 Some(ref s) if s == "native" => {
633 let features_string = unsafe {
639 let ptr = llvm::LLVMGetHostCPUFeatures();
640 let features_string = if !ptr.is_null() {
641 CStr::from_ptr(ptr)
642 .to_str()
643 .unwrap_or_else(|e| {
644 bug!("LLVM returned a non-utf8 features string: {}", e);
645 })
646 .to_owned()
647 } else {
648 bug!("could not allocate host CPU features, LLVM returned a `null` string");
649 };
650
651 llvm::LLVMDisposeMessage(ptr);
652
653 features_string
654 };
655 features.extend(features_string.split(',').map(String::from));
656 }
657 Some(_) | None => {}
658 };
659
660 features.extend(
662 sess.target
663 .features
664 .split(',')
665 .filter(|v| !v.is_empty())
666 .filter(|v| *v != "+v8plus" || get_version() >= (20, 0, 0))
668 .map(String::from),
669 );
670
671 if wants_wasm_eh(sess) && sess.panic_strategy() == PanicStrategy::Unwind {
672 features.push("+exception-handling".into());
673 }
674
675 if !only_base_features {
677 let known_features = sess.target.rust_target_features();
678 let mut featsmap = FxHashMap::default();
680
681 let mut all_rust_features = vec![];
683 for feature in sess.opts.cg.target_feature.split(',') {
684 if let Some(feature) = feature.strip_prefix('+') {
685 all_rust_features.extend(
686 UnordSet::from(sess.target.implied_target_features(feature))
687 .to_sorted_stable_ord()
688 .iter()
689 .map(|&&s| (true, s)),
690 )
691 } else if let Some(feature) = feature.strip_prefix('-') {
692 all_rust_features.push((false, feature));
696 } else if !feature.is_empty() {
697 if diagnostics {
698 sess.dcx().emit_warn(UnknownCTargetFeaturePrefix { feature });
699 }
700 }
701 }
702 all_rust_features.retain(|(_, feature)| {
704 !RUSTC_SPECIFIC_FEATURES.contains(feature)
706 });
707
708 if diagnostics {
710 for &(enable, feature) in &all_rust_features {
711 let feature_state = known_features.iter().find(|&&(v, _, _)| v == feature);
712 match feature_state {
713 None => {
714 let rust_feature =
715 known_features.iter().find_map(|&(rust_feature, _, _)| {
716 let llvm_features = to_llvm_features(sess, rust_feature)?;
717 if llvm_features.contains(feature)
718 && !llvm_features.contains(rust_feature)
719 {
720 Some(rust_feature)
721 } else {
722 None
723 }
724 });
725 let unknown_feature = if let Some(rust_feature) = rust_feature {
726 UnknownCTargetFeature {
727 feature,
728 rust_feature: PossibleFeature::Some { rust_feature },
729 }
730 } else {
731 UnknownCTargetFeature { feature, rust_feature: PossibleFeature::None }
732 };
733 sess.dcx().emit_warn(unknown_feature);
734 }
735 Some((_, stability, _)) => {
736 if let Err(reason) = stability.toggle_allowed() {
737 sess.dcx().emit_warn(ForbiddenCTargetFeature {
738 feature,
739 enabled: if enable { "enabled" } else { "disabled" },
740 reason,
741 });
742 } else if stability.requires_nightly().is_some() {
743 sess.dcx().emit_warn(UnstableCTargetFeature { feature });
747 }
748 }
749 }
750
751 featsmap.insert(feature, enable);
753 }
754 }
755
756 let feats = all_rust_features
758 .iter()
759 .filter_map(|&(enable, feature)| {
760 let enable_disable = if enable { '+' } else { '-' };
761 let llvm_feature = to_llvm_features(sess, feature)?;
766
767 Some(
768 std::iter::once(format!(
769 "{}{}",
770 enable_disable, llvm_feature.llvm_feature_name
771 ))
772 .chain(llvm_feature.dependency.into_iter().filter_map(
773 move |feat| match (enable, feat) {
774 (_, TargetFeatureFoldStrength::Both(f))
775 | (true, TargetFeatureFoldStrength::EnableOnly(f)) => {
776 Some(format!("{enable_disable}{f}"))
777 }
778 _ => None,
779 },
780 )),
781 )
782 })
783 .flatten();
784 features.extend(feats);
785
786 if diagnostics && let Some(f) = check_tied_features(sess, &featsmap) {
787 sess.dcx().emit_err(rustc_codegen_ssa::errors::TargetFeatureDisableOrEnable {
788 features: f,
789 span: None,
790 missing_features: None,
791 });
792 }
793 }
794
795 if sess.opts.unstable_opts.fixed_x18 {
797 if sess.target.arch != "aarch64" {
798 sess.dcx().emit_fatal(FixedX18InvalidArch { arch: &sess.target.arch });
799 } else {
800 features.push("+reserve-x18".into());
801 }
802 }
803
804 features
805}
806
807pub(crate) fn tune_cpu(sess: &Session) -> Option<&str> {
808 let name = sess.opts.unstable_opts.tune_cpu.as_ref()?;
809 Some(handle_native(name))
810}