@@ -77,9 +77,37 @@ pub fn set_instrument_function(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
77
77
if cx. sess ( ) . instrument_mcount ( ) {
78
78
// Similar to `clang -pg` behavior. Handled by the
79
79
// `post-inline-ee-instrument` LLVM pass.
80
+
81
+ // The function name varies on platforms.
82
+ // See test/CodeGen/mcount.c in clang.
83
+ let mcount_name = if cfg ! ( target_os = "netbsd" ) {
84
+ const_cstr ! ( "__mcount" )
85
+ } else if cfg ! ( any(
86
+ target_arch = "mips" , target_arch = "mips64" ,
87
+ target_arch = "powerpc" , target_arch = "powerpc64" ) ) {
88
+ const_cstr ! ( "_mcount" )
89
+ } else if cfg ! ( target_os = "darwin" ) {
90
+ const_cstr ! ( "\0 1mcount" )
91
+ } else if cfg ! ( target_arch = "aarch64" )
92
+ && ( cfg ! ( target_os = "linux" )
93
+ || ( cfg ! ( target_os = "unknown" ) && cfg ! ( target_env = "gnu" ) ) )
94
+ {
95
+ const_cstr ! ( "\0 1_mcount" )
96
+ } else if cfg ! ( target_arch = "arm" )
97
+ && cfg ! ( any( target_os = "linux" , target_os = "unknown" ) )
98
+ {
99
+ if cfg ! ( target_env = "gnu" ) {
100
+ const_cstr ! ( "\0 1__gnu_mcount_nc" )
101
+ } else {
102
+ const_cstr ! ( "\0 1mcount" )
103
+ }
104
+ } else {
105
+ const_cstr ! ( "mcount" )
106
+ } ;
107
+
80
108
llvm:: AddFunctionAttrStringValue (
81
109
llfn, llvm:: AttributePlace :: Function ,
82
- const_cstr ! ( "instrument-function-entry-inlined" ) , const_cstr ! ( "mcount" ) ) ;
110
+ const_cstr ! ( "instrument-function-entry-inlined" ) , mcount_name ) ;
83
111
}
84
112
}
85
113
0 commit comments