Skip to content

Commit f7df4c3

Browse files
author
kulst
committed
Persist target features used for codegen beyond tcx
Bitcode linkers like llvm-bitcode-linker or bpf linker hand over the target features to llvm during link stage. During link stage the `TyCtxt` is already gone so it is not possible to create a query for the global backend features any longer. The features preserved in `Session.target_features` only incorporate target features known to rustc. This would contradict with the behaviour during codegen stage which also passes target features to llvm which are unknown to rustc. This commit adds target features as a field to the `CrateInfo` struct and queries the target features in its new function. This way the target features are preserved beyond tcx and available at link stage.
1 parent 820bfff commit f7df4c3

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

compiler/rustc_codegen_ssa/src/base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,7 @@ impl CrateInfo {
920920
let n_crates = crates.len();
921921
let mut info = CrateInfo {
922922
target_cpu,
923+
target_features: tcx.global_backend_features(()).clone(),
923924
crate_types,
924925
exported_symbols,
925926
linked_symbols,

compiler/rustc_codegen_ssa/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ impl From<&cstore::NativeLib> for NativeLib {
190190
#[derive(Debug, Encodable, Decodable)]
191191
pub struct CrateInfo {
192192
pub target_cpu: String,
193+
pub target_features: Vec<String>,
193194
pub crate_types: Vec<CrateType>,
194195
pub exported_symbols: UnordMap<CrateType, Vec<String>>,
195196
pub linked_symbols: FxIndexMap<CrateType, Vec<(String, SymbolExportKind)>>,

0 commit comments

Comments
 (0)