Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying LLVM args in target specifications #68059

Merged
merged 1 commit into from
Jan 10, 2020
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
15 changes: 6 additions & 9 deletions src/librustc_codegen_llvm/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn require_inited() {
}

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

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

let user_specified_args: FxHashSet<_> = sess
.opts
.cg
.llvm_args
.iter()
.map(|s| llvm_arg_to_arg_name(s))
.filter(|s| s.len() > 0)
.collect();
let cg_opts = sess.opts.cg.llvm_args.iter();
let tg_opts = sess.target.target.options.llvm_args.iter();

let user_specified_args: FxHashSet<_> =
cg_opts.chain(tg_opts).map(|s| llvm_arg_to_arg_name(s)).filter(|s| s.len() > 0).collect();

{
// This adds the given argument to LLVM. Unless `force` is true
Expand Down
6 changes: 6 additions & 0 deletions src/librustc_target/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,9 @@ pub struct TargetOptions {

/// Whether or not RelaxElfRelocation flag will be passed to the linker
pub relax_elf_relocations: bool,

/// Additional arguments to pass to LLVM, similar to the `-C llvm-args` codegen option.
pub llvm_args: Vec<String>,
}

impl Default for TargetOptions {
Expand Down Expand Up @@ -893,6 +896,7 @@ impl Default for TargetOptions {
target_mcount: "mcount".to_string(),
llvm_abiname: "".to_string(),
relax_elf_relocations: false,
llvm_args: vec![],
}
}
}
Expand Down Expand Up @@ -1206,6 +1210,7 @@ impl Target {
key!(target_mcount);
key!(llvm_abiname);
key!(relax_elf_relocations, bool);
key!(llvm_args, list);

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

if default.abi_blacklist != self.options.abi_blacklist {
d.insert(
Expand Down