Skip to content

Commit a800a05

Browse files
kelnosjothanplietar
authored and
gitbot
committed
Teach rust core about Xtensa VaListImpl and add a custom lowering of vaarg for xtensa.
LLVM does not include an implementation of the va_arg instruction for Xtensa. From what I understand, this is a conscious decision and instead language frontends are encouraged to implement it themselves. The rationale seems to be that loading values correctly requires language and ABI-specific knowledge that LLVM lacks. This is true of most architectures, and rustc already provides implementation for a number of them. This commit extends the support to include Xtensa. See https://lists.llvm.org/pipermail/llvm-dev/2017-August/116337.html for some discussion on the topic. Unfortunately there does not seem to be a reference document for the semantics of the va_list and va_arg on Xtensa. The most reliable source is the GCC implementation, which this commit tries to follow. Clang also provides its own compatible implementation. This was tested for all the types that rustc allows in variadics. Co-authored-by: Brian Tarricone <[email protected]> Co-authored-by: Jonathan Bastien-Filiatrault <[email protected]> Co-authored-by: Paul Lietar <[email protected]>
1 parent be1d244 commit a800a05

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

core/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ check-cfg = [
4343
'cfg(bootstrap)',
4444
'cfg(no_fp_fmt_parse)',
4545
'cfg(stdarch_intel_sde)',
46+
'cfg(target_arch, values("xtensa"))',
4647
# core use #[path] imports to portable-simd `core_simd` crate
4748
# and to stdarch `core_arch` crate which messes-up with Cargo list
4849
# of declared features, we therefor expect any feature cfg

core/src/ffi/va_list.rs

+19
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::ops::{Deref, DerefMut};
1515
not(target_arch = "aarch64"),
1616
not(target_arch = "powerpc"),
1717
not(target_arch = "s390x"),
18+
not(target_arch = "xtensa"),
1819
not(target_arch = "x86_64")
1920
),
2021
all(target_arch = "aarch64", target_vendor = "apple"),
@@ -37,6 +38,7 @@ pub struct VaListImpl<'f> {
3738
not(target_arch = "aarch64"),
3839
not(target_arch = "powerpc"),
3940
not(target_arch = "s390x"),
41+
not(target_arch = "xtensa"),
4042
not(target_arch = "x86_64")
4143
),
4244
all(target_arch = "aarch64", target_vendor = "apple"),
@@ -113,6 +115,18 @@ pub struct VaListImpl<'f> {
113115
_marker: PhantomData<&'f mut &'f c_void>,
114116
}
115117

118+
/// Xtensa ABI implementation of a `va_list`.
119+
#[cfg(target_arch = "xtensa")]
120+
#[repr(C)]
121+
#[derive(Debug)]
122+
#[lang = "va_list"]
123+
pub struct VaListImpl<'f> {
124+
stk: *mut i32,
125+
reg: *mut i32,
126+
ndx: i32,
127+
_marker: PhantomData<&'f mut &'f c_void>,
128+
}
129+
116130
/// A wrapper for a `va_list`
117131
#[repr(transparent)]
118132
#[derive(Debug)]
@@ -124,6 +138,7 @@ pub struct VaList<'a, 'f: 'a> {
124138
not(target_arch = "s390x"),
125139
not(target_arch = "x86_64")
126140
),
141+
target_arch = "xtensa",
127142
all(target_arch = "aarch64", target_vendor = "apple"),
128143
target_family = "wasm",
129144
target_os = "uefi",
@@ -138,6 +153,7 @@ pub struct VaList<'a, 'f: 'a> {
138153
target_arch = "s390x",
139154
target_arch = "x86_64"
140155
),
156+
not(target_arch = "xtensa"),
141157
any(not(target_arch = "aarch64"), not(target_vendor = "apple")),
142158
not(target_family = "wasm"),
143159
not(target_os = "uefi"),
@@ -155,6 +171,7 @@ pub struct VaList<'a, 'f: 'a> {
155171
not(target_arch = "s390x"),
156172
not(target_arch = "x86_64")
157173
),
174+
target_arch = "xtensa",
158175
all(target_arch = "aarch64", target_vendor = "apple"),
159176
target_family = "wasm",
160177
target_os = "uefi",
@@ -173,8 +190,10 @@ impl<'f> VaListImpl<'f> {
173190
target_arch = "aarch64",
174191
target_arch = "powerpc",
175192
target_arch = "s390x",
193+
target_arch = "xtensa",
176194
target_arch = "x86_64"
177195
),
196+
not(target_arch = "xtensa"),
178197
any(not(target_arch = "aarch64"), not(target_vendor = "apple")),
179198
not(target_family = "wasm"),
180199
not(target_os = "uefi"),

0 commit comments

Comments
 (0)