Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2518,6 +2518,12 @@ fn add_order_independent_options(
"--target-cpu",
&codegen_results.crate_info.target_cpu,
]);
if codegen_results.crate_info.target_features.len() > 0 {
cmd.link_arg(&format!(
"--target-feature={}",
&codegen_results.crate_info.target_features.join(",")
));
}
} else if flavor == LinkerFlavor::Ptx {
cmd.link_args(&["--fallback-arch", &codegen_results.crate_info.target_cpu]);
} else if flavor == LinkerFlavor::Bpf {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_ssa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)>>,
Expand Down Expand Up @@ -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`
Expand Down
6 changes: 5 additions & 1 deletion src/tools/llvm-bitcode-linker/src/bin/llvm-bitcode-linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ pub struct Args {
#[arg(long)]
target_cpu: Option<String>,

/// The target features
#[arg(long)]
target_feature: Option<String>,

/// Write output to the filename
#[arg(short, long)]
output: PathBuf,
Expand All @@ -49,7 +53,7 @@ fn main() -> anyhow::Result<()> {

let args = Args::parse();

let mut linker = Session::new(args.target, args.target_cpu, args.output);
let mut linker = Session::new(args.target, args.target_cpu, args.target_feature, args.output);

linker.add_exported_symbols(args.export_symbol);

Expand Down
13 changes: 12 additions & 1 deletion src/tools/llvm-bitcode-linker/src/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{Optimization, Target};
pub struct Session {
target: Target,
cpu: Option<String>,
feature: Option<String>,
symbols: Vec<String>,

/// A file that `llvm-link` supports, like a bitcode file or an archive.
Expand All @@ -21,14 +22,20 @@ pub struct Session {
}

impl Session {
pub fn new(target: crate::Target, cpu: Option<String>, out_path: PathBuf) -> Self {
pub fn new(
target: crate::Target,
cpu: Option<String>,
feature: Option<String>,
out_path: PathBuf,
) -> Self {
let link_path = out_path.with_extension("o");
let opt_path = out_path.with_extension("optimized.o");
let sym_path = out_path.with_extension("symbols.txt");

Session {
target,
cpu,
feature,
symbols: Vec::new(),
files: Vec::new(),
link_path,
Expand Down Expand Up @@ -134,6 +141,10 @@ impl Session {
lcc_command.arg("--mcpu").arg(mcpu);
}

if let Some(mattr) = &self.feature {
lcc_command.arg(&format!("--mattr={}", mattr));
}

let lcc_output = lcc_command
.arg(&self.opt_path)
.arg("-o").arg(&self.out_path)
Expand Down
Loading