about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuki OKUSHI <huyuumi.dev@gmail.com>2019-03-29 06:44:31 +0900
committerYuki OKUSHI <huyuumi.dev@gmail.com>2019-03-29 06:44:31 +0900
commit261a91519d57590283b250ea9dc1d924b01d4dd6 (patch)
treee4ff738c4b2f7118135511ba08eececd36717013
parent237bf3244fffef501cf37d4bda00e1fce3fcfb46 (diff)
downloadrust-261a91519d57590283b250ea9dc1d924b01d4dd6.tar.gz
rust-261a91519d57590283b250ea9dc1d924b01d4dd6.zip
Use platform dependent mcount function
-rw-r--r--src/librustc_codegen_llvm/attributes.rs30
-rw-r--r--src/test/codegen/instrument-mcount.rs7
2 files changed, 36 insertions, 1 deletions
diff --git a/src/librustc_codegen_llvm/attributes.rs b/src/librustc_codegen_llvm/attributes.rs
index 71e7535313f..e765b986d62 100644
--- a/src/librustc_codegen_llvm/attributes.rs
+++ b/src/librustc_codegen_llvm/attributes.rs
@@ -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);
     }
 }
 
diff --git a/src/test/codegen/instrument-mcount.rs b/src/test/codegen/instrument-mcount.rs
new file mode 100644
index 00000000000..bd01556d986
--- /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() {}