Skip to content

Commit 539de43

Browse files
committed
Allow specifying key "llvm-abiname" in target specification
This addresses #65024, as it allows RISC-V target specification files to set "llvm-abiname": "lp64d". In general, it is useful for the programmer to be able to set this codegen parameter, which other languages usually expose under a compiler argument like "-mabi=<XYZ>".
1 parent aa69777 commit 539de43

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

src/librustc_codegen_llvm/back/write.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ pub fn target_machine_factory(sess: &Session, optlvl: config::OptLevel, find_fea
161161
let cpu = SmallCStr::new(llvm_util::target_cpu(sess));
162162
let features = features.join(",");
163163
let features = CString::new(features).unwrap();
164+
let abi = SmallCStr::new(&sess.target.target.options.llvm_abiname);
164165
let is_pie_binary = !find_features && is_pie_binary(sess);
165166
let trap_unreachable = sess.target.target.options.trap_unreachable;
166167
let emit_stack_size_section = sess.opts.debugging_opts.emit_stack_sizes;
@@ -170,7 +171,7 @@ pub fn target_machine_factory(sess: &Session, optlvl: config::OptLevel, find_fea
170171
Arc::new(move || {
171172
let tm = unsafe {
172173
llvm::LLVMRustCreateTargetMachine(
173-
triple.as_ptr(), cpu.as_ptr(), features.as_ptr(),
174+
triple.as_ptr(), cpu.as_ptr(), features.as_ptr(), abi.as_ptr(),
174175
code_model,
175176
reloc_model,
176177
opt_level,

src/librustc_codegen_llvm/llvm/ffi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1684,6 +1684,7 @@ extern "C" {
16841684
pub fn LLVMRustCreateTargetMachine(Triple: *const c_char,
16851685
CPU: *const c_char,
16861686
Features: *const c_char,
1687+
Abi: *const c_char,
16871688
Model: CodeModel,
16881689
Reloc: RelocMode,
16891690
Level: CodeGenOptLevel,

src/librustc_target/spec/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,10 @@ pub struct TargetOptions {
793793
pub merge_functions: MergeFunctions,
794794

795795
/// Use platform dependent mcount function
796-
pub target_mcount: String
796+
pub target_mcount: String,
797+
798+
/// LLVM ABI name, corresponds to the '-mabi' parameter available in multilib C compilers
799+
pub llvm_abiname: String,
797800
}
798801

799802
impl Default for TargetOptions {
@@ -880,6 +883,7 @@ impl Default for TargetOptions {
880883
override_export_symbols: None,
881884
merge_functions: MergeFunctions::Aliases,
882885
target_mcount: "mcount".to_string(),
886+
llvm_abiname: "".to_string(),
883887
}
884888
}
885889
}
@@ -1196,6 +1200,7 @@ impl Target {
11961200
key!(override_export_symbols, opt_list);
11971201
key!(merge_functions, MergeFunctions)?;
11981202
key!(target_mcount);
1203+
key!(llvm_abiname);
11991204

12001205
if let Some(array) = obj.find("abi-blacklist").and_then(Json::as_array) {
12011206
for name in array.iter().filter_map(|abi| abi.as_string()) {
@@ -1414,6 +1419,7 @@ impl ToJson for Target {
14141419
target_option_val!(override_export_symbols);
14151420
target_option_val!(merge_functions);
14161421
target_option_val!(target_mcount);
1422+
target_option_val!(llvm_abiname);
14171423

14181424
if default.abi_blacklist != self.options.abi_blacklist {
14191425
d.insert("abi-blacklist".to_string(), self.options.abi_blacklist.iter()

src/rustllvm/PassWrapper.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ extern "C" const char* LLVMRustGetHostCPUName(size_t *len) {
343343

344344
extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
345345
const char *TripleStr, const char *CPU, const char *Feature,
346-
LLVMRustCodeModel RustCM, LLVMRustRelocMode RustReloc,
346+
const char *ABIStr, LLVMRustCodeModel RustCM, LLVMRustRelocMode RustReloc,
347347
LLVMRustCodeGenOptLevel RustOptLevel, bool UseSoftFloat,
348348
bool PositionIndependentExecutable, bool FunctionSections,
349349
bool DataSections,
@@ -374,6 +374,7 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
374374
Options.FunctionSections = FunctionSections;
375375
Options.MCOptions.AsmVerbose = AsmComments;
376376
Options.MCOptions.PreserveAsmComments = AsmComments;
377+
Options.MCOptions.ABIName = ABIStr;
377378

378379
if (TrapUnreachable) {
379380
// Tell LLVM to codegen `unreachable` into an explicit trap instruction.

0 commit comments

Comments
 (0)