11//! Disassembly calling function for most targets.
22
33use crate :: Function ;
4- use std:: { collections:: HashSet , env, process :: Command , str} ;
4+ use std:: { collections:: HashSet , env, str} ;
55
66// Extracts the "shim" name from the `symbol`.
77fn normalize ( mut symbol : & str ) -> String {
@@ -39,10 +39,11 @@ fn normalize(mut symbol: &str) -> String {
3939 symbol
4040}
4141
42+ #[ cfg( windows) ]
4243pub ( crate ) fn disassemble_myself ( ) -> HashSet < Function > {
4344 let me = env:: current_exe ( ) . expect ( "failed to get current exe" ) ;
4445
45- let disassembly = if cfg ! ( target_os = "windows" ) && cfg ! ( target_env = "msvc" ) {
46+ let disassembly = if cfg ! ( target_env = "msvc" ) {
4647 let target = if cfg ! ( target_arch = "x86_64" ) {
4748 "x86_64-pc-windows-msvc"
4849 } else if cfg ! ( target_arch = "x86" ) {
@@ -65,32 +66,39 @@ pub(crate) fn disassemble_myself() -> HashSet<Function> {
6566 assert ! ( output. status. success( ) ) ;
6667 // Windows does not return valid UTF-8 output:
6768 String :: from_utf8_lossy ( Vec :: leak ( output. stdout ) )
68- } else if cfg ! ( target_os = "windows" ) {
69- panic ! ( "disassembly unimplemented" )
7069 } 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+ } ;
9172
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 ! [ ]
9386 } ;
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 ) ) ;
94102
95103 parse ( & disassembly)
96104}
0 commit comments