forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#127491 - Oneirical:bulletproof-test, r=jieyouxu Migrate 8 very similar FFI `run-make` tests to rmake Part of rust-lang#121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html). There are some more of these, but while the code is almost always the same, I want to keep the number reasonable so my doc comments can be inspected for potential inaccuracies. Tell me if 8 is too much, I can cut this down. For the tracking issue: - issue-25581 - extern-fn-with-extern-types - extern-fn-struct-passing-abi - longjmp-across-rust - static-extern-type - extern-fn-explicit-align - extern-fn-with-packed-struct - extern-fn-mangle
- Loading branch information
Showing
19 changed files
with
133 additions
and
56 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 was deleted.
Oops, something went wrong.
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,17 @@ | ||
// The compiler's rules of alignment for indirectly passed values in a 16-byte aligned argument, | ||
// in a C external function, used to be arbitrary. Unexpected behavior would occasionally occur | ||
// and cause memory corruption. This was fixed in #112157, streamlining the way alignment occurs, | ||
// and this test reproduces the case featured in the issue, checking that it compiles and executes | ||
// successfully. | ||
// See https://github.com/rust-lang/rust/issues/80127 | ||
|
||
//@ ignore-cross-compile | ||
// Reason: the compiled binary is executed | ||
|
||
use run_make_support::{build_native_static_lib, run, rustc}; | ||
|
||
fn main() { | ||
build_native_static_lib("test"); | ||
rustc().input("test.rs").run(); | ||
run("test"); | ||
} |
This file was deleted.
Oops, something went wrong.
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,16 @@ | ||
// In this test, the functions foo() and bar() must avoid being mangled, as | ||
// the external C function depends on them to return the correct sum of 3 + 5 = 8. | ||
// This test therefore checks that the compiled and executed program respects the | ||
// #[no_mangle] flags successfully. | ||
// See https://github.com/rust-lang/rust/pull/15831 | ||
|
||
//@ ignore-cross-compile | ||
// Reason: the compiled binary is executed | ||
|
||
use run_make_support::{build_native_static_lib, run, rustc}; | ||
|
||
fn main() { | ||
build_native_static_lib("test"); | ||
rustc().input("test.rs").run(); | ||
run("test"); | ||
} |
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,17 @@ | ||
// Slices were broken when implicated in foreign-function interface (FFI) with | ||
// a C library, with something as simple as measuring the length or returning | ||
// an item at a certain index of a slice would cause an internal compiler error (ICE). | ||
// This was fixed in #25653, and this test checks that slices in Rust-C FFI can be part | ||
// of a program that compiles and executes successfully. | ||
// See https://github.com/rust-lang/rust/issues/25581 | ||
|
||
//@ ignore-cross-compile | ||
// Reason: the compiled binary is executed | ||
|
||
use run_make_support::{build_native_static_lib, run, rustc}; | ||
|
||
fn main() { | ||
build_native_static_lib("test"); | ||
rustc().input("test.rs").run(); | ||
run("test"); | ||
} |
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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,16 @@ | ||
// Functions with more than 6 arguments using foreign function interfaces (FFI) with C libraries | ||
// would have their arguments unexpectedly swapped, causing unexpected behaviour in Rust-C FFI | ||
// programs. This test compiles and executes Rust code with bulky functions of up to 7 arguments | ||
// and uses assertions to check for unexpected swaps. | ||
// See https://github.com/rust-lang/rust/issues/25594 | ||
|
||
//@ ignore-cross-compile | ||
// Reason: the compiled binary is executed | ||
|
||
use run_make_support::{build_native_static_lib, run, rustc}; | ||
|
||
fn main() { | ||
build_native_static_lib("test"); | ||
rustc().input("test.rs").run(); | ||
run("test"); | ||
} |
This file was deleted.
Oops, something went wrong.
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,16 @@ | ||
// This test checks the functionality of foreign function interface (FFI) where Rust | ||
// must call upon a C library defining functions, where these functions also use custom | ||
// types defined by the C file. In addition to compilation being successful, the binary | ||
// should also successfully execute. | ||
// See https://github.com/rust-lang/rust/pull/44295 | ||
|
||
//@ ignore-cross-compile | ||
// Reason: the compiled binary is executed | ||
|
||
use run_make_support::{build_native_static_lib, run, rustc}; | ||
|
||
fn main() { | ||
build_native_static_lib("ctest"); | ||
rustc().input("test.rs").run(); | ||
run("test"); | ||
} |
This file was deleted.
Oops, something went wrong.
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,17 @@ | ||
// Packed structs, in C, occupy less bytes in memory, but are more | ||
// vulnerable to alignment errors. Passing them around in a Rust-C foreign | ||
// function interface (FFI) would cause unexpected behavior, until this was | ||
// fixed in #16584. This test checks that a Rust program with a C library | ||
// compiles and executes successfully, even with usage of a packed struct. | ||
// See https://github.com/rust-lang/rust/issues/16574 | ||
|
||
//@ ignore-cross-compile | ||
// Reason: the compiled binary is executed | ||
|
||
use run_make_support::{build_native_static_lib, run, rustc}; | ||
|
||
fn main() { | ||
build_native_static_lib("test"); | ||
rustc().input("test.rs").run(); | ||
run("test"); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,18 @@ | ||
// longjmp, an error handling function used in C, is useful | ||
// for jumping out of nested call chains... but it used to accidentally | ||
// trigger Rust's cleanup system in a way that caused an unexpected abortion | ||
// of the program. After this was fixed in #48572, this test compiles and executes | ||
// a program that jumps between Rust and its C library, with longjmp included. For | ||
// the test to succeed, no unexpected abortion should occur. | ||
// See https://github.com/rust-lang/rust/pull/48572 | ||
|
||
//@ ignore-cross-compile | ||
// Reason: the compiled binary is executed | ||
|
||
use run_make_support::{build_native_static_lib, run, rustc}; | ||
|
||
fn main() { | ||
build_native_static_lib("foo"); | ||
rustc().input("main.rs").run(); | ||
run("main"); | ||
} |
This file was deleted.
Oops, something went wrong.
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,16 @@ | ||
// Static variables coming from a C library through foreign function interface (FFI) are unsized | ||
// at compile time - and assuming they are sized used to cause an internal compiler error (ICE). | ||
// After this was fixed in #58192, this test checks that external statics can be safely used in | ||
// a program that both compiles and executes successfully. | ||
// See https://github.com/rust-lang/rust/issues/57876 | ||
|
||
//@ ignore-cross-compile | ||
// Reason: the compiled binary is executed | ||
|
||
use run_make_support::{build_native_static_lib, run, rustc}; | ||
|
||
fn main() { | ||
build_native_static_lib("define-foo"); | ||
rustc().arg("-ldefine-foo").input("use-foo.rs").run(); | ||
run("use-foo"); | ||
} |