Skip to content

Commit

Permalink
WIP object reading
Browse files Browse the repository at this point in the history
  • Loading branch information
gilescope committed Oct 29, 2020
1 parent 0675c0e commit 7ca4fbd
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ im-rc = "15.0.0"
# for more information.
rustc-workspace-hack = "1.0.0"

[dependencies.object]
version = "0.20.0"
default-features = false
features = ['read_core', 'elf', 'macho', 'pe', 'unaligned']

[target.'cfg(target_os = "macos")'.dependencies]
core-foundation = { version = "0.9.0", features = ["mac_os_10_7_support"] }

Expand Down
14 changes: 14 additions & 0 deletions src/cargo/core/compiler/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1824,6 +1824,16 @@ fn find_stale_file(
}
format!("{:?}", hasher.result())
}
FileHashAlgorithm::SvhInBin => {
debug!("found! got here");
use object::Object;
let v : Vec<u8> = vec![];
let obj = object::read::File::parse(&v).unwrap();
for sym in obj.symbols() {
println!("{:#?}", sym);
}
"todo!".to_string()
}
FileHashAlgorithm::Filename => {
"0".to_string()
}
Expand Down Expand Up @@ -1859,6 +1869,7 @@ fn find_stale_file(
#[derive(Clone, Copy, Eq, PartialEq)]
pub enum FileHashAlgorithm {
Md5,
SvhInBin,
Sha1,
/// If the hash is in the filename then as long as the file exists we can
/// assume it is up to date.
Expand All @@ -1871,6 +1882,7 @@ impl FromStr for FileHashAlgorithm {
fn from_str(s: &str) -> Result<FileHashAlgorithm, ()> {
match s {
"md5" => Ok(FileHashAlgorithm::Md5),
"svh_in_bin" => Ok(FileHashAlgorithm::SvhInBin),
"sha1" => Ok(FileHashAlgorithm::Sha1),
"hash_in_filename" => Ok(FileHashAlgorithm::Filename),
_ => Err(()),
Expand Down Expand Up @@ -2025,6 +2037,7 @@ impl EncodedDepInfo {
0 => FileHashAlgorithm::Md5,
1 => FileHashAlgorithm::Sha1,
2 => FileHashAlgorithm::Filename,
3 => FileHashAlgorithm::SvhInBin,
_ => return None,
};
let ty = match read_u8(bytes)? {
Expand Down Expand Up @@ -2108,6 +2121,7 @@ impl EncodedDepInfo {
FileHashAlgorithm::Md5 => dst.push(0),
FileHashAlgorithm::Sha1 => dst.push(1),
FileHashAlgorithm::Filename => dst.push(2),
FileHashAlgorithm::SvhInBin => dst.push(3),
}
match ty {
DepInfoPathType::PackageRootRelative => dst.push(0),
Expand Down
1 change: 1 addition & 0 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,7 @@ fn build_base_args(

match cx.files().metadata(unit) {
Some(m) => {
println!("extra filename called {}", m);
cmd.arg("-C").arg(&format!("metadata={}", m));
cmd.arg("-C").arg(&format!("extra-filename=-{}", m));
}
Expand Down
24 changes: 24 additions & 0 deletions tests/testsuite/tool_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,30 @@ fn pathless_tools() {
.run();
}

#[cargo_test]
fn obj_test() {
use object::Object;
use object::ObjectSegment;
use std::io::Read;
use std::fs::File;

// let mut file = File::open("/Users/gilescope/projects/tst/target/debug/deps/libmydep2-244330a37db7aca2.rlib").unwrap();
let mut file = File::open("/Users/gilescope/projects/tst/target/debug/deps/tst").unwrap();

let mut data = Vec::new();
file.read_to_end(&mut data).unwrap();
let obj = object::read::File::parse(&data).unwrap();
for sym in obj.symbols() {
println!("{:#?}", sym);
}
for seg in obj.segments() {//will be in __DATA seg for mach-o
if let Ok(Some("__DATA")) = seg.name()
{
println!("{:#?}", seg);
}
}
}

#[cargo_test]
fn absolute_tools() {
let target = rustc_host();
Expand Down

0 comments on commit 7ca4fbd

Please sign in to comment.