Skip to content

Commit 2445dd7

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. To make sure the `global_backend_features` query is always registered even if the CodegenBackend does not register it, this registration is added to the `provide`function of the `rustc_codegen_ssa` crate.
1 parent a3d4bd3 commit 2445dd7

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

compiler/rustc_codegen_ssa/src/base.rs

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

compiler/rustc_codegen_ssa/src/lib.rs

+2
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)>>,
@@ -230,6 +231,7 @@ pub fn provide(providers: &mut Providers) {
230231
crate::base::provide(providers);
231232
crate::target_features::provide(providers);
232233
crate::codegen_attrs::provide(providers);
234+
providers.queries.global_backend_features = |_tcx: TyCtxt<'_>, ()| vec![];
233235
}
234236

235237
/// Checks if the given filename ends with the `.rcgu.o` extension that `rustc`

0 commit comments

Comments
 (0)