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.
This commit is contained in:
parent
a3d4bd382a
commit
2445dd794e
2 changed files with 3 additions and 0 deletions
|
@ -921,6 +921,7 @@ impl CrateInfo {
|
|||
let n_crates = crates.len();
|
||||
let mut info = CrateInfo {
|
||||
target_cpu,
|
||||
target_features: tcx.global_backend_features(()).clone(),
|
||||
crate_types,
|
||||
exported_symbols,
|
||||
linked_symbols,
|
||||
|
|
|
@ -190,6 +190,7 @@ impl From<&cstore::NativeLib> for NativeLib {
|
|||
#[derive(Debug, Encodable, Decodable)]
|
||||
pub struct CrateInfo {
|
||||
pub target_cpu: String,
|
||||
pub target_features: Vec<String>,
|
||||
pub crate_types: Vec<CrateType>,
|
||||
pub exported_symbols: UnordMap<CrateType, Vec<String>>,
|
||||
pub linked_symbols: FxIndexMap<CrateType, Vec<(String, SymbolExportKind)>>,
|
||||
|
@ -230,6 +231,7 @@ pub fn provide(providers: &mut Providers) {
|
|||
crate::base::provide(providers);
|
||||
crate::target_features::provide(providers);
|
||||
crate::codegen_attrs::provide(providers);
|
||||
providers.queries.global_backend_features = |_tcx: TyCtxt<'_>, ()| vec![];
|
||||
}
|
||||
|
||||
/// Checks if the given filename ends with the `.rcgu.o` extension that `rustc`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue