Skip to content

Commit 6d3a168

Browse files
committed
[WIP]
1 parent 93a86b8 commit 6d3a168

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

gen_intrinsics/Cargo.lock

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen_intrinsics/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ proc-macro2 = "1.0.84"
1111
quote = "1.0.36"
1212
syn = { version = "2.0.66", features = ["full", "visit", "extra-traits"] }
1313

14+
object = { version = "0.36", default-features = false, features = ["read", "std"] }
15+
1416
[features]
1517
unstable-features = [] # for rust-analyzer

gen_intrinsics/src/main.rs

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ mod def_visitor;
33
use std::io::Write;
44
use std::process::Stdio;
55

6+
use object::{Object, ObjectSection, ObjectSymbol};
67
use syn::visit::Visit;
78
use syn::Ident;
89

910
use crate::def_visitor::{DefVisitor, LlvmIntrinsicDef};
1011

11-
fn main() {
12+
fn compile_object() {
1213
println!("Running rustc -Zunpretty=expanded --edition=2021 core_arch/src/lib.rs ...");
1314
let expanded_file = std::process::Command::new("rustc")
1415
.arg("-Zunpretty=expanded")
@@ -89,12 +90,13 @@ fn main() {
8990
println!("Compiling blob");
9091
let mut child = std::process::Command::new("rustc")
9192
.arg("-Copt-level=3")
93+
.arg("-Cpanic=abort")
9294
.arg("--crate-type")
9395
.arg("cdylib")
9496
.arg("--emit=obj")
9597
//.arg("--target=x86_64-unknown-linux-gnu")
96-
.arg("--out-dir")
97-
.arg("target")
98+
.arg("-o")
99+
.arg("target/rust_out.o")
98100
.arg("-")
99101
.stdin(Stdio::piped())
100102
.spawn()
@@ -105,3 +107,39 @@ fn main() {
105107
let status = child.wait().unwrap();
106108
assert!(status.success(), "{status}");
107109
}
110+
111+
fn main() {
112+
if
113+
/*true || // */
114+
false {
115+
compile_object();
116+
}
117+
118+
let obj = std::fs::read("target/rust_out.o").unwrap();
119+
let obj = object::File::parse(&*obj).unwrap();
120+
121+
let imports = obj.symbols().filter(|sym| sym.is_undefined()).collect::<Vec<_>>();
122+
assert!(imports.is_empty(), "{imports:?}");
123+
124+
for section in obj.sections() {
125+
let section_name = section.name().unwrap();
126+
if !section_name.starts_with(".text") {
127+
continue;
128+
}
129+
130+
if section_name == ".text" {
131+
assert_eq!(section.size(), 0);
132+
continue;
133+
}
134+
135+
let name = section_name.strip_prefix(".text.__rust_cranelift_").unwrap().replace("__", ".");
136+
137+
// Sanity checks
138+
assert!(section.relocations().next().is_none(), "function {name} has relocations");
139+
assert!(
140+
section.size() <= 0x14,
141+
"function {name} is too big. it is {} bytes",
142+
section.size(),
143+
);
144+
}
145+
}

0 commit comments

Comments
 (0)