Skip to content

Commit 7ca4fbd

Browse files
committed
WIP object reading
1 parent 0675c0e commit 7ca4fbd

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ im-rc = "15.0.0"
7777
# for more information.
7878
rustc-workspace-hack = "1.0.0"
7979

80+
[dependencies.object]
81+
version = "0.20.0"
82+
default-features = false
83+
features = ['read_core', 'elf', 'macho', 'pe', 'unaligned']
84+
8085
[target.'cfg(target_os = "macos")'.dependencies]
8186
core-foundation = { version = "0.9.0", features = ["mac_os_10_7_support"] }
8287

src/cargo/core/compiler/fingerprint.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1824,6 +1824,16 @@ fn find_stale_file(
18241824
}
18251825
format!("{:?}", hasher.result())
18261826
}
1827+
FileHashAlgorithm::SvhInBin => {
1828+
debug!("found! got here");
1829+
use object::Object;
1830+
let v : Vec<u8> = vec![];
1831+
let obj = object::read::File::parse(&v).unwrap();
1832+
for sym in obj.symbols() {
1833+
println!("{:#?}", sym);
1834+
}
1835+
"todo!".to_string()
1836+
}
18271837
FileHashAlgorithm::Filename => {
18281838
"0".to_string()
18291839
}
@@ -1859,6 +1869,7 @@ fn find_stale_file(
18591869
#[derive(Clone, Copy, Eq, PartialEq)]
18601870
pub enum FileHashAlgorithm {
18611871
Md5,
1872+
SvhInBin,
18621873
Sha1,
18631874
/// If the hash is in the filename then as long as the file exists we can
18641875
/// assume it is up to date.
@@ -1871,6 +1882,7 @@ impl FromStr for FileHashAlgorithm {
18711882
fn from_str(s: &str) -> Result<FileHashAlgorithm, ()> {
18721883
match s {
18731884
"md5" => Ok(FileHashAlgorithm::Md5),
1885+
"svh_in_bin" => Ok(FileHashAlgorithm::SvhInBin),
18741886
"sha1" => Ok(FileHashAlgorithm::Sha1),
18751887
"hash_in_filename" => Ok(FileHashAlgorithm::Filename),
18761888
_ => Err(()),
@@ -2025,6 +2037,7 @@ impl EncodedDepInfo {
20252037
0 => FileHashAlgorithm::Md5,
20262038
1 => FileHashAlgorithm::Sha1,
20272039
2 => FileHashAlgorithm::Filename,
2040+
3 => FileHashAlgorithm::SvhInBin,
20282041
_ => return None,
20292042
};
20302043
let ty = match read_u8(bytes)? {
@@ -2108,6 +2121,7 @@ impl EncodedDepInfo {
21082121
FileHashAlgorithm::Md5 => dst.push(0),
21092122
FileHashAlgorithm::Sha1 => dst.push(1),
21102123
FileHashAlgorithm::Filename => dst.push(2),
2124+
FileHashAlgorithm::SvhInBin => dst.push(3),
21112125
}
21122126
match ty {
21132127
DepInfoPathType::PackageRootRelative => dst.push(0),

src/cargo/core/compiler/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ fn build_base_args(
860860

861861
match cx.files().metadata(unit) {
862862
Some(m) => {
863+
println!("extra filename called {}", m);
863864
cmd.arg("-C").arg(&format!("metadata={}", m));
864865
cmd.arg("-C").arg(&format!("extra-filename=-{}", m));
865866
}

tests/testsuite/tool_paths.rs

+24
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,30 @@ fn pathless_tools() {
3232
.run();
3333
}
3434

35+
#[cargo_test]
36+
fn obj_test() {
37+
use object::Object;
38+
use object::ObjectSegment;
39+
use std::io::Read;
40+
use std::fs::File;
41+
42+
// let mut file = File::open("/Users/gilescope/projects/tst/target/debug/deps/libmydep2-244330a37db7aca2.rlib").unwrap();
43+
let mut file = File::open("/Users/gilescope/projects/tst/target/debug/deps/tst").unwrap();
44+
45+
let mut data = Vec::new();
46+
file.read_to_end(&mut data).unwrap();
47+
let obj = object::read::File::parse(&data).unwrap();
48+
for sym in obj.symbols() {
49+
println!("{:#?}", sym);
50+
}
51+
for seg in obj.segments() {//will be in __DATA seg for mach-o
52+
if let Ok(Some("__DATA")) = seg.name()
53+
{
54+
println!("{:#?}", seg);
55+
}
56+
}
57+
}
58+
3559
#[cargo_test]
3660
fn absolute_tools() {
3761
let target = rustc_host();

0 commit comments

Comments
 (0)