From 7300a7d8dd6043d7a3719ae629ffe7c02ec7a2f2 Mon Sep 17 00:00:00 2001 From: Jun Wu Date: Mon, 31 Dec 2018 14:49:27 -0800 Subject: [PATCH] Use platform-dependent mcount function Follow up with @nagisa's comment on #57220. Not all platforms use the `mcount` name. Added a test. --- src/librustc_codegen_llvm/attributes.rs | 15 ++++++++++++++- src/test/codegen/instrument-mcount.rs | 7 +++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/test/codegen/instrument-mcount.rs diff --git a/src/librustc_codegen_llvm/attributes.rs b/src/librustc_codegen_llvm/attributes.rs index 226b03c99c043..7edab81305134 100644 --- a/src/librustc_codegen_llvm/attributes.rs +++ b/src/librustc_codegen_llvm/attributes.rs @@ -84,9 +84,22 @@ pub fn set_instrument_function(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) { if cx.sess().instrument_mcount() { // Similar to `clang -pg` behavior. Handled by the // `post-inline-ee-instrument` LLVM pass. + + // The function name varies on platforms. + // See test/CodeGen/mcount.c in clang. + let mcount_name = if cfg!(target_os = "netbsd") { + const_cstr!("__mcount") + } else if cfg!(any( + target_arch = "mips", target_arch = "mips64", + target_arch = "powerpc", target_arch = "powerpc64")) { + const_cstr!("_mcount") + } else { + const_cstr!("mcount") + }; + llvm::AddFunctionAttrStringValue( llfn, llvm::AttributePlace::Function, - const_cstr!("instrument-function-entry-inlined"), const_cstr!("mcount")); + const_cstr!("instrument-function-entry-inlined"), mcount_name); } } diff --git a/src/test/codegen/instrument-mcount.rs b/src/test/codegen/instrument-mcount.rs new file mode 100644 index 0000000000000..bd01556d986a8 --- /dev/null +++ b/src/test/codegen/instrument-mcount.rs @@ -0,0 +1,7 @@ +// ignore-tidy-linelength +// compile-flags: -Z instrument-mcount + +#![crate_type = "lib"] + +// CHECK: attributes #{{.*}} "instrument-function-entry-inlined"="{{_*}}mcount" "no-frame-pointer-elim"="true" +pub fn foo() {}