Skip to content

Commit e0117fe

Browse files
committed
Auto merge of #105381 - uweigand:s390x-ffi-vaarg, r=nikic
Implement va_list and va_arg for s390x FFI Following the s390x ELF ABI and based on the clang implementation, provide appropriate definitions of va_list in library/core/src/ffi/mod.rs and va_arg handling in compiler/rustc_codegen_llvm/src/va_arg.rs. Fixes the following test cases on s390x: src/test/run-make-fulldeps/c-link-to-rust-va-list-fn src/test/ui/abi/variadic-ffi.rs Fixes rust-lang/rust#84628.
2 parents 2d171bc + b3d2d98 commit e0117fe

File tree

1 file changed

+50
-5
lines changed

1 file changed

+50
-5
lines changed

core/src/ffi/mod.rs

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,12 @@ impl fmt::Debug for c_void {
227227
/// Basic implementation of a `va_list`.
228228
// The name is WIP, using `VaListImpl` for now.
229229
#[cfg(any(
230-
all(not(target_arch = "aarch64"), not(target_arch = "powerpc"), not(target_arch = "x86_64")),
230+
all(
231+
not(target_arch = "aarch64"),
232+
not(target_arch = "powerpc"),
233+
not(target_arch = "s390x"),
234+
not(target_arch = "x86_64")
235+
),
231236
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")),
232237
target_family = "wasm",
233238
target_arch = "asmjs",
@@ -251,7 +256,12 @@ pub struct VaListImpl<'f> {
251256
}
252257

253258
#[cfg(any(
254-
all(not(target_arch = "aarch64"), not(target_arch = "powerpc"), not(target_arch = "x86_64")),
259+
all(
260+
not(target_arch = "aarch64"),
261+
not(target_arch = "powerpc"),
262+
not(target_arch = "s390x"),
263+
not(target_arch = "x86_64")
264+
),
255265
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")),
256266
target_family = "wasm",
257267
target_arch = "asmjs",
@@ -319,6 +329,25 @@ pub struct VaListImpl<'f> {
319329
_marker: PhantomData<&'f mut &'f c_void>,
320330
}
321331

332+
/// s390x ABI implementation of a `va_list`.
333+
#[cfg(target_arch = "s390x")]
334+
#[repr(C)]
335+
#[derive(Debug)]
336+
#[unstable(
337+
feature = "c_variadic",
338+
reason = "the `c_variadic` feature has not been properly tested on \
339+
all supported platforms",
340+
issue = "44930"
341+
)]
342+
#[lang = "va_list"]
343+
pub struct VaListImpl<'f> {
344+
gpr: i64,
345+
fpr: i64,
346+
overflow_arg_area: *mut c_void,
347+
reg_save_area: *mut c_void,
348+
_marker: PhantomData<&'f mut &'f c_void>,
349+
}
350+
322351
/// x86_64 ABI implementation of a `va_list`.
323352
#[cfg(all(target_arch = "x86_64", not(target_os = "uefi"), not(windows)))]
324353
#[repr(C)]
@@ -352,6 +381,7 @@ pub struct VaList<'a, 'f: 'a> {
352381
all(
353382
not(target_arch = "aarch64"),
354383
not(target_arch = "powerpc"),
384+
not(target_arch = "s390x"),
355385
not(target_arch = "x86_64")
356386
),
357387
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")),
@@ -363,7 +393,12 @@ pub struct VaList<'a, 'f: 'a> {
363393
inner: VaListImpl<'f>,
364394

365395
#[cfg(all(
366-
any(target_arch = "aarch64", target_arch = "powerpc", target_arch = "x86_64"),
396+
any(
397+
target_arch = "aarch64",
398+
target_arch = "powerpc",
399+
target_arch = "s390x",
400+
target_arch = "x86_64"
401+
),
367402
any(not(target_arch = "aarch64"), not(any(target_os = "macos", target_os = "ios"))),
368403
not(target_family = "wasm"),
369404
not(target_arch = "asmjs"),
@@ -376,7 +411,12 @@ pub struct VaList<'a, 'f: 'a> {
376411
}
377412

378413
#[cfg(any(
379-
all(not(target_arch = "aarch64"), not(target_arch = "powerpc"), not(target_arch = "x86_64")),
414+
all(
415+
not(target_arch = "aarch64"),
416+
not(target_arch = "powerpc"),
417+
not(target_arch = "s390x"),
418+
not(target_arch = "x86_64")
419+
),
380420
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")),
381421
target_family = "wasm",
382422
target_arch = "asmjs",
@@ -398,7 +438,12 @@ impl<'f> VaListImpl<'f> {
398438
}
399439

400440
#[cfg(all(
401-
any(target_arch = "aarch64", target_arch = "powerpc", target_arch = "x86_64"),
441+
any(
442+
target_arch = "aarch64",
443+
target_arch = "powerpc",
444+
target_arch = "s390x",
445+
target_arch = "x86_64"
446+
),
402447
any(not(target_arch = "aarch64"), not(any(target_os = "macos", target_os = "ios"))),
403448
not(target_family = "wasm"),
404449
not(target_arch = "asmjs"),

0 commit comments

Comments
 (0)