Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/librustc_codegen_llvm/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not seem to cover it.

Looking at clang’s this->MCountName instances:

  • darwin uses \01mcount;
  • On Aarch64 if abi is gnueabi, \01_mcount is used;
  • On ARM-linux or ARM-unknown if abi is gnueabi \01__gnu_mcount_nc is used and \01mcount if not gnueabi;

Please make this a target property (specified in target files) and use that property here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I used github search like this. I’m sure it missed some cases as well)


llvm::AddFunctionAttrStringValue(
llfn, llvm::AttributePlace::Function,
const_cstr!("instrument-function-entry-inlined"), const_cstr!("mcount"));
const_cstr!("instrument-function-entry-inlined"), mcount_name);
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/test/codegen/instrument-mcount.rs
Original file line number Diff line number Diff line change
@@ -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() {}