You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Segfault when using C compatible variadic functions #58980
Compiling and running in release mode causes a segfault in glibc/stdio-common/vfprintf.c:1286 because ap is nul. Enabling debug info in release mode via Cargo.toml makes the segfault go away.
@thedataking thanks for reporting this. The example should probably look more like the following. The example still segfaults (even in debug mode).
#![feature(c_variadic)]use std::ffi::VaList;extern"C"{// vprintf signature is `int vprintf(const char * format, va_list arg)`#[no_mangle]fnvprintf(_:*const libc::c_char, _:VaList) -> libc::c_int;}#[no_mangle]unsafeextern"C"fnvariadic(fmt:*const libc::c_char, a: ...) -> libc::c_int{// `va_start` in theory should be automatically called giving you a// `VaList` at `a` here.vprintf(fmt, a)// `va_end` should be called here.}fnmain(){let fmt = std::ffi::CString::new("test %d %d %d\n").expect("new failed");unsafe{variadic(fmt.as_ptr(),1,2,3);}}
If a is used in the function variadic the issue does not happen. Essentially we're optimizing variadic to the following
Activity
dlrobertson commentedon Mar 7, 2019
@thedataking thanks for reporting this. The example should probably look more like the following. The example still segfaults (even in debug mode).
If
ais used in the functionvariadicthe issue does not happen. Essentially we're optimizingvariadicto the followingNote the missing
va_startandva_end. I think this is happening because we're hitting src/librustc_codegen_ssa/mir/mod.rs:536-540. I'll do some more investigation shortly.dlrobertson commentedon Mar 7, 2019
@thedataking the code I list in the above example should work after #58985 is merged.
Auto merge of #58985 - dlrobertson:fix_58980, r=alexreg