Skip to content

Commit 3dfd8f7

Browse files
committedDec 7, 2018
codegen: Fix va_list - aaarch64 iOS/Windows
According to the Apple developer docs: > The type va_list is an alias for char * rather than for the struct > type specified in the generic PCS. The current implementation uses the generic Aarch64 structure for VaList for Aarch64 iOS. Windows always uses the char * variant of the va_list.

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed
 

‎src/libcore/ffi.rs

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ impl fmt::Debug for c_void {
4545
/// Basic implementation of a `va_list`.
4646
#[cfg(any(all(not(target_arch = "aarch64"), not(target_arch = "powerpc"),
4747
not(target_arch = "x86_64")),
48+
all(target_arch = "aarch4", target_os = "ios"),
4849
windows))]
4950
#[unstable(feature = "c_variadic",
5051
reason = "the `c_variadic` feature has not been properly tested on \
@@ -192,6 +193,7 @@ impl<'a> VaList<'a> {
192193
where F: for<'copy> FnOnce(VaList<'copy>) -> R {
193194
#[cfg(any(all(not(target_arch = "aarch64"), not(target_arch = "powerpc"),
194195
not(target_arch = "x86_64")),
196+
all(target_arch = "aarch4", target_os = "ios"),
195197
windows))]
196198
let mut ap = va_copy(self);
197199
#[cfg(all(any(target_arch = "aarch64", target_arch = "powerpc", target_arch = "x86_64"),

‎src/librustc_codegen_llvm/va_arg.rs

+26-10
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,30 @@ pub(super) fn emit_va_arg(
105105
) -> &'ll Value {
106106
// Determine the va_arg implementation to use. The LLVM va_arg instruction
107107
// is lacking in some instances, so we should only use it as a fallback.
108+
let target = &bx.cx.tcx.sess.target.target;
108109
let arch = &bx.cx.tcx.sess.target.target.arch;
109-
match (&**arch,
110-
bx.cx.tcx.sess.target.target.options.is_like_windows) {
110+
match (&**arch, target.options.is_like_windows) {
111+
// Windows x86
111112
("x86", true) => {
112113
emit_ptr_va_arg(bx, addr, target_ty, false,
113114
Align::from_bytes(4).unwrap(), false)
114115
}
116+
// Generic x86
117+
("x86", _) => {
118+
emit_ptr_va_arg(bx, addr, target_ty, false,
119+
Align::from_bytes(4).unwrap(), true)
120+
}
121+
// Windows Aarch64
122+
("aarch4", true) => {
123+
emit_ptr_va_arg(bx, addr, target_ty, false,
124+
Align::from_bytes(8).unwrap(), false)
125+
}
126+
// iOS Aarch64
127+
("aarch4", _) if target.target_os == "ios" => {
128+
emit_ptr_va_arg(bx, addr, target_ty, false,
129+
Align::from_bytes(8).unwrap(), true)
130+
}
131+
// Windows x86_64
115132
("x86_64", true) => {
116133
let target_ty_size = bx.cx.size_of(target_ty).bytes();
117134
let indirect = if target_ty_size > 8 || !target_ty_size.is_power_of_two() {
@@ -122,15 +139,14 @@ pub(super) fn emit_va_arg(
122139
emit_ptr_va_arg(bx, addr, target_ty, indirect,
123140
Align::from_bytes(8).unwrap(), false)
124141
}
125-
("x86", false) => {
126-
emit_ptr_va_arg(bx, addr, target_ty, false,
127-
Align::from_bytes(4).unwrap(), true)
128-
}
142+
// For all other architecture/OS combinations fall back to using
143+
// the LLVM va_arg instruction.
144+
// https://llvm.org/docs/LangRef.html#va-arg-instruction
129145
_ => {
130-
let va_list = if (bx.tcx().sess.target.target.arch == "aarch64" ||
131-
bx.tcx().sess.target.target.arch == "x86_64" ||
132-
bx.tcx().sess.target.target.arch == "powerpc") &&
133-
!bx.tcx().sess.target.target.options.is_like_windows {
146+
let va_list = if (target.arch == "aarch64" ||
147+
target.arch == "x86_64" ||
148+
target.arch == "powerpc") &&
149+
!target.options.is_like_windows {
134150
bx.load(addr.immediate(), bx.tcx().data_layout.pointer_align.abi)
135151
} else {
136152
addr.immediate()

0 commit comments

Comments
 (0)
Please sign in to comment.