forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix segfaults in release build C-variadic fns
`va_start` and `va_end` must be called to initialize/cleanup the "spoofed" `VaList` in a Rust defined C-variadic function even if the `VaList` is not used.
- Loading branch information
1 parent
f22dca0
commit 1d72037
Showing
3 changed files
with
27 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// compile-flags: -C opt-level=3 | ||
|
||
#![crate_type = "lib"] | ||
#![feature(c_variadic)] | ||
#![no_std] | ||
use core::ffi::VaList; | ||
|
||
extern "C" { | ||
fn vprintf(fmt: *const i8, ap: VaList) -> i32; | ||
} | ||
|
||
// Ensure that `va_start` and `va_end` are properly injected even | ||
// when the "spoofed" `VaList` is not used. | ||
#[no_mangle] | ||
pub unsafe extern "C" fn c_variadic_no_use(fmt: *const i8, mut ap: ...) -> i32 { | ||
// CHECK: call void @llvm.va_start | ||
vprintf(fmt, ap) | ||
// CHECK: call void @llvm.va_end | ||
} |