@@ -3,12 +3,13 @@ mod def_visitor;
3
3
use std:: io:: Write ;
4
4
use std:: process:: Stdio ;
5
5
6
+ use object:: { Object , ObjectSection , ObjectSymbol } ;
6
7
use syn:: visit:: Visit ;
7
8
use syn:: Ident ;
8
9
9
10
use crate :: def_visitor:: { DefVisitor , LlvmIntrinsicDef } ;
10
11
11
- fn main ( ) {
12
+ fn compile_object ( ) {
12
13
println ! ( "Running rustc -Zunpretty=expanded --edition=2021 core_arch/src/lib.rs ..." ) ;
13
14
let expanded_file = std:: process:: Command :: new ( "rustc" )
14
15
. arg ( "-Zunpretty=expanded" )
@@ -89,12 +90,13 @@ fn main() {
89
90
println ! ( "Compiling blob" ) ;
90
91
let mut child = std:: process:: Command :: new ( "rustc" )
91
92
. arg ( "-Copt-level=3" )
93
+ . arg ( "-Cpanic=abort" )
92
94
. arg ( "--crate-type" )
93
95
. arg ( "cdylib" )
94
96
. arg ( "--emit=obj" )
95
97
//.arg("--target=x86_64-unknown-linux-gnu")
96
- . arg ( "--out-dir " )
97
- . arg ( "target" )
98
+ . arg ( "-o " )
99
+ . arg ( "target/rust_out.o " )
98
100
. arg ( "-" )
99
101
. stdin ( Stdio :: piped ( ) )
100
102
. spawn ( )
@@ -105,3 +107,39 @@ fn main() {
105
107
let status = child. wait ( ) . unwrap ( ) ;
106
108
assert ! ( status. success( ) , "{status}" ) ;
107
109
}
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