Skip to content

Commit 83f552f

Browse files
committed
pass target features and optimization level to llvm-bitcode-linker
1 parent 6dd75f0 commit 83f552f

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+6
Original file line numberDiff line numberDiff line change
@@ -2518,6 +2518,12 @@ fn add_order_independent_options(
25182518
"--target-cpu",
25192519
&codegen_results.crate_info.target_cpu,
25202520
]);
2521+
if let Some(feat) = [sess.opts.cg.target_feature.as_str(), &sess.target.options.features]
2522+
.into_iter()
2523+
.find(|feat| !feat.is_empty())
2524+
{
2525+
cmd.link_args(&["--target-feature", feat]);
2526+
}
25212527
} else if flavor == LinkerFlavor::Ptx {
25222528
cmd.link_args(&["--fallback-arch", &codegen_results.crate_info.target_cpu]);
25232529
} else if flavor == LinkerFlavor::Bpf {

compiler/rustc_codegen_ssa/src/back/linker.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1926,14 +1926,14 @@ impl<'a> Linker for LlbcLinker<'a> {
19261926
}
19271927

19281928
fn optimize(&mut self) {
1929-
match self.sess.opts.optimize {
1929+
self.link_arg(match self.sess.opts.optimize {
19301930
OptLevel::No => "-O0",
19311931
OptLevel::Less => "-O1",
19321932
OptLevel::Default => "-O2",
19331933
OptLevel::Aggressive => "-O3",
19341934
OptLevel::Size => "-Os",
19351935
OptLevel::SizeMin => "-Oz",
1936-
};
1936+
});
19371937
}
19381938

19391939
fn full_relro(&mut self) {}

src/tools/llvm-bitcode-linker/src/bin/llvm-bitcode-linker.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ pub struct Args {
2727
#[arg(long)]
2828
target_cpu: Option<String>,
2929

30+
/// The target feature
31+
#[arg(long)]
32+
target_feature: Option<String>,
33+
3034
/// Write output to the filename
3135
#[arg(short, long)]
3236
output: PathBuf,
@@ -49,7 +53,7 @@ fn main() -> anyhow::Result<()> {
4953

5054
let args = Args::parse();
5155

52-
let mut linker = Session::new(args.target, args.target_cpu, args.output);
56+
let mut linker = Session::new(args.target, args.target_cpu, args.target_feature, args.output);
5357

5458
linker.add_exported_symbols(args.export_symbol);
5559

src/tools/llvm-bitcode-linker/src/linker.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::{Optimization, Target};
88
pub struct Session {
99
target: Target,
1010
cpu: Option<String>,
11+
attr: Option<String>,
1112
symbols: Vec<String>,
1213

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

2324
impl Session {
24-
pub fn new(target: crate::Target, cpu: Option<String>, out_path: PathBuf) -> Self {
25+
pub fn new(
26+
target: crate::Target,
27+
cpu: Option<String>,
28+
attr: Option<String>,
29+
out_path: PathBuf,
30+
) -> Self {
2531
let link_path = out_path.with_extension("o");
2632
let opt_path = out_path.with_extension("optimized.o");
2733
let sym_path = out_path.with_extension("symbols.txt");
2834

2935
Session {
3036
target,
3137
cpu,
38+
attr,
3239
symbols: Vec::new(),
3340
files: Vec::new(),
3441
link_path,
@@ -133,6 +140,9 @@ impl Session {
133140
if let Some(mcpu) = &self.cpu {
134141
lcc_command.arg("--mcpu").arg(mcpu);
135142
}
143+
if let Some(mattr) = &self.attr {
144+
lcc_command.arg("--mattr").arg(mattr);
145+
}
136146

137147
let lcc_output = lcc_command
138148
.arg(&self.opt_path)

0 commit comments

Comments
 (0)