-
Notifications
You must be signed in to change notification settings - Fork 13.4k
tests: Port symbol-mangling-hashed
to rmake.rs
#135768
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
Merged
bors
merged 5 commits into
rust-lang:master
from
jieyouxu:migrate-symbol-mangling-hashed
Feb 1, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
09f6848
run-make-support: add `-Csymbol-mangling-version` and `-Cprefer-dynam…
jieyouxu 17e0fc6
run-make-support: collapse re-export
jieyouxu c15c970
run-make-support: add `is_windows_gnu` helper
jieyouxu 0bc1b4f
run-make-support: add `object`-based symbol helpers
jieyouxu 9734ebb
tests: port `symbol-mangling-hashed` to rmake.rs
jieyouxu 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,2 +1 @@ | ||
run-make/split-debuginfo/Makefile | ||
run-make/symbol-mangling-hashed/Makefile |
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 hidden or 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,9 @@ | ||
extern crate default_dylib; | ||
extern crate hashed_dylib; | ||
extern crate hashed_rlib; | ||
|
||
fn main() { | ||
hashed_rlib::hrhello(); | ||
hashed_dylib::hdhello(); | ||
default_dylib::ddhello(); | ||
} |
This file contains hidden or 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,9 @@ | ||
#![crate_type = "dylib"] | ||
|
||
extern crate hashed_dylib; | ||
extern crate hashed_rlib; | ||
|
||
pub fn ddhello() { | ||
hashed_rlib::hrhello(); | ||
hashed_dylib::hdhello(); | ||
} |
2 changes: 1 addition & 1 deletion
2
...un-make/symbol-mangling-hashed/a_dylib.rs → ...ke/symbol-mangling-hashed/hashed_dylib.rs
This file contains hidden or 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#![crate_type = "dylib"] | ||
pub fn hello() { | ||
pub fn hdhello() { | ||
println!("hello dylib"); | ||
} |
2 changes: 1 addition & 1 deletion
2
...run-make/symbol-mangling-hashed/a_rlib.rs → ...ake/symbol-mangling-hashed/hashed_rlib.rs
This file contains hidden or 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#![crate_type = "rlib"] | ||
|
||
pub fn hello() { | ||
pub fn hrhello() { | ||
println!("hello rlib"); | ||
} |
This file contains hidden or 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,108 @@ | ||
// ignore-tidy-linelength | ||
//! Basic smoke test for the unstable option `-C symbol_mangling_version=hashed` which aims to | ||
//! replace full symbol mangling names based on hash digests to shorten symbol name lengths in | ||
//! dylibs for space savings. | ||
//! | ||
//! # References | ||
//! | ||
//! - MCP #705: Provide option to shorten symbol names by replacing them with a digest: | ||
//! <https://github.com/rust-lang/compiler-team/issues/705>. | ||
//! - Implementation PR: <https://github.com/rust-lang/rust/pull/118636>. | ||
//! - PE format: <https://learn.microsoft.com/en-us/windows/win32/debug/pe-format>. | ||
|
||
//@ ignore-cross-compile | ||
|
||
#![deny(warnings)] | ||
|
||
use run_make_support::symbols::exported_dynamic_symbol_names; | ||
use run_make_support::{bin_name, cwd, dynamic_lib_name, is_darwin, object, rfs, run, rustc}; | ||
|
||
macro_rules! adjust_symbol_prefix { | ||
($name:literal) => { | ||
if is_darwin() { concat!("_", $name) } else { $name } | ||
}; | ||
} | ||
|
||
fn main() { | ||
rustc() | ||
.input("hashed_dylib.rs") | ||
.prefer_dynamic() | ||
.arg("-Zunstable-options") | ||
.symbol_mangling_version("hashed") | ||
.metadata("foo") | ||
.run(); | ||
|
||
rustc() | ||
.input("hashed_rlib.rs") | ||
.prefer_dynamic() | ||
.arg("-Zunstable-options") | ||
.symbol_mangling_version("hashed") | ||
.metadata("bar") | ||
.run(); | ||
|
||
rustc().input("default_dylib.rs").library_search_path(cwd()).prefer_dynamic().run(); | ||
rustc().input("default_bin.rs").library_search_path(cwd()).prefer_dynamic().run(); | ||
|
||
{ | ||
// Check hashed symbol name | ||
|
||
let dylib_filename = dynamic_lib_name("hashed_dylib"); | ||
println!("checking dylib `{dylib_filename}`"); | ||
|
||
let dylib_blob = rfs::read(&dylib_filename); | ||
let dylib_file = object::File::parse(&*dylib_blob) | ||
.unwrap_or_else(|e| panic!("failed to parse `{dylib_filename}`: {e}")); | ||
|
||
let dynamic_symbols = exported_dynamic_symbol_names(&dylib_file); | ||
|
||
if dynamic_symbols.iter().filter(|sym| sym.contains("hdhello")).count() != 0 { | ||
eprintln!("exported dynamic symbols: {:#?}", dynamic_symbols); | ||
panic!("expected no occurrence of `hdhello`"); | ||
} | ||
|
||
let expected_prefix = adjust_symbol_prefix!("_RNxC12hashed_dylib"); | ||
if dynamic_symbols.iter().filter(|sym| sym.starts_with(expected_prefix)).count() != 2 { | ||
eprintln!("exported dynamic symbols: {:#?}", dynamic_symbols); | ||
panic!("expected two dynamic symbols starting with `{expected_prefix}`"); | ||
} | ||
} | ||
|
||
{ | ||
let dylib_filename = dynamic_lib_name("default_dylib"); | ||
println!("checking so `{dylib_filename}`"); | ||
|
||
let dylib_blob = rfs::read(&dylib_filename); | ||
let dylib_file = object::File::parse(&*dylib_blob) | ||
.unwrap_or_else(|e| panic!("failed to parse `{dylib_filename}`: {e}")); | ||
|
||
let dynamic_symbols = exported_dynamic_symbol_names(&dylib_file); | ||
|
||
if dynamic_symbols | ||
.iter() | ||
.filter(|sym| sym.contains("default_dylib") && sym.contains("ddhello")) | ||
.count() | ||
!= 1 | ||
{ | ||
eprintln!("exported dynamic symbols: {:#?}", dynamic_symbols); | ||
panic!("expected one occurrence of mangled `ddhello`"); | ||
} | ||
|
||
let expected_rlib_prefix = adjust_symbol_prefix!("_RNxC11hashed_rlib"); | ||
if dynamic_symbols.iter().filter(|sym| sym.starts_with(expected_rlib_prefix)).count() != 2 { | ||
eprintln!("exported dynamic symbols: {:#?}", dynamic_symbols); | ||
panic!("expected two exported symbols starting with `{expected_rlib_prefix}`"); | ||
} | ||
|
||
let expected_dylib_prefix = adjust_symbol_prefix!("_RNxC12hashed_dylib"); | ||
if dynamic_symbols.iter().any(|sym| sym.starts_with("_RNxC12hashed_dylib")) { | ||
eprintln!("exported dynamic symbols: {:#?}", dynamic_symbols); | ||
panic!("did not expect any symbols starting with `{expected_dylib_prefix}`"); | ||
} | ||
} | ||
|
||
// Check that the final binary can be run. | ||
{ | ||
let bin_filename = bin_name("default_bin"); | ||
run(&bin_filename); | ||
} | ||
jieyouxu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.