Use platform dependent mcount function
This commit is contained in:
parent
237bf3244f
commit
261a91519d
2 changed files with 36 additions and 1 deletions
|
@ -77,9 +77,37 @@ 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 if cfg!(target_os = "darwin") {
|
||||
const_cstr!("\01mcount")
|
||||
} else if cfg!(target_arch = "aarch64")
|
||||
&& (cfg!(target_os = "linux")
|
||||
|| (cfg!(target_os = "unknown") && cfg!(target_env = "gnu")))
|
||||
{
|
||||
const_cstr!("\01_mcount")
|
||||
} else if cfg!(target_arch = "arm")
|
||||
&& cfg!(any(target_os = "linux", target_os = "unknown"))
|
||||
{
|
||||
if cfg!(target_env = "gnu") {
|
||||
const_cstr!("\01__gnu_mcount_nc")
|
||||
} else {
|
||||
const_cstr!("\01mcount")
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
7
src/test/codegen/instrument-mcount.rs
Normal file
7
src/test/codegen/instrument-mcount.rs
Normal file
|
@ -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() {}
|
Loading…
Add table
Add a link
Reference in a new issue