-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate relro-levels
, static-pie
to rmake
#126715
Merged
+126
−87
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6db3289
Add more flags for `llvm-readobj`
Rejyr 5a66a79
Add `stdin` to `run_make_support::command::Command`
Rejyr e16f492
Migrate `relro-levels` to `rmake`
Rejyr f90d4e4
Migrate `static-pie` to `rmake`
Rejyr c69770d
Migrate `static-pie` scripts to `rmake`
Rejyr a19077d
Enable cross compilation on `run-make/relro-levels`
Rejyr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 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,29 @@ | ||
// This tests the different -Crelro-level values, and makes sure that they work properly. | ||
|
||
//@ ignore-cross-compile | ||
//@ only-linux | ||
|
||
use run_make_support::llvm_readobj; | ||
use run_make_support::rustc; | ||
|
||
fn compile(relro_level: &str) { | ||
rustc().arg(format!("-Crelro-level={relro_level}")).input("hello.rs").run(); | ||
} | ||
|
||
fn main() { | ||
// Ensure that binaries built with the full relro level links them with both | ||
// RELRO and BIND_NOW for doing eager symbol resolving. | ||
|
||
compile("full"); | ||
llvm_readobj().program_headers().input("hello").run().assert_stdout_contains("GNU_RELRO"); | ||
llvm_readobj().dynamic_table().input("hello").run().assert_stdout_contains("BIND_NOW"); | ||
|
||
compile("partial"); | ||
llvm_readobj().program_headers().input("hello").run().assert_stdout_contains("GNU_RELRO"); | ||
|
||
// Ensure that we're *not* built with RELRO when setting it to off. We do | ||
// not want to check for BIND_NOW however, as the linker might have that | ||
// enabled by default. | ||
compile("off"); | ||
llvm_readobj().program_headers().input("hello").run().assert_stdout_not_contains("GNU_RELRO"); | ||
} |
This file was deleted.
Oops, something went wrong.
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,73 @@ | ||
// How to manually run this | ||
// $ ./x.py test --target x86_64-unknown-linux-[musl,gnu] tests/run-make/static-pie | ||
|
||
//@ only-x86_64 | ||
//@ only-linux | ||
//@ ignore-32bit | ||
|
||
use std::process::Command; | ||
|
||
use run_make_support::llvm_readobj; | ||
use run_make_support::regex::Regex; | ||
use run_make_support::rustc; | ||
use run_make_support::{cmd, run_with_args, target}; | ||
|
||
// Minimum major versions supporting -static-pie | ||
const GCC_VERSION: u32 = 8; | ||
const CLANG_VERSION: u32 = 9; | ||
|
||
// Return `true` if the `compiler` version supports `-static-pie`. | ||
fn ok_compiler_version(compiler: &str) -> bool { | ||
let (trigger, version_threshold) = match compiler { | ||
"clang" => ("__clang_major__", CLANG_VERSION), | ||
"gcc" => ("__GNUC__", GCC_VERSION), | ||
other => panic!("unexpected compiler '{other}', expected 'clang' or 'gcc'"), | ||
}; | ||
|
||
if Command::new(compiler).spawn().is_err() { | ||
jieyouxu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
eprintln!("No {compiler} version detected"); | ||
return false; | ||
} | ||
|
||
let compiler_output = | ||
cmd(compiler).stdin(trigger).arg("-").arg("-E").arg("-x").arg("c").run().stdout_utf8(); | ||
let re = Regex::new(r"(?m)^(\d+)").unwrap(); | ||
jieyouxu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let version: u32 = | ||
re.captures(&compiler_output).unwrap().get(1).unwrap().as_str().parse().unwrap(); | ||
|
||
if version >= version_threshold { | ||
eprintln!("{compiler} supports -static-pie"); | ||
true | ||
} else { | ||
eprintln!("{compiler} too old to support -static-pie, skipping test"); | ||
false | ||
} | ||
} | ||
|
||
fn test(compiler: &str) { | ||
if !ok_compiler_version(compiler) { | ||
return; | ||
} | ||
|
||
rustc() | ||
.input("test-aslr.rs") | ||
.target(&target()) | ||
.linker(compiler) | ||
.arg("-Clinker-flavor=gcc") | ||
.arg("-Ctarget-feature=+crt-static") | ||
.run(); | ||
|
||
llvm_readobj() | ||
.symbols() | ||
.input("test-aslr") | ||
.run() | ||
.assert_stdout_not_contains("INTERP") | ||
.assert_stdout_contains("DYNAMIC"); | ||
|
||
run_with_args("test-aslr", &["--test-aslr"]); | ||
} | ||
|
||
fn main() { | ||
test("clang"); | ||
test("gcc"); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: is ignoring cross-compilation load-bearing here? We can try to see if this test fails in cross-compiling CI jobs if you remove this for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: can you try removing this
//@ ignore-cross-compile
and we can run try jobs to check if that is needed.