1
1
//! Disassembly calling function for most targets.
2
2
3
3
use crate :: Function ;
4
- use std:: { collections:: HashSet , env, process :: Command , str} ;
4
+ use std:: { collections:: HashSet , env, str} ;
5
5
6
6
// Extracts the "shim" name from the `symbol`.
7
7
fn normalize ( mut symbol : & str ) -> String {
@@ -39,10 +39,11 @@ fn normalize(mut symbol: &str) -> String {
39
39
symbol
40
40
}
41
41
42
+ #[ cfg( windows) ]
42
43
pub ( crate ) fn disassemble_myself ( ) -> HashSet < Function > {
43
44
let me = env:: current_exe ( ) . expect ( "failed to get current exe" ) ;
44
45
45
- let disassembly = if cfg ! ( target_os = "windows" ) && cfg ! ( target_env = "msvc" ) {
46
+ let disassembly = if cfg ! ( target_env = "msvc" ) {
46
47
let target = if cfg ! ( target_arch = "x86_64" ) {
47
48
"x86_64-pc-windows-msvc"
48
49
} else if cfg ! ( target_arch = "x86" ) {
@@ -65,32 +66,39 @@ pub(crate) fn disassemble_myself() -> HashSet<Function> {
65
66
assert ! ( output. status. success( ) ) ;
66
67
// Windows does not return valid UTF-8 output:
67
68
String :: from_utf8_lossy ( Vec :: leak ( output. stdout ) )
68
- } else if cfg ! ( target_os = "windows" ) {
69
- panic ! ( "disassembly unimplemented" )
70
69
} else {
71
- let objdump = env:: var ( "OBJDUMP" ) . unwrap_or_else ( |_| "objdump" . to_string ( ) ) ;
72
- let add_args = if cfg ! ( target_os = "macos" ) && cfg ! ( target_arch = "aarch64" ) {
73
- // Target features need to be enabled for LLVM objdump on Macos ARM64
74
- vec ! [ "--mattr=+v8.6a,+crypto,+tme" ]
75
- } else {
76
- vec ! [ ]
77
- } ;
78
- let output = Command :: new ( objdump. clone ( ) )
79
- . arg ( "--disassemble" )
80
- . arg ( "--no-show-raw-insn" )
81
- . args ( add_args)
82
- . arg ( & me)
83
- . output ( )
84
- . unwrap_or_else ( |_| panic ! ( "failed to execute objdump. OBJDUMP={objdump}" ) ) ;
85
- println ! (
86
- "{}\n {}" ,
87
- output. status,
88
- String :: from_utf8_lossy( & output. stderr)
89
- ) ;
90
- assert ! ( output. status. success( ) ) ;
70
+ panic ! ( "disassembly unimplemented" )
71
+ } ;
91
72
92
- String :: from_utf8_lossy ( Vec :: leak ( output. stdout ) )
73
+ parse ( & disassembly)
74
+ }
75
+
76
+ #[ cfg( not( windows) ) ]
77
+ pub ( crate ) fn disassemble_myself ( ) -> HashSet < Function > {
78
+ let me = env:: current_exe ( ) . expect ( "failed to get current exe" ) ;
79
+
80
+ let objdump = env:: var ( "OBJDUMP" ) . unwrap_or_else ( |_| "objdump" . to_string ( ) ) ;
81
+ let add_args = if cfg ! ( target_os = "macos" ) && cfg ! ( target_arch = "aarch64" ) {
82
+ // Target features need to be enabled for LLVM objdump on Macos ARM64
83
+ vec ! [ "--mattr=+v8.6a,+crypto,+tme" ]
84
+ } else {
85
+ vec ! [ ]
93
86
} ;
87
+ let output = std:: process:: Command :: new ( objdump. clone ( ) )
88
+ . arg ( "--disassemble" )
89
+ . arg ( "--no-show-raw-insn" )
90
+ . args ( add_args)
91
+ . arg ( & me)
92
+ . output ( )
93
+ . unwrap_or_else ( |_| panic ! ( "failed to execute objdump. OBJDUMP={objdump}" ) ) ;
94
+ println ! (
95
+ "{}\n {}" ,
96
+ output. status,
97
+ String :: from_utf8_lossy( & output. stderr)
98
+ ) ;
99
+ assert ! ( output. status. success( ) ) ;
100
+
101
+ let disassembly = String :: from_utf8_lossy ( Vec :: leak ( output. stdout ) ) ;
94
102
95
103
parse ( & disassembly)
96
104
}
0 commit comments