Skip to content

Commit afced94

Browse files
author
Jethro Beekman
committed
Allow specifying LLVM args in target specifications
1 parent adc6572 commit afced94

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/librustc_codegen_llvm/llvm_util.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn require_inited() {
4646
}
4747

4848
unsafe fn configure_llvm(sess: &Session) {
49-
let n_args = sess.opts.cg.llvm_args.len();
49+
let n_args = sess.opts.cg.llvm_args.len() + sess.target.target.options.llvm_args.len();
5050
let mut llvm_c_strs = Vec::with_capacity(n_args + 1);
5151
let mut llvm_args = Vec::with_capacity(n_args + 1);
5252

@@ -56,14 +56,11 @@ unsafe fn configure_llvm(sess: &Session) {
5656
full_arg.trim().split(|c: char| c == '=' || c.is_whitespace()).next().unwrap_or("")
5757
}
5858

59-
let user_specified_args: FxHashSet<_> = sess
60-
.opts
61-
.cg
62-
.llvm_args
63-
.iter()
64-
.map(|s| llvm_arg_to_arg_name(s))
65-
.filter(|s| s.len() > 0)
66-
.collect();
59+
let cg_opts = sess.opts.cg.llvm_args.iter();
60+
let tg_opts = sess.target.target.options.llvm_args.iter();
61+
62+
let user_specified_args: FxHashSet<_> =
63+
cg_opts.chain(tg_opts).map(|s| llvm_arg_to_arg_name(s)).filter(|s| s.len() > 0).collect();
6764

6865
{
6966
// This adds the given argument to LLVM. Unless `force` is true

src/librustc_target/spec/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,9 @@ pub struct TargetOptions {
805805

806806
/// Whether or not RelaxElfRelocation flag will be passed to the linker
807807
pub relax_elf_relocations: bool,
808+
809+
/// Additional arguments to pass to LLVM, similar to the `-C llvm-args` codegen option.
810+
pub llvm_args: Vec<String>,
808811
}
809812

810813
impl Default for TargetOptions {
@@ -893,6 +896,7 @@ impl Default for TargetOptions {
893896
target_mcount: "mcount".to_string(),
894897
llvm_abiname: "".to_string(),
895898
relax_elf_relocations: false,
899+
llvm_args: vec![],
896900
}
897901
}
898902
}
@@ -1206,6 +1210,7 @@ impl Target {
12061210
key!(target_mcount);
12071211
key!(llvm_abiname);
12081212
key!(relax_elf_relocations, bool);
1213+
key!(llvm_args, list);
12091214

12101215
if let Some(array) = obj.find("abi-blacklist").and_then(Json::as_array) {
12111216
for name in array.iter().filter_map(|abi| abi.as_string()) {
@@ -1433,6 +1438,7 @@ impl ToJson for Target {
14331438
target_option_val!(target_mcount);
14341439
target_option_val!(llvm_abiname);
14351440
target_option_val!(relax_elf_relocations);
1441+
target_option_val!(llvm_args);
14361442

14371443
if default.abi_blacklist != self.options.abi_blacklist {
14381444
d.insert(

0 commit comments

Comments
 (0)